From dd1f4ca250d4f6055531a3af4280b979d8495548 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Tue, 4 Mar 2014 09:34:04 +0000 Subject: [PATCH] flag for saving both compressed and normal files git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@746 951219d9-93cf-4727-9268-0efd64621fa3 --- slsDetectorSoftware/Makefile | 2 +- .../slsReceiver/slsReceiverFunctionList.cpp | 291 +++++++++++++----- .../slsReceiver/slsReceiverFunctionList.h | 12 +- 3 files changed, 219 insertions(+), 86 deletions(-) diff --git a/slsDetectorSoftware/Makefile b/slsDetectorSoftware/Makefile index dd8c7df1b..5e281a97e 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 #-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/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index 41763dac8..de347ab1c 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -114,7 +114,10 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): for(int i=0;i DO_NOTHING){ //close - if(sfilefd){ - fclose(sfilefd); - sfilefd = NULL; + if(sfilefdAll[ithr]){ + fclose(sfilefdAll[ithr]); + sfilefdAll[ithr] = NULL; } //open file - if (NULL == (sfilefd = fopen((const char *) (savefilename), "w"))){ + if (NULL == (sfilefdAll[ithr] = fopen((const char *) (savefilename), "w"))){ cout << "Error: Could not create file " << savefilename << endl; return FAIL; } //setting buffer - setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - //printing packet losses and file names - if(!packetsCaught) - cout << savefilename << endl; - else{ - cout << savefilename - << "\tpacket loss " - << setw(4)< 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); + //printing packet losses and file names + if(!packetsCaught) + cout << savefilename << endl; + else{ + cout << savefilename + << "\tpacket loss " + << setw(4)< 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(dataCompression){ +#ifdef ALLFILE + //file write + if((enableFileWrite) && (sfilefdAll[ithr])){ + 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 + lastpacket))))+1)& (frameIndexMask)) >> frameIndexOffset); + tempframenum = (((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))+1)& (frameIndexMask)) >> frameIndexOffset); else - tempframenum = ((((uint32_t)(*((uint32_t*)(buf + lastpacket))))& (frameIndexMask)) >> frameIndexOffset); + tempframenum = ((((uint32_t)(*((uint32_t*)(buf + HEADER_SIZE_NUM_TOT_PACKETS))))& (frameIndexMask)) >> frameIndexOffset); if(numWriterThreads == 1) currframenum = tempframenum; @@ -1625,18 +1653,115 @@ void slsReceiverFunctionList::writeToFile_withoutCompression(char* buf,int numpa cout << "tempframenum:" << dec << tempframenum << " curframenum:" << currframenum << endl; #endif - createNewFile(); + //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; + } + } + //no file write + else{ + packetsInAllFile[ithr] += numpackets; + } +#endif + } + + 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; } - offset += (packetsToSave * onePacketSize); - numpackets -= packetsToSave; } - } - //no file write - else{ - packetsInFile += numpackets; - packetsCaught += numpackets; - totalPacketsCaught += numpackets; + else{ + packetsInFile += numpackets; + packetsCaught += numpackets; + totalPacketsCaught += numpackets; + } + } } diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h index c78772878..876e3bab5 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.h @@ -270,9 +270,10 @@ private: /** * Creates new file + * @param ithr thread number *\returns OK for succces or FAIL for failure */ - int createNewFile(); + int createNewFile(int ithr = 0); /** * Static function - Thread started which listens to packets. @@ -307,8 +308,9 @@ private: * Writing to file without compression * @param buf is the address of buffer popped out of fifo * @param num + * @param ithr thread number */ - void writeToFile_withoutCompression(char* buf,int numpackets); + void writeToFile_withoutCompression(char* buf,int numpackets,int ithr = 0); @@ -529,7 +531,13 @@ private: /** 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 /**