diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index 5e281a97e..867d67e6f 100644 --- a/slsDetectorSoftware/Makefile +++ b/slsDetectorSoftware/Makefile @@ -1,7 +1,7 @@ CFLAGS= -g -DC_ONLY -fPIC #FLAGS+= #-DVERBOSE -DVERYVERBOSE -DFLAGS= -g -DDACS_INT -DTHIS_PATH='"$(shell pwd)"' -DSLS_RECEIVER_FUNCTION_LIST $(shell root-config --cflags --glibs) -DMYROOT1 -DALLFILE #-DMYROOT1 `root-config --cflags --glibs` +DFLAGS= -g -DDACS_INT -DTHIS_PATH='"$(shell pwd)"' -DSLS_RECEIVER_FUNCTION_LIST $(shell root-config --cflags --glibs) -DMYROOT1 -DALLFILE #-DMYROOT1 `root-config --cflags --glibs` #ASM=$(shell echo "/lib/modules/`uname -r`/build/include") diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index d75a335f1..cf4fcf33a 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -86,7 +86,7 @@ public: 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"); + retval.append("Could not enable/disable data compression in receiver.\nThread creation failed or recompile code with MYROOT1 flag.\n"); diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index f22870fb5..3e7e5dd26 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -73,7 +73,6 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): thread_started(0), currentWriterThreadIndex(-1), totalListeningFrameCount(0), - commonModeSubtractionEnable(false), sfilefd(NULL), writerthreads_mask(0x0), listening_thread_running(0), @@ -110,19 +109,19 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): strcpy(savefilename,""); strcpy(filePath,""); strcpy(fileName,"run"); - cmSub = NULL; + for(int i=0;i(receiverdata[i], csize, sigma, sign, cmSub); - +#endif } @@ -723,12 +727,6 @@ int slsReceiverFunctionList::setupWriter(){ //reset writing thread variables packetsInFile=0; -#ifdef ALLFILE - for(int i=0;i DO_NOTHING){ //close - if(sfilefdAll[ithr]){ - fclose(sfilefdAll[ithr]); - sfilefdAll[ithr] = NULL; + if(sfilefd){ + fclose(sfilefd); + sfilefd = NULL; } //open file - if (NULL == (sfilefdAll[ithr] = fopen((const char *) (savefilename), "w"))){ + if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ cout << "Error: Could not create file " << savefilename << endl; return FAIL; } //setting buffer - setvbuf(sfilefdAll[ithr],NULL,_IOFBF,BUF_SIZE); + setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - cout << "File Created:" << savefilename << endl; - - //reset counters for each new file - if(packetsCaught){ - prevframenum = currframenum; - packetsInAllFile[ithr] = 0; - } -#endif - }else{ - - //create file name - if(frameIndexNeeded==-1) - sprintf(savefilename, "%s/%s_%d.raw", filePath,fileName,fileIndex); - else - sprintf(savefilename, "%s/%s_f%012d_%d.raw", filePath,fileName,(packetsCaught/packetsPerFrame),fileIndex); - - //if filewrite and we are allowed to write - if(enableFileWrite && cbAction > DO_NOTHING){ - //close - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; - } - //open file - if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ - cout << "Error: Could not create file " << savefilename << endl; - return FAIL; - } - //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + if(!dataCompression){ //printing packet losses and file names if(!packetsCaught) cout << savefilename << endl; @@ -896,13 +874,21 @@ int slsReceiverFunctionList::createNewFile(int ithr){ } } - - //reset counters for each new file - if(packetsCaught){ - prevframenum = currframenum; - packetsInFile = 0; + //data compression and dvpr flag allfile + else{ +#ifdef ALLFILE + cout << "File created:" << savefilename << endl; +#endif } + } + + //reset counters for each new file + if(packetsCaught){ + prevframenum = currframenum; + packetsInFile = 0; + } + return OK; } @@ -934,12 +920,12 @@ void slsReceiverFunctionList::closeFile(int ithr){ #ifdef ALLFILE //close file - if(sfilefdAll[ithr]){ + if(sfilefd){ #ifdef VERBOSE - cout << "sfield:" << (int)sfilefdAll[ithr] << endl; + cout << "sfield:" << (int)sfilefd << endl; #endif - fclose(sfilefdAll[ithr]); - sfilefdAll[ithr] = NULL; + fclose(sfilefd); + sfilefd = NULL; } #endif pthread_mutex_lock(&write_mutex); @@ -1471,10 +1457,15 @@ int slsReceiverFunctionList::startWriting(){ //data compression else{ -#ifdef MYROOT1 + #ifdef ALLFILE - writeToFile_withoutCompression(wbuf, numpackets,ithread); + writeToFile_withoutCompression(wbuf, numpackets); +#ifndef MYROOT1 + copyFrameToGui(wbuf + HEADER_SIZE_NUM_TOT_PACKETS); #endif +#endif + +#ifdef MYROOT1 eventType thisEvent = PEDESTAL; int ndata; char* buff = 0; @@ -1527,14 +1518,13 @@ int slsReceiverFunctionList::startWriting(){ } nf++; - +#ifndef ALLFILE pthread_mutex_lock(&progress_mutex); - packetsInFile += packetsPerFrame; packetsCaught += packetsPerFrame; totalPacketsCaught += packetsPerFrame; - pthread_mutex_unlock(&progress_mutex); +#endif if(!once){ copyFrameToGui(buff); once = 1; @@ -1547,13 +1537,12 @@ int slsReceiverFunctionList::startWriting(){ cout <<" **************ERROR SHOULD NOT COME HERE, Error 142536!"<push(wbuf)); #ifdef VERYVERBOSE cout<<"buf freed:"<<(void*)wbuf< 0){ - //for progress and packet loss calculation(new files) + offset = HEADER_SIZE_NUM_TOT_PACKETS; + while(numpackets > 0){ + + //for progress and packet loss calculation(new files) + if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + else + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + + if(numWriterThreads == 1) + currframenum = tempframenum; + else{ + if(tempframenum > currframenum) + currframenum = tempframenum; + } +#ifdef VERYDEBUG + cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; +#endif + + //lock + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + + + //to create new file when max reached + packetsToSave = maxPacketsPerFile - packetsInFile; + if(packetsToSave > numpackets) + packetsToSave = numpackets; + + fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); + packetsInFile += packetsToSave; + packetsCaught += packetsToSave; + totalPacketsCaught += packetsToSave; + + + //new file + if(packetsInFile >= maxPacketsPerFile){ + //for packet loss + lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -1654,118 +1670,32 @@ void slsReceiverFunctionList::writeToFile_withoutCompression(char* buf,int numpa #ifdef VERYDEBUG cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; #endif - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInAllFile[ithr]; - if(packetsToSave > numpackets) - packetsToSave = numpackets; - - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefdAll[ithr]); - packetsInAllFile[ithr] += packetsToSave; - - //new file - if(packetsInAllFile[ithr] >= maxPacketsPerFile){ - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - - - //for packet loss - if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - createNewFile(ithr); - } - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; + //create + createNewFile(); } - } - //no file write - else{ - packetsInAllFile[ithr] += numpackets; - } -#endif - } + //unlock + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); + + + offset += (packetsToSave * onePacketSize); + numpackets -= packetsToSave; + } + + } else{ - //file write - if((enableFileWrite) && (sfilefd)){ - - offset = HEADER_SIZE_NUM_TOT_PACKETS; - while(numpackets > 0){ - //for progress and packet loss calculation(new files) - if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - - //to create new file when max reached - packetsToSave = maxPacketsPerFile - packetsInFile; - if(packetsToSave > numpackets) - packetsToSave = numpackets; - - fwrite(buf+offset, 1, packetsToSave * onePacketSize, sfilefd); - packetsInFile += packetsToSave; - packetsCaught += packetsToSave; - totalPacketsCaught += packetsToSave; - - //new file - if(packetsInFile >= maxPacketsPerFile){ - lastpacket = (((packetsToSave - 1) * onePacketSize) + offset); - - //for packet loss - if ((myDetectorType == GOTTHARD) && (shortFrame == -1)) - tempframenum = (((((uint32_t)(*((uint32_t*)(buf + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); - else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); - - if(numWriterThreads == 1) - currframenum = tempframenum; - else{ - if(tempframenum > currframenum) - currframenum = tempframenum; - } -#ifdef VERYDEBUG - cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; -#endif - - createNewFile(ithr); - } - - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; - } - - } - else{ - packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; - } - + if(numWriterThreads > 1) + pthread_mutex_lock(&write_mutex); + packetsInFile += numpackets; + packetsCaught += numpackets; + totalPacketsCaught += numpackets; + if(numWriterThreads > 1) + pthread_mutex_unlock(&write_mutex); } + + } #endif diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h index 876e3bab5..325ad25dc 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h @@ -13,11 +13,10 @@ #include "genericSocket.h" #include "circularFifo.h" +#ifdef MYROOT1 #include "singlePhotonDetector.h" #include "slsReceiverData.h" #include "moenchCommonMode.h" - -#ifdef MYROOT1 #include #include #endif @@ -270,10 +269,9 @@ private: /** * Creates new file - * @param ithr thread number *\returns OK for succces or FAIL for failure */ - int createNewFile(int ithr = 0); + int createNewFile(); /** * Static function - Thread started which listens to packets. @@ -307,10 +305,9 @@ private: /** * Writing to file without compression * @param buf is the address of buffer popped out of fifo - * @param num - * @param ithr thread number + * @param numpackets is the number of packets */ - void writeToFile_withoutCompression(char* buf,int numpackets,int ithr = 0); + void writeToFile_withoutCompression(char* buf,int numpackets); @@ -487,14 +484,6 @@ private: int killAllWritingThreads; -//filter - singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; - - slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; - - moenchCommonMode *cmSub; - - bool commonModeSubtractionEnable; //semaphores @@ -519,8 +508,16 @@ private: /** mutex for writing data to file */ pthread_mutex_t write_mutex; + /** File Descriptor */ + FILE *sfilefd; #ifdef MYROOT1 + //filter + singlePhotonDetector *singlePhotonDet[MAX_NUM_WRITER_THREADS]; + slsReceiverData *receiverdata[MAX_NUM_WRITER_THREADS]; + moenchCommonMode *cmSub; + bool commonModeSubtractionEnable; + /** Tree where the hits are stored */ TTree *myTree[MAX_NUM_WRITER_THREADS]; @@ -528,17 +525,6 @@ private: TFile *myFile[MAX_NUM_WRITER_THREADS]; #endif - /** File Descriptor */ - FILE *sfilefd; - -#ifdef ALLFILE - /** File Descriptor */ - FILE *sfilefdAll[MAX_NUM_WRITER_THREADS]; - - /** Pckets currently in current file, starts new file when it reaches max for the current thread*/ - int packetsInAllFile[MAX_NUM_WRITER_THREADS]; -#endif - /** callback arguments are