From dafbc970e382f64c234d52e7be301554d723c755 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 2 Oct 2018 18:13:00 +0200 Subject: [PATCH] client stage2 ongoing, utils removed but not compile ready; left to do imod for every multi, connect client to multi --- Makefile | 2 +- Makefile.include | 2 +- commonFiles/utilities.cpp | 148 +++ commonFiles/utilities.h | 113 +- slsDetectorSoftware/CMakeLists.txt | 2 + slsDetectorSoftware/Makefile | 4 +- .../multiSlsDetector/multiSlsDetector.cpp | 500 ++++++++- .../multiSlsDetector/multiSlsDetector.h | 92 +- .../slsDetector/slsDetector.cpp | 22 +- slsDetectorSoftware/slsDetector/slsDetector.h | 2 +- .../slsDetector/slsDetectorBase.h | 845 ++++++++++++++- .../slsDetector/slsDetectorUtils.cpp | 523 +--------- .../slsDetector/slsDetectorUtils.h | 981 +----------------- .../slsDetectorAnalysis/postProcessing.cpp | 18 +- .../slsDetectorAnalysis/postProcessing.h | 5 +- slsReceiverSoftware/CMakeLists.txt | 16 +- slsReceiverSoftware/Makefile | 2 +- 17 files changed, 1644 insertions(+), 1633 deletions(-) create mode 100644 commonFiles/utilities.cpp diff --git a/Makefile b/Makefile index 574ceb8b7..c78f2b53a 100755 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ TABSPACE := "\t" INCLUDES=-I. -I$(WD)/commonFiles -I$(LIBRARYDIR)/slsDetector -I$(LIBRARYDIR)/usersFunctions -I$(LIBRARYDIR)/multiSlsDetector -I$(LIBRARYDIR)/slsDetectorUtils -I$(LIBRARYDIR)/slsDetectorCommand -I$(LIBRARYDIR)/slsDetectorAnalysis -I$(LIBRARYDIR)/slsReceiverInterface -I$(LIBRARYRXRDIR)/include -I$(LIBRARYDIR)/threadFiles -I$(LIBRARYDIR)/sharedMemory -I$(ASM) -INCLUDESRXR += -I. -I$(LIBRARYRXRDIR)/include -I$(CALIBDIR) -I$(ASM) +INCLUDESRXR += -I. -I$(LIBRARYRXRDIR)/include -I$(WD)/commonFiles -I$(CALIBDIR) -I$(ASM) #LIBFLAGRXR += $(info ) diff --git a/Makefile.include b/Makefile.include index 71dba3160..6e4693d9a 100755 --- a/Makefile.include +++ b/Makefile.include @@ -29,7 +29,7 @@ HDF5_DIR = /opt/hdf5v1.10.0 ifeq ($(HDF5),yes) LDFLAGRXR = -L$(LIBDIR) -Wl,-rpath=$(LIBDIR) -lSlsReceiver -L$(HDF5_DIR)/lib -Wl,-rpath=$(HDF5_DIR)/lib -lhdf5 -lhdf5_cpp -lsz -lz -DHDF5C -L/usr/lib64/ -pthread - INCLUDESRXR = -I$(HDF5_DIR)/include + INCLUDESRXR = -I$(HDF5_DIR)/include endif diff --git a/commonFiles/utilities.cpp b/commonFiles/utilities.cpp new file mode 100644 index 000000000..97263ce56 --- /dev/null +++ b/commonFiles/utilities.cpp @@ -0,0 +1,148 @@ +#include "utilities.h" +#include "logger.h" + +#include +#include + + + + +int read_config_file(std::string fname, int *tcpip_port_no, + std::map * configuration_map) { + + std::ifstream infile; + std::string sLine,sargname, sargvalue; + int iline = 0; + int success = slsReceiverDefs::OK; + + + FILE_LOG(logINFO) << "config file name " << fname; + try { + infile.open(fname.c_str(), std::ios_base::in); + } catch(...) { + FILE_LOG(logERROR) << "Could not open configuration file " << fname ; + success = slsReceiverDefs::FAIL; + } + + if (success == slsReceiverDefs::OK && infile.is_open()) { + while(infile.good()){ + getline(infile,sLine); + iline++; + + //VERBOSE_PRINT(sLine); + + if(sLine.find('#') != std::string::npos) + continue; + + else if(sLine.length()<2) + continue; + + else{ + std::istringstream sstr(sLine); + + //parameter name + if(sstr.good()){ + sstr >> sargname; + + if (! sstr.good()) + continue; + + sstr >> sargvalue; + (*configuration_map)[sargname] = sargvalue; + } + //tcp port + if(sargname=="rx_tcpport"){ + if(sstr.good()) { + sstr >> sargname; + if(sscanf(sargname.c_str(),"%d",tcpip_port_no)) + cprintf(RESET, "dataport: %d\n" , *tcpip_port_no); + else{ + cprintf(RED, "could not decode port in config file. Exiting.\n"); + success = slsReceiverDefs::FAIL; + } + } + } + } + } + infile.close(); + } + + return success; +} + + + +int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) { + int ichan, iline=0; + short int idata; + int interrupt=0; + std::string str; + while (infile.good() and interrupt==0) { + getline(infile,str); + std::istringstream ssstr(str); + ssstr >> ichan >> idata; + if (ssstr.fail() || ssstr.bad()) { + interrupt=1; + break; + } + if (iline=offset) { + data[iline]=idata; + iline++; + } + } else { + interrupt=1; + break; + } + return iline; + }; + return iline; +} + + + +int readDataFile(std::string fname, short int *data, int nch) { + std::ifstream infile; + int iline=0; + std::string str; + infile.open(fname.c_str(), std::ios_base::in); + if (infile.is_open()) { + iline=readDataFile(infile, data, nch, 0); + infile.close(); + } else { + std::cout<< "Could not read file " << fname << std::endl; + return -1; + } + return iline; +} + + + +int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset) { + if (data==NULL) + return slsReceiverDefs::FAIL; + for (int ichan=0; ichan #include -#include -#include #include #include #include +/** + * Read config file for receiver + * @param fname config file name + * @param tcpip_port_no pointer to tcp port number + * @param map map + * @returns OK or FAIL + */ +int read_config_file(std::string fname, int *tcpip_port_no, + std::map * configuration_map); + + +/** (used by multi and sls) + * reads a short int raw data file + * @param infile input file stream + * @param data array of data values + * @param nch number of channels + * @param offset start channel value + * @returns OK or FAIL if it could not read the file or data=NULL + */ +int readDataFile(std::ifstream &infile, short int *data, int nch, int offset=0); + + +/** (used by multi and sls) + * reads a short int rawdata file + * @param name of the file to be read + * @param data array of data value + * @param nch number of channels + * @returns OK or FAIL if it could not read the file or data=NULL + */ +int readDataFile(std::string fname, short int *data, int nch); + + +/** (used by multi and sls) + * writes a short int raw data file + * @param outfile output file stream + * @param nch number of channels + * @param data array of data values + * @param offset start channel number + * @returns OK or FAIL if it could not write the file or data=NULL + */ +int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset=0); -int read_config_file(std::string fname, int *tcpip_port_no, std::map * configuration_map) { - - std::ifstream infile; - std::string sLine,sargname, sargvalue; - int iline = 0; - int success = slsReceiverDefs::OK; +/** (used by multi and sls) + * writes a short int raw data file + * @param fname of the file to be written + * @param nch number of channels + * @param data array of data values + * @returns OK or FAIL if it could not write the file or data=NULL + */ +int writeDataFile(std::string fname,int nch, short int *data); - FILE_LOG(logINFO) << "config file name " << fname; - try { - infile.open(fname.c_str(), std::ios_base::in); - } catch(...) { - FILE_LOG(logERROR) << "Could not open configuration file " << fname ; - success = slsReceiverDefs::FAIL; - } - if (success == slsReceiverDefs::OK && infile.is_open()) { - while(infile.good()){ - getline(infile,sLine); - iline++; - //VERBOSE_PRINT(sLine); - - if(sLine.find('#') != std::string::npos) - continue; - - else if(sLine.length()<2) - continue; - - else{ - std::istringstream sstr(sLine); - - //parameter name - if(sstr.good()){ - sstr >> sargname; - - if (! sstr.good()) - continue; - - sstr >> sargvalue; - (*configuration_map)[sargname] = sargvalue; - } - //tcp port - if(sargname=="rx_tcpport"){ - if(sstr.good()) { - sstr >> sargname; - if(sscanf(sargname.c_str(),"%d",tcpip_port_no)) - cprintf(RESET, "dataport: %d\n" , *tcpip_port_no); - else{ - cprintf(RED, "could not decode port in config file. Exiting.\n"); - success = slsReceiverDefs::FAIL; - } - } - } - } - } - infile.close(); - } - - return success; -} -} diff --git a/slsDetectorSoftware/CMakeLists.txt b/slsDetectorSoftware/CMakeLists.txt index f32671b9a..5b7ddbafa 100644 --- a/slsDetectorSoftware/CMakeLists.txt +++ b/slsDetectorSoftware/CMakeLists.txt @@ -10,6 +10,7 @@ set(SOURCES threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp + ../commonFiles/utilities.cpp ) set(HEADERS @@ -62,6 +63,7 @@ set(PUBLICHEADERS ../commonFiles/error_defs.h ../commonFiles/versionAPI.h ../commonFiles/sls_receiver_exceptions.h + ../commonFiles/utilties.h sharedMemory/SharedMemory.h slsDetector/slsDetectorUtils.h slsDetector/slsDetector.h diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index 07aa6bf7b..a9525ceb0 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -16,8 +16,8 @@ INCLUDES?= -I../commonFiles -IslsDetector -I../slsReceiverSoftware/MySocketTCP LIBZMQDIR = ../commonFiles LIBZMQ = -L$(LIBZMQDIR) -Wl,-rpath=$(LIBZMQDIR) -lzmq -SRC_CLNT= slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp slsReceiverInterface/receiverInterface.cpp slsDetector/slsDetectorUsers.cpp threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp sharedMemory/SharedMemory.cpp #../slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp -DEPSINCLUDES = ../commonFiles/sls_receiver_defs.h ../commonFiles/sls_receiver_funcs.h ../commonFiles/ansi.h ../commonFiles/sls_detector_defs.h ../commonFiles/sls_detector_funcs.h ../commonFiles/error_defs.h slsDetector/slsDetectorBase.h slsDetectorAnalysis/detectorData.h threadFiles/Global.h threadFiles/Task.h sharedMemory/SharedMemory.h ../commonFiles/sls_receiver_exceptions.h ../commonFiles/versionAPI.h +SRC_CLNT= slsDetector/slsDetectorUtils.cpp slsDetector/slsDetectorCommand.cpp slsDetectorAnalysis/postProcessing.cpp slsDetector/slsDetector.cpp multiSlsDetector/multiSlsDetector.cpp slsReceiverInterface/receiverInterface.cpp slsDetector/slsDetectorUsers.cpp threadFiles/CondVar.cpp threadFiles/Mutex.cpp threadFiles/ThreadPool.cpp sharedMemory/SharedMemory.cpp ../commonFiles/utilities.cpp#../slsReceiverSoftware/MySocketTCP/MySocketTCP.cpp +DEPSINCLUDES = ../commonFiles/sls_receiver_defs.h ../commonFiles/sls_receiver_funcs.h ../commonFiles/ansi.h ../commonFiles/sls_detector_defs.h ../commonFiles/sls_detector_funcs.h ../commonFiles/error_defs.h slsDetector/slsDetectorBase.h slsDetectorAnalysis/detectorData.h threadFiles/Global.h threadFiles/Task.h sharedMemory/SharedMemory.h ../commonFiles/sls_receiver_exceptions.h ../commonFiles/versionAPI.h ../commonFiles/utilities.h diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index c8bda72c7..e034ca869 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -1,13 +1,3 @@ -/******************************************************************* - -Date: $Date$ -Revision: $Rev$ -Author: $Author$ -URL: $URL$ -ID: $Id$ - - ********************************************************************/ - #include "multiSlsDetector.h" #include "SharedMemory.h" #include "slsDetector.h" @@ -16,6 +6,7 @@ ID: $Id$ #include "ZmqSocket.h" #include "multiSlsDetectorClient.h" #include "multiSlsDetectorCommand.h" +#include "utilities.h" #include #include @@ -24,7 +15,7 @@ ID: $Id$ #include //json header in zmq stream #include #include - +//#include //clock() multiSlsDetector::multiSlsDetector(int id, bool verify, bool update) @@ -33,7 +24,16 @@ multiSlsDetector::multiSlsDetector(int id, bool verify, bool update) sharedMemory(0), thisMultiDetector(0), client_downstream(false), - threadpool(0) { + threadpool(0), + totalProgress(0), + progressIndex(0), + acquisition_finished(NULL), + measurement_finished(NULL), + acqFinished_p(NULL), + measFinished_p(NULL), + progress_call(0), + pProgressCallArg(0) +{ setupMultiDetector(verify, update); } @@ -593,12 +593,6 @@ void multiSlsDetector::initializeDetectorStructure() { } void multiSlsDetector::initializeMembers(bool verify) { - //slsDetectorUtils - stoppedFlag = &thisMultiDetector->stoppedFlag; - timerValue = thisMultiDetector->timerValue; - currentSettings = &thisMultiDetector->currentSettings; - currentThresholdEV = &thisMultiDetector->currentThresholdEV; - //postprocessing threadedProcessing = &thisMultiDetector->threadedProcessing; fdata = NULL; @@ -1694,7 +1688,7 @@ int multiSlsDetector::stopAcquisition() { } } - *stoppedFlag = 1; + thisMultiDetector->stoppedFlag = 1; pthread_mutex_unlock(&mg); return ret; } @@ -1782,6 +1776,12 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int imod) { ret = detectors[imod]->setTimer(index,t,imod); if(detectors[imod]->getErrorMask()) setErrorMask(getErrorMask()|(1<timerValue[index] = ret; return ret; @@ -2283,7 +2288,7 @@ int multiSlsDetector::loadImageToDetector(imageType index, std::string const fna std::cout << " image from file " << fname << std::endl; #endif for (unsigned int idet = 0; idet < detectors.size(); ++idet) { - if (detectors[idet]->readDataFile(infile, imageVals) >= 0) { + if (readDataFile(infile, imageVals, getTotalNumberOfChannels()) >= 0) { ret1 = detectors[idet]->sendImageToDetector(index, imageVals); if (ret == -100) ret = ret1; @@ -2319,7 +2324,7 @@ int multiSlsDetector::writeCounterBlockFile(std::string const fname, int startAC if (ret1 != OK) ret = FAIL; else { - ret1 = detectors[idet]->writeDataFile(outfile, arg); + ret1 = writeDataFile(outfile, getTotalNumberOfChannels(), arg); if (ret1 != OK) ret = FAIL; } @@ -3930,3 +3935,456 @@ int multiSlsDetector::setCTBPatWaitAddr(int level, int addr) { int multiSlsDetector::setCTBPatWaitTime(int level, uint64_t t) { return callDetectorMember(&slsDetector::setCTBPatWaitTime, level, t); } + + +int multiSlsDetector::retrieveDetectorSetup(std::string const fname1, int level){ + + + slsDetectorCommand *cmd; + + int skip=0; + std::string fname; + std::string str; + std::ifstream infile; + int iargval; + int interrupt=0; + char *args[10]; + + char myargs[10][1000]; +; + + std::string sargname, sargval; + int iline=0; + + if (level==2) { +#ifdef VERBOSE + cout << "config file read" << endl; +#endif + fname=fname1+std::string(".det"); + } else + fname=fname1; + + infile.open(fname.c_str(), std::ios_base::in); + if (infile.is_open()) { + cmd=new slsDetectorCommand(this); + while (infile.good() and interrupt==0) { + sargname="none"; + sargval="0"; + getline(infile,str); + iline++; +#ifdef VERBOSE + std::cout<< str << std::endl; +#endif + if (str.find('#')!=std::string::npos) { +#ifdef VERBOSE + std::cout<< "Line is a comment " << std::endl; + std::cout<< str << std::endl; +#endif + continue; + } else { + std::istringstream ssstr(str); + iargval=0; + while (ssstr.good()) { + ssstr >> sargname; + // if (ssstr.good()) { + strcpy(myargs[iargval],sargname.c_str()); + args[iargval]=myargs[iargval]; +#ifdef VERBOSE + std::cout<< args[iargval] << std::endl; +#endif + iargval++; + // } + skip=0; + } + + if (level!=2) { + if (std::string(args[0])==std::string("trimbits")) + skip=1; + } + if (skip==0) + cmd->executeLine(iargval,args,PUT_ACTION); + } + iline++; + } + delete cmd; + infile.close(); + + } else { + std::cout<< "Error opening " << fname << " for reading" << std::endl; + return FAIL; + } +#ifdef VERBOSE + std::cout<< "Read " << iline << " lines" << std::endl; +#endif + + if (getErrorMask()) + return FAIL; + + return OK; + + +} + + +int multiSlsDetector::dumpDetectorSetup(std::string const fname, int level){ + + slsDetectorCommand *cmd; + detectorType type = getDetectorsType(); + std::string names[100]; + int nvar=0; + + // common config + names[nvar++]="fname"; + names[nvar++]="index"; + names[nvar++]="enablefwrite"; + names[nvar++]="overwrite"; + names[nvar++]="dr"; + names[nvar++]="settings"; + names[nvar++]="exptime"; + names[nvar++]="period"; + names[nvar++]="frames"; + names[nvar++]="cycles"; + names[nvar++]="measurements"; + names[nvar++]="timing"; + + switch (type) { + case EIGER: + names[nvar++]="flags"; + names[nvar++]="clkdivider"; + names[nvar++]="threshold"; + names[nvar++]="ratecorr"; + names[nvar++]="trimbits"; + break; + case GOTTHARD: + names[nvar++]="delay"; + break; + case JUNGFRAU: + names[nvar++]="delay"; + names[nvar++]="clkdivider"; + break; + case JUNGFRAUCTB: + names[nvar++]="dac:0"; + names[nvar++]="dac:1"; + names[nvar++]="dac:2"; + names[nvar++]="dac:3"; + names[nvar++]="dac:4"; + names[nvar++]="dac:5"; + names[nvar++]="dac:6"; + names[nvar++]="dac:7"; + names[nvar++]="dac:8"; + names[nvar++]="dac:9"; + names[nvar++]="dac:10"; + names[nvar++]="dac:11"; + names[nvar++]="dac:12"; + names[nvar++]="dac:13"; + names[nvar++]="dac:14"; + names[nvar++]="dac:15"; + names[nvar++]="adcvpp"; + + + + names[nvar++]="adcclk"; + names[nvar++]="clkdivider"; + names[nvar++]="adcphase"; + names[nvar++]="adcpipeline"; + names[nvar++]="adcinvert"; // + names[nvar++]="adcdisable"; + names[nvar++]="patioctrl"; + names[nvar++]="patclkctrl"; + names[nvar++]="patlimits"; + names[nvar++]="patloop0"; + names[nvar++]="patnloop0"; + names[nvar++]="patwait0"; + names[nvar++]="patwaittime0"; + names[nvar++]="patloop1"; + names[nvar++]="patnloop1"; + names[nvar++]="patwait1"; + names[nvar++]="patwaittime1"; + names[nvar++]="patloop2"; + names[nvar++]="patnloop2"; + names[nvar++]="patwait2"; + names[nvar++]="patwaittime2"; + break; + default: + break; + } + + + int iv=0; + std::string fname1; + + + + std::ofstream outfile; + char *args[4]; + for (int ia=0; ia<4; ia++) { + args[ia]=new char[1000]; + } + + + if (level==2) { + fname1=fname+std::string(".config"); + writeConfigurationFile(fname1); + fname1=fname+std::string(".det"); + } else + fname1=fname; + + + + outfile.open(fname1.c_str(),std::ios_base::out); + if (outfile.is_open()) { + cmd=new slsDetectorCommand(this); + for (iv=0; ivexecuteLine(1,args,GET_ACTION) << std::endl; + } + + delete cmd; + + outfile.close(); + } + else { + std::cout<< "Error opening parameters file " << fname1 << " for writing" << std::endl; + return FAIL; + } + +#ifdef VERBOSE + std::cout<< "wrote " <0) + nc=timerValue[CYCLES_NUMBER]; + + if (timerValue[STORAGE_CELL_NUMBER]>0) + ns=timerValue[STORAGE_CELL_NUMBER]+1; + + if (timerValue[MEASUREMENTS_NUMBER]>0) + nm=timerValue[MEASUREMENTS_NUMBER]; + + totalProgress=nm*nf*nc*ns; + +#ifdef VERBOSE + cout << "nm " << nm << endl; + cout << "nf " << nf << endl; + cout << "nc " << nc << endl; + cout << "ns " << ns << endl; + cout << "Set total progress " << totalProgress << endl; +#endif + return totalProgress; +} + + +double multiSlsDetector::getCurrentProgress() { + pthread_mutex_lock(&mp); +#ifdef VERBOSE + cout << progressIndex << " / " << totalProgress << endl; +#endif + + double p=100.*((double)progressIndex)/((double)totalProgress); + pthread_mutex_unlock(&mp); + return p; +} + + +void multiSlsDetector::incrementProgress() { + pthread_mutex_lock(&mp); + progressIndex++; + cout << std::fixed << std::setprecision(2) << std::setw (6) + << 100.*((double)progressIndex)/((double)totalProgress) << " \%"; + pthread_mutex_unlock(&mp); +#ifdef VERBOSE + cout << endl; +#else + cout << "\r" << flush; +#endif + +}; + + +void multiSlsDetector::setCurrentProgress(int i){ + pthread_mutex_lock(&mp); + progressIndex=i; + cout << std::fixed << std::setprecision(2) << std::setw (6) + << 100.*((double)progressIndex)/((double)totalProgress) << " \%"; + pthread_mutex_unlock(&mp); +#ifdef VERBOSE + cout << endl; +#else + cout << "\r" << flush; +#endif +} + + +int multiSlsDetector::acquire(){ + + //ensure acquire isnt started multiple times by same client + if (isAcquireReady() == FAIL) + return FAIL; + +#ifdef VERBOSE + struct timespec begin,end; + clock_gettime(CLOCK_REALTIME, &begin); +#endif + + //in the real time acquisition loop, processing thread will wait for a post each time + sem_init(&sem_newRTAcquisition,1,0); + //in the real time acquistion loop, main thread will wait for processing thread to be done each time (which in turn waits for receiver/ext process) + sem_init(&sem_endRTAcquisition,1,0); + + + bool receiver = (setReceiverOnline()==ONLINE_FLAG); + + progressIndex=0; + thisMultiDetector->stoppedFlag=0; + void *status; + setJoinThread(0); + + int nm=timerValue[MEASUREMENTS_NUMBER]; + if (nm<1) + nm=1; + + // verify receiver is idle + if(receiver){ + pthread_mutex_lock(&mg); + if(getReceiverStatus()!=IDLE) + if(stopReceiver() == FAIL) + thisMultiDetector->stoppedFlag=1; + pthread_mutex_unlock(&mg); + } + + // start processing thread + if (*threadedProcessing) + startThread(); + + + //resets frames caught in receiver + if(receiver){ + pthread_mutex_lock(&mg); + if (resetFramesCaught() == FAIL) + thisMultiDetector->stoppedFlag=1; + pthread_mutex_unlock(&mg); + } + + // loop through measurements + for(int im=0;imstoppedFlag) + break; + + // start receiver + if(receiver){ + + pthread_mutex_lock(&mg); + if(startReceiver() == FAIL) { + cout << "Start receiver failed " << endl; + stopReceiver(); + thisMultiDetector->stoppedFlag=1; + pthread_mutex_unlock(&mg); + break; + } + pthread_mutex_unlock(&mg); + + //let processing thread listen to these packets + sem_post(&sem_newRTAcquisition); + } + + // detector start + startAndReadAll(); + + if (*threadedProcessing==0){ + processData(); + } + + + // stop receiver + if(receiver){ + pthread_mutex_lock(&mg); + if (stopReceiver() == FAIL) { + thisMultiDetector->stoppedFlag = 1; + pthread_mutex_unlock(&mg); + } else { + pthread_mutex_unlock(&mg); + if (*threadedProcessing && dataReady) + sem_wait(&sem_endRTAcquisition); // waits for receiver's external process to be done sending data to gui + } + } + + int findex = 0; + pthread_mutex_lock(&mg); + findex = incrementFileIndex(); + pthread_mutex_unlock(&mg); + + if (measurement_finished){ + pthread_mutex_lock(&mg); + measurement_finished(im,findex,measFinished_p); + pthread_mutex_unlock(&mg); + } + + if (thisMultiDetector->stoppedFlag) { + break; + } + + }//end measurements loop im + + + // waiting for the data processing thread to finish! + if (*threadedProcessing) { + setJoinThread(1); + + //let processing thread continue and checkjointhread + sem_post(&sem_newRTAcquisition); + + pthread_join(dataProcessingThread, &status); + } + + + if(progress_call) + progress_call(getCurrentProgress(),pProgressCallArg); + + if (acquisition_finished) + acquisition_finished(getCurrentProgress(),getDetectorStatus(),acqFinished_p); + + sem_destroy(&sem_newRTAcquisition); + sem_destroy(&sem_endRTAcquisition); + +#ifdef VERBOSE + clock_gettime(CLOCK_REALTIME, &end); + cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl; +#endif + + setAcquiringFlag(false); + + return OK; + + +} + diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 2356c3671..6d483c086 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -23,7 +23,7 @@ class ZmqSocket; #define SHORT_STRING_LENGTH 50 #define DATE_LENGTH 30 -class multiSlsDetector : public slsDetectorUtils { +class multiSlsDetector : public postProcessing { private: @@ -1408,6 +1408,56 @@ public: */ int setCTBPatWaitTime(int level, uint64_t t=-1); + /** + * Loads the detector setup from file + * @param fname file to read from + * @param level if 2 reads also reads trimbits, angular conversion coefficients etc. + * from files with default extensions as generated by dumpDetectorSetup + * @returns OK or FAIL + */ + int retrieveDetectorSetup(std::string const fname, int level=0); + + /** + * Saves the detector setup to file + * @param fname file to write to + * @param level if 2 reads also trimbits, flat field, angular correction etc. + * and writes them to files with automatically added extension + * @returns OK or FAIL + */ + int dumpDetectorSetup(std::string const fname, int level=0); + + /** + * register callback for accessing acquisition final data + * @param func function to be called at the end of the acquisition. + * gets detector status and progress index as arguments + * @param pArg argument + */ + void registerAcquisitionFinishedCallback(int( *func)(double,int, void*), void *pArg); + + /** + * register callback for accessing measurement final data + * @param func function to be called at the end of the acquisition. + * gets detector status and progress index as arguments + * @param pArg argument + */ + void registerMeasurementFinishedCallback(int( *func)(int,int, void*), void *pArg); + + /** + * register callback for accessing detector progress + * @param func function to be called at the end of the acquisition. + * gets detector status and progress index as arguments + * @param pArg argument + */ + void registerProgressCallback(int( *func)(double,void*), void *pArg); + + /** + * Performs a complete acquisition + * resets frames caught in receiver, starts receiver, starts detector, + * blocks till detector finished acquisition, stop receiver, increments file index, + * loops for measurements, calls required call backs. + * @returns OK or FAIL depending on if it already started + */ + int acquire(); private: /** @@ -1455,6 +1505,30 @@ private: */ int processImageWithGapPixels(char* image, char*& gpImage); + /** + * Set total progress (total number of frames/images in an acquisition) + * @returns total progress + */ + int setTotalProgress(); + + /** + * Get progress in current acquisition + * @returns current progress + */ + double getCurrentProgress(); + + /** + * Increment progress by one + */ + void incrementProgress(); + + /** + * Set current progress to argument + * @param i current progress + */ + void setCurrentProgress(int i=0); + + /** Multi detector Id */ int detId; @@ -1476,6 +1550,22 @@ private: /** Threadpool */ 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; }; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 4ee4e1fde..e326e52e4 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -6,7 +6,7 @@ #include "gitInfoLib.h" #include "versionAPI.h" #include "slsDetectorCommand.h" - +#include "utilities.h" #include @@ -21,6 +21,9 @@ using namespace std; +#define DEFAULT_HOSTNAME "localhost" + + slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify, multiSlsDetector* m) : slsDetectorUtils(), detId(id), @@ -630,13 +633,6 @@ void slsDetector::initializeMembers() { } thisReceiver = new receiverInterface(dataSocket); - - // slsDetectorUtils - stoppedFlag = &thisDetector->stoppedFlag; - timerValue = thisDetector->timerValue; - currentSettings = &thisDetector->currentSettings; - currentThresholdEV = &thisDetector->currentThresholdEV; - //postProcessing threadedProcessing = &thisDetector->threadedProcessing; fdata = NULL; @@ -3056,12 +3052,6 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t, int imod) { if(t!=-1){ - /* set progress */ - if ((index==FRAME_NUMBER) || (index==CYCLES_NUMBER) || - (index==STORAGE_CELL_NUMBER)) { - setTotalProgress(); - } - //if eiger, rate corr on, a put statement, dr=32 &setting subexp or dr =16 //& setting exptime, set ratecorr to update table double r; @@ -4571,7 +4561,7 @@ int slsDetector::loadImageToDetector(imageType index,string const fname) { std::cout<<" image from file " << fname << std::endl; #endif - if(readDataFile(fname,arg)){ + if(readDataFile(fname,arg,getTotalNumberOfChannels())){ ret = sendImageToDetector(index,arg); return ret; } @@ -4629,7 +4619,7 @@ int slsDetector::writeCounterBlockFile(string const fname,int startACQ) { ret=getCounterBlock(counterVals,startACQ); if(ret==OK) - ret=writeDataFile(fname, counterVals); + ret=writeDataFile(fname, getTotalNumberOfChannels(), counterVals); return ret; } diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index d63ee1499..026dc7480 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -38,7 +38,7 @@ typedef struct detParameterList { } detParameterList; -class slsDetector : public slsDetectorUtils { +class slsDetector : public postProcessing { private: /** diff --git a/slsDetectorSoftware/slsDetector/slsDetectorBase.h b/slsDetectorSoftware/slsDetector/slsDetectorBase.h index 42f699418..853706b55 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorBase.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorBase.h @@ -369,9 +369,9 @@ class slsDetectorBase : public virtual slsDetectorDefs, public virtual errorDef */ virtual int readConfigurationFile(std::string const fname)=0; - virtual int dumpDetectorSetup(std::string const fname, int level)=0; + virtual int dumpDetectorSetup(std::string const fname, int level){return 0;}; int dumpDetectorSetup(std::string const fname){return dumpDetectorSetup(fname,0);}; - virtual int retrieveDetectorSetup(std::string const fname, int level)=0; + virtual int retrieveDetectorSetup(std::string const fname, int level){return 0;}; int retrieveDetectorSetup(std::string const fname){return retrieveDetectorSetup(fname,0);}; /** @short @@ -463,6 +463,847 @@ virtual int enableDataStreamingFromReceiver(int enable=-1)=0; virtual int setReadReceiverFrequency(int freq=-1)=0; + int enableCountRateCorrection(int i=-1) {if (i>0) setRateCorrection(-1); else if (i==0) setRateCorrection(0); return getRateCorrection();}; + + /** + * Set/Get receiver streaming out ZMQ port + * For multi modules, it calculates (increments) and sets the ports + * @param i sets, -1 gets + * @returns receiver streaming out ZMQ port + */ + int setReceiverDataStreamingOutPort(int i) { \ + if (i >= 0) { \ + std::ostringstream ss; ss << i; std::string s = ss.str(); \ + int prev_streaming = enableDataStreamingFromReceiver(); \ + setNetworkParameter(RECEIVER_STREAMING_PORT, s); \ + if (prev_streaming) { \ + enableDataStreamingFromReceiver(0); \ + enableDataStreamingFromReceiver(1);}} \ + return atoi(getNetworkParameter(RECEIVER_STREAMING_PORT).c_str());}; \ + + /** + * Set/Get client streaming in ZMQ port + * For multi modules, it calculates (increments) and sets the ports + * @param i sets, -1 gets + * @returns client streaming in ZMQ port + */ + int setClientDataStreamingInPort(int i){ \ + if (i >= 0) { \ + std::ostringstream ss; ss << i; std::string s = ss.str(); \ + int prev_streaming = enableDataStreamingToClient(); \ + setNetworkParameter(CLIENT_STREAMING_PORT, s); \ + if (prev_streaming) { \ + enableDataStreamingToClient(0); \ + enableDataStreamingToClient(1);}} \ + return atoi(getNetworkParameter(CLIENT_STREAMING_PORT).c_str());}; \ + + /** + * Set/Get receiver streaming out ZMQ port + * For multi modules, it calculates (increments) and sets the ports + * @param i sets, -1 gets + * @returns receiver streaming out ZMQ port + */ + std::string setReceiverDataStreamingOutIP(std::string ip) { \ + if (ip.length()) { \ + int prev_streaming = enableDataStreamingFromReceiver(); \ + setNetworkParameter(RECEIVER_STREAMING_SRC_IP, ip); \ + if (prev_streaming) { \ + enableDataStreamingFromReceiver(0); \ + enableDataStreamingFromReceiver(1);}} \ + return getNetworkParameter(RECEIVER_STREAMING_SRC_IP);}; \ + + /** + * Set/Get client streaming in ZMQ port + * For multi modules, it calculates (increments) and sets the ports + * @param i sets, -1 gets + * @returns client streaming in ZMQ port + */ + std::string setClientDataStreamingInIP(std::string ip){ \ + if (ip.length()) { \ + int prev_streaming = enableDataStreamingToClient(); \ + setNetworkParameter(CLIENT_STREAMING_SRC_IP, ip); \ + if (prev_streaming) { \ + enableDataStreamingToClient(0); \ + enableDataStreamingToClient(1);}} \ + return getNetworkParameter(CLIENT_STREAMING_SRC_IP);}; \ + + + int setFlowControl10G(int i = -1) { + std::string sret=""; + if (i != -1) { + std::ostringstream o; + o << ((i >= 1) ? 1 : 0); + std::string sval = o.str(); + sret = setNetworkParameter(FLOW_CONTROL_10G, sval); + } else + sret = getNetworkParameter(FLOW_CONTROL_10G); + + return atoi(sret.c_str()); + } + + /** + * Used when reference is slsDetectorUtils and to determine + * if command can be implemented as slsDetector/multiSlsDetector object/ + */ + virtual bool isMultiSlsDetectorClass() = 0; + + /** + * Set acquiring flag in shared memory + * @param b acquiring flag + */ + virtual void setAcquiringFlag(bool b=false) = 0; + + /** + * Get acquiring flag from shared memory + * @returns acquiring flag + */ + virtual bool getAcquiringFlag() = 0; + + /** + * Check if acquiring flag is set, set error if set + * @returns FAIL if not ready, OK if ready + */ + virtual bool isAcquireReady() = 0; + + /** + * Check version compatibility with detector/receiver software + * (if hostname/rx_hostname has been set/ sockets created) + * @param p port type control port or receiver port + * @returns FAIL for incompatibility, OK for compatibility + */ + virtual int checkVersionCompatibility(portType t) = 0; + + /** + * Free shared memory and delete shared memory structure + */ + virtual void freeSharedMemory() = 0; + + /** + * Get user details of shared memory + * Should only be called from multi detector level + * @returns string with user details + */ + virtual std::string getUserDetails() = 0; + + /** + * Sets the hostname of all sls detectors in shared memory + * Connects to them to set up online flag + * @param name concatenated hostname of all the sls detectors + */ + virtual void setHostname(const char* name)=0; + + /** + * Gets the hostname of detector at particular position + * or concatenated hostnames of all the sls detectors + * @param pos position of detector in array, -1 for all detectors + * @returns concatenated hostnames of all detectors or hostname of specific one + */ + virtual std::string getHostname(int pos=-1)=0; + + /** + * Appends detectors to the end of the list in shared memory + * Connects to them to set up online flag + * @param name concatenated hostname of the sls detectors to be appended to the list + */ + virtual void addMultipleDetectors(const char* name)=0; + + + using slsDetectorBase::getDetectorsType; + /** + * Concatenates string types of all sls detectors or + * returns the detector type of the first sls detector + * @param pos position of sls detector in array, if -1, returns first detector type + * @returns detector type of sls detector in position pos, if -1, concatenates + */ + virtual std::string sgetDetectorsType(int pos=-1)=0; + + /** + * Returns the number of detectors in the multidetector structure + * @returns number of detectors + */ + virtual int getNumberOfDetectors(){return 1;}; + + /** + * Returns the total number of channels of all sls detectors from shared memory + * @returns the total number of channels of all sls detectors + */ + virtual int getTotalNumberOfChannels()=0; + + /** + * Returns the total number of channels of all sls detectors in dimension d + * from shared memory + * @param d dimension d + * @returns the total number of channels of all sls detectors in dimension d + */ + virtual int getTotalNumberOfChannels(dimension d)=0; + + /** + * Returns the maximum number of channels of all sls detectors in each dimension d + * from shared memory. multi detector shared memory variable to calculate + * offsets for each sls detector + * @param d dimension d + * @returns the maximum number of channels of all sls detectors in dimension d + */ + virtual int getMaxNumberOfChannelsPerDetector(dimension d){return -1;}; + + /** + * Sets the maximum number of channels of all sls detectors in each dimension d + * from shared memory, multi detector shared memory variable to calculate + * offsets for each sls detector + * @param d dimension d + * @param i maximum number of channels for multi structure in dimension d + * @returns the maximum number of channels of all sls detectors in dimension d + */ + virtual int setMaxNumberOfChannelsPerDetector(dimension d,int i){return -1;}; + + /** + * Checks if each of the detectors are online/offline + * @returns empty string if they are all online, + * else returns concatenation of strings of all detectors that are offline + */ + virtual std::string checkOnline()=0; + + /** + * Set/Gets TCP Port of detector or receiver + * @param t port type + * @param num port number (-1 gets) + * @returns port number + */ + virtual int setPort(portType t, int num=-1)=0; + + /** + * Get last client IP saved on detector server + * @returns last client IP saved on detector server + */ + virtual std::string getLastClientIP()=0; + + /** + * Exit detector server + * @returns OK or FAIL + */ + virtual int exitServer()=0; + + /** + * Write current configuration to a file + * @param fname configuration file name + * @returns OK or FAIL + */ + virtual int writeConfigurationFile(std::string const fname)=0; + + /** + * Returns the trimfile or settings file name (Useless??) + * @returns the trimfile or settings file name + */ + virtual std::string getSettingsFile()=0; + + /** + * Set threshold energy (Mythen and Eiger) + * @param e_eV threshold in eV + * @param imod module number (-1 all) + * @param isettings ev. change settings + * @param tb 1 to include trimbits, 0 to exclude + * @returns current threshold value for imod in ev (-1 failed) + */ + virtual int setThresholdEnergy(int e_eV, int imod=-1, detectorSettings isettings=GET_SETTINGS,int tb=1)=0; + + /** + * Returns the detector trimbit/settings directory \sa sharedSlsDetector + * @returns the trimbit/settings directory + */ + virtual std::string getSettingsDir()=0; + + /** + * Sets the detector trimbit/settings directory \sa sharedSlsDetector + * @param s trimbits/settings directory + * @returns the trimbit/settings directory + */ + virtual std::string setSettingsDir(std::string s)=0; + + /** + * Returns the calibration files directory \sa sharedSlsDetector (Mythen) + * @returns the calibration files directory + */ + virtual std::string getCalDir()=0; + + /** + * Sets the calibration files directory \sa sharedSlsDetector (Mythen) + * @param s the calibration files directory + * @returns the calibration files directory + */ + virtual std::string setCalDir(std::string s)=0; + + /** + * Loads the modules settings/trimbits reading from a specific file + * file name extension is automatically generated. + * @param fname specific settings/trimbits file + * @param imod module number (-1 for all) + * returns OK or FAIL + */ + virtual int loadSettingsFile(std::string fname, int imod=-1)=0; + + /** + * Saves the modules settings/trimbits to a specific file + * file name extension is automatically generated. + * @param fname specific settings/trimbits file + * @param imod module number (-1 for all) + * returns OK or FAIL + */ + virtual int saveSettingsFile(std::string fname, int imod=-1)=0; + + /** + * Give an internal software trigger to the detector (Eiger only) + * @return OK or FAIL + */ + virtual int sendSoftwareTrigger()=0; + + /** + * Start detector acquisition and read all data (Blocking until end of acquisition) + * @returns OK or FAIL + */ + virtual int startAndReadAll()=0; + + /** + * Requests and receives all data from the detector (Eiger store in ram) + * @returns OK or FAIL + */ + virtual int readAll()=0; + + /** + * Configures in detector the destination for UDP packets (Not Mythen) + * @returns OK or FAIL + */ + virtual int configureMAC()=0; + + /** + * Set/get timer value left in acquisition (not all implemented for all detectors) + * @param index timer index + * @param t time in ns or number of...(e.g. frames, gates, probes) + * @param imod module number + * @returns timer set value in ns or number of...(e.g. frames, gates, probes) + */ + virtual int64_t getTimeLeft(timerIndex index, int imod = -1)=0; + + /** + * Set speed + * @param sp speed type (clkdivider option for Jungfrau and Eiger, others for Mythen/Gotthard) + * @param value (clkdivider 0,1,2 for full, half and quarter speed). Other values check manual + * @returns value of speed set + */ + virtual int setSpeed(speedVariable sp, int value=-1)=0; + + /** + * Set/get dacs value + * @param val value (in V) + * @param index DAC index + * @param mV 0 in dac units or 1 in mV + * @param imod module number (if -1 all modules) + * @returns current DAC value + */ + virtual dacs_t setDAC(dacs_t val, dacIndex index , int mV, int imod=-1)=0; + + /** + * Get adc value + * @param index adc(DAC) index + * @param imod module number (if -1 all modules) + * @returns current adc value (temperature for eiger and jungfrau in millidegrees) + */ + virtual dacs_t getADC(dacIndex index, int imod=-1)=0; + + /** + * Set/get external signal flags (to specify triggerinrising edge etc) (Gotthard, Mythen) + * @param pol external signal flag (-1 gets) + * @param signalindex singal index (0 - 3) + * @returns current timing mode + */ + virtual externalSignalFlag setExternalSignalFlags(externalSignalFlag pol=GET_EXTERNAL_SIGNAL_FLAG , int signalindex=0)=0; + + /** + * Set/get readout flags (Eiger, Mythen) + * @param flag readout flag (Eiger options: parallel, nonparallel, safe etc.) (-1 gets) + * @returns readout flag + */ + virtual int setReadOutFlags(readOutFlags flag=GET_READOUT_FLAGS)=0; + + /** + * Write in a register. For Advanced users + * @param addr address of register + * @param val value to write into register + * @returns value read after writing + */ + virtual uint32_t writeRegister(uint32_t addr, uint32_t val)=0; + + /** + * Read from a register. For Advanced users + * @param addr address of register + * @returns value read from register + */ + virtual uint32_t readRegister(uint32_t addr)=0; + + /** + * Set bit in a register. For Advanced users + * @param addr address of register + * @param n nth bit + * @returns value read from register + */ + virtual uint32_t setBit(uint32_t addr, int n)=0; + + /** + * Clear bit in a register. For Advanced users + * @param addr address of register + * @param n nth bit + * @returns value read from register + */ + virtual uint32_t clearBit(uint32_t addr, int n)=0; + + /** + * Set network parameter + * @param p network parameter type + * @param s network parameter value + * @returns network parameter value set (from getNetworkParameter) + */ + virtual std::string setNetworkParameter(networkParameter p, std::string s)=0; + + /** + * Get network parameter + * @param p network parameter type + * @returns network parameter value set (from getNetworkParameter) + */ + virtual std::string getNetworkParameter(networkParameter)=0; + + /** + * Execute a digital test (Gotthard, Mythen) + * @param mode testmode type + * @param imod module index (-1 for all) + * @returns result of test + */ + virtual int digitalTest(digitalTestMode mode, int imod=0)=0; + + /** + * Load dark or gain image to detector (Gotthard) + * @param index image type + * @param fname file name from which to load image + * @returns OK or FAIL + */ + virtual int loadImageToDetector(imageType index,std::string const fname)=0; + + /** + * Writes the counter memory block from the detector (Gotthard) + * @param fname file name to load data from + * @param startACQ is 1 to start acquisition after reading counter + * @returns OK or FAIL + */ + virtual int writeCounterBlockFile(std::string const fname,int startACQ=0)=0; + + /** + * Resets counter in detector (Gotthard) + * @param startACQ is 1 to start acquisition after resetting counter + * @returns OK or FAIL + */ + virtual int resetCounterBlock(int startACQ=0)=0; + + /** + * Set/get counter bit in detector (Gotthard) + * @param i is -1 to get, 0 to reset and any other value to set the counter bit + * @returns the counter bit in detector + */ + virtual int setCounterBit(int i = -1)=0; + + /** + * Set ROI (Gotthard) + * At the moment only one set allowed + * @param n number of rois + * @param roiLimits array of roi + * @returns OK or FAIL + */ + virtual int setROI(int n=-1,ROI roiLimits[]=NULL)=0; + + /** + * Get ROI from each detector and convert it to the multi detector scale (Gotthard) + * @param n number of rois + * @returns OK or FAIL + */ + virtual ROI* getROI(int &n)=0; + + /** + * Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert users + * @param addr address of adc register + * @param val value + * @returns return value (mostly -1 as it can't read adc register) + */ + virtual int writeAdcRegister(int addr, int val)=0; + + /** + * Returns the enable if data will be flipped across x or y axis (Eiger) + * @param d axis across which data is flipped + * @returns 1 for flipped, else 0 + */ + virtual int getFlippedData(dimension d=X)=0; + + /** + * Sets the enable which determines if + * data will be flipped across x or y axis (Eiger) + * @param d axis across which data is flipped + * @param value 0 or 1 to reset/set or -1 to get value + * @returns enable flipped data across x or y axis + */ + virtual int setFlippedData(dimension d=X, int value=-1)=0; + + /** + * Sets all the trimbits to a particular value (Eiger) + * @param val trimbit value + * @param imod module number, -1 means all modules + * @returns OK or FAIL + */ + virtual int setAllTrimbits(int val, int imod=-1)=0; + + /** + * Enable gap pixels, only for Eiger and for 8,16 and 32 bit mode. (Eiger) + * 4 bit mode gap pixels only in gui call back + * @param val 1 sets, 0 unsets, -1 gets + * @returns gap pixel enable or -1 for error + */ + virtual int enableGapPixels(int val=-1)=0; + + /** + * Sets the number of trim energies and their value (Eiger) + * \sa sharedSlsDetector + * @param nen number of energies + * @param en array of energies + * @returns number of trim energies + */ + virtual int setTrimEn(int nen, int *en=NULL)=0; + + /** + * Returns the number of trim energies and their value (Eiger) + * \sa sharedSlsDetector + * @param en array of energies + * @returns number of trim energies + */ + virtual int getTrimEn(int *en=NULL)=0; + + /** + * Pulse Pixel (Eiger) + * @param n is number of times to pulse + * @param x is x coordinate + * @param y is y coordinate + * @returns OK or FAIL + */ + virtual int pulsePixel(int n=0,int x=0,int y=0)=0; + + /** + * Pulse Pixel and move by a relative value (Eiger) + * @param n is number of times to pulse + * @param x is relative x value + * @param y is relative y value + * @returns OK or FAIL + */ + virtual int pulsePixelNMove(int n=0,int x=0,int y=0)=0; + + /** + * Pulse Chip (Eiger) + * @param n is number of times to pulse + * @returns OK or FAIL + */ + virtual int pulseChip(int n=0)=0; + + /** + * Set/gets threshold temperature (Jungfrau) + * @param val value in millidegrees, -1 gets + * @param imod module number, -1 is all + * @returns threshold temperature in millidegrees + */ + virtual int setThresholdTemperature(int val=-1, int imod=-1)=0; + + /** + * Enables/disables temperature control (Jungfrau) + * @param val value, -1 gets + * @param imod module number, -1 is all + * @returns temperature control enable + */ + virtual int setTemperatureControl(int val=-1, int imod=-1)=0; + + /** + * Resets/ gets over-temperature event (Jungfrau) + * @param val value, -1 gets + * @param imod module number, -1 is all + * @returns over-temperature event + */ + virtual int setTemperatureEvent(int val=-1, int imod=-1)=0; + + /** + * Set storage cell that stores first acquisition of the series (Jungfrau) + * @param value storage cell index. Value can be 0 to 15. (-1 gets) + * @returns the storage cell that stores the first acquisition of the series + */ + virtual int setStoragecellStart(int pos=-1)=0; + + /** + * Programs FPGA with pof file (Jungfrau) + * @param fname file name + * @returns OK or FAIL + */ + virtual int programFPGA(std::string fname)=0; + + /** + * Resets FPGA (Jungfrau) + * @returns OK or FAIL + */ + virtual int resetFPGA()=0; + + /** + * Power on/off Chip (Jungfrau) + * @param ival on is 1, off is 0, -1 to get + * @returns OK or FAIL + */ + virtual int powerChip(int ival= -1)=0; + + /** + * Automatic comparator disable (Jungfrau) + * @param ival on is 1, off is 0, -1 to get + * @returns OK or FAIL + */ + virtual int setAutoComparatorDisableMode(int ival= -1)=0; + + /** + * Calibrate Pedestal (ChipTestBoard) + * Starts acquisition, calibrates pedestal and writes to fpga + * @param frames number of frames + * @returns number of frames + */ + virtual int calibratePedestal(int frames = 0)=0; + + /** + * Get rate correction tau (Mythen, Eiger) + * @returns 0 if rate correction disabled, otherwise the tau used for the correction + */ + virtual double getRateCorrectionTau()=0; + + /** + * Checks if the receiver is really online + * @returns empty string if all online, else concatenates hostnames of all + * detectors that are offline + */ + virtual std::string checkReceiverOnline()=0; + + /** + * Locks/Unlocks the connection to the receiver + * @param lock sets (1), usets (0), gets (-1) the lock + * @returns lock status of the receiver + */ + virtual int lockReceiver(int lock=-1)=0; + + /** + * Returns the IP of the last client connecting to the receiver + * @returns IP of last client connecting to receiver + */ + virtual std::string getReceiverLastClientIP()=0; + + /** + * Turns off the receiver server! + * @returns OK or FAIL + */ + virtual int exitReceiver()=0; + + /** + * Returns output file directory + * @returns output file directory + */ + virtual std::string getFilePath()=0; + + /** + * Sets up the file directory + * @param s file directory + * @returns file dir + */ + virtual std::string setFilePath(std::string s)=0; + + /** + * Returns file name prefix + * @returns file name prefix + */ + virtual std::string getFileName()=0; + + /** + * Sets up the file name prefix + * @param s file name prefix + * @returns file name prefix + */ + virtual std::string setFileName(std::string s)=0; + + /** + * Sets the max frames per file in receiver + * @param f max frames per file + * @returns max frames per file in receiver + */ + virtual int setReceiverFramesPerFile(int f=-1)=0; + + /** + * Sets the frames discard policy in receiver + * @param f frames discard policy + * @returns frames discard policy set in receiver + */ + virtual frameDiscardPolicy setReceiverFramesDiscardPolicy(frameDiscardPolicy f = GET_FRAME_DISCARD_POLICY)=0; + + /** + * Sets the partial frames padding enable in receiver + * @param f partial frames padding enable + * @returns partial frames padding enable in receiver + */ + virtual int setReceiverPartialFramesPadding(int f = -1)=0; + + /** + * Returns file format + * @returns file name + */ + virtual fileFormat getFileFormat()=0; + + /** + * Sets up the file format + * @param f file format + * @returns file format + */ + virtual fileFormat setFileFormat(fileFormat f)=0; + + /** + * Gets the number of frames caught by receiver + * @returns number of frames caught by receiver + */ + virtual int getFramesCaughtByReceiver()=0; + + /** + * Gets the number of frames caught by any one receiver (to avoid using threadpool) + * @returns number of frames caught by any one receiver (master receiver if exists) + */ + virtual int getFramesCaughtByAnyReceiver()=0; + + /** + * Gets the current frame index of receiver + * @returns current frame index of receiver + */ + virtual int getReceiverCurrentFrameIndex()=0; + + /** + * Resets framescaught in receiver + * Use this when using startAcquisition instead of acquire + * @returns OK or FAIL + */ + virtual int resetFramesCaught()=0; + + /** + * Create Receiving Data Sockets + * @param destroy is true to destroy all the sockets + * @returns OK or FAIL + */ + virtual int createReceivingDataSockets(const bool destroy = false){return -1;}; + + /** + * Reads frames from receiver through a constant socket + * Called during acquire() when call back registered or when using gui + */ + virtual void readFrameFromReceiver(){}; + + /** + * Sets/Gets receiver file write enable + * @param enable 1 or 0 to set/reset file write enable + * @returns file write enable + */ + virtual int enableWriteToFile(int enable=-1)=0; + + /** + * Sets/Gets file overwrite enable + * @param enable 1 or 0 to set/reset file overwrite enable + * @returns file overwrite enable + */ + virtual int overwriteFile(int enable=-1)=0; + + /** + * Sets the read receiver frequency + * if data required from receiver randomly readRxrFrequency=0, + * else every nth frame to be sent to gui/callback + * @param freq is the receiver read frequency. Value 0 is 200 ms timer (other + * frames not sent), 1 is every frame, 2 is every second frame etc. + * @returns read receiver frequency + */ + virtual int setReadReceiverFrequency(int freq=-1)=0; + + /** + * Enable data streaming to client + * @param enable 0 to disable, 1 to enable, -1 to get the value + * @returns data streaming to client enable + */ + virtual int enableDataStreamingToClient(int enable=-1)=0; + + /** + * Enable or disable streaming data from receiver to client + * @param enable 0 to disable 1 to enable -1 to only get the value + * @returns data streaming from receiver enable + */ + virtual int enableDataStreamingFromReceiver(int enable=-1)=0; + + /** + * Enable/disable or 10Gbe + * @param i is -1 to get, 0 to disable and 1 to enable + * @returns if 10Gbe is enabled + */ + virtual int enableTenGigabitEthernet(int i = -1)=0; + + /** + * Set/get receiver fifo depth + * @param i is -1 to get, any other value to set the fifo deph + * @returns the receiver fifo depth + */ + virtual int setReceiverFifoDepth(int i = -1)=0; + + /** + * Set/get receiver silent mode + * @param i is -1 to get, 0 unsets silent mode, 1 sets silent mode + * @returns the receiver silent mode enable + */ + virtual int setReceiverSilentMode(int i = -1)=0; + + /** + * Opens pattern file and sends pattern to CTB + * @param fname pattern file to open + * @returns OK/FAIL + */ + virtual int setCTBPattern(std::string fname)=0; + + /** + * Writes a pattern word to the CTB + * @param addr address of the word, -1 is I/O control register, + * -2 is clk control register + * @param word 64bit word to be written, -1 gets + * @returns actual value + */ + virtual uint64_t setCTBWord(int addr,uint64_t word=-1)=0; + + /** + * Sets the pattern or loop limits in the CTB + * @param level -1 complete pattern, 0,1,2, loop level + * @param start start address if >=0 + * @param stop stop address if >=0 + * @param n number of loops (if level >=0) + * @returns OK/FAIL + */ + virtual int setCTBPatLoops(int level,int &start, int &stop, int &n)=0; + + /** + * Sets the wait address in the CTB + * @param level 0,1,2, wait level + * @param addr wait address, -1 gets + * @returns actual value + */ + virtual int setCTBPatWaitAddr(int level, int addr=-1)=0; + + /** + * Sets the wait time in the CTB + * @param level 0,1,2, wait level + * @param t wait time, -1 gets + * @returns actual value + */ + virtual int setCTBPatWaitTime(int level, uint64_t t=-1)=0; + + /** returns detector type std::string from detector type index \param t std::string can be Eiger, Gotthard, Jungfrau, Unknown \returns EIGER, GOTTHARD, JUNGFRAU, GENERIC diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 2f01d3c30..4b0057ba2 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -11,538 +11,19 @@ using namespace std; slsDetectorUtils::slsDetectorUtils(): - stoppedFlag(0), - timerValue(0), - currentSettings(0), - currentThresholdEV(0), - totalProgress(0), - progressIndex(0), - acquisition_finished(NULL), - measurement_finished(NULL), - acqFinished_p(NULL), - measFinished_p(NULL), - progress_call(0), - pProgressCallArg(0) + { -#ifdef VERBOSE - registerAcquisitionFinishedCallback(&dummyAcquisitionFinished,this); - registerMeasurementFinishedCallback(&dummyMeasurementFinished,this); - cout << "done " << endl; -#endif + } -int slsDetectorUtils::acquire(int delflag){ - //ensure acquire isnt started multiple times by same client - if (isAcquireReady() == FAIL) - return FAIL; -#ifdef VERBOSE - struct timespec begin,end; - clock_gettime(CLOCK_REALTIME, &begin); -#endif - //in the real time acquisition loop, processing thread will wait for a post each time - sem_init(&sem_newRTAcquisition,1,0); - //in the real time acquistion loop, main thread will wait for processing thread to be done each time (which in turn waits for receiver/ext process) - sem_init(&sem_endRTAcquisition,1,0); - bool receiver = (setReceiverOnline()==ONLINE_FLAG); - progressIndex=0; - *stoppedFlag=0; - void *status; - setJoinThread(0); - int nm=timerValue[MEASUREMENTS_NUMBER]; - if (nm<1) - nm=1; - - // verify receiver is idle - if(receiver){ - pthread_mutex_lock(&mg); - if(getReceiverStatus()!=IDLE) - if(stopReceiver() == FAIL) - *stoppedFlag=1; - pthread_mutex_unlock(&mg); - } - - // start processing thread - if (*threadedProcessing) - startThread(delflag); - - - //resets frames caught in receiver - if(receiver){ - pthread_mutex_lock(&mg); - if (resetFramesCaught() == FAIL) - *stoppedFlag=1; - pthread_mutex_unlock(&mg); - } - - // loop through measurements - for(int im=0;im0) - nc=timerValue[CYCLES_NUMBER]; - - if (timerValue[STORAGE_CELL_NUMBER]>0) - ns=timerValue[STORAGE_CELL_NUMBER]+1; - - if (timerValue[MEASUREMENTS_NUMBER]>0) - nm=timerValue[MEASUREMENTS_NUMBER]; - - totalProgress=nm*nf*nc*ns; - -#ifdef VERBOSE - cout << "nm " << nm << endl; - cout << "nf " << nf << endl; - cout << "nc " << nc << endl; - cout << "ns " << ns << endl; - cout << "Set total progress " << totalProgress << endl; -#endif - return totalProgress; -} - - - -double slsDetectorUtils::getCurrentProgress() { - pthread_mutex_lock(&mp); -#ifdef VERBOSE - cout << progressIndex << " / " << totalProgress << endl; -#endif - - double p=100.*((double)progressIndex)/((double)totalProgress); - pthread_mutex_unlock(&mp); - return p; -} - - - -void slsDetectorUtils::incrementProgress() { - pthread_mutex_lock(&mp); - progressIndex++; - cout << fixed << setprecision(2) << setw (6) - << 100.*((double)progressIndex)/((double)totalProgress) << " \%"; - pthread_mutex_unlock(&mp); -#ifdef VERBOSE - cout << endl; -#else - cout << "\r" << flush; -#endif - -}; - - -void slsDetectorUtils::setCurrentProgress(int i){ - pthread_mutex_lock(&mp); - progressIndex=i; - cout << fixed << setprecision(2) << setw (6) - << 100.*((double)progressIndex)/((double)totalProgress) << " \%"; - pthread_mutex_unlock(&mp); -#ifdef VERBOSE - cout << endl; -#else - cout << "\r" << flush; -#endif -} - - -int slsDetectorUtils::retrieveDetectorSetup(string const fname1, int level){ - - - slsDetectorCommand *cmd; - - int skip=0; - string fname; - string str; - ifstream infile; - int iargval; - int interrupt=0; - char *args[10]; - - char myargs[10][1000]; -; - - string sargname, sargval; - int iline=0; - - if (level==2) { -#ifdef VERBOSE - cout << "config file read" << endl; -#endif - fname=fname1+string(".det"); - } else - fname=fname1; - - infile.open(fname.c_str(), ios_base::in); - if (infile.is_open()) { - cmd=new slsDetectorCommand(this); - while (infile.good() and interrupt==0) { - sargname="none"; - sargval="0"; - getline(infile,str); - iline++; -#ifdef VERBOSE - std::cout<< str << std::endl; -#endif - if (str.find('#')!=string::npos) { -#ifdef VERBOSE - std::cout<< "Line is a comment " << std::endl; - std::cout<< str << std::endl; -#endif - continue; - } else { - istringstream ssstr(str); - iargval=0; - while (ssstr.good()) { - ssstr >> sargname; - // if (ssstr.good()) { - strcpy(myargs[iargval],sargname.c_str()); - args[iargval]=myargs[iargval]; -#ifdef VERBOSE - std::cout<< args[iargval] << std::endl; -#endif - iargval++; - // } - skip=0; - } - - if (level!=2) { - if (string(args[0])==string("trimbits")) - skip=1; - } - if (skip==0) - cmd->executeLine(iargval,args,PUT_ACTION); - } - iline++; - } - delete cmd; - infile.close(); - - } else { - std::cout<< "Error opening " << fname << " for reading" << std::endl; - return FAIL; - } -#ifdef VERBOSE - std::cout<< "Read " << iline << " lines" << std::endl; -#endif - - if (getErrorMask()) - return FAIL; - - return OK; - - -} - - -int slsDetectorUtils::dumpDetectorSetup(string const fname, int level){ - - slsDetectorCommand *cmd; - detectorType type = getDetectorsType(); - string names[100]; - int nvar=0; - - // common config - names[nvar++]="fname"; - names[nvar++]="index"; - names[nvar++]="enablefwrite"; - names[nvar++]="overwrite"; - names[nvar++]="dr"; - names[nvar++]="settings"; - names[nvar++]="exptime"; - names[nvar++]="period"; - names[nvar++]="frames"; - names[nvar++]="cycles"; - names[nvar++]="measurements"; - names[nvar++]="timing"; - - switch (type) { - case EIGER: - names[nvar++]="flags"; - names[nvar++]="clkdivider"; - names[nvar++]="threshold"; - names[nvar++]="ratecorr"; - names[nvar++]="trimbits"; - break; - case GOTTHARD: - names[nvar++]="delay"; - break; - case JUNGFRAU: - names[nvar++]="delay"; - names[nvar++]="clkdivider"; - break; - case JUNGFRAUCTB: - names[nvar++]="dac:0"; - names[nvar++]="dac:1"; - names[nvar++]="dac:2"; - names[nvar++]="dac:3"; - names[nvar++]="dac:4"; - names[nvar++]="dac:5"; - names[nvar++]="dac:6"; - names[nvar++]="dac:7"; - names[nvar++]="dac:8"; - names[nvar++]="dac:9"; - names[nvar++]="dac:10"; - names[nvar++]="dac:11"; - names[nvar++]="dac:12"; - names[nvar++]="dac:13"; - names[nvar++]="dac:14"; - names[nvar++]="dac:15"; - names[nvar++]="adcvpp"; - - - - names[nvar++]="adcclk"; - names[nvar++]="clkdivider"; - names[nvar++]="adcphase"; - names[nvar++]="adcpipeline"; - names[nvar++]="adcinvert"; // - names[nvar++]="adcdisable"; - names[nvar++]="patioctrl"; - names[nvar++]="patclkctrl"; - names[nvar++]="patlimits"; - names[nvar++]="patloop0"; - names[nvar++]="patnloop0"; - names[nvar++]="patwait0"; - names[nvar++]="patwaittime0"; - names[nvar++]="patloop1"; - names[nvar++]="patnloop1"; - names[nvar++]="patwait1"; - names[nvar++]="patwaittime1"; - names[nvar++]="patloop2"; - names[nvar++]="patnloop2"; - names[nvar++]="patwait2"; - names[nvar++]="patwaittime2"; - break; - default: - break; - } - - - int iv=0; - string fname1; - - - - ofstream outfile; - char *args[4]; - for (int ia=0; ia<4; ia++) { - args[ia]=new char[1000]; - } - - - if (level==2) { - fname1=fname+string(".config"); - writeConfigurationFile(fname1); - fname1=fname+string(".det"); - } else - fname1=fname; - - - - outfile.open(fname1.c_str(),ios_base::out); - if (outfile.is_open()) { - cmd=new slsDetectorCommand(this); - for (iv=0; ivexecuteLine(1,args,GET_ACTION) << std::endl; - } - - delete cmd; - - outfile.close(); - } - else { - std::cout<< "Error opening parameters file " << fname1 << " for writing" << std::endl; - return FAIL; - } - -#ifdef VERBOSE - std::cout<< "wrote " <> ichan >> idata; - if (ssstr.fail() || ssstr.bad()) { - interrupt=1; - break; - } - if (iline=offset) { - data[iline]=idata; - iline++; - } - } else { - interrupt=1; - break; - } - return iline; - }; - return iline; -} - - -int slsDetectorUtils::writeDataFile(std::string fname,int nch, short int *data) { - std::ofstream outfile; - if (data==NULL) - return slsDetectorDefs::FAIL; - outfile.open (fname.c_str(),std::ios_base::out); - if (outfile.is_open()) { - writeDataFile(outfile, nch, data, 0); - outfile.close(); - return slsDetectorDefs::OK; - } else { - std::cout<< "Could not open file " << fname << "for writing"<< std::endl; - return slsDetectorDefs::FAIL; - } -} - - -int slsDetectorUtils::writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset) { - if (data==NULL) - return slsDetectorDefs::FAIL; - for (int ichan=0; ichan=0 - * @param stop stop address if >=0 - * @param n number of loops (if level >=0) - * @returns OK/FAIL - */ - virtual int setCTBPatLoops(int level,int &start, int &stop, int &n)=0; - - /** - * Sets the wait address in the CTB - * @param level 0,1,2, wait level - * @param addr wait address, -1 gets - * @returns actual value - */ - virtual int setCTBPatWaitAddr(int level, int addr=-1)=0; - - /** - * Sets the wait time in the CTB - * @param level 0,1,2, wait level - * @param t wait time, -1 gets - * @returns actual value - */ - virtual int setCTBPatWaitTime(int level, uint64_t t=-1)=0; - - - - - - - - - - - - - int enableCountRateCorrection(int i=-1) {if (i>0) setRateCorrection(-1); else if (i==0) setRateCorrection(0); return getRateCorrection();}; - - /** - * Set/Get receiver streaming out ZMQ port - * For multi modules, it calculates (increments) and sets the ports - * @param i sets, -1 gets - * @returns receiver streaming out ZMQ port - */ - int setReceiverDataStreamingOutPort(int i) { \ - if (i >= 0) { \ - std::ostringstream ss; ss << i; std::string s = ss.str(); \ - int prev_streaming = enableDataStreamingFromReceiver(); \ - setNetworkParameter(RECEIVER_STREAMING_PORT, s); \ - if (prev_streaming) { \ - enableDataStreamingFromReceiver(0); \ - enableDataStreamingFromReceiver(1);}} \ - return atoi(getNetworkParameter(RECEIVER_STREAMING_PORT).c_str());}; \ - - /** - * Set/Get client streaming in ZMQ port - * For multi modules, it calculates (increments) and sets the ports - * @param i sets, -1 gets - * @returns client streaming in ZMQ port - */ - int setClientDataStreamingInPort(int i){ \ - if (i >= 0) { \ - std::ostringstream ss; ss << i; std::string s = ss.str(); \ - int prev_streaming = enableDataStreamingToClient(); \ - setNetworkParameter(CLIENT_STREAMING_PORT, s); \ - if (prev_streaming) { \ - enableDataStreamingToClient(0); \ - enableDataStreamingToClient(1);}} \ - return atoi(getNetworkParameter(CLIENT_STREAMING_PORT).c_str());}; \ - - /** - * Set/Get receiver streaming out ZMQ port - * For multi modules, it calculates (increments) and sets the ports - * @param i sets, -1 gets - * @returns receiver streaming out ZMQ port - */ - std::string setReceiverDataStreamingOutIP(std::string ip) { \ - if (ip.length()) { \ - int prev_streaming = enableDataStreamingFromReceiver(); \ - setNetworkParameter(RECEIVER_STREAMING_SRC_IP, ip); \ - if (prev_streaming) { \ - enableDataStreamingFromReceiver(0); \ - enableDataStreamingFromReceiver(1);}} \ - return getNetworkParameter(RECEIVER_STREAMING_SRC_IP);}; \ - - /** - * Set/Get client streaming in ZMQ port - * For multi modules, it calculates (increments) and sets the ports - * @param i sets, -1 gets - * @returns client streaming in ZMQ port - */ - std::string setClientDataStreamingInIP(std::string ip){ \ - if (ip.length()) { \ - int prev_streaming = enableDataStreamingToClient(); \ - setNetworkParameter(CLIENT_STREAMING_SRC_IP, ip); \ - if (prev_streaming) { \ - enableDataStreamingToClient(0); \ - enableDataStreamingToClient(1);}} \ - return getNetworkParameter(CLIENT_STREAMING_SRC_IP);}; \ - - - int setFlowControl10G(int i = -1) { - std::string sret=""; - if (i != -1) { - std::ostringstream o; - o << ((i >= 1) ? 1 : 0); - std::string sval = o.str(); - sret = setNetworkParameter(FLOW_CONTROL_10G, sval); - } else - sret = getNetworkParameter(FLOW_CONTROL_10G); - - return atoi(sret.c_str()); - } - - - /** performs a complete acquisition including scansand data processing - * moves the detector to next position
- * starts and reads the detector
- * reads the IC (if required)
- * reads the encoder (iof required for angualr conversion)
- * processes the data (flat field, rate, angular conversion and merging ::processData()) - * @param delflag 0 leaves the data in the final data queue - * @returns OK or FAIL depending on if it already started - */ - int acquire(int delflag=1); - - int setTotalProgress(); - - double getCurrentProgress(); - - void incrementProgress(); - - void setCurrentProgress(int i=0); - - /** - * Saves the detector setup to file - * @param fname file to write to - * @param level if 2 reads also trimbits, flat field, angular correction etc. - * and writes them to files with automatically added extension - * @returns OK or FAIL - */ - int dumpDetectorSetup(std::string const fname, int level=0); - - /** (used by multi and sls) - * reads a short int rawdata file - * @param name of the file to be read - * @param data array of data value - * @param nch number of channels - * @returns OK or FAIL if it could not read the file or data=NULL - */ - int readDataFile(std::string fname, short int *data, int nch); - - /** (used by multi and sls) - * reads a short int raw data file - * @param infile input file stream - * @param data array of data values - * @param nch number of channels - * @param offset start channel value - * @returns OK or FAIL if it could not read the file or data=NULL - */ - int readDataFile(std::ifstream &infile, short int *data, int nch, int offset); - - /** - * reads a short int raw data file - * @param fname of the file to be read - * @param data array of data values - * @returns OK or FAIL if it could not read the file or data=NULL - */ - int readDataFile(std::string fname, short int *data){ - return readDataFile(fname, data, getTotalNumberOfChannels()); - }; - /** - * reads a short int raw data file - * @param infile input file stream - * @param data array of data values - * @param offset first channel number to be expected - * @returns OK or FAIL if it could not read the file or data=NULL - */ - int readDataFile(std::ifstream &infile, short int *data, int offset=0){ - return readDataFile(infile, data, getTotalNumberOfChannels(),offset); - }; - - /** (used by multi and sls) - * writes a short int raw data file - * @param fname of the file to be written - * @param nch number of channels - * @param data array of data values - * @returns OK or FAIL if it could not write the file or data=NULL - */ - int writeDataFile(std::string fname,int nch, short int *data); - - /** (used by multi and sls) - * writes a short int raw data file - * @param outfile output file stream - * @param nch number of channels - * @param data array of data values - * @param offset start channel number - * @returns OK or FAIL if it could not write the file or data=NULL - */ - int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset=0) ; - - /** - * writes a data file of short ints - * @param fname of the file to be written - * @param data array of data values - * @returns OK or FAIL if it could not write the file or data=NULL - */ - int writeDataFile(std::string fname, short int *data){ - return writeDataFile(fname, getTotalNumberOfChannels(), data); - }; - - /** - * writes a data file of short ints - * @param outfile output file stream - * @param data array of data values - * @param offset start channel number - * @returns OK or FAIL if it could not write the file or data=NULL - */ - int writeDataFile(std::ofstream &outfile, short int *data, int offset=0){ - return writeDataFile(outfile, getTotalNumberOfChannels(), data, offset); - }; - - /** - * Loads the detector setup from file - * @param fname file to read from - * @param level if 2 reads also reads trimbits, angular conversion coefficients etc. - * from files with default extensions as generated by dumpDetectorSetup - * @returns OK or FAIL - */ - int retrieveDetectorSetup(std::string const fname, int level=0); - - void registerAcquisitionFinishedCallback(int( *func)(double,int, void*), void *pArg){acquisition_finished=func; acqFinished_p=pArg;}; - - void registerMeasurementFinishedCallback(int( *func)(int,int, void*), void *pArg){measurement_finished=func; measFinished_p=pArg;}; - - void registerProgressCallback(int( *func)(double,void*), void *pArg){progress_call=func; pProgressCallArg=pArg;}; - - static int dummyAcquisitionFinished(double prog,int status,void* p){std::cout <<"Acquisition finished callback! " << prog << " " << status << std::endl; return 0;} - - static int dummyMeasurementFinished(int im,int findex,void* p){std::cout <<"Measurement finished callback! " << im << " " << findex << std::endl; return 0;} protected: - int *stoppedFlag; - int64_t *timerValue; - detectorSettings *currentSettings; - int *currentThresholdEV; - 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; }; diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp index 0575e88da..393207b7a 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.cpp @@ -5,17 +5,11 @@ static void* startProcessData(void *n){ postProcessing *myDet=(postProcessing*)n; - myDet->processData(1); + myDet->processData(); pthread_exit(NULL); }; -static void* startProcessDataNoDelete(void *n){ - postProcessing *myDet=(postProcessing*)n; - myDet->processData(0); - pthread_exit(NULL); - -}; int postProcessing::kbhit(){ @@ -57,7 +51,7 @@ postProcessing::~postProcessing(){ } -void* postProcessing::processData(int delflag) { +void* postProcessing::processData() { if(setReceiverOnline()==OFFLINE_FLAG){ return 0; } //receiver @@ -138,7 +132,7 @@ void postProcessing::setJoinThread( int v) { -void postProcessing::startThread(int delflag) { +void postProcessing::startThread() { setTotalProgress(); @@ -164,11 +158,9 @@ void postProcessing::startThread(int delflag) { ret = pthread_setschedparam(pthread_self(), policy, &mparam); - if (delflag) + ret = pthread_create(&dataProcessingThread, &tattr,startProcessData, (void*)this); - else - ret = pthread_create(&dataProcessingThread, &tattr,startProcessDataNoDelete, (void*)this); - + if (ret) printf("ret %d\n", ret); diff --git a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h index 00de291cd..5b85d65ac 100644 --- a/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h +++ b/slsDetectorSoftware/slsDetectorAnalysis/postProcessing.h @@ -38,10 +38,9 @@ public: int setThreadedProcessing(int b=-1) {if (b>=0) *threadedProcessing=b; return *threadedProcessing;}; /** processes the data - \param delflag 0 leaves the data in the final data queue \returns nothing */ - void *processData(int delflag); + void *processData(); int checkJoinThread(); void setJoinThread(int v); @@ -62,7 +61,7 @@ protected: /** start data processing thread */ - void startThread(int delflag=1); + void startThread(); /** mutex to synchronize main and data processing threads */ pthread_mutex_t mp; diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index c48c40763..12d40316c 100644 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -14,6 +14,7 @@ set(SOURCES src/DataProcessor.cpp src/DataStreamer.cpp src/Fifo.cpp + ../commonFiles/utilities.cpp ) @@ -64,13 +65,14 @@ add_library(slsReceiverShared SHARED ) set(PUBLICHEADERS - ../commonfiles/sls_receiver_defs.h - ../commonfiles/ansi.h - ../commonfiles/sls_receiver_funcs.h - ../commonfiles/MySocketTCP.h - ../commonfiles/genericSocket.h - ../commonfiles/logger.h - ../commonfiles/sls_receiver_exceptions.h + ../commonFiles/sls_receiver_defs.h + ../commonFiles/ansi.h + ../commonFiles/sls_receiver_funcs.h + ../commonFiles/MySocketTCP.h + ../commonFiles/genericSocket.h + ../commonFiles/logger.h + ../commonFiles/sls_receiver_exceptions.h + ../commonFiles/utilities.h ) diff --git a/slsReceiverSoftware/Makefile b/slsReceiverSoftware/Makefile index e7895bcc3..527055b59 100644 --- a/slsReceiverSoftware/Makefile +++ b/slsReceiverSoftware/Makefile @@ -26,7 +26,7 @@ LIBZMQ = -L$(LIBZMQDIR) -Wl,-rpath=$(LIBZMQDIR) -lzmq -SRC_CLNT = MySocketTCP.cpp ThreadObject.cpp Listener.cpp DataProcessor.cpp DataStreamer.cpp Fifo.cpp File.cpp BinaryFile.cpp UDPInterface.cpp UDPBaseImplementation.cpp UDPStandardImplementation.cpp slsReceiverTCPIPInterface.cpp slsReceiver.cpp slsReceiverUsers.cpp utilities.cpp +SRC_CLNT = MySocketTCP.cpp ThreadObject.cpp Listener.cpp DataProcessor.cpp DataStreamer.cpp Fifo.cpp File.cpp BinaryFile.cpp UDPInterface.cpp UDPBaseImplementation.cpp UDPStandardImplementation.cpp slsReceiverTCPIPInterface.cpp slsReceiver.cpp slsReceiverUsers.cpp $(COMMONDIR)/utilities.cpp DEPSINCLUDES = $(COMMONDIR)/ansi.h $(COMMONDIR)/sls_receiver_defs.h $(COMMONDIR)/sls_receiver_funcs.h $(COMMONDIR)/GeneralData.h $(INCDIR)/circularFifo.h $(COMMONDIR)/genericSocket.h $(COMMONDIR)/logger.h $(INCDIR)/receiver_defs.h $(INCDIR)/UDPInterface.h $(COMMONDIR)/utilities.h $(COMMONDIR)/ZmqSocket.h $(INCDIR)/BinaryFileStatic.h $(INCDIR)/HDF5FileStatic.h $(COMMONDIR)/sls_receiver_exceptions.h