client: removed slsDetectorutils and postprocessing. yet to compile, yet to add detpos index for every multi sls detector command and call from command interface, removed multiple threading, yet to interface with eriks single template for multiple threading

This commit is contained in:
2018-10-03 11:15:39 +02:00
parent dafbc970e3
commit 70ea4b48c3
279 changed files with 578 additions and 10937 deletions

View File

@ -7,6 +7,7 @@
#include "multiSlsDetectorClient.h"
#include "multiSlsDetectorCommand.h"
#include "utilities.h"
#include "detectorData.h"
#include <sys/types.h>
#include <iostream>
@ -27,14 +28,30 @@ multiSlsDetector::multiSlsDetector(int id, bool verify, bool update)
threadpool(0),
totalProgress(0),
progressIndex(0),
acquisition_finished(NULL),
measurement_finished(NULL),
acqFinished_p(NULL),
measFinished_p(NULL),
threadedProcessing(1),
jointhread(0),
acquiringDone(0),
fdata(0),
thisData(0),
acquisition_finished(0),
acqFinished_p(0),
measurement_finished(0),
measFinished_p(0),
progress_call(0),
pProgressCallArg(0)
pProgressCallArg(0),
dataReady(0),
pCallbackArg(0)
{
pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER;
mp=mp1;
pthread_mutex_init(&mp, NULL);
mg=mp1;
pthread_mutex_init(&mg, NULL);
ms=mp1;
pthread_mutex_init(&ms, NULL);
setupMultiDetector(verify, update);
}
@ -60,10 +77,6 @@ multiSlsDetector::~multiSlsDetector() {
}
bool multiSlsDetector::isMultiSlsDetectorClass() {
return true;
}
void multiSlsDetector::setupMultiDetector(bool verify, bool update) {
if (initSharedMemory(verify))
// shared memory just created, so initialize the structure
@ -4175,6 +4188,17 @@ void multiSlsDetector::registerProgressCallback(int( *func)(double,void*), void
}
void multiSlsDetector::registerDataCallback(int( *userCallback)(detectorData*, int, int, void*),
void *pArg) {
dataReady = userCallback;
pCallbackArg = pArg;
if (setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) {
enableDataStreamingToClient(1);
enableDataStreamingFromReceiver(1);
}
}
int multiSlsDetector::setTotalProgress() {
int nf=1, nc=1, ns=1, nm=1;
@ -4227,7 +4251,7 @@ void multiSlsDetector::incrementProgress() {
cout << "\r" << flush;
#endif
};
}
void multiSlsDetector::setCurrentProgress(int i){
@ -4282,8 +4306,8 @@ int multiSlsDetector::acquire(){
}
// start processing thread
if (*threadedProcessing)
startThread();
if (threadedProcessing)
startProcessingThread();
//resets frames caught in receiver
@ -4320,7 +4344,7 @@ int multiSlsDetector::acquire(){
// detector start
startAndReadAll();
if (*threadedProcessing==0){
if (threadedProcessing==0){
processData();
}
@ -4333,7 +4357,7 @@ int multiSlsDetector::acquire(){
pthread_mutex_unlock(&mg);
} else {
pthread_mutex_unlock(&mg);
if (*threadedProcessing && dataReady)
if (threadedProcessing && dataReady)
sem_wait(&sem_endRTAcquisition); // waits for receiver's external process to be done sending data to gui
}
}
@ -4357,7 +4381,7 @@ int multiSlsDetector::acquire(){
// waiting for the data processing thread to finish!
if (*threadedProcessing) {
if (threadedProcessing) {
setJoinThread(1);
//let processing thread continue and checkjointhread
@ -4388,3 +4412,144 @@ int multiSlsDetector::acquire(){
}
int multiSlsDetector::setThreadedProcessing(int enable=-1) {
if (enable>=0)
threadedProcessing=enable;
return threadedProcessing;
}
void multiSlsDetector::startProcessingThread() {
setTotalProgress();
#ifdef VERBOSE
std::cout << "start thread stuff" << std::endl;
#endif
pthread_attr_t tattr;
int ret;
sched_param param, mparam;
int policy= SCHED_OTHER;
// set the priority; others are unchanged
//newprio = 30;
mparam.sched_priority =1;
param.sched_priority =1;
/* Initialize and set thread detached attribute */
pthread_attr_init(&tattr);
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);
ret = pthread_setschedparam(pthread_self(), policy, &mparam);
ret = pthread_create(&dataProcessingThread, &tattr,startProcessData, (void*)this);
if (ret)
printf("ret %d\n", ret);
pthread_attr_destroy(&tattr);
// scheduling parameters of target thread
ret = pthread_setschedparam(dataProcessingThread, policy, &param);
}
void* multiSlsDetector::startProcessData(void *n) {
postProcessing *myDet=(postProcessing*)n;
myDet->processData();
pthread_exit(NULL);
}
void* multiSlsDetector::processData() {
if(setReceiverOnline()==OFFLINE_FLAG){
return 0;
} //receiver
else{
//cprintf(RED,"In post processing threads\n");
if(dataReady) {
readFrameFromReceiver();
}
//only update progress
else{
int caught = -1;
char c;
int ifp;
while(true){
// set only in startThread
if (*threadedProcessing==0)
setTotalProgress();
// to exit acquire by typing q
ifp=kbhit();
if (ifp!=0){
c=fgetc(stdin);
if (c=='q') {
std::cout<<"Caught the command to stop acquisition"<<std::endl;
stopAcquisition();
}
}
//get progress
if(setReceiverOnline() == ONLINE_FLAG){
pthread_mutex_lock(&mg);
caught = getFramesCaughtByAnyReceiver();
pthread_mutex_unlock(&mg);
}
//updating progress
if(caught!= -1){
setCurrentProgress(caught);
#ifdef VERY_VERY_DEBUG
std::cout << "caught:" << caught << std::endl;
#endif
}
// exiting loop
if (*threadedProcessing==0)
break;
if (checkJoinThread()){
break;
}
usleep(100 * 1000); //20ms need this else connecting error to receiver (too fast)
}
}
}
return 0;
}
int multiSlsDetector::checkJoinThread() {
int retval;
pthread_mutex_lock(&mp);
retval=jointhread;
pthread_mutex_unlock(&mp);
return retval;
}
void multiSlsDetector::setJoinThread( int v) {
pthread_mutex_lock(&mp);
jointhread=v;
pthread_mutex_unlock(&mp);
}
int multiSlsDetector::kbhit() {
struct timeval tv;
fd_set fds;
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(STDIN_FILENO, &fds); //STDIN_FILENO is 0
select(STDIN_FILENO+1, &fds, NULL, NULL, &tv);
return FD_ISSET(STDIN_FILENO, &fds);
}

View File

@ -7,13 +7,13 @@
* @author Anna Bergamaschi
*/
#include "slsDetectorUtils.h"
#include "slsDetectorBase.h"
class slsDetector;
class SharedMemory;
class ThreadPool;
class ZmqSocket;
class detectorData;
#include <vector>
#include <string>
@ -23,7 +23,7 @@ class ZmqSocket;
#define SHORT_STRING_LENGTH 50
#define DATE_LENGTH 30
class multiSlsDetector : public postProcessing {
class multiSlsDetector : public slsDetectorBase {
private:
@ -142,12 +142,6 @@ public:
*/
virtual ~multiSlsDetector();
/**
* returns true. Used when reference is slsDetectorUtils and to determine
* if command can be implemented as slsDetector/multiSlsDetector object/
*/
bool isMultiSlsDetectorClass();
/**
* Creates/open shared memory, initializes detector structure and members
* Called by constructor/ set hostname / read config file
@ -1450,6 +1444,17 @@ public:
*/
void registerProgressCallback(int( *func)(double,void*), void *pArg);
/**
* register calbback for accessing detector final data,
* also enables data streaming in client and receiver
* @param userCallback function for plotting/analyzing the data.
* Its arguments are
* the data structure d and the frame number f,
* s is for subframe number for eiger for 32 bit mode
* @param pArg argument
*/
void registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg);
/**
* Performs a complete acquisition
* resets frames caught in receiver, starts receiver, starts detector,
@ -1459,6 +1464,12 @@ public:
*/
int acquire();
/**
* Set/get if the data processing thread si enabled
* @param enable 0 no data processing thread, 1 separate thread, -1 get
*/
int setThreadedProcessing(int enable=-1);
private:
/**
* Initialize (open/create) shared memory for the sharedMultiDetector structure
@ -1528,6 +1539,39 @@ private:
*/
void setCurrentProgress(int i=0);
/**
* Start data processing thread
*/
void startProcessingThread();
/**
* Static function to call processing thread
*/
static void* startProcessData(void *n);
/**
* Combines data from all readouts and gives it to the gui
* or just gives progress of acquisition by polling receivers
*/
void* processData();
/**
* Check if processing thread is ready to join main thread
* @returns true if ready, else false
*/
int checkJoinThread();
/**
* Main thread sets if the processing thread should join it
* @param v true if it should join, else false
*/
void setJoinThread(int v);
/**
* Listen to key event to stop acquiring
* when using acquire command
*/
int kbhit(void);
/** Multi detector Id */
@ -1552,20 +1596,54 @@ private:
ThreadPool* threadpool;
int totalProgress;
int progressIndex;
int (*acquisition_finished)(double,int,void*);
int (*measurement_finished)(int,int,void*);
void *acqFinished_p, *measFinished_p;
int (*progress_call)(double,void*);
void *pProgressCallArg;
/** semaphore to let postprocessing thread continue for next scan/measurement */
sem_t sem_newRTAcquisition;
/** semaphore to let main thread know it got all the dummy packets (also from ext. process) */
sem_t sem_endRTAcquisition;
int totalProgress;
int progressIndex;
/** mutex to synchronize main and data processing threads */
pthread_mutex_t mp;
/** mutex to synchronizedata processing and plotting threads */
pthread_mutex_t mg;
/** mutex to synchronize slsdetector threads */
pthread_mutex_t ms;
int threadedProcessing;
/** sets when the acquisition is finished */
int jointhread;
/** set when detector finishes acquiring */
int acquiringDone;
/** the data processing thread */
pthread_t dataProcessingThread;
double *fdata;
detectorData *thisData;
int (*acquisition_finished)(double,int,void*);
void *acqFinished_p;
int (*measurement_finished)(int,int,void*);
void *measFinished_p;
int (*progress_call)(double,void*);
void *pProgressCallArg;
int (*dataReady)(detectorData*,int, int, void*);
void *pCallbackArg;
};

View File

@ -14,54 +14,43 @@
class multiSlsDetectorCommand : public slsDetectorCommand {
public:
public:
multiSlsDetectorCommand(multiSlsDetector *det) : slsDetectorCommand(det) {myDet=det;};
multiSlsDetectorCommand(multiSlsDetector *det) : slsDetectorCommand(det) {myDet=det;};
/* /\** */
/* executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing */
/* \param narg number of arguments */
/* \param args array of string arguments */
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
/* \returns answer string */
/* *\/ */
/* /\** */
/* executes a set of string arguments according to a given format. It is used to read/write configuration file, dump and retrieve detector settings and for the command line interface command parsing */
/* \param narg number of arguments */
/* \param args array of string arguments */
/* \param action can be PUT_ACTION or GET_ACTION (from text client even READOUT_ACTION for acquisition) */
/* \returns answer string */
/* *\/ */
std::string executeLine(int narg, char *args[], int action, int id=-1) { \
std::string s; \
if (id>=0) {
slsDetector *d=myDet->getSlsDetector(id); \
if (d) { \
slsDetectorCommand *cmd=new slsDetectorCommand(d); \
s=cmd->executeLine(narg, args, action); \
if(d->getErrorMask()) \
myDet->setErrorMask((myDet->getErrorMask())|(1<<id)); \
delete cmd;
} else
s=std::string("detector does no exist"); \
} else \
s=slsDetectorCommand::executeLine(narg,args,action); \
return s;
};
std::string executeLine(int narg, char *args[], int action, int id=-1) { \
std::string s; \
s=slsDetectorCommand::executeLine(narg,args,action, id); \
return s;
};
/**
* calls executeLine with PUT_ACTION
*/
std::string putCommand(int narg, char *args[], int pos=-1){\
return executeLine(narg, args,slsDetectorDefs::PUT_ACTION,pos);\
};
/**
* calls executeLine with GET_ACTION
*/
std::string getCommand(int narg, char *args[], int pos=-1){\
return executeLine(narg, args,slsDetectorDefs::GET_ACTION,pos);\
};
/**
* calls executeLine with PUT_ACTION
*/
std::string putCommand(int narg, char *args[], int pos=-1){\
return executeLine(narg, args,slsDetectorDefs::PUT_ACTION,pos);\
};
/**
* calls executeLine with GET_ACTION
*/
std::string getCommand(int narg, char *args[], int pos=-1){\
return executeLine(narg, args,slsDetectorDefs::GET_ACTION,pos);\
};
private:
private:
multiSlsDetector *myDet;
multiSlsDetector *myDet;
};