Compare commits

..

2 Commits

Author SHA1 Message Date
splitPoleDAQ 06f9191095 move the FIleIno and Group structure to fsuReader.h 2024-01-22 13:56:18 -05:00
splitPoleDAQ 80eb7cb56b bugs fix for EventBuilder. use 600 data size due to max event /agg is 511 2024-01-20 13:35:19 -05:00
6 changed files with 118 additions and 112 deletions

View File

@ -8,42 +8,7 @@
#include "TFile.h" #include "TFile.h"
#include "TTree.h" #include "TTree.h"
#define MAX_MULTI 100 #define MAX_MULTI 1000
#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<unsigned short> fileIDList;
uInt sn;
unsigned short currentID ; // the ID of the readerIDList;
ulong hitCount ; // this is the hitCount for the currentID;
uInt usedHitCount ;
bool finished;
};
//^############################################################# //^#############################################################
//^############################################################# //^#############################################################
@ -63,18 +28,13 @@ int main(int argc, char **argv) {
printf("\n"); printf("\n");
printf("=========================== Working flow\n"); printf("=========================== Working flow\n");
printf(" 1) Break down the fsu files into dual channel, save in tempFolder as *.fsu.X\n"); printf(" 1) Break down the fsu files into dual channel, save in tempFolder as *.fsu.X\n");
printf(" 1a) if the *.fsu file has trace, *.fsu.ts will also has trace.\n");
printf(" 2) Load the *.fsu.X files and do the event building\n"); printf(" 2) Load the *.fsu.X files and do the event building\n");
printf("\n\n"); printf("\n\n");
return 1; return 1;
} }
/// File format must be YYY...Y_runXXX_AAA_BBB_TT_CCC.fsu uInt runStartTime = get_time_us();
/// 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 ///============= read input
unsigned int timeWindow = atoi(argv[1]); unsigned int timeWindow = atoi(argv[1]);
@ -126,8 +86,16 @@ int main(int argc, char **argv) {
// file name format is expName_runID_SN_DPP_tick2ns_order.fsu // file name format is expName_runID_SN_DPP_tick2ns_order.fsu
for( int i = 0; i < nFile; i++){ for( int i = 0; i < nFile; i++){
printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile); printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile);
reader[i] = new FSUReader(inFileName[i].Data(), 1, false); reader[i] = new FSUReader(inFileName[i].Data(), 600, false);
if( !reader[i]->isOpen() ) continue;
if( !reader[i]->isOpen() ){
printf("------- cannot open file.\n");
continue;
}
if( reader[i]->GetFileByteSize() == 0 ){
printf("------- file size is ZERO.\n");
continue;
}
reader[i]->ScanNumBlock(false, 2); reader[i]->ScanNumBlock(false, 2);
@ -162,8 +130,17 @@ int main(int argc, char **argv) {
printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile); printf("Processing %s (%d/%d) ..... \n", inFileName[i].Data(), i+1, nFile);
reader[i] = new FSUTSReader(inFileName[i].Data(), false); reader[i] = new FSUTSReader(inFileName[i].Data(), false);
if( !reader[i]->isOpen() ){
printf("------- cannot open file.\n");
continue;
}
reader[i]->ScanFile(0); reader[i]->ScanFile(0);
if( reader[i]->GetNumHit() == 0 ){
printf("------- file has no data.\n");
continue;
}
FileInfo tempInfo; FileInfo tempInfo;
tempInfo.fileName = inFileName[i].Data(); tempInfo.fileName = inFileName[i].Data();
tempInfo.readerID = i; tempInfo.readerID = i;
@ -183,6 +160,8 @@ int main(int argc, char **argv) {
} }
nFile = (int) fileInfo.size();
std::sort(fileInfo.begin(), fileInfo.end(), [](const FileInfo& a, const FileInfo& b) { std::sort(fileInfo.begin(), fileInfo.end(), [](const FileInfo& a, const FileInfo& b) {
return a.ID < b.ID; return a.ID < b.ID;
}); });
@ -266,9 +245,7 @@ int main(int argc, char **argv) {
for( int i = 0; i < nGroup; i++){ for( int i = 0; i < nGroup; i++){
std::string fileName = fileInfo[group[i].fileIDList[0]].fileName; std::string fileName = fileInfo[group[i].fileIDList[0]].fileName;
tsReader[i] = new FSUTSReader(fileName); tsReader[i] = new FSUTSReader(fileName);
tsReader[i]->ScanFile(0);
tsReader[i]->ScanFile(1);
group[i].usedHitCount = 0; group[i].usedHitCount = 0;
} }
@ -281,6 +258,9 @@ int main(int argc, char **argv) {
ullong t0 = -1; ullong t0 = -1;
uShort gp0 = -1; uShort gp0 = -1;
ullong tStart = 0;
ullong tEnd = 0;
bool hasEvent = false; bool hasEvent = false;
for( int i = 0; i < nGroup; i++){ for( int i = 0; i < nGroup; i++){
@ -291,9 +271,6 @@ int main(int argc, char **argv) {
} }
if( debug ) printf("First timestamp is %llu, group : %u\n", t0, gp0); if( debug ) printf("First timestamp is %llu, group : %u\n", t0, gp0);
unsigned int maxUInt = -1;
do{ do{
if( debug ) printf("################################ ev build %llu \n", evID); if( debug ) printf("################################ ev build %llu \n", evID);
@ -301,14 +278,11 @@ int main(int argc, char **argv) {
///===================== check if the file is finished. ///===================== check if the file is finished.
for( int i = 0; i < nGroup; i++){ for( int i = 0; i < nGroup; i++){
uShort gpID = (i + gp0) % nGroup; uShort gpID = (i + gp0) % nGroup;
if( group[gpID].finished ) continue; if( group[gpID].finished ) continue;
short endCount = 0; short endCount = 0;
do{ 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 ){ if( tsReader[gpID]->ReadNextHit(traceOn, 0) == 0 ){
hitProcessed ++; hitProcessed ++;
if( debug ){ printf("............ Get Data | "); tsReader[gpID]->GetHit()->Print();} if( debug ){ printf("............ Get Data | "); tsReader[gpID]->GetHit()->Print();}
@ -317,6 +291,9 @@ int main(int argc, char **argv) {
if( tsReader[gpID]->GetHit()->timestamp - t0 <= timeWindow ) { if( tsReader[gpID]->GetHit()->timestamp - t0 <= timeWindow ) {
if( evID == 0) tStart = tsReader[gpID]->GetHit()->timestamp;
if( hitProcessed >= totHitCount ) tEnd = tsReader[gpID]->GetHit()->timestamp;
sn[multi] = tsReader[gpID]->GetHit()->sn; sn[multi] = tsReader[gpID]->GetHit()->sn;
ch[multi] = tsReader[gpID]->GetHit()->ch; ch[multi] = tsReader[gpID]->GetHit()->ch;
e[multi] = tsReader[gpID]->GetHit()->energy; e[multi] = tsReader[gpID]->GetHit()->energy;
@ -344,6 +321,10 @@ int main(int argc, char **argv) {
if( debug ){ printf("..Get Data after fill | "); tsReader[gpID]->GetHit()->Print();} if( debug ){ printf("..Get Data after fill | "); tsReader[gpID]->GetHit()->Print();}
} }
if( multi > MAX_MULTI) {
printf(" !!!!!! multi > %d\n", MAX_MULTI);
}
}else{ }else{
break; break;
} }
@ -367,7 +348,6 @@ int main(int argc, char **argv) {
printf("hit Porcessed %u/%u....%.2f%%\n\033[A\r", hitProcessed, totHitCount, hitProcessed*100./totHitCount); printf("hit Porcessed %u/%u....%.2f%%\n\033[A\r", hitProcessed, totHitCount, hitProcessed*100./totHitCount);
///===================== find the next first timestamp ///===================== find the next first timestamp
t0 = -1; t0 = -1;
gp0 = -1; gp0 = -1;
@ -420,8 +400,16 @@ int main(int argc, char **argv) {
tree->Write(); tree->Write();
uInt runEndTime = get_time_us();
double runTime = (runEndTime - runStartTime) * 1e-6;
printf("========================= finished.\n"); printf("========================= finished.\n");
printf("total events built = %llu(%llu)\n", evID, tree->GetEntriesFast()); printf(" event building time = %.2f sec = %.2f min\n", runTime, runTime/60.);
printf(" total events built = %llu by event builder (%llu in tree)\n", evID, tree->GetEntriesFast());
double tDuration_sec = (tEnd - tStart) * 1e-9;
printf(" first timestamp = %20llu ns\n", tStart);
printf(" last timestamp = %20llu ns\n", tEnd);
printf(" total data duration = %.2f sec = %.2f min\n", tDuration_sec, tDuration_sec/60.);
printf("=======> saved to %s \n", outFileName.Data()); printf("=======> saved to %s \n", outFileName.Data());
outRootFile->Close(); outRootFile->Close();

View File

@ -7,40 +7,7 @@
#include "TFile.h" #include "TFile.h"
#include "TTree.h" #include "TTree.h"
#define MAX_MULTI 10000 #define MAX_MULTI 1000
#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<unsigned short> 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;
};
//^############################################################# //^#############################################################
//^############################################################# //^#############################################################
@ -55,19 +22,16 @@ int main(int argc, char **argv) {
printf(" timeWindow : in ns \n"); printf(" timeWindow : in ns \n");
printf(" verbose : > 0 for debug \n"); printf(" verbose : > 0 for debug \n");
printf(" Output file name is contructed from inFile1 \n"); printf(" Output file name is contructed from inFile1 \n");
printf("\n");
printf("=========================== Working flow\n");
printf(" 1) Load all data into memories as vector and sort\n");
printf(" 2) Build event.\n");
printf("\n\n");
return 1; return 1;
} }
uInt runStartTime = get_time_us(); 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 ///============= read input
unsigned int timeWindow = atoi(argv[1]); unsigned int timeWindow = atoi(argv[1]);
//bool traceOn = atoi(argv[3]); //bool traceOn = atoi(argv[3]);
@ -104,9 +68,10 @@ int main(int argc, char **argv) {
printf("Processing %s (%d/%d) ..... \n\033[A\r", inFileName[i].Data(), i+1, nFile); printf("Processing %s (%d/%d) ..... \n\033[A\r", inFileName[i].Data(), i+1, nFile);
reader[i] = new FSUReader(inFileName[i].Data(), 50, 0); // the 1000 is expecting each agg, there are maximum 1000 hit/ch. reader[i] = new FSUReader(inFileName[i].Data(), 600, 0); // the 600 is expecting each agg, there are maximum 1000 hit/ch.
reader[i]->ScanNumBlock(1, 1); reader[i]->ScanNumBlock(1, 1);
// reader[i]->FillHitList();
reader[i]->GetData()->ClearDataPointer();
FileInfo tempInfo; FileInfo tempInfo;
tempInfo.fileName = inFileName[i]; tempInfo.fileName = inFileName[i];
@ -174,7 +139,6 @@ int main(int argc, char **argv) {
unsigned long long evID = 0; unsigned long long evID = 0;
unsigned int multi = 0; unsigned int multi = 0;
unsigned short sn[MAX_MULTI] = {0}; /// board SN unsigned short sn[MAX_MULTI] = {0}; /// board SN
//unsigned short bd[MAX_MULTI] = {0}; /// boardID
unsigned short ch[MAX_MULTI] = {0}; /// chID unsigned short ch[MAX_MULTI] = {0}; /// chID
unsigned short e[MAX_MULTI] = {0}; /// 15 bit unsigned short e[MAX_MULTI] = {0}; /// 15 bit
unsigned short e2[MAX_MULTI] = {0}; /// 15 bit unsigned short e2[MAX_MULTI] = {0}; /// 15 bit
@ -184,7 +148,6 @@ int main(int argc, char **argv) {
tree->Branch("evID", &evID, "event_ID/l"); tree->Branch("evID", &evID, "event_ID/l");
tree->Branch("multi", &multi, "multi/i"); tree->Branch("multi", &multi, "multi/i");
tree->Branch("sn", sn, "sn[multi]/s"); tree->Branch("sn", sn, "sn[multi]/s");
//tree->Branch("bd", bd, "bd[multi]/s");
tree->Branch("ch", ch, "ch[multi]/s"); tree->Branch("ch", ch, "ch[multi]/s");
tree->Branch("e", e, "e[multi]/s"); tree->Branch("e", e, "e[multi]/s");
tree->Branch("e2", e2, "e2[multi]/s"); tree->Branch("e2", e2, "e2[multi]/s");
@ -202,7 +165,6 @@ int main(int argc, char **argv) {
// arrayTrace->BypassStreamer(); // arrayTrace->BypassStreamer();
// } // }
//*====================================== build events //*====================================== build events
printf("================= Building events....\n"); printf("================= Building events....\n");
@ -241,7 +203,7 @@ int main(int argc, char **argv) {
group[gpID].hitID = 0; group[gpID].hitID = 0;
uShort rID = group[gpID].readerIDList[group[gpID].currentID]; uShort rID = group[gpID].readerIDList[group[gpID].currentID];
group[gpID].hitCount = reader[rID]->GetHitCount(); 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() );
} }
} }
@ -253,7 +215,7 @@ int main(int argc, char **argv) {
group0 = gpID; 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); printf("hit Porcessed %u/%u....%.2f%%\n\033[A\r", hitProcessed, totHitCount, hitProcessed*100./totHitCount);
@ -293,7 +255,7 @@ int main(int argc, char **argv) {
if( evID == 0) tStart = event.front().timestamp; if( evID == 0) tStart = event.front().timestamp;
if( multi > 0 ) { if( multi > 0 ) {
tEnd = event.back().timestamp; if( hitProcessed >= totHitCount ) tEnd = event.back().timestamp;
for( size_t j = 0; j < multi ; j++){ for( size_t j = 0; j < multi ; j++){
sn[j] = event[j].sn; sn[j] = event[j].sn;

View File

@ -3,6 +3,47 @@
#include <algorithm> #include <algorithm>
#include <filesystem> #include <filesystem>
#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<unsigned short> fileIDList;
uInt usedHitCount ;
std::vector<unsigned short> 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{ class FSUReader{
public: 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){ 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"); inFile = fopen(fileName.c_str(), "r");
if( inFile == NULL ){ if( inFile == NULL ){

View File

@ -30,6 +30,7 @@ class FSUTSReader{
std::string GetFileName() const {return fileName;} std::string GetFileName() const {return fileName;}
unsigned long GetFileByteSize() const {return inFileSize;} unsigned long GetFileByteSize() const {return inFileSize;}
unsigned int GetFilePos() const {return filePos;}
int GetFileOrder() const {return order;} int GetFileOrder() const {return order;}
uShort GetSN() const {return sn;} uShort GetSN() const {return sn;}
ullong GetT0() const {return t0;} ullong GetT0() const {return t0;}
@ -110,7 +111,7 @@ inline void FSUTSReader::OpenFile(std::string fileName, int verbose){
fseek(inFile, 0L, SEEK_END); fseek(inFile, 0L, SEEK_END);
inFileSize = ftell(inFile); 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); fseek(inFile, 0L, SEEK_SET);
filePos = 0; filePos = 0;

View File

@ -206,6 +206,8 @@ inline void Data::AllocateDataSize(uShort dataSize){
inline void Data::ClearDataPointer(){ inline void Data::ClearDataPointer(){
if( dataSize == 0) return;
for(int ch = 0; ch < numInputCh; ch++){ for(int ch = 0; ch < numInputCh; ch++){
delete [] Timestamp[ch] ; delete [] Timestamp[ch] ;
delete [] fineTime[ch]; delete [] fineTime[ch];

View File

@ -210,7 +210,11 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
bhAutoSetEventPulling = new QPushButton("Autoset Reading Conf.", this); bhAutoSetEventPulling = new QPushButton("Autoset Reading Conf.", this);
buttonLayout->addWidget(bhAutoSetEventPulling, rowID, 1); buttonLayout->addWidget(bhAutoSetEventPulling, rowID, 1);
connect(bhAutoSetEventPulling, &QPushButton::clicked, this, [=](){ digi[ID]->AutoSetDPPEventAggregation(); UpdateBoardAndChannelsStatus();}); connect(bhAutoSetEventPulling, &QPushButton::clicked, this, [=](){
SendLogMsg("Digi-" +QString::number(digi[ID]->GetSerialNumber()) + " : AutoSetDPPEventAggregation()");
digi[ID]->AutoSetDPPEventAggregation();
UpdateBoardAndChannelsStatus();
});
// bnSendSoftwareClockSyncSignal = new QPushButton("Send SW Clock-Sync Signal", this); // bnSendSoftwareClockSyncSignal = new QPushButton("Send SW Clock-Sync Signal", this);
// buttonLayout->addWidget(bnSendSoftwareClockSyncSignal, rowID, 1); // buttonLayout->addWidget(bnSendSoftwareClockSyncSignal, rowID, 1);