diff --git a/Aux/AggSeparator.cpp b/Aux/AggSeparator.cpp index b06d555..15eea37 100644 --- a/Aux/AggSeparator.cpp +++ b/Aux/AggSeparator.cpp @@ -14,9 +14,8 @@ #include #include -int main(int argc, char **argv) { - std::string inFileName = argv[1]; +int AggSeperator(std::string inFileName, short verbose = false){ FILE * file = fopen(inFileName.c_str(), "r"); @@ -25,16 +24,27 @@ int main(int argc, char **argv) { return -1; } + std::string folder = ""; + size_t found = inFileName.find_last_of('/'); + std::string fileName = inFileName; + if( found != std::string::npos ){ + folder = inFileName.substr(0, found + 1); + fileName = inFileName.substr(found +1 ); + } + + // printf(" folder : %s \n", folder.c_str()); + // printf("fileName : %s \n", fileName.c_str()); + char * buffer = nullptr; unsigned int word; // 4 bytes = 32 bits bool newFileFlag[8] = {true}; - while( !feof(file)){ + do{ size_t dummy = fread(&word, 4, 1, file); if( dummy != 1 ){ - printf("read file error. abort.\n"); + printf("End of File.\n"); break; } @@ -54,19 +64,19 @@ int main(int argc, char **argv) { dummy = fread(&word, 4, 1, file); unsigned int bdAggCounter = word; - printf("Agg counter : %u\n", bdAggCounter); + if( verbose ) printf("Agg counter : %u\n", bdAggCounter); dummy = fread(&word, 4, 1, file); unsigned int aggTimeTag = word; for( int chMask = 0; chMask < 8 ; chMask ++ ){ // the max numnber of Coupled/RegChannel is 8 for PHA, PSD, QDC if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue; - printf("==================== Dual/Group Channel Block, ch Mask : 0x%X\n", chMask *2); + if( verbose ) printf("==================== Dual/Group Channel Block, ch Mask : 0x%X\n", chMask *2); dummy = fread(&word, 4, 1, file); unsigned int dualChannelBlockSize = ( word & 0x7FFFFFFF ) * 4 ; - printf("dual channel size : %d words\n", dualChannelBlockSize / 4); + if( verbose ) printf("dual channel size : %d words\n", dualChannelBlockSize / 4); buffer = new char[dualChannelBlockSize]; fseek(file, -4, SEEK_CUR); @@ -75,10 +85,10 @@ int main(int argc, char **argv) { FILE * haha = nullptr; if( newFileFlag[chMask] ) { - haha = fopen( (inFileName + "." + std::to_string(chMask)).c_str(), "wb"); + haha = fopen( (fileName + "." + std::to_string(chMask )).c_str(), "wb"); newFileFlag[chMask] = false; }else{ - haha = fopen( (inFileName + "." + std::to_string(chMask)).c_str(), "a+"); + haha = fopen( (fileName + "." + std::to_string(chMask )).c_str(), "a+"); } fwrite(buffer, dualChannelBlockSize, 1, haha); @@ -87,12 +97,14 @@ int main(int argc, char **argv) { } - }; + }while( !feof(file)); + fclose(file); printf("======================= Duel channel seperated \n"); - return 0; + return 1; + } #endif \ No newline at end of file diff --git a/Aux/EventBuilderNoTrace.cpp b/Aux/EventBuilderNoTrace.cpp index 0dfa271..fbe0d72 100644 --- a/Aux/EventBuilderNoTrace.cpp +++ b/Aux/EventBuilderNoTrace.cpp @@ -9,7 +9,6 @@ #include "TTree.h" #define MAX_MULTI 100 -#define TIMEJUMP 1e8 // 0.1 sec or 10 Hz, any signal less than 10 Hz should increase the value. #define ORDERSHIFT 100000 diff --git a/Aux/fsuReader.h b/Aux/fsuReader.h index 4963767..9785035 100644 --- a/Aux/fsuReader.h +++ b/Aux/fsuReader.h @@ -117,11 +117,12 @@ inline void FSUReader::OpenFile(std::string fileName, bool verbose){ } std::string fileNameNoExt; + found = fileName.find_last_of(".fsu"); size_t found2 = fileName.find_last_of('/'); - if( found == std::string::npos ){ - fileNameNoExt = fileName.substr(0, found); + if( found2 == std::string::npos ){ + fileNameNoExt = fileName.substr(0, found-4); }else{ - fileNameNoExt = fileName.substr(found2+1, found); + fileNameNoExt = fileName.substr(found2+1, found-4); } // Split the string by underscores @@ -186,34 +187,6 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose,bool saveData){ data->DecodeBuffer(buffer, aggSize, fast, verbose); // data will own the buffer - if( saveData ){ - - for( int ch = 0; ch < data->GetNChannel(); ch++){ - if( data->NumEventsDecoded[ch] == 0 ) continue; - - int start = data->DataIndex[ch] - data->NumEventsDecoded[ch] + 1; - int stop = data->DataIndex[ch]; - - for( int i = start; i <= stop; i++ ){ - i = i % MaxNData; - - temp.sn = sn; - temp.ch = ch; - temp.energy = data->Energy[ch][i]; - temp.energy2 = data->Energy2[ch][i]; - temp.timestamp = data->Timestamp[ch][i]; - temp.fineTime = data->fineTime[ch][i]; - - hit.push_back(temp); - - numHit ++; - } - } - } - - data->ClearTriggerRate(); - data->ClearBuffer(); // this will clear the buffer. - }else if( (header & 0xF ) == 0x8 ) { /// dual channel header unsigned int dualSize = (word[0] & 0x7FFFFFFF) * 4; ///byte @@ -222,16 +195,42 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose,bool saveData){ filePos = ftell(inFile); data->buffer = buffer; - data->DecodeDualBlock(buffer, dualSize, DPPType, chMask, false, verbose); - data->ClearTriggerRate(); - data->ClearBuffer(); - + data->DecodeDualBlock(buffer, dualSize, DPPType, chMask, false, verbose); }else{ printf("incorrect header.\n trminate."); return -20; } + + if( saveData ){ + + for( int ch = 0; ch < data->GetNChannel(); ch++){ + if( data->NumEventsDecoded[ch] == 0 ) continue; + + int start = data->DataIndex[ch] - data->NumEventsDecoded[ch] + 1; + int stop = data->DataIndex[ch]; + + for( int i = start; i <= stop; i++ ){ + i = i % MaxNData; + + temp.sn = sn; + temp.ch = ch; + temp.energy = data->Energy[ch][i]; + temp.energy2 = data->Energy2[ch][i]; + temp.timestamp = data->Timestamp[ch][i]; + temp.fineTime = data->fineTime[ch][i]; + + hit.push_back(temp); + + numHit ++; + } + } + } + + data->ClearTriggerRate(); + data->ClearBuffer(); // this will clear the buffer. + return 0; }