fixed EventBuilder.cpp
This commit is contained in:
parent
29736359ac
commit
e9a9b4aa7d
13
.vscode/c_cpp_properties.json
vendored
13
.vscode/c_cpp_properties.json
vendored
|
@ -13,6 +13,19 @@
|
||||||
"cppStandard": "gnu++17",
|
"cppStandard": "gnu++17",
|
||||||
"intelliSenseMode": "linux-gcc-x64"
|
"intelliSenseMode": "linux-gcc-x64"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "RyanUbuntu",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**",
|
||||||
|
"/usr/include/x86_64-linux-gnu/qt6/**",
|
||||||
|
"/opt/root/include/**"
|
||||||
|
],
|
||||||
|
"defines": [],
|
||||||
|
"compilerPath": "/usr/bin/gcc",
|
||||||
|
"cStandard": "c17",
|
||||||
|
"cppStandard": "gnu++17",
|
||||||
|
"intelliSenseMode": "linux-gcc-x64"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Splitpole",
|
"name": "Splitpole",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
|
|
186
EventBuilder.cpp
186
EventBuilder.cpp
|
@ -96,7 +96,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
quickSort(&(ID[0]), &(type[0]), &(inFileName[0]), 0, nFile-1);
|
quickSort(&(ID[0]), &(type[0]), &(inFileName[0]), 0, nFile-1);
|
||||||
for( int i = 0 ; i < nFile; i++){
|
for( int i = 0 ; i < nFile; i++){
|
||||||
printf("%d | %6d | %3d | %s | %u\n", i, ID[i], type[i], inFileName[i].Data(), fileSize[i]);
|
printf("%d | %6d | %3d | %s | %u Bytes = %.2f MB\n", i, ID[i], type[i], inFileName[i].Data(), fileSize[i], fileSize[i]/1024./1024.);
|
||||||
}
|
}
|
||||||
|
|
||||||
//*======================================= Sort files in to group
|
//*======================================= Sort files in to group
|
||||||
|
@ -121,7 +121,7 @@ int main(int argc, char **argv) {
|
||||||
int nGroup = snList.size();
|
int nGroup = snList.size();
|
||||||
printf("===================================== number of file Group by digitizer %d.\n", nGroup);
|
printf("===================================== number of file Group by digitizer %d.\n", nGroup);
|
||||||
for( int i = 0; i < nGroup; i++){
|
for( int i = 0; i < nGroup; i++){
|
||||||
printf("............ %d \n", snList[i]);
|
printf("............ Digi-%d \n", snList[i]);
|
||||||
for( int j = 0; j< (int) fileList[i].size(); j++){
|
for( int j = 0; j< (int) fileList[i].size(); j++){
|
||||||
printf("%s | %d\n", fileList[i][j].Data(), typeList[i]);
|
printf("%s | %d\n", fileList[i][j].Data(), typeList[i]);
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,7 @@ 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 bd[MAX_MULTI] = {0}; /// boardID
|
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
|
||||||
|
@ -162,6 +163,7 @@ 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("bd", bd, "bd[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");
|
||||||
|
@ -193,6 +195,7 @@ int main(int argc, char **argv) {
|
||||||
int lastDataIndex[nGroup][MaxNChannels]={0}; // keep track of the DataIndex
|
int lastDataIndex[nGroup][MaxNChannels]={0}; // keep track of the DataIndex
|
||||||
int lastLoopIndex[nGroup][MaxNChannels]={0}; // keep track of the DataIndex
|
int lastLoopIndex[nGroup][MaxNChannels]={0}; // keep track of the DataIndex
|
||||||
|
|
||||||
|
int aggCount[nGroup] = {0};
|
||||||
do{
|
do{
|
||||||
|
|
||||||
/// fill the data class with some agg;
|
/// fill the data class with some agg;
|
||||||
|
@ -204,77 +207,93 @@ int main(int argc, char **argv) {
|
||||||
if( inFile[i] == nullptr ) continue;
|
if( inFile[i] == nullptr ) continue;
|
||||||
size_t dummy = fread(word, 4, 1, inFile[i]);
|
size_t dummy = fread(word, 4, 1, inFile[i]);
|
||||||
if( dummy != 1) {
|
if( dummy != 1) {
|
||||||
printf("fread error, should read 4 bytes, but read %ld x 4 byte, file pos: %ld byte (%s)\n", dummy, ftell(inFile[i]), fileList[i][inFileIndex[i]].Data());
|
//printf("fread error, should read 4 bytes, but read %ld x 4 byte, file pos: %ld byte (%s)\n", dummy, ftell(inFile[i]), fileList[i][inFileIndex[i]].Data());
|
||||||
}
|
// go to next file in same digitizer
|
||||||
|
if( feof(inFile[i])){
|
||||||
fseek(inFile[i], -4, SEEK_CUR); // rool back
|
fclose(inFile[i]);
|
||||||
|
inFile[i] = fopen(fileList[i][inFileIndex[i]+1], "r");
|
||||||
short header = ((word[0] >> 28 ) & 0xF);
|
if( inFile[i] ){
|
||||||
if( header != 0xA ) break;
|
inFileIndex[i]++;
|
||||||
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
printf("---- go to next file for digi-%d\n", snList[i]);
|
||||||
|
}else{
|
||||||
buffer = new char[aggSize];
|
inFileIndex[i] = -1;
|
||||||
size_t dummy2 = fread(buffer, aggSize, 1, inFile[i]);
|
printf("---- no more file for digi-%d.\n", snList[i]);
|
||||||
if( dummy2 != 1) {
|
continue;
|
||||||
printf("fread error, should read %d bytes, but read %ld x %d byte, file pos: %ld byte (%s)\n", aggSize, dummy, aggSize, ftell(inFile[i]), fileList[i][inFileIndex[i]].Data());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
data[i]->DecodeBuffer(buffer, aggSize, false, 0);
|
|
||||||
data[i]->ClearBuffer();
|
|
||||||
|
|
||||||
//check if Data Index near MaxNData. if near by 50%, break
|
|
||||||
for( int ch = 0; ch < MaxNChannels; ch ++){
|
|
||||||
if( data[i]->LoopIndex[ch]*MaxNData + data[i]->DataIndex[ch] - lastLoopIndex[i][ch]*MaxNData - lastDataIndex[i][ch] > MaxNData * 0.5 ) {
|
|
||||||
breakFlag = true;
|
|
||||||
printf("digi:%d | ch: %d DataIndex: %d (%d) \n", data[i]->boardSN, ch, data[i]->DataIndex[ch], lastDataIndex[i][ch]);
|
|
||||||
}
|
}
|
||||||
lastDataIndex[i][ch] = data[i]->DataIndex[ch];
|
|
||||||
lastLoopIndex[i][ch] = data[i]->LoopIndex[ch];
|
|
||||||
}
|
|
||||||
if( breakFlag ) break;
|
|
||||||
|
|
||||||
if( feof(inFile[i]) || dummy != 1 ){
|
}else{
|
||||||
fclose(inFile[i]);
|
fseek(inFile[i], -4, SEEK_CUR); // rool back
|
||||||
inFile[i] = fopen(fileList[i][inFileIndex[i]+1], "r");
|
|
||||||
if( inFile[i] ){
|
short header = ((word[0] >> 28 ) & 0xF);
|
||||||
inFileIndex[i]++;
|
if( header != 0xA ) break;
|
||||||
printf("---- go to next file\n");
|
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
||||||
|
|
||||||
|
buffer = new char[aggSize];
|
||||||
|
size_t dummy2 = fread(buffer, aggSize, 1, inFile[i]);
|
||||||
|
if( dummy2 != 1) {
|
||||||
|
printf("fread error, should read %d bytes, but read %ld x %d byte, file pos: %ld byte (%s)\n", aggSize, dummy, aggSize, ftell(inFile[i]), fileList[i][inFileIndex[i]].Data());
|
||||||
}else{
|
}else{
|
||||||
inFileIndex[i] = -1;
|
data[i]->DecodeBuffer(buffer, aggSize, false, 0);
|
||||||
printf("---- no more file for this digitizer.\n");
|
data[i]->ClearBuffer();
|
||||||
continue;
|
|
||||||
|
aggCount[i] ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if all file exhausted, break
|
||||||
|
int okFileNum = 0;
|
||||||
|
for( int i = 0; i < nGroup; i++){
|
||||||
|
if( inFileIndex[i] != -1 ) okFileNum ++;
|
||||||
|
}
|
||||||
|
if( okFileNum == 0 ) break;
|
||||||
|
|
||||||
|
//check if Data Index near MaxNData. if near by 50%, break
|
||||||
|
//printf("-----------------------------------\n");
|
||||||
|
for( int i = 0; i < nGroup; i++){
|
||||||
|
for( int ch = 0; ch < MaxNChannels; ch ++){
|
||||||
|
if( data[i]->LoopIndex[ch]*MaxNData + data[i]->DataIndex[ch] - lastLoopIndex[i][ch]*MaxNData - lastDataIndex[i][ch] > MaxNData * 0.5 ) {
|
||||||
|
breakFlag = true;
|
||||||
|
//printf("digi:%d | ch: %d DataIndex: %d (%d) \n", data[i]->boardSN, ch, data[i]->DataIndex[ch], lastDataIndex[i][ch]);
|
||||||
|
}
|
||||||
|
lastDataIndex[i][ch] = data[i]->DataIndex[ch];
|
||||||
|
lastLoopIndex[i][ch] = data[i]->LoopIndex[ch];
|
||||||
|
}
|
||||||
|
//printf("%3d | agg : %d | %s\n", snList[i], aggCount[i], breakFlag ? "Break" : "cont." );
|
||||||
|
}
|
||||||
|
|
||||||
}while(breakFlag);
|
}while(breakFlag);
|
||||||
|
|
||||||
//data[0]->PrintStat();
|
|
||||||
mb->BuildEvents(0, 0, debug);
|
mb->BuildEvents(0, 0, debug);
|
||||||
|
|
||||||
///----------- save to tree;
|
///----------- save to tree;
|
||||||
long startIndex = mb->eventIndex - mb->eventBuilt + 1;
|
long startIndex = mb->eventIndex - mb->eventBuilt + 1;
|
||||||
//printf("startIndex : %ld -> %ld, %ld, %ld\n", startIndex, startIndex < 0 ? startIndex + MaxNEvent : startIndex, mb->eventIndex, mb->eventBuilt);
|
//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;
|
if (startIndex < 0 ) startIndex += MaxNEvent;
|
||||||
|
for( long p = startIndex; p < startIndex + mb->eventBuilt; p++){
|
||||||
for( long i = startIndex; i <= mb->eventIndex; i++){
|
int k = p % MaxNEvent;
|
||||||
multi = mb->events[i].size();
|
multi = mb->events[k].size();
|
||||||
if( multi > MAX_MULTI) break;
|
if( multi > MAX_MULTI) {
|
||||||
|
printf("!!!!! MAX_MULTI %d reached.\n", MAX_MULTI);
|
||||||
|
break;
|
||||||
|
}
|
||||||
evID ++;
|
evID ++;
|
||||||
for( int j = 0; j < multi; j ++){
|
for( int j = 0; j < multi; j ++){
|
||||||
bd[j] = mb->events[i][j].sn;
|
bd[j] = mb->events[k][j].bd;
|
||||||
ch[j] = mb->events[i][j].ch;
|
sn[j] = mb->events[k][j].sn;
|
||||||
e[j] = mb->events[i][j].energy;
|
ch[j] = mb->events[k][j].ch;
|
||||||
e2[j] = mb->events[i][j].energy2;
|
e[j] = mb->events[k][j].energy;
|
||||||
e_t[j] = mb->events[i][j].timestamp;
|
e2[j] = mb->events[k][j].energy2;
|
||||||
e_f[j] = mb->events[i][j].fineTime;
|
e_t[j] = mb->events[k][j].timestamp;
|
||||||
|
e_f[j] = mb->events[k][j].fineTime;
|
||||||
if( traceOn ){
|
if( traceOn ){
|
||||||
traceLength[j] = mb->events[i][j].trace.size();
|
traceLength[j] = mb->events[k][j].trace.size();
|
||||||
trace = (TGraph *) arrayTrace->ConstructedAt(j, "C");
|
trace = (TGraph *) arrayTrace->ConstructedAt(j, "C");
|
||||||
trace->Clear();
|
trace->Clear();
|
||||||
for( int hh = 0; hh < traceLength[j]; hh++){
|
for( int hh = 0; hh < traceLength[j]; hh++){
|
||||||
trace->SetPoint(hh, hh, mb->events[i][j].trace[hh]);
|
trace->SetPoint(hh, hh, mb->events[k][j].trace[hh]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,46 +309,53 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
}while(true);
|
}while(true);
|
||||||
|
|
||||||
printf("------------------- build the last data\n");
|
if( timeWindow > 0 ){
|
||||||
|
printf("------------------- build the last data\n");
|
||||||
|
|
||||||
mb->BuildEvents(1, 0, debug);
|
mb->BuildEvents(1, 0, debug);
|
||||||
|
|
||||||
///----------- save to tree;
|
///----------- save to tree;
|
||||||
long startIndex = mb->eventIndex - mb->eventBuilt + 1;
|
long startIndex = mb->eventIndex - mb->eventBuilt + 1;
|
||||||
printf("startIndex : %ld -> %ld, %ld, %ld\n", startIndex, startIndex < 0 ? startIndex + MaxNEvent : startIndex, mb->eventIndex, mb->eventBuilt);
|
//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;
|
if( startIndex < 0 ) startIndex += MaxNEvent;
|
||||||
//printf("startIndex : %ld, %ld\n", startIndex, mb->eventIndex);
|
for( long p = startIndex; p <= startIndex + mb->eventBuilt; p++){
|
||||||
for( long i = startIndex; i <= mb->eventIndex; i++){
|
int k = p % MaxNEvent;
|
||||||
evID ++;
|
multi = mb->events[k].size();
|
||||||
multi = mb->events[i].size();
|
if( multi > MAX_MULTI) {
|
||||||
if( multi > MAX_MULTI) break;
|
printf("!!!!! MAX_MULTI %d reached.\n", MAX_MULTI);
|
||||||
for( int j = 0; j < multi; j ++){
|
break;
|
||||||
bd[j] = mb->events[i][j].sn;
|
}
|
||||||
ch[j] = mb->events[i][j].ch;
|
evID ++;
|
||||||
e[j] = mb->events[i][j].energy;
|
for( int j = 0; j < multi; j ++){
|
||||||
e2[j] = mb->events[i][j].energy2;
|
bd[j] = mb->events[k][j].bd;
|
||||||
e_t[j] = mb->events[i][j].timestamp;
|
sn[j] = mb->events[k][j].sn;
|
||||||
e_f[j] = mb->events[i][j].fineTime;
|
ch[j] = mb->events[k][j].ch;
|
||||||
if( traceOn ){
|
e[j] = mb->events[k][j].energy;
|
||||||
traceLength[j] = mb->events[i][j].trace.size();
|
e2[j] = mb->events[k][j].energy2;
|
||||||
trace = (TGraph *) arrayTrace->ConstructedAt(j, "C");
|
e_t[j] = mb->events[k][j].timestamp;
|
||||||
trace->Clear();
|
e_f[j] = mb->events[k][j].fineTime;
|
||||||
for( int hh = 0; hh < traceLength[j]; hh++){
|
if( traceOn ){
|
||||||
trace->SetPoint(hh, hh, mb->events[i][j].trace[hh]);
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
outRootFile->cd();
|
||||||
|
tree->Fill();
|
||||||
}
|
}
|
||||||
outRootFile->cd();
|
|
||||||
tree->Fill();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tree->Write();
|
tree->Write();
|
||||||
outRootFile->Close();
|
|
||||||
|
|
||||||
printf("========================= finsihed.\n");
|
printf("========================= finsihed.\n");
|
||||||
printf("total events built = %llu \n", evID + 1);
|
printf("total events built = %llu(%llu)\n", evID + 1, tree->GetEntriesFast());
|
||||||
printf("=======> saved to %s \n", outFileName.Data());
|
printf("=======> saved to %s \n", outFileName.Data());
|
||||||
|
|
||||||
|
outRootFile->Close();
|
||||||
|
|
||||||
delete mb;
|
delete mb;
|
||||||
for( int i = 0 ; i < nGroup; i++) delete data[i];
|
for( int i = 0 ; i < nGroup; i++) delete data[i];
|
||||||
delete [] data;
|
delete [] data;
|
||||||
|
|
|
@ -100,7 +100,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 < MaxNChannels ; ch++){
|
for( int ch = 0; ch < MaxNChannels ; ch++){
|
||||||
printf("%d %d | %d \n", i, ch, nextIndex[i][ch]);
|
printf("%d %3d %2d | %7d (%d)\n", i, snList[i], ch, nextIndex[i][ch], loopIndex[i][ch]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user