diff --git a/Aux/EventBuilder.cpp b/Aux/EventBuilder.cpp index 604dc74..79e1624 100644 --- a/Aux/EventBuilder.cpp +++ b/Aux/EventBuilder.cpp @@ -8,42 +8,7 @@ #include "TFile.h" #include "TTree.h" -#define MAX_MULTI 100 - -#define ORDERSHIFT 100000 - -struct FileInfo { - std::string fileName; - unsigned int fileSize; - unsigned int SN; - unsigned long hitCount; - unsigned short DPPType; - unsigned short tick2ns; - unsigned short order; - unsigned short readerID; - - unsigned long long t0; - - unsigned long ID; // sn + 100000 * order - - void CalOrder(){ ID = ORDERSHIFT * SN + order; } - - void Print(){ - printf(" %10lu | %3d | %50s | %2d | %6lu | %10u Bytes = %.2f MB\n", - ID, DPPType, fileName.c_str(), tick2ns, hitCount, fileSize, fileSize/1024./1024.); - } -}; - -struct GroupInfo{ - - std::vector fileIDList; - uInt sn; - unsigned short currentID ; // the ID of the readerIDList; - ulong hitCount ; // this is the hitCount for the currentID; - uInt usedHitCount ; - bool finished; - -}; +#define MAX_MULTI 1000 //^############################################################# //^############################################################# @@ -71,14 +36,6 @@ int main(int argc, char **argv) { uInt runStartTime = get_time_us(); - /// File format must be YYY...Y_runXXX_AAA_BBB_TT_CCC.fsu - /// YYY...Y = prefix - /// XXX = runID, 3 digits - /// AAA = board Serial Number, 3 digits - /// BBB = DPPtype, 3 digits - /// TT = tick2ns, any digits - /// CCC = over size index, 3 digits - ///============= read input unsigned int timeWindow = atoi(argv[1]); bool traceOn = atoi(argv[2]); @@ -173,8 +130,17 @@ int main(int argc, char **argv) { printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile); reader[i] = new FSUTSReader(inFileName[i].Data(), false); + if( !reader[i]->isOpen() ){ + printf("------- cannot open file.\n"); + continue; + } reader[i]->ScanFile(0); - + + if( reader[i]->GetNumHit() == 0 ){ + printf("------- file has no data.\n"); + continue; + } + FileInfo tempInfo; tempInfo.fileName = inFileName[i].Data(); tempInfo.readerID = i; @@ -279,9 +245,7 @@ int main(int argc, char **argv) { for( int i = 0; i < nGroup; i++){ std::string fileName = fileInfo[group[i].fileIDList[0]].fileName; tsReader[i] = new FSUTSReader(fileName); - - tsReader[i]->ScanFile(1); - + tsReader[i]->ScanFile(0); group[i].usedHitCount = 0; } @@ -307,9 +271,6 @@ int main(int argc, char **argv) { } if( debug ) printf("First timestamp is %llu, group : %u\n", t0, gp0); - - unsigned int maxUInt = -1; - do{ if( debug ) printf("################################ ev build %llu \n", evID); @@ -317,14 +278,11 @@ int main(int argc, char **argv) { ///===================== check if the file is finished. for( int i = 0; i < nGroup; i++){ uShort gpID = (i + gp0) % nGroup; - if( group[gpID].finished ) continue; - short endCount = 0; - do{ - if( group[gpID].usedHitCount > tsReader[gpID]->GetHitID() || tsReader[gpID]->GetHitID() == maxUInt){ + if( group[gpID].usedHitCount > tsReader[gpID]->GetHitID() || tsReader[gpID]->GetFilePos() <= 4){ if( tsReader[gpID]->ReadNextHit(traceOn, 0) == 0 ){ hitProcessed ++; if( debug ){ printf("............ Get Data | "); tsReader[gpID]->GetHit()->Print();} @@ -363,6 +321,10 @@ int main(int argc, char **argv) { if( debug ){ printf("..Get Data after fill | "); tsReader[gpID]->GetHit()->Print();} } + if( multi > MAX_MULTI) { + printf(" !!!!!! multi > %d\n", MAX_MULTI); + } + }else{ break; } diff --git a/Aux/EventBuilderNoTrace.cpp b/Aux/EventBuilderNoTrace.cpp index b655130..e26864e 100644 --- a/Aux/EventBuilderNoTrace.cpp +++ b/Aux/EventBuilderNoTrace.cpp @@ -7,40 +7,7 @@ #include "TFile.h" #include "TTree.h" -#define MAX_MULTI 10000 - -#define ORDERSHIFT 100000 - -struct FileInfo { - TString fileName; - unsigned int fileSize; - unsigned int SN; - unsigned long hitCount; - unsigned short DPPType; - unsigned short tick2ns; - unsigned short order; - unsigned short readerID; - - unsigned long ID; // sn + 100000 * order - - void CalOrder(){ ID = ORDERSHIFT * SN + order; } - - void Print(){ - printf(" %10lu | %3d | %50s | %2d | %6lu | %10u Bytes = %.2f MB\n", - ID, DPPType, fileName.Data(), tick2ns, hitCount, fileSize, fileSize/1024./1024.); - } -}; - -struct GroupInfo{ - - std::vector readerIDList; - uInt sn; - unsigned short currentID ; // the ID of the readerIDList; - ulong hitCount ; // this is the hitCount for the currentID; - ulong hitID ; // this is the ID for the reader->GetHit(hitID); - bool finished; - -}; +#define MAX_MULTI 1000 //^############################################################# //^############################################################# @@ -64,14 +31,6 @@ int main(int argc, char **argv) { } uInt runStartTime = get_time_us(); - - /// File format must be YYY...Y_runXXX_AAA_BBB_TT_CCC.fsu - /// YYY...Y = prefix - /// XXX = runID, 3 digits - /// AAA = board Serial Number, 3 digits - /// BBB = DPPtype, 3 digits - /// TT = tick2ns, any digits - /// CCC = over size index, 3 digits ///============= read input unsigned int timeWindow = atoi(argv[1]); @@ -180,7 +139,6 @@ int main(int argc, char **argv) { unsigned long long evID = 0; unsigned int multi = 0; unsigned short sn[MAX_MULTI] = {0}; /// board SN - //unsigned short bd[MAX_MULTI] = {0}; /// boardID unsigned short ch[MAX_MULTI] = {0}; /// chID unsigned short e[MAX_MULTI] = {0}; /// 15 bit unsigned short e2[MAX_MULTI] = {0}; /// 15 bit @@ -190,7 +148,6 @@ int main(int argc, char **argv) { tree->Branch("evID", &evID, "event_ID/l"); tree->Branch("multi", &multi, "multi/i"); tree->Branch("sn", sn, "sn[multi]/s"); - //tree->Branch("bd", bd, "bd[multi]/s"); tree->Branch("ch", ch, "ch[multi]/s"); tree->Branch("e", e, "e[multi]/s"); tree->Branch("e2", e2, "e2[multi]/s"); @@ -208,7 +165,6 @@ int main(int argc, char **argv) { // arrayTrace->BypassStreamer(); // } - //*====================================== build events printf("================= Building events....\n"); @@ -247,7 +203,7 @@ int main(int argc, char **argv) { group[gpID].hitID = 0; uShort rID = group[gpID].readerIDList[group[gpID].currentID]; group[gpID].hitCount = reader[rID]->GetHitCount(); - printf("-----> go to the next file, %s \n", fileInfo[rID].fileName.Data() ); + printf("-----> go to the next file, %s \n", fileInfo[rID].fileName.c_str() ); } } @@ -259,7 +215,7 @@ int main(int argc, char **argv) { group0 = gpID; } } - if (debug ) printf("the eariliest time is %llu at Group : %u, hitID : %lu, %s\n", t0, group0, group[group0].hitID, fileInfo[group[group0].currentID].fileName.Data()); + if (debug ) printf("the eariliest time is %llu at Group : %u, hitID : %lu, %s\n", t0, group0, group[group0].hitID, fileInfo[group[group0].currentID].fileName.c_str()); printf("hit Porcessed %u/%u....%.2f%%\n\033[A\r", hitProcessed, totHitCount, hitProcessed*100./totHitCount); diff --git a/Aux/fsuReader.h b/Aux/fsuReader.h index d5dc155..9b0b505 100644 --- a/Aux/fsuReader.h +++ b/Aux/fsuReader.h @@ -3,6 +3,47 @@ #include #include +#define ORDERSHIFT 100000 + +struct FileInfo { + std::string fileName; + unsigned int fileSize; + unsigned int SN; + unsigned long hitCount; + unsigned short DPPType; + unsigned short tick2ns; + unsigned short order; + unsigned short readerID; + + unsigned long long t0; + + unsigned long ID; // sn + 100000 * order + + void CalOrder(){ ID = ORDERSHIFT * SN + order; } + + void Print(){ + printf(" %10lu | %3d | %50s | %2d | %6lu | %10u Bytes = %.2f MB\n", + ID, DPPType, fileName.c_str(), tick2ns, hitCount, fileSize, fileSize/1024./1024.); + } +}; + +struct GroupInfo{ + + std::vector fileIDList; + uInt usedHitCount ; + + std::vector readerIDList; + ulong hitID ; // this is the ID for the reader->GetHit(hitID); + + unsigned short currentID ; // the ID of the readerIDList; + ulong hitCount ; // this is the hitCount for the currentID; + uInt sn; + bool finished; + + unsigned long long timeShift; + +}; + class FSUReader{ public: @@ -107,6 +148,14 @@ inline FSUReader::FSUReader(std::string fileName, uShort dataSize, int verbose){ inline void FSUReader::OpenFile(std::string fileName, uShort dataSize, int verbose){ + /// File format must be YYY...Y_runXXX_AAA_BBB_TT_CCC.fsu + /// YYY...Y = prefix + /// XXX = runID, 3 digits + /// AAA = board Serial Number, 3 digits + /// BBB = DPPtype, 3 digits + /// TT = tick2ns, any digits + /// CCC = over size index, 3 digits + inFile = fopen(fileName.c_str(), "r"); if( inFile == NULL ){ diff --git a/Aux/fsutsReader.h b/Aux/fsutsReader.h index 11e5391..ec57531 100644 --- a/Aux/fsutsReader.h +++ b/Aux/fsutsReader.h @@ -30,6 +30,7 @@ class FSUTSReader{ std::string GetFileName() const {return fileName;} unsigned long GetFileByteSize() const {return inFileSize;} + unsigned int GetFilePos() const {return filePos;} int GetFileOrder() const {return order;} uShort GetSN() const {return sn;} ullong GetT0() const {return t0;} @@ -110,7 +111,7 @@ inline void FSUTSReader::OpenFile(std::string fileName, int verbose){ 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.); + if(verbose) printf("###### %50s | %11ld Byte = %.2f MB\n", fileName.c_str() , inFileSize, inFileSize/1024./1024.); fseek(inFile, 0L, SEEK_SET); filePos = 0;