added EventBuilder2.cpp, modified fsuReader

This commit is contained in:
splitPoleDAQ 2024-01-18 18:55:37 -05:00
parent ec5470a372
commit c38f4ae401
9 changed files with 501 additions and 74 deletions

2
.gitignore vendored
View File

@ -5,8 +5,8 @@ FSUDAQ_Qt6
test test
test_indep test_indep
programSettings.txt programSettings.txt
EventKenshikushi
EventBuilder EventBuilder
EventBuilder2
EventBuilderNoTrace EventBuilderNoTrace
EventBuilder_sortTime EventBuilder_sortTime
DataGenerator DataGenerator

View File

@ -14,14 +14,21 @@
#include <vector> #include <vector>
#include <sys/stat.h> #include <sys/stat.h>
#define NumCoupledChannel 8 // the max numnber of Coupled/RegChannel is 8 for PHA, PSD, QDC
int AggSeperator(std::string inFileName, short verbose = false){
std::vector<std::string> AggSeperator(std::string inFileName, std::string saveFolder = "./", short verbose = false){
printf("================ AggSeperator \n");
std::vector<std::string> outputFileList;
outputFileList.clear();
FILE * file = fopen(inFileName.c_str(), "r"); FILE * file = fopen(inFileName.c_str(), "r");
if( file == NULL ) { if( file == NULL ) {
printf("file : %s cannot be open. exit program.\n", inFileName.c_str()); printf("file : %s cannot be open. exit program.\n", inFileName.c_str());
return -1; return outputFileList;
} }
std::string folder = ""; std::string folder = "";
@ -32,19 +39,28 @@ int AggSeperator(std::string inFileName, short verbose = false){
fileName = inFileName.substr(found +1 ); fileName = inFileName.substr(found +1 );
} }
// printf(" folder : %s \n", folder.c_str()); if( saveFolder.empty() ) saveFolder = "./";
// printf("fileName : %s \n", fileName.c_str()); if( saveFolder.back() != '/') saveFolder += '/';
printf(" fileName : %s \n", fileName.c_str());
printf(" folder : %s \n", folder.c_str());
printf(" save folder : %s\n", saveFolder.c_str());
char * buffer = nullptr; char * buffer = nullptr;
unsigned int word; // 4 bytes = 32 bits unsigned int word; // 4 bytes = 32 bits
bool newFileFlag[8] = {true}; bool newFileFlag[NumCoupledChannel];
for( int i = 0; i < NumCoupledChannel; i++){
newFileFlag[i] = true;
outputFileList.push_back( saveFolder + fileName + "." + std::to_string(i));
}
do{ do{
size_t dummy = fread(&word, 4, 1, file); size_t dummy = fread(&word, 4, 1, file);
if( dummy != 1 ){ if( dummy != 1 ){
printf("End of File.\n"); printf("=====> End of File.\n");
break; break;
} }
@ -53,12 +69,12 @@ int AggSeperator(std::string inFileName, short verbose = false){
printf("header error. abort.\n"); printf("header error. abort.\n");
break; break;
} }
unsigned int aggSize = (word & 0x0FFFFFFF) * 4; ///byte //unsigned int aggSize = (word & 0x0FFFFFFF) * 4; ///byte
dummy = fread(&word, 4, 1, file); dummy = fread(&word, 4, 1, file);
unsigned int BoardID = ((word >> 27) & 0x1F); //unsigned int BoardID = ((word >> 27) & 0x1F);
unsigned short pattern = ((word >> 8 ) & 0x7FFF ); //unsigned short pattern = ((word >> 8 ) & 0x7FFF );
bool BoardFailFlag = ((word >> 26) & 0x1 ); //bool BoardFailFlag = ((word >> 26) & 0x1 );
unsigned int ChannelMask = ( word & 0xFF ) ; unsigned int ChannelMask = ( word & 0xFF ) ;
dummy = fread(&word, 4, 1, file); dummy = fread(&word, 4, 1, file);
@ -67,11 +83,11 @@ int AggSeperator(std::string inFileName, short verbose = false){
if( verbose ) printf("Agg counter : %u\n", bdAggCounter); if( verbose ) printf("Agg counter : %u\n", bdAggCounter);
dummy = fread(&word, 4, 1, file); dummy = fread(&word, 4, 1, file);
unsigned int aggTimeTag = word; //unsigned int aggTimeTag = word;
for( int chMask = 0; chMask < 8 ; chMask ++ ){ // the max numnber of Coupled/RegChannel is 8 for PHA, PSD, QDC for( int chMask = 0; chMask < NumCoupledChannel ; chMask ++ ){
if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue; if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue;
if( verbose ) printf("==================== Dual/Group Channel Block, ch Mask : 0x%X\n", chMask *2); if( verbose ) printf("==================== Dual/Group Channel Block, ch Mask : 0x%X (%d)\n", chMask *2, chMask );
dummy = fread(&word, 4, 1, file); dummy = fread(&word, 4, 1, file);
unsigned int dualChannelBlockSize = ( word & 0x7FFFFFFF ) * 4 ; unsigned int dualChannelBlockSize = ( word & 0x7FFFFFFF ) * 4 ;
@ -85,10 +101,10 @@ int AggSeperator(std::string inFileName, short verbose = false){
FILE * haha = nullptr; FILE * haha = nullptr;
if( newFileFlag[chMask] ) { if( newFileFlag[chMask] ) {
haha = fopen( (fileName + "." + std::to_string(chMask )).c_str(), "wb"); haha = fopen( outputFileList[chMask].c_str(), "wb");
newFileFlag[chMask] = false; newFileFlag[chMask] = false;
}else{ }else{
haha = fopen( (fileName + "." + std::to_string(chMask )).c_str(), "a+"); haha = fopen( outputFileList[chMask].c_str(), "a+");
} }
fwrite(buffer, dualChannelBlockSize, 1, haha); fwrite(buffer, dualChannelBlockSize, 1, haha);
@ -101,9 +117,13 @@ int AggSeperator(std::string inFileName, short verbose = false){
fclose(file); fclose(file);
printf("======================= Duel channel seperated \n"); printf("======================= Duel channels seperated \n");
return 1; for( int i = NumCoupledChannel -1 ; i >= 0 ; i--){
if( newFileFlag[i] == true ) outputFileList.erase(outputFileList.begin() + i );
}
return outputFileList;
} }

View File

@ -38,11 +38,12 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
/// File format must be YYY...Y_runXXX_AAA_BBB_CCC.fsu /// File format must be YYY...Y_runXXX_AAA_BBB_TT_CCC.fsu
/// YYY...Y = prefix /// YYY...Y = prefix
/// XXX = runID, 3 digits /// XXX = runID, 3 digits
/// AAA = board Serial Number, 3 digits /// AAA = board Serial Number, 3 digits
/// BBB = DPPtype, 3 digits /// BBB = DPPtype, 3 digits
/// TT = tick2ns, any digits
/// CCC = over size index, 3 digits /// CCC = over size index, 3 digits
///============= read input ///============= read input
@ -166,7 +167,6 @@ int main(int argc, char **argv) {
unsigned long long evID = -1; unsigned long long evID = -1;
unsigned short multi = 0; unsigned short 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
@ -176,7 +176,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/s"); tree->Branch("multi", &multi, "multi/s");
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");
@ -336,7 +335,6 @@ int main(int argc, char **argv) {
} }
evID ++; evID ++;
for( int j = 0; j < multi; j ++){ for( int j = 0; j < multi; j ++){
bd[j] = mb->events[k][j].bd;
sn[j] = mb->events[k][j].sn; sn[j] = mb->events[k][j].sn;
ch[j] = mb->events[k][j].ch; ch[j] = mb->events[k][j].ch;
e[j] = mb->events[k][j].energy; e[j] = mb->events[k][j].energy;
@ -383,7 +381,6 @@ int main(int argc, char **argv) {
} }
evID ++; evID ++;
for( int j = 0; j < multi; j ++){ for( int j = 0; j < multi; j ++){
bd[j] = mb->events[k][j].bd;
sn[j] = mb->events[k][j].sn; sn[j] = mb->events[k][j].sn;
ch[j] = mb->events[k][j].ch; ch[j] = mb->events[k][j].ch;
e[j] = mb->events[k][j].energy; e[j] = mb->events[k][j].energy;

404
Aux/EventBuilder2.cpp Normal file
View File

@ -0,0 +1,404 @@
#include "fsuReader.h"
#include "AggSeparator.h"
#include "../MultiBuilder.h"
#include <chrono>
#include "TROOT.h"
#include "TSystem.h"
#include "TClonesArray.h"
#include "TGraph.h"
#include "TFile.h"
#include "TTree.h"
#define MAX_MULTI 100
#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;
int chMask;
long ID;
void CalOrder(){ ID = ORDERSHIFT * SN + 10 * order + (chMask == -1 ? 0 : chMask); }
void Print(){
printf("%6ld | %3d | %30s | %2d | %6lu | %u Bytes = %.2f MB\n",
ID, DPPType, fileName.Data(), tick2ns, hitCount, fileSize, fileSize/1024./1024.);
}
};
struct GroupInfo{
std::vector<unsigned short> readerIDList;
uInt sn;
int chMask;
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);
uShort DPPType;
bool finished;
};
unsigned long long getTime_ns(){
std::chrono::high_resolution_clock::time_point currentTime = std::chrono::high_resolution_clock::now();
std::chrono::nanoseconds nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime.time_since_epoch());
return nanoseconds.count();
}
//^#############################################################
//^#############################################################
int main(int argc, char **argv) {
printf("=========================================\n");
printf("=== *.fsu Events Builder ===\n");
printf("=========================================\n");
if (argc <= 3) {
printf("Incorrect number of arguments:\n");
printf("%s [timeWindow] [withTrace] [verbose] [tempFolder] [inFile1] [inFile2] .... \n", argv[0]);
printf(" timeWindow : in ns \n");
printf(" withTrace : 0 for no trace, 1 for trace \n");
printf(" verbose : > 0 for debug \n");
printf(" tempFolder : temperary folder for file breakdown \n");
printf(" Output file name is contructed from inFile1 \n");
printf("\n");
printf("=========================== Working flow\n");
printf(" 1) Break down the fsu files into dual channel, save in tempFolder as *.fsu.X\n");
printf(" 2) Load the *.fsu.X files and do the event building\n");
printf("\n\n");
return 1;
}
/// 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]);
unsigned int debug = atoi(argv[3]);
std::string tempFolder = argv[4];
int nFile = argc - 5;
TString inFileName[nFile];
for( int i = 0 ; i < nFile ; i++){ inFileName[i] = argv[i+5];}
/// Form outFileName;
TString outFileName = inFileName[0];
int pos = outFileName.Index("_");
pos = outFileName.Index("_", pos+1);
outFileName.Remove(pos);
outFileName += ".root";
printf("-------> Out file name : %s \n", outFileName.Data());
printf(" Number of Files : %d \n", nFile);
for( int i = 0; i < nFile; i++) printf("%2d | %s \n", i, inFileName[i].Data());
printf("=====================================\n");
printf(" Time Window = %u ns = %.1f us\n", timeWindow, timeWindow/1000.);
//printf(" Buffer size = %.0f event/channel\n", MaxNData * bufferSize);
printf("===================================== Breaking down files\n");
std::vector<std::string> tempFileList;
for( int i = 0; i < nFile; i++){
std::vector<std::string> haha = AggSeperator(inFileName[i].Data(), tempFolder);
tempFileList.insert(tempFileList.end(), haha.begin(), haha.end()) ;
}
///========================================
printf("===================================== Load the files\n");
nFile = tempFileList.size();
///============= sorting file by the serial number & order
std::vector<FileInfo> 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\033[A\r", tempFileList[i].c_str(), i+1, nFile);
reader[i] = new FSUReader(tempFileList[i], false);
if( !reader[i]->isOpen() ) continue;
reader[i]->ScanNumBlock(false, 0); //not saving data
// reader[i]->FillHitList();
FileInfo tempInfo;
tempInfo.fileName = tempFileList[i];
tempInfo.readerID = i;
tempInfo.SN = reader[i]->GetSN();
tempInfo.hitCount = reader[i]->GetHitCount();
tempInfo.fileSize = reader[i]->GetFileByteSize();
tempInfo.tick2ns = reader[i]->GetTick2ns();
tempInfo.DPPType = reader[i]->GetDPPType();
tempInfo.order = reader[i]->GetFileOrder();
tempInfo.chMask = reader[i]->GetChMask();
tempInfo.CalOrder();
fileInfo.push_back(tempInfo);
}
std::sort(fileInfo.begin(), fileInfo.end(), [](const FileInfo& a, const FileInfo& b) {
return a.ID < b.ID;
});
unsigned int totHitCount = 0;
for( int i = 0 ; i < nFile; i++){
printf("%d |", i);
fileInfo[i].Print();
totHitCount += fileInfo[i].hitCount;
//printf(" %30s | ID %10ld \n", fileInfo[i].fileName.Data(), fileInfo[i].ID);
}
printf("----- total number of hit : %u.\n", totHitCount);
//*======================================= Sort files into groups
std::vector<GroupInfo> group; // group by SN and chMask
for( int i = 0; i < nFile; i++){
if( i == 0 || group.back().sn != fileInfo[i].SN || group.back().chMask != fileInfo[i].chMask ){
group.push_back(GroupInfo());
group.back().readerIDList.push_back(fileInfo[i].readerID); // an empty struct
group.back().currentID = 0;
group.back().hitCount = fileInfo[i].hitCount;
group.back().hitID = 0;
group.back().sn = fileInfo[i].SN;
group.back().chMask = fileInfo[i].chMask;
group.back().DPPType = fileInfo[i].DPPType;
group.back().finished = false;
}else{
group.back().readerIDList.push_back(fileInfo[i].readerID);
}
}
int nGroup = group.size();
printf("===================================== number of file Group by digitizer %d.\n", nGroup);
for( int i = 0; i < nGroup; i++){
printf(" Digi-%d, chMask-%d, DPPType: %d \n", group[i].sn, group[i].chMask, reader[group[i].readerIDList[0]]->GetDPPType());
for( int j = 0; j< (int) group[i].readerIDList.size(); j++){
uShort rID = group[i].readerIDList[j];
printf(" %s \n", reader[rID]->GetFileName().c_str());
//uLong hitCount = reader[rID]->GetHitCount();
//for( uLong k = 0; k < (hitCount < 5 ? hitCount : 5); k++){ reader[rID]->GetHit(k).Print();}
}
}
// //*====================================== create tree
TFile * outRootFile = new TFile(outFileName, "recreate");
TTree * tree = new TTree("tree", outFileName);
unsigned long long evID = -1;
unsigned short multi = 0;
unsigned short sn[MAX_MULTI] = {0}; /// board SN
unsigned short ch[MAX_MULTI] = {0}; /// chID
unsigned short e[MAX_MULTI] = {0}; /// 15 bit
unsigned short e2[MAX_MULTI] = {0}; /// 15 bit
unsigned long long e_t[MAX_MULTI] = {0}; /// timestamp 47 bit
unsigned short e_f[MAX_MULTI] = {0}; /// fine time 10 bit
tree->Branch("evID", &evID, "event_ID/l");
tree->Branch("multi", &multi, "multi/s");
tree->Branch("sn", sn, "sn[multi]/s");
tree->Branch("ch", ch, "ch[multi]/s");
tree->Branch("e", e, "e[multi]/s");
tree->Branch("e2", e2, "e2[multi]/s");
tree->Branch("e_t", e_t, "e_timestamp[multi]/l");
tree->Branch("e_f", e_f, "e_timestamp[multi]/s");
TClonesArray * arrayTrace = nullptr;
unsigned short traceLength[MAX_MULTI];
TGraph * trace = nullptr;
if( traceOn ) {
arrayTrace = new TClonesArray("TGraph");
tree->Branch("traceLength", traceLength, "traceLength[multi]/s");
tree->Branch("trace", arrayTrace, 2560000);
arrayTrace->BypassStreamer();
}
//*====================================== build events
printf("================= Building events....\n");
uInt hitProcessed = 0;
std::vector<int> snList;
std::vector<int> typeList;
Data ** data = nullptr;
data = new Data * [nGroup];
for( int i = 0; i < nGroup; i++){
uShort rID = group[i].readerIDList[group[i].currentID];
data[i] = reader[rID]->GetData();
data[i]->ClearData();
reader[i]->ClearHitListandCount();
snList.push_back(group[i].sn);
typeList.push_back(group[i].DPPType);
}
MultiBuilder * mb = new MultiBuilder(data, typeList, snList);
mb->SetTimeWindow(timeWindow);
mb->SetTimeJump(-1);
do{
// use reader to fill Data,
for(int gpID = 0; gpID < nGroup; gpID++){
if( group[gpID].finished ) continue;
uShort rID = group[gpID].readerIDList[group[gpID].currentID];
int preLoad = 100; // #. pre-read block
for( int i = 0; i < preLoad; i++ ) reader[rID]->ReadNextBlock(false, 0, 0);
group[gpID].hitID = reader[rID]->GetHitCount();
if( debug){
printf(" %lu / %lu \n", group[gpID].hitID , group[gpID].hitCount);
data[gpID]->PrintAllData();
}
//when all hit are used, go to next file or make the group.finished = true
if( group[gpID].hitID >= group[gpID].hitCount) {
printf(" group ID : %d, reader ID : %d is finished. \n", gpID, group[gpID].readerIDList[group[gpID].currentID]);
group[gpID].currentID ++;
if( group[gpID].currentID >= group[gpID].readerIDList.size() ) {
group[gpID].finished = true;
printf("-----> no more file for this group, S/N : %d.\n", group[gpID].sn);
continue;
}else{
group[gpID].hitID = 0;
group[gpID].hitCount = reader[rID]->GetHitCount();
data[gpID] = reader[rID]->GetData();
printf("-----> go to the next file, %s \n", fileInfo[rID].fileName.Data() );
}
}
}
mb->BuildEvents(false, !traceOn, debug);
if( debug ) mb->PrintStat();
///----------- save to tree;
long startIndex = mb->eventIndex - mb->eventBuilt + 1;
//printf("startIndex : %6ld -> %6ld, %6ld, %6ld, %ld | %llu\n", startIndex, startIndex < 0 ? startIndex + MaxNEvent : startIndex, mb->eventIndex, mb->eventBuilt, mb->totalEventBuilt, tree->GetEntries());
if (startIndex < 0 ) startIndex += MaxNEvent;
for( long p = startIndex; p < startIndex + mb->eventBuilt; p++){
int k = p % MaxNEvent;
multi = mb->events[k].size();
if( multi > MAX_MULTI) {
printf("!!!!! MAX_MULTI %d reached.\n", MAX_MULTI);
break;
}
evID ++;
for( int j = 0; j < multi; j ++){
sn[j] = mb->events[k][j].sn;
ch[j] = mb->events[k][j].ch;
e[j] = mb->events[k][j].energy;
e2[j] = mb->events[k][j].energy2;
e_t[j] = mb->events[k][j].timestamp;
e_f[j] = mb->events[k][j].fineTime;
if( traceOn ){
traceLength[j] = mb->events[k][j].trace.size();
trace = (TGraph *) arrayTrace->ConstructedAt(j, "C");
trace->Clear();
for( int hh = 0; hh < traceLength[j]; hh++){
trace->SetPoint(hh, hh, mb->events[k][j].trace[hh]);
}
}
hitProcessed ++;
}
outRootFile->cd();
tree->Fill();
}
int gpCount = 0;
for( size_t i = 0; i < group.size(); i++){
if( group[i].finished ) gpCount ++;
}
if( gpCount == (int) group.size() ) break;
}while(true);
if( timeWindow > 0 ){
printf("------------------- build the last data\n");
mb->BuildEvents(1, 0, debug);
//mb->PrintStat();
///----------- save to tree;
long startIndex = mb->eventIndex - mb->eventBuilt + 1;
//printf("startIndex : %ld -> %ld, %ld, %ld, %ld\n", startIndex, startIndex < 0 ? startIndex + MaxNEvent : startIndex, mb->eventIndex, mb->eventBuilt, mb->totalEventBuilt);
if( startIndex < 0 ) startIndex += MaxNEvent;
for( long p = startIndex; p < startIndex + mb->eventBuilt; p++){
int k = p % MaxNEvent;
multi = mb->events[k].size();
if( multi > MAX_MULTI) {
printf("!!!!! MAX_MULTI %d reached.\n", MAX_MULTI);
break;
}
evID ++;
for( int j = 0; j < multi; j ++){
sn[j] = mb->events[k][j].sn;
ch[j] = mb->events[k][j].ch;
e[j] = mb->events[k][j].energy;
e2[j] = mb->events[k][j].energy2;
e_t[j] = mb->events[k][j].timestamp;
e_f[j] = mb->events[k][j].fineTime;
if( traceOn ){
traceLength[j] = mb->events[k][j].trace.size();
trace = (TGraph *) arrayTrace->ConstructedAt(j, "C");
trace->Clear();
for( int hh = 0; hh < traceLength[j]; hh++){
trace->SetPoint(hh, hh, mb->events[k][j].trace[hh]);
}
}
hitProcessed ++;
}
outRootFile->cd();
tree->Fill();
}
}
tree->Write();
printf("========================= finished.\n");
printf("total events built = %llu(%llu)\n", evID + 1, tree->GetEntriesFast());
printf("=======> saved to %s \n", outFileName.Data());
outRootFile->Close();
for( int i = 0 ; i < nFile; i++) delete reader[i];
delete [] reader;
delete [] data;
}

View File

@ -12,11 +12,6 @@
#define ORDERSHIFT 100000 #define ORDERSHIFT 100000
typedef unsigned short uShort;
typedef unsigned int uInt;
typedef unsigned long uLong;
typedef unsigned long long ullong;
struct FileInfo { struct FileInfo {
TString fileName; TString fileName;
unsigned int fileSize; unsigned int fileSize;
@ -29,7 +24,7 @@ struct FileInfo {
unsigned ID; // sn + 100000 * order unsigned ID; // sn + 100000 * order
void CalOrder(){ ID = ORDERSHIFT * order + SN; } void CalOrder(){ ID = ORDERSHIFT * SN + order; }
void Print(){ void Print(){
printf("%6d | %3d | %30s | %2d | %6lu | %u Bytes = %.2f MB\n", printf("%6d | %3d | %30s | %2d | %6lu | %u Bytes = %.2f MB\n",
@ -71,18 +66,15 @@ 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(" * there is a TIMEJUMP = 1e8 ns in EventBuilder.cpp.\n");
printf(" This control the time diff for a time jumping.\n");
printf(" Any signal with trigger rate < 1/TIMEJUMP should increase the value.\n");
return 1; return 1;
} }
/// File format must be YYY...Y_runXXX_AAA_BBB_CCC.fsu /// File format must be YYY...Y_runXXX_AAA_BBB_TT_CCC.fsu
/// YYY...Y = prefix /// YYY...Y = prefix
/// XXX = runID, 3 digits /// XXX = runID, 3 digits
/// AAA = board Serial Number, 3 digits /// AAA = board Serial Number, 3 digits
/// BBB = DPPtype, 3 digits /// BBB = DPPtype, 3 digits
/// TT = tick2ns, any digits
/// CCC = over size index, 3 digits /// CCC = over size index, 3 digits
///============= read input ///============= read input
@ -123,7 +115,7 @@ 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(), false); reader[i] = new FSUReader(inFileName[i].Data(), false);
reader[i]->ScanNumBlock(false); reader[i]->ScanNumBlock(0, 1);
// reader[i]->FillHitList(); // reader[i]->FillHitList();
FileInfo tempInfo; FileInfo tempInfo;
@ -160,7 +152,7 @@ int main(int argc, char **argv) {
std::vector<GroupInfo> group; std::vector<GroupInfo> group;
for( int i = 0; i < nFile; i++){ for( int i = 0; i < nFile; i++){
if( fileInfo[i].ID / ORDERSHIFT == 0 ){ if( i == 0 || group.back().sn != fileInfo[i].SN ){
group.push_back(GroupInfo()); group.push_back(GroupInfo());
group.back().readerIDList.push_back(fileInfo[i].readerID); // an empty struct group.back().readerIDList.push_back(fileInfo[i].readerID); // an empty struct
group.back().currentID = 0; group.back().currentID = 0;
@ -172,7 +164,6 @@ int main(int argc, char **argv) {
}else{ }else{
group.back().readerIDList.push_back(fileInfo[i].readerID); group.back().readerIDList.push_back(fileInfo[i].readerID);
} }
} }
int nGroup = group.size(); int nGroup = group.size();
@ -184,9 +175,7 @@ int main(int argc, char **argv) {
printf(" %s \n", reader[rID]->GetFileName().c_str()); printf(" %s \n", reader[rID]->GetFileName().c_str());
uLong hitCount = reader[rID]->GetHitCount(); uLong hitCount = reader[rID]->GetHitCount();
for( uLong k = 0; k < (hitCount < 5 ? hitCount : 10); k++){ for( uLong k = 0; k < (hitCount < 5 ? hitCount : 10); k++){ reader[rID]->GetHit(k).Print(); }
reader[rID]->GetHit(k).Print();
}
} }
} }

View File

@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs`
OBJS = ClassDigitizer.o MultiBuilder.o OBJS = ClassDigitizer.o MultiBuilder.o
ALL = test test_indep DataGenerator EventBuilder EventBuilderNoTrace DataReader DumpFSU2ROOT SettingsExplorer ALL = test test_indep DataGenerator EventBuilder EventBuilder2 EventBuilderNoTrace DataReader DumpFSU2ROOT SettingsExplorer
######################################################################### #########################################################################
@ -49,6 +49,10 @@ EventBuilder : EventBuilder.cpp ../ClassData.h MultiBuilder.o fsuReader.h
@echo "--------- making EventBuilder" @echo "--------- making EventBuilder"
$(CC) $(COPTS) -o EventBuilder EventBuilder.cpp MultiBuilder.o $(ROOTLIBS) $(CC) $(COPTS) -o EventBuilder EventBuilder.cpp MultiBuilder.o $(ROOTLIBS)
EventBuilder2 : EventBuilder2.cpp ../ClassData.h fsuReader.h AggSeparator.h MultiBuilder.o
@echo "--------- making EventBuilder2"
$(CC) $(COPTS) -o EventBuilder2 EventBuilder2.cpp MultiBuilder.o $(ROOTLIBS)
EventBuilderNoTrace : EventBuilderNoTrace.cpp ../ClassData.h fsuReader.h ../Hit.h EventBuilderNoTrace : EventBuilderNoTrace.cpp ../ClassData.h fsuReader.h ../Hit.h
@echo "--------- making EventBuilderNoTrace" @echo "--------- making EventBuilderNoTrace"
$(CC) $(COPTS) -o EventBuilderNoTrace EventBuilderNoTrace.cpp $(ROOTLIBS) $(CC) $(COPTS) -o EventBuilderNoTrace EventBuilderNoTrace.cpp $(ROOTLIBS)

View File

@ -10,12 +10,14 @@ class FSUReader{
~FSUReader(); ~FSUReader();
void OpenFile(std::string fileName, bool verbose = true); void OpenFile(std::string fileName, bool verbose = true);
bool isOpen() const{return inFile == nullptr ? false : true;}
void ScanNumBlock(bool verbose = true); void ScanNumBlock(bool verbose = true, uShort saveData = 0);
int ReadNextBlock(bool fast = false, int verbose = 0, bool saveData = false); int ReadNextBlock(bool fast = false, int verbose = 0, uShort saveData = 0); // saveData = 0 (no save), 1 (no trace), 2 (with trace);
int ReadBlock(unsigned int ID, int verbose = 0); int ReadBlock(unsigned int ID, int verbose = 0);
unsigned long GetTotNumBlock() const{ return totNumBlock;} unsigned long GetTotNumBlock() const{ return totNumBlock;}
std::vector<unsigned int> GetBlockTimestamp() const {return blockTimeStamp;}
Data * GetData() const{return data;} Data * GetData() const{return data;}
@ -25,12 +27,12 @@ class FSUReader{
int GetTick2ns() const{return tick2ns;} int GetTick2ns() const{return tick2ns;}
int GetNumCh() const{return numCh;} int GetNumCh() const{return numCh;}
int GetFileOrder() const{return order;} int GetFileOrder() const{return order;}
int GetChMask() const{return chMask;}
unsigned long GetFileByteSize() const {return inFileSize;} unsigned long GetFileByteSize() const {return inFileSize;}
std::vector<unsigned int> GetBlockTimestamp() const {return blockTimeStamp;} void ClearHitListandCount() { hit.clear(); numHit = 0;}
Hit GetHit(int id) const {return hit[id];} Hit GetHit(int id) const {return hit[id];}
unsigned long GetHitCount() const{ return hit.size();} unsigned long GetHitCount() const{ return numHit;}
std::vector<Hit> GetHitVector() const {return hit;} std::vector<Hit> GetHitVector() const {return hit;}
private: private:
@ -44,7 +46,8 @@ class FSUReader{
unsigned long totNumBlock; unsigned long totNumBlock;
unsigned int blockID; unsigned int blockID;
// for dual block bool isDualBlock;
int sn; int sn;
int DPPType; int DPPType;
int tick2ns; int tick2ns;
@ -65,6 +68,13 @@ class FSUReader{
}; };
inline FSUReader::~FSUReader(){
delete data;
fclose(inFile);
}
inline FSUReader::FSUReader(){ inline FSUReader::FSUReader(){
inFile = nullptr; inFile = nullptr;
data = nullptr; data = nullptr;
@ -84,7 +94,7 @@ inline void FSUReader::OpenFile(std::string fileName, bool verbose){
inFile = fopen(fileName.c_str(), "r"); inFile = fopen(fileName.c_str(), "r");
if( inFile == NULL ){ if( inFile == NULL ){
printf("Cannot open file : %s \n", fileName.c_str()); printf("FSUReader::Cannot open file : %s \n", fileName.c_str());
this->fileName = ""; this->fileName = "";
return; return;
} }
@ -111,8 +121,11 @@ inline void FSUReader::OpenFile(std::string fileName, bool verbose){
if( ext.find("fsu") != std::string::npos ) { if( ext.find("fsu") != std::string::npos ) {
if(verbose) printf("It is an raw data *.fsu format\n"); if(verbose) printf("It is an raw data *.fsu format\n");
isDualBlock = false;
chMask = -1;
}else{ }else{
chMask = atoi(ext.c_str()); chMask = atoi(ext.c_str());
isDualBlock = true;
if(verbose) printf("It is a splitted dual block data *.fsu.X format, dual channel mask : %d \n", chMask); if(verbose) printf("It is a splitted dual block data *.fsu.X format, dual channel mask : %d \n", chMask);
} }
@ -146,18 +159,10 @@ inline void FSUReader::OpenFile(std::string fileName, bool verbose){
data->tick2ns = tick2ns; data->tick2ns = tick2ns;
data->boardSN = sn; data->boardSN = sn;
data->DPPType = DPPType; data->DPPType = DPPType;
//ScanNumBlock();
} }
inline FSUReader::~FSUReader(){ inline int FSUReader::ReadNextBlock(bool fast, int verbose, uShort saveData){
delete data;
fclose(inFile);
}
inline int FSUReader::ReadNextBlock(bool fast, int verbose,bool saveData){
if( inFile == NULL ) return -1; if( inFile == NULL ) return -1;
if( feof(inFile) ) return -1; if( feof(inFile) ) return -1;
if( filePos >= inFileSize) return -1; if( filePos >= inFileSize) return -1;
@ -202,12 +207,12 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose,bool saveData){
return -20; return -20;
} }
for( int ch = 0; ch < data->GetNChannel(); ch++){
if( data->NumEventsDecoded[ch] == 0 ) continue;
if( saveData ){ numHit += data->NumEventsDecoded[ch];
for( int ch = 0; ch < data->GetNChannel(); ch++){
if( data->NumEventsDecoded[ch] == 0 ) continue;
if( saveData ){
int start = data->DataIndex[ch] - data->NumEventsDecoded[ch] + 1; int start = data->DataIndex[ch] - data->NumEventsDecoded[ch] + 1;
int stop = data->DataIndex[ch]; int stop = data->DataIndex[ch];
@ -220,10 +225,10 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose,bool saveData){
temp.energy2 = data->Energy2[ch][i]; temp.energy2 = data->Energy2[ch][i];
temp.timestamp = data->Timestamp[ch][i]; temp.timestamp = data->Timestamp[ch][i];
temp.fineTime = data->fineTime[ch][i]; temp.fineTime = data->fineTime[ch][i];
if( saveData > 1 ) temp.trace = data->Waveform1[ch][i];
hit.push_back(temp); hit.push_back(temp);
numHit ++;
} }
} }
} }
@ -252,7 +257,7 @@ inline int FSUReader::ReadBlock(unsigned int ID, int verbose){
} }
inline void FSUReader::ScanNumBlock(bool verbose){ inline void FSUReader::ScanNumBlock(bool verbose, uShort saveData){
if( feof(inFile) ) return; if( feof(inFile) ) return;
blockID = 0; blockID = 0;
@ -262,7 +267,7 @@ inline void FSUReader::ScanNumBlock(bool verbose){
fseek(inFile, 0L, SEEK_SET); fseek(inFile, 0L, SEEK_SET);
filePos = 0; filePos = 0;
while( ReadNextBlock(true, false, true) == 0 ){ while( ReadNextBlock(true, false, saveData) == 0 ){
blockPos.push_back(filePos); blockPos.push_back(filePos);
blockTimeStamp.push_back(data->aggTime); blockTimeStamp.push_back(data->aggTime);
blockID ++; blockID ++;
@ -274,18 +279,21 @@ inline void FSUReader::ScanNumBlock(bool verbose){
printf("\nScan complete: number of data Block : %lu\n", totNumBlock); printf("\nScan complete: number of data Block : %lu\n", totNumBlock);
printf( " number of hit : %lu\n", numHit); printf( " number of hit : %lu\n", numHit);
size_t sizeT = sizeof(hit[0]) * hit.size(); if( saveData ){
printf("size of hit array : %lu byte = %.2f kByte, = %.2f MByte\n", sizeT, sizeT/1024., sizeT/1024./1024.); size_t sizeT = sizeof(hit[0]) * hit.size();
printf("size of hit array : %lu byte = %.2f kByte, = %.2f MByte\n", sizeT, sizeT/1024., sizeT/1024./1024.);
}
} }
rewind(inFile); rewind(inFile);
blockID = 0; blockID = 0;
filePos = 0; filePos = 0;
if(verbose) printf("\nQuick Sort hit array according to time..."); if(saveData) {
std::sort(hit.begin(), hit.end(), [](const Hit& a, const Hit& b) { if( verbose) printf("\nQuick Sort hit array according to time...");
return a.timestamp < b.timestamp; std::sort(hit.begin(), hit.end(), [](const Hit& a, const Hit& b) {
}); return a.timestamp < b.timestamp;
if(verbose) printf(".......done.\n"); });
if( verbose) printf(".......done.\n");
}
} }

View File

@ -66,7 +66,7 @@ void MultiBuilder::PrintStat(){
printf("Total number of evet built : %ld\n", totalEventBuilt); printf("Total number of evet built : %ld\n", totalEventBuilt);
for( int i = 0; i < nData ; i++){ for( int i = 0; i < nData ; i++){
for( int ch = 0; ch < data[i]->GetNChannel() ; ch++){ for( int ch = 0; ch < data[i]->GetNChannel() ; ch++){
printf("%d %3d %2d | %7d (%d)\n", i, snList[i], ch, nextIndex[i][ch], loopIndex[i][ch]); if( nextIndex[i][ch] >= 0 ) printf("%d %3d %2d | %7d (%d)\n", i, snList[i], ch, nextIndex[i][ch], loopIndex[i][ch]);
} }
} }
@ -308,7 +308,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
break; break;
} }
printf("----- next bd : %d, ch : %d, next earlist Time : %llu.\n", earlistDigi, earlistCh, earlistTime); printf("----- next bd : %d, ch : %d, next earlist Time : %llu.\n", earlistDigi, earlistCh, earlistTime);
printf("leftOver %llu, breakTime %llu \n", leftOverTime, breakTime); //printf("leftOver %llu, breakTime %llu \n", leftOverTime, breakTime);
} }
if( !isFinal ){ if( !isFinal ){

View File

@ -31,4 +31,9 @@ inline unsigned int get_time(){
return time_us; return time_us;
} }
typedef unsigned short uShort;
typedef unsigned int uInt;
typedef unsigned long uLong;
typedef unsigned long long ullong;
#endif #endif