diff --git a/Aux/EventBuilder2.cpp b/Aux/EventBuilder2.cpp index 942f535..d911be3 100644 --- a/Aux/EventBuilder2.cpp +++ b/Aux/EventBuilder2.cpp @@ -29,7 +29,7 @@ struct FileInfo { void CalOrder(){ ID = ORDERSHIFT * SN + order; } void Print(){ - printf(" %10lu | %3d | %50s | %2d | %6lu | %u Bytes = %.2f MB\n", + printf(" %10lu | %3d | %50s | %2d | %6lu | %10u Bytes = %.2f MB\n", ID, DPPType, fileName.c_str(), tick2ns, hitCount, fileSize, fileSize/1024./1024.); } }; @@ -106,48 +106,82 @@ int main(int argc, char **argv) { printf("===================================== Load the files\n"); //check if all input files is ts file; - // bool isTSFiles = false; - // int count = 0; - // for( int i = 0; i < nFile; i++){ - // FILE * temp = fopen(inFileName[i].Data(), "r"); - // uint32_t header; - // size_t dummy = fread(&header, 4, 1, temp); - // if( (header >> 24) != 0xAA ){ count++; } - // } - // if( count == nFile ) isTSFiles = true; + bool isTSFiles = false; + int count = 0; + for( int i = 0; i < nFile; i++){ + FILE * temp = fopen(inFileName[i].Data(), "r"); + uint32_t header; + fread(&header, 4, 1, temp); + if( (header >> 24) == 0xAA ) count++; + } + if( count == nFile ) isTSFiles = true; - ///============= sorting file by the serial number & order std::vector fileInfo; - FSUReader ** reader = new FSUReader*[nFile]; - // file name format is expName_runID_SN_DPP_tick2ns_order.fsu - for( int i = 0; i < nFile; i++){ - printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile); - reader[i] = new FSUReader(inFileName[i].Data(), 1, false); - if( !reader[i]->isOpen() ) continue; + if( !isTSFiles ){ + printf("######### All files are not time-sorted files\n"); - reader[i]->ScanNumBlock(false, 2); + ///============= sorting file by the serial number & order + FSUReader ** reader = new FSUReader*[nFile]; + // file name format is expName_runID_SN_DPP_tick2ns_order.fsu + for( int i = 0; i < nFile; i++){ + printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile); + reader[i] = new FSUReader(inFileName[i].Data(), 1, false); + if( !reader[i]->isOpen() ) continue; + + reader[i]->ScanNumBlock(false, 2); + + std::string outFileName = reader[i]->SaveHit2NewFile(tempFolder); + + FileInfo tempInfo; + tempInfo.fileName = outFileName; + tempInfo.readerID = i; + tempInfo.SN = reader[i]->GetSN(); + tempInfo.hitCount = reader[i]->GetHitCount(); + tempInfo.fileSize = reader[i]->GetTSFileSize(); + tempInfo.tick2ns = reader[i]->GetTick2ns(); + tempInfo.DPPType = reader[i]->GetDPPType(); + tempInfo.order = reader[i]->GetFileOrder(); + tempInfo.CalOrder(); + + tempInfo.t0 = reader[i]->GetHit(0).timestamp; + + fileInfo.push_back(tempInfo); + + delete reader[i]; + } + delete [] reader; + + }else{ + + printf("######### All files are time sorted files\n"); + + FSUTSReader ** reader = new FSUTSReader*[nFile]; + // file name format is expName_runID_SN_DPP_tick2ns_order.fsu + for( int i = 0; i < nFile; i++){ + printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile); + reader[i] = new FSUTSReader(inFileName[i].Data(), false); + + reader[i]->ScanFile(0); - std::string outFileName = reader[i]->SaveHit2NewFile(tempFolder); + FileInfo tempInfo; + tempInfo.fileName = inFileName[i].Data(); + tempInfo.readerID = i; + tempInfo.SN = reader[i]->GetSN(); + tempInfo.hitCount = reader[i]->GetNumHit(); + tempInfo.fileSize = reader[i]->GetFileByteSize(); + tempInfo.order = reader[i]->GetFileOrder(); + tempInfo.CalOrder(); - FileInfo tempInfo; - tempInfo.fileName = outFileName; - tempInfo.readerID = i; - tempInfo.SN = reader[i]->GetSN(); - tempInfo.hitCount = reader[i]->GetHitCount(); - tempInfo.fileSize = reader[i]->GetTSFileSize(); - tempInfo.tick2ns = reader[i]->GetTick2ns(); - tempInfo.DPPType = reader[i]->GetDPPType(); - tempInfo.order = reader[i]->GetFileOrder(); - tempInfo.CalOrder(); + tempInfo.t0 = reader[i]->GetT0();; - tempInfo.t0 = reader[i]->GetHit(0).timestamp; + fileInfo.push_back(tempInfo); + + delete reader[i]; + } + delete [] reader; - fileInfo.push_back(tempInfo); - - delete reader[i]; } - delete [] reader; std::sort(fileInfo.begin(), fileInfo.end(), [](const FileInfo& a, const FileInfo& b) { return a.ID < b.ID; diff --git a/Aux/EventBuilderNoTrace.cpp b/Aux/EventBuilderNoTrace.cpp index cdff7e9..91bfb54 100644 --- a/Aux/EventBuilderNoTrace.cpp +++ b/Aux/EventBuilderNoTrace.cpp @@ -26,7 +26,7 @@ struct FileInfo { void CalOrder(){ ID = ORDERSHIFT * SN + order; } void Print(){ - printf("%6d | %3d | %30s | %2d | %6lu | %u Bytes = %.2f MB\n", + printf("%6d | %3d | %50s | %2d | %6lu | %10u Bytes = %.2f MB\n", ID, DPPType, fileName.Data(), tick2ns, hitCount, fileSize, fileSize/1024./1024.); } }; diff --git a/Aux/fsutsReader.h b/Aux/fsutsReader.h index 5615986..dfd3972 100644 --- a/Aux/fsutsReader.h +++ b/Aux/fsutsReader.h @@ -15,23 +15,25 @@ class FSUTSReader{ public: FSUTSReader(); - FSUTSReader(std::string fileName, int verbose = true); + FSUTSReader(std::string fileName, int verbose = 1); ~FSUTSReader(); - void OpenFile(std::string fileName, int verbose = true); + void OpenFile(std::string fileName, int verbose = 1); bool isOpen() const{return inFile == nullptr ? false : true;} - void ScanFile(int verbose = true); + void ScanFile(int verbose = 1); int ReadNextHit(bool withTrace = true, int verbose = 0); int ReadHitAt(unsigned int ID, bool withTrace = true, int verbose = 0); - unsigned int GetHitID() const{return hitIndex;} - unsigned long GetNumHit() const{ return numHit;} + unsigned int GetHitID() const {return hitIndex;} + unsigned long GetNumHit() const {return numHit;} - std::string GetFileName() const{return fileName;} + std::string GetFileName() const {return fileName;} unsigned long GetFileByteSize() const {return inFileSize;} - int GetSN() const{return sn;} - + int GetFileOrder() const {return order;} + uShort GetSN() const {return sn;} + ullong GetT0() const {return t0;} + Hit* GetHit() const{return hit;} private: @@ -43,12 +45,15 @@ class FSUTSReader{ unsigned int filePos; unsigned long numHit; - ushort sn; + uShort sn; + int order; Hit* hit; unsigned int hitIndex; std::vector hitStartPos; + unsigned long long t0; + uint32_t header; size_t dummy; @@ -85,6 +90,24 @@ inline void FSUTSReader::OpenFile(std::string fileName, int verbose){ this->fileName = fileName; + std::string fileNameNoExt; + size_t found = fileName.find_last_of(".fsu.ts"); + size_t found2 = fileName.find_last_of('/'); + if( found2 == std::string::npos ){ + fileNameNoExt = fileName.substr(0, found-7); + }else{ + fileNameNoExt = fileName.substr(found2+1, found-7); + } + + // Split the string by underscores + std::istringstream iss(fileNameNoExt); + std::vector tokens; + std::string token; + + while (std::getline(iss, token, '_')) { tokens.push_back(token); } + sn = atoi(tokens[2].c_str()); + order = atoi(tokens[5].c_str()); + fseek(inFile, 0L, SEEK_END); inFileSize = ftell(inFile); if(verbose) printf("###### %s | file size : %ld Byte = %.2f MB\n", fileName.c_str() , inFileSize, inFileSize/1024./1024.); @@ -178,6 +201,8 @@ inline void FSUTSReader::ScanFile(int verbose){ while( ReadNextHit(false, verbose-1) == 0 ){ // no trace hitStartPos.push_back(filePos); + if( hitIndex == 0 ) t0 = hit->timestamp; + if(verbose > 1 ) printf("hitIndex : %u, Pos : %u - %u\n" , hitIndex, hitStartPos[hitIndex], hitStartPos[hitIndex+1]); if(verbose) printf(" %u, %.2f%% %u/%lu\n\033[A\r", hitIndex, filePos*100./inFileSize, filePos, inFileSize);