diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 5b05ff71b..d75a335f1 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -29,6 +29,7 @@ using namespace std; #define FILE_PATH_DOES_NOT_EXIST 0x0400000000000000ULL #define COULDNOT_CREATE_UDP_SOCKET 0x0200000000000000ULL #define COULDNOT_CREATE_FILE 0x0100000000000000ULL +#define COULDNOT_ENABLE_COMPRESSION 0x0080000000000000ULL @@ -84,6 +85,9 @@ public: if(slsErrorMask&COULDNOT_CREATE_FILE) retval.append("Could not create file to start receiver.\nCheck permissions of output directory\n"); + if(slsErrorMask&COULDNOT_ENABLE_COMPRESSION) + retval.append("Could not enable/disable data compression in receiver.\nThread creation failed.\n"); + diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index 0b494bb96..9eabed1cb 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -134,7 +134,9 @@ enum { F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */ - F_READ_RECEIVER_FREQUENCY /**< sets the frequency of receiver sending frames to gui */ + F_READ_RECEIVER_FREQUENCY, /**< sets the frequency of receiver sending frames to gui */ + + F_ENABLE_COMPRESSION /**< enable compression in receiver */ /* Always append functions hereafter!!! */ }; diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 755ed343f..5b52c58c9 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -4734,3 +4734,17 @@ int multiSlsDetector::setReadReceiverFrequency(int getFromReceiver,int i){ +int multiSlsDetector::enableReceiverCompression(int i){ + int ret=-100,ret1; + for (int idet=0; idetnumberOfDetectors; idet++) + if (detectors[idet]){ + ret1=detectors[idet]->enableReceiverCompression(i); + if(detectors[idet]->getErrorMask()) + setErrorMask(getErrorMask()|(1<sendInt(fnum,retval,i); + if(ret==FAIL) + setErrorMask((getErrorMask())|(COULDNOT_ENABLE_COMPRESSION)); + } + return retval; +} + diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 219bc0bbf..fdfa0f70b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -1609,6 +1609,12 @@ class slsDetector : public slsDetectorUtils, public energyConversion { */ int setReadReceiverFrequency(int getFromReceiver, int i=-1); + /** enable/disable or get data compression in receiver + * @param i is -1 to get, 0 to disable and 1 to enable + /returns data compression in receiver + */ + int enableReceiverCompression(int i = -1); + protected: diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index 5b09c029d..9c22864e2 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -847,6 +847,11 @@ slsDetectorCommand::slsDetectorCommand(slsDetectorUtils *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; i++; + descrToFuncMap[i].m_pFuncName="r_compression"; // + descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdReceiver; + i++; + + numberOfCommands=i; // #ifdef VERBOSE @@ -4005,6 +4010,17 @@ string slsDetectorCommand::cmdReceiver(int narg, char *args[], int action) { sprintf(answer,"%d",myDet->setReadReceiverFrequency(1)); return string(answer); + } + else if(cmd=="r_compression"){ + if (action==PUT_ACTION){ + if (!sscanf(args[1],"%d",&ival)) + return string("Could not scan receiver compression input ")+string(args[1]); + if(ival>=0) + sprintf(answer,"%d",myDet->enableReceiverCompression(ival)); + }else + sprintf(answer,"%d",myDet->enableReceiverCompression()); + return string(answer); + } diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h index e80d8deed..ea8afd5b0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.h @@ -683,7 +683,11 @@ virtual ROI* getROI(int &n)=0; virtual int setReadReceiverFrequency(int getFromReceiver, int i=-1)=0; - +/** enable/disable or get data compression in receiver + * @param i is -1 to get, 0 to disable and 1 to enable + /returns data compression in receiver + */ +virtual int enableReceiverCompression(int i = -1)=0; protected: diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index f4d7e5d6d..a6edbbda1 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -77,6 +77,8 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): sfilefd(NULL), writerthreads_mask(0x0), listening_thread_running(0), + killListeningThread(0), + killAllWritingThreads(0), cbAction(DO_EVERYTHING), startAcquisitionCallBack(NULL), pStartAcquisition(NULL), @@ -317,8 +319,8 @@ int64_t slsReceiverFunctionList::setAcquisitionPeriod(int64_t index){ -/******************* need to look at exit strategy **************************/ -void slsReceiverFunctionList::enableDataCompression(bool enable){ + +int slsReceiverFunctionList::enableDataCompression(bool enable){ cout << "Data compression "; if(enable) cout << "enabled" << endl; @@ -341,13 +343,15 @@ void slsReceiverFunctionList::enableDataCompression(bool enable){ if(createWriterThreads() == FAIL){ cout << "ERROR: Could not create writer threads" << endl; - exit (-1); + return FAIL; } setThreadPriorities(); if(enable) setupFilter(); + + return OK; } @@ -583,15 +587,18 @@ int slsReceiverFunctionList::createUDPSocket(){ int slsReceiverFunctionList::createListeningThreads(bool destroy){ + void* status; + + killListeningThread = 0; + + pthread_mutex_lock(&status_mutex); + listening_thread_running = 0; + pthread_mutex_unlock(&(status_mutex)); if(!destroy){ - pthread_mutex_lock(&status_mutex); - listening_thread_running = 0; - pthread_mutex_unlock(&(status_mutex)); - //listening thread cout << "Creating Listening Thread" << endl; - sem_init(&listensmp,0,0); + sem_init(&listensmp,0,1); if(pthread_create(&listening_thread, NULL,startListeningThread, (void*) this)){ cout << "Could not create listening thread" << endl; return FAIL; @@ -601,11 +608,12 @@ int slsReceiverFunctionList::createListeningThreads(bool destroy){ #endif }else{ cout<<"Destroying Listening Thread"<pop(wbuf); numpackets = (uint16_t)(*((uint16_t*)wbuf)); #ifdef VERYDEBUG - cout << "numpackets:" << dec << numpackets << endl; - cout << ithread << "*** popped from fifo " << numpackets << endl; + cout << ithread << " numpackets:" << dec << numpackets << endl; + cout << ithread << " *** popped from fifo " << numpackets << endl; #endif @@ -1277,23 +1308,25 @@ int slsReceiverFunctionList::startWriting(){ //last dummy packet if(numpackets == 0xFFFF){ #ifdef VERYDEBUG - cout << "**********************popped last dummy frame:" << (void*)wbuf << " from thread " << ithread << endl; + cout << ithread << " **********************popped last dummy frame:" << (void*)wbuf << endl; #endif //free fifo while(!fifoFree->push(wbuf)); #ifdef VERYDEBUG - cout << "fifo freed:" << (void*)wbuf << " from thread " << ithread << endl; + cout << ithread << " fifo freed:" << (void*)wbuf << endl; #endif //all threads need to close file, reset mask and exit loop - pthread_mutex_lock(&status_mutex); + pthread_mutex_lock(&write_mutex); closeFile(ithread); + pthread_mutex_unlock(&write_mutex); + pthread_mutex_lock(&status_mutex); writerthreads_mask^=(1<getFrameNumber(buff); + pthread_mutex_lock(&write_mutex); myTree[ithread]->Fill(); + pthread_mutex_unlock(&write_mutex); //cout << "Fill in event: frmNr: " << iFrame << " ix " << ix << " iy " << iy << " type " << thisEvent << endl; } } @@ -1431,13 +1466,13 @@ int slsReceiverFunctionList::startWriting(){ nf++; - pthread_mutex_lock(&write_mutex); + pthread_mutex_lock(&progress_mutex); packetsInFile += packetsPerFrame; packetsCaught += packetsPerFrame; totalPacketsCaught += packetsPerFrame; - pthread_mutex_unlock(&write_mutex); + pthread_mutex_unlock(&progress_mutex); if(!once){ copyFrameToGui(buff); once = 1; @@ -1460,9 +1495,16 @@ int slsReceiverFunctionList::startWriting(){ } } + /*int k; + sem_getvalue(&writersmp[ithread],&k); + cout< *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + + moenchCommonMode *cmSub; + + bool commonModeSubtractionEnable; //semaphores @@ -477,6 +497,7 @@ private: /** semaphore to synchronize writer threads */ sem_t writersmp[MAX_NUM_WRITER_THREADS]; + //mutex /** guiDataReady mutex */ pthread_mutex_t dataReadyMutex; @@ -491,6 +512,20 @@ private: pthread_mutex_t write_mutex; +#ifdef MYROOT1 + /** Tree where the hits are stored */ + TTree *myTree[MAX_NUM_WRITER_THREADS]; + + /** File where the tree is saved */ + TFile *myFile[MAX_NUM_WRITER_THREADS]; +#endif + + /** File Descriptor */ + FILE *sfilefd; + + + + /** callback arguments are filepath @@ -533,34 +568,9 @@ private: * 2 we open, close, write file, callback does not do anything */ int cbAction; - //filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - - moenchCommonMode *cmSub; - - bool commonModeSubtractionEnable; public: -#ifdef MYROOT1 - /** Tree where the hits are stored */ - TTree *myTree[MAX_NUM_WRITER_THREADS]; - - /** File where the tree is saved */ - TFile *myFile[MAX_NUM_WRITER_THREADS]; -#endif - - - /** File Descriptor */ - FILE *sfilefd; - - /** mask showing which threads are running */ - volatile uint32_t writerthreads_mask; - - /** 0 if listening thread is idle, 1 otherwise */ - int listening_thread_running; /** callback arguments are diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp index aa073b9c8..341f0ced9 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.cpp @@ -24,9 +24,6 @@ int slsReceiverFuncs::socketDescriptor(-1); slsReceiverFuncs::~slsReceiverFuncs() { - /*if(file_des != -1){close(file_des);file_des = -1;} - //shutdown(socketDescriptor,SHUT_RDWR); - close(socketDescriptor);*/ if(socket) delete socket; closeFile(0); } @@ -45,7 +42,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): string sLine,sargname; int iline = 0; bool dcompr = false; - /*int jobthread = -1;*/ success=OK; @@ -115,9 +111,14 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): } } } - - - + //compression + else if(sargname=="compression"){ + if(sstr.good()) { + sstr >> sargname; + if((!strcasecmp(sargname.c_str(),"yes"))||(!strcasecmp(sargname.c_str(),"y"))) + dcompr = true; + } + } } } infile.close(); @@ -176,32 +177,15 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): cout << "no value given after -compression in command line. Exiting." << endl; success=FAIL; }else { - if(!strcasecmp(argv[iarg+1],"yes")){ + if((!strcasecmp(argv[iarg+1],"yes"))||(!strcasecmp(argv[iarg+1],"y"))){ dcompr = true; iarg++; - }else if(!strcasecmp(argv[iarg+1],"no")){ - dcompr = true; - iarg++; - }else{ + }else{ cout << "could not decode value for compression in command line. \n\nExiting." << endl; success=FAIL; } } } - /*//jobstothread - else if(!strcasecmp(argv[iarg],"-jobthread")){ - if(iarg+1==argc){ - cout << "no value given after -jobthread in command line. Exiting." << endl; - success=FAIL; - }else { - if(sscanf(argv[iarg+1],"%d",&jobthread)){ - iarg++; - }else{ - cout << "could not decode value for jobthread in command line. \n\nExiting." << endl; - success=FAIL; - } - } - }*/ else{ cout << "Unknown argument:" << argv[iarg] << endl; success=FAIL; @@ -232,7 +216,6 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): cout << "type:\t\t Type of receiver. Default: Gotthard. Options: Moench" << endl; cout << "rx_tcpport:\t TCP Communication Port with the client. Default:1954. " << endl; cout << "compression:\t Data Compression. Saving only hits. Option:yes, no" << endl << endl;; - /*cout << "jobthread:\t Number of jobs given to a thread for compression." << endl << endl;*/ } @@ -256,8 +239,8 @@ slsReceiverFuncs::slsReceiverFuncs(int argc, char *argv[], int &success): //Catch signal SIGINT to close files properly signal(SIGINT,staticCloseFile); - /*if(dcompr)*/ slsReceiverList->enableDataCompression(dcompr); - /*if(jobthread!=-1) slsReceiverList->setNumberOfJobsPerThread(jobthread);*/ + if(dcompr) + slsReceiverList->enableDataCompression(dcompr); #ifdef VERBOSE cout << "Function table assigned." << endl; @@ -326,7 +309,7 @@ int slsReceiverFuncs::function_table(){ flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame; flist[F_START_READOUT] = &slsReceiverFuncs::start_readout; flist[F_SET_TIMER] = &slsReceiverFuncs::set_acquisition_period; - + flist[F_ENABLE_COMPRESSION] = &slsReceiverFuncs::enable_compression; //General Functions flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver; @@ -405,7 +388,7 @@ void slsReceiverFuncs::closeFile(int p){ cout<<"Closing Files... "<closeFile(); cout << "Goodbye!" << endl; - exit(1); + exit(-1); } void slsReceiverFuncs::staticCloseFile(int p){ @@ -545,7 +528,7 @@ int slsReceiverFuncs::set_file_index() { // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_FUNCTION_LIST if (ret==OK) { - if (lockStatus==1 && socket->differentClients==1){//necessary??? + if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } @@ -598,7 +581,7 @@ int slsReceiverFuncs::set_frame_index() { // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_FUNCTION_LIST if (ret==OK) { - if (lockStatus==1 && socket->differentClients==1){//necessary??? + if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } @@ -655,7 +638,7 @@ int slsReceiverFuncs::setup_udp(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_FUNCTION_LIST if (ret==OK) { - if (lockStatus==1 && socket->differentClients==1){//necessary??? + if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } @@ -922,7 +905,7 @@ int slsReceiverFuncs::set_short_frame() { // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_FUNCTION_LIST if (ret==OK) { - if (lockStatus==1 && socket->differentClients==1){//necessary??? + if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } @@ -1301,7 +1284,7 @@ int slsReceiverFuncs::set_read_frequency(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_FUNCTION_LIST if (ret==OK) { - if (lockStatus==1 && socket->differentClients==1){//necessary??? + if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; }/* @@ -1351,7 +1334,7 @@ int slsReceiverFuncs::enable_file_write(){ // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_FUNCTION_LIST if (ret==OK) { - if (lockStatus==1 && socket->differentClients==1){//necessary??? + if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } @@ -1453,7 +1436,7 @@ int slsReceiverFuncs::set_acquisition_period() { // execute action if the arguments correctly arrived #ifdef SLS_RECEIVER_FUNCTION_LIST if (ret==OK) { - if (lockStatus==1 && socket->differentClients==1){//necessary??? + if (lockStatus==1 && socket->differentClients==1){ sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); ret=FAIL; } @@ -1488,6 +1471,53 @@ int slsReceiverFuncs::set_acquisition_period() { +int slsReceiverFuncs::enable_compression() { + ret=OK; + int enable=-1; + int retval=-100; + strcpy(mess,"Could not enable/disable compression for receiver\n"); + + // receive arguments + if(socket->ReceiveDataOnly(&enable,sizeof(enable)) < 0 ){ + strcpy(mess,"Error reading from socket\n"); + ret = FAIL; + } + + + // execute action if the arguments correctly arrived +#ifdef SLS_RECEIVER_FUNCTION_LIST + if (ret==OK) { + if(enable >= 0){ + if (lockStatus==1 && socket->differentClients==1){ + sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP); + ret=FAIL; + } + else if(slsReceiverList->getStatus()==RUNNING){ + strcpy(mess,"Cannot enable/disable compression while status is running\n"); + ret=FAIL; + } + else + ret = slsReceiverList->enableDataCompression(enable); + } + + retval=slsReceiverList->getDataCompression(); + } +#endif + + if(ret==OK && socket->differentClients){ + cout << "Force update" << endl; + ret=FORCE_UPDATE; + } + + // send answer + socket->SendDataOnly(&ret,sizeof(ret)); + if(ret==FAIL) + socket->SendDataOnly(mess,sizeof(mess)); + socket->SendDataOnly(&retval,sizeof(retval)); + + //return ok/fail + return ret; +} diff --git a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h index 33a6ed0b8..a8b8ae726 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiver_funcs.h @@ -154,6 +154,9 @@ public: /** set acquisition period to find the value of n */ int set_acquisition_period(); + /** enable compression */ + int enable_compression(); + //General Functions /** Locks Receiver */