in progress to fix the EventBuilder.cpp
This commit is contained in:
parent
cb1aac16df
commit
29736359ac
|
@ -61,12 +61,12 @@ void DataReader(std::string fileName, int DPPType){
|
||||||
//if( countBdAgg % 100 == 0) data->PrintStat();
|
//if( countBdAgg % 100 == 0) data->PrintStat();
|
||||||
//data->ClearData();
|
//data->ClearData();
|
||||||
|
|
||||||
if( countBdAgg > 10 ){
|
//if( countBdAgg > 10 ){
|
||||||
//data->PrintAllData();
|
//data->PrintAllData();
|
||||||
|
|
||||||
mb->BuildEvents(false, true, false);
|
//mb->BuildEvents(false, true, false);
|
||||||
//mb->BuildEventsBackWard(false);
|
//mb->BuildEventsBackWard(false);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
}while(!feof(haha) && ftell(haha) < inFileSize);
|
}while(!feof(haha) && ftell(haha) < inFileSize);
|
||||||
|
|
|
@ -186,27 +186,27 @@ int main(int argc, char **argv) {
|
||||||
MultiBuilder * mb = new MultiBuilder(data, typeList, snList);
|
MultiBuilder * mb = new MultiBuilder(data, typeList, snList);
|
||||||
mb->SetTimeWindow(timeWindow);
|
mb->SetTimeWindow(timeWindow);
|
||||||
|
|
||||||
///------------------ re data
|
///------------------ read data
|
||||||
char * buffer = nullptr;
|
char * buffer = nullptr;
|
||||||
unsigned int word[1]; // 4 byte = 32 bit
|
unsigned int word[1]; // 4 byte = 32 bit
|
||||||
|
|
||||||
|
int lastDataIndex[nGroup][MaxNChannels]={0}; // keep track of the DataIndex
|
||||||
|
int lastLoopIndex[nGroup][MaxNChannels]={0}; // keep track of the DataIndex
|
||||||
|
|
||||||
do{
|
do{
|
||||||
|
|
||||||
/// fill the data class with some agg;
|
/// fill the data class with some agg;
|
||||||
bool earlyTermination = false;
|
bool breakFlag = false;
|
||||||
int aggCount = 0;
|
|
||||||
do{
|
do{
|
||||||
|
|
||||||
|
// Get 1 agg. from each file.
|
||||||
for ( int i = 0; i < nGroup; i++){
|
for ( int i = 0; i < nGroup; i++){
|
||||||
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());
|
||||||
earlyTermination = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( earlyTermination == false){
|
|
||||||
fseek(inFile[i], -4, SEEK_CUR); // rool back
|
fseek(inFile[i], -4, SEEK_CUR); // rool back
|
||||||
|
|
||||||
short header = ((word[0] >> 28 ) & 0xF);
|
short header = ((word[0] >> 28 ) & 0xF);
|
||||||
|
@ -214,45 +214,56 @@ int main(int argc, char **argv) {
|
||||||
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
||||||
|
|
||||||
buffer = new char[aggSize];
|
buffer = new char[aggSize];
|
||||||
dummy = fread(buffer, aggSize, 1, inFile[i]);
|
size_t dummy2 = fread(buffer, aggSize, 1, inFile[i]);
|
||||||
if( dummy != 1) {
|
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());
|
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());
|
||||||
earlyTermination = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( earlyTermination == false){
|
|
||||||
data[i]->DecodeBuffer(buffer, aggSize, false, 0);
|
data[i]->DecodeBuffer(buffer, aggSize, false, 0);
|
||||||
data[i]->ClearBuffer();
|
data[i]->ClearBuffer();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( feof(inFile[i]) || earlyTermination ){
|
//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 ){
|
||||||
fclose(inFile[i]);
|
fclose(inFile[i]);
|
||||||
inFile[i] = fopen(fileList[i][inFileIndex[i]+1], "r");
|
inFile[i] = fopen(fileList[i][inFileIndex[i]+1], "r");
|
||||||
if( inFile[i] ){
|
if( inFile[i] ){
|
||||||
inFileIndex[i]++;
|
inFileIndex[i]++;
|
||||||
|
printf("---- go to next file\n");
|
||||||
}else{
|
}else{
|
||||||
inFileIndex[i] = -1;
|
inFileIndex[i] = -1;
|
||||||
|
printf("---- no more file for this digitizer.\n");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
aggCount++;
|
|
||||||
|
|
||||||
}while(aggCount < 10); // get 10 agg should be enough for events building
|
}
|
||||||
|
|
||||||
|
}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;
|
||||||
while( startIndex < 0 ) startIndex += MaxNEvent;
|
//printf("startIndex : %ld -> %ld, %ld, %ld\n", startIndex, startIndex < 0 ? startIndex + MaxNEvent : startIndex, mb->eventIndex, mb->eventBuilt);
|
||||||
//printf("startIndex : %ld, %ld\n", startIndex, mb->eventIndex);
|
if (startIndex < 0 ) startIndex += MaxNEvent;
|
||||||
for( long i = startIndex; i <= mb->eventIndex; i++){
|
|
||||||
|
|
||||||
|
for( long i = startIndex; i <= mb->eventIndex; i++){
|
||||||
multi = mb->events[i].size();
|
multi = mb->events[i].size();
|
||||||
if( multi > MAX_MULTI) break;
|
if( multi > 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].bd;
|
bd[j] = mb->events[i][j].sn;
|
||||||
ch[j] = mb->events[i][j].ch;
|
ch[j] = mb->events[i][j].ch;
|
||||||
e[j] = mb->events[i][j].energy;
|
e[j] = mb->events[i][j].energy;
|
||||||
e2[j] = mb->events[i][j].energy2;
|
e2[j] = mb->events[i][j].energy2;
|
||||||
|
@ -275,15 +286,17 @@ int main(int argc, char **argv) {
|
||||||
for( int i = 0; i < nGroup; i++){
|
for( int i = 0; i < nGroup; i++){
|
||||||
if( inFileIndex[i] != -1 ) okFileNum ++;
|
if( inFileIndex[i] != -1 ) okFileNum ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( okFileNum == 0 ) break;
|
if( okFileNum == 0 ) break;
|
||||||
|
|
||||||
}while(true);
|
}while(true);
|
||||||
|
|
||||||
|
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);
|
||||||
if( startIndex < 0 ) startIndex += MaxNEvent;
|
if( startIndex < 0 ) startIndex += MaxNEvent;
|
||||||
//printf("startIndex : %ld, %ld\n", startIndex, mb->eventIndex);
|
//printf("startIndex : %ld, %ld\n", startIndex, mb->eventIndex);
|
||||||
for( long i = startIndex; i <= mb->eventIndex; i++){
|
for( long i = startIndex; i <= mb->eventIndex; i++){
|
||||||
|
@ -291,7 +304,7 @@ int main(int argc, char **argv) {
|
||||||
multi = mb->events[i].size();
|
multi = mb->events[i].size();
|
||||||
if( multi > MAX_MULTI) break;
|
if( multi > MAX_MULTI) break;
|
||||||
for( int j = 0; j < multi; j ++){
|
for( int j = 0; j < multi; j ++){
|
||||||
bd[j] = mb->events[i][j].bd;
|
bd[j] = mb->events[i][j].sn;
|
||||||
ch[j] = mb->events[i][j].ch;
|
ch[j] = mb->events[i][j].ch;
|
||||||
e[j] = mb->events[i][j].energy;
|
e[j] = mb->events[i][j].energy;
|
||||||
e2[j] = mb->events[i][j].energy2;
|
e2[j] = mb->events[i][j].energy2;
|
||||||
|
@ -318,10 +331,7 @@ int main(int argc, char **argv) {
|
||||||
printf("=======> saved to %s \n", outFileName.Data());
|
printf("=======> saved to %s \n", outFileName.Data());
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,11 +258,11 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( timeWindow == 0 ) break;
|
if( timeWindow <= 0 ) break;
|
||||||
}while( true );
|
}while( true );
|
||||||
if( timeWindow == 0 ) break;
|
if( timeWindow <= 0 ) break;
|
||||||
}
|
}
|
||||||
if( timeWindow == 0 ) break;
|
if( timeWindow <= 0 ) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( timeWindow > 0 ) {
|
if( timeWindow > 0 ) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "ClassData.h"
|
#include "ClassData.h"
|
||||||
#include "ClassDigitizer.h"
|
#include "ClassDigitizer.h"
|
||||||
|
|
||||||
#define MaxNEvent 5000 // circular
|
#define MaxNEvent 100000 // circular, this number should be at least nDigi * MaxNChannel * MaxNData
|
||||||
|
|
||||||
class Hit{
|
class Hit{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user