EventBuilder2 can accept *.fsu.ts files

This commit is contained in:
splitPoleDAQ 2024-01-19 19:45:41 -05:00
parent 6da09f6232
commit bfd5f38def
3 changed files with 103 additions and 44 deletions

View File

@ -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,19 +106,22 @@ 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> fileInfo;
if( !isTSFiles ){
printf("######### All files are not time-sorted files\n");
///============= 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++){
@ -149,6 +152,37 @@ int main(int argc, char **argv) {
}
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);
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();
tempInfo.t0 = reader[i]->GetT0();;
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;
});

View File

@ -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.);
}
};

View File

@ -15,22 +15,24 @@ 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;}
@ -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<unsigned int> 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<std::string> 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);