fix MultiBuilder use MaxRegChannel, which should not

This commit is contained in:
splitPoleDAQ 2023-11-21 17:17:31 -05:00
parent ab54bbbc09
commit 926517df91
3 changed files with 39 additions and 24 deletions

View File

@ -73,6 +73,8 @@ class Data{
void ClearTriggerRate();
void ClearBuffer();
unsigned short GetNChannel() const {return numInputCh;}
void CopyBuffer( const char * buffer, const unsigned int size);
void DecodeBuffer(bool fastDecode, int verbose = 0); /// fastDecode will not save waveform

View File

@ -31,7 +31,7 @@ void MultiBuilder::ClearEvents(){
for( int i = 0; i < MaxNEvent; i++) events[i].clear();
for( int i = 0; i < MaxNDigitizer; i++){
for( int j = 0; j < MaxRegChannel; j++){
for( int j = 0; j < MaxNChannels; j++){
loopIndex[i][j] = 0;
nextIndex[i][j] = -1;
chExhaused[i][j] = false;
@ -51,7 +51,7 @@ void MultiBuilder::PrintStat(){
printf("Total number of evet built : %ld\n", totalEventBuilt);
for( int i = 0; i < nData ; i++){
for( int ch = 0; ch < MaxRegChannel ; 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]);
}
}
@ -68,12 +68,20 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
for( int i = 0; i < nData; i++){
for( int j = 0; j < MaxRegChannel; j++ ){
for( int j = 0; j < data[i]->GetNChannel(); j++ ){
chExhaused[i][j] = false;
}
for(unsigned int ch = 0; ch < MaxRegChannel; ch ++){
if( data[i]->Timestamp[ch][data[i]->DataIndex[ch]] == 0 || data[i]->DataIndex[ch] == -1 || loopIndex[i][ch] * MaxNData + nextIndex[i][ch] > data[i]->LoopIndex[ch] * MaxNData + data[i]->DataIndex[ch]) {
for(unsigned int ch = 0; ch < MaxNChannels; ch ++){
if( ch >= data[i]->GetNChannel() ) {
nExhaushedCh ++;
chExhaused[i][ch] = true;
continue;
}
if( data[i]->Timestamp[ch][data[i]->DataIndex[ch]] == 0 ||
data[i]->DataIndex[ch] == -1 ||
loopIndex[i][ch] * MaxNData + nextIndex[i][ch] > data[i]->LoopIndex[ch] * MaxNData + data[i]->DataIndex[ch]) {
nExhaushedCh ++;
chExhaused[i][ch] = true;
continue;
@ -104,13 +112,13 @@ void MultiBuilder::FindLatestTimeAndCh(bool verbose){
for( int i = 0; i < nData; i++){
for( int j = 0; j < MaxRegChannel; j++ ){
for( int j = 0; j < data[i]->GetNChannel(); j++ ){
chExhaused[i][j] = false;
}
for(unsigned int ch = 0; ch < MaxRegChannel; ch ++){
for(unsigned int ch = 0; ch < MaxNChannels; ch ++){
// printf(" %d, %d | %d", i, ch, nextIndex[i][ch]);
if( nextIndex[i][ch] < 0 ) {
if( nextIndex[i][ch] < 0 || ch >= data[i]->GetNChannel()) {
nExhaushedCh ++;
chExhaused[i][ch] = true;
@ -137,7 +145,7 @@ void MultiBuilder::FindLatestTimeOfData(bool verbose){
latestCh = -1;
latestDigi = -1;
for( int i = 0; i < nData; i++){
for( unsigned ch = 0; ch < MaxRegChannel; ch++ ){
for( unsigned ch = 0; ch < data[i]->GetNChannel(); ch++ ){
int index = data[i]->DataIndex[ch];
if( index == -1 ) continue;
if( data[i]->Timestamp[ch][index] > latestTime ) {
@ -155,7 +163,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
FindLatestTimeOfData(verbose);
FindEarlistTimeAndCh(verbose);
if( earlistCh == -1 || nExhaushedCh == nData * MaxRegChannel) return; /// no data
if( earlistCh == -1 || nExhaushedCh == nData * MaxNChannels) return; /// no data
eventBuilt = 0;
//======= Start building event
@ -177,8 +185,10 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
// printf("##### %d/%d | ", k, nData);
// data[k]->PrintAllData(true, 10);
for( unsigned int i = 0; i < MaxRegChannel; i++){
int ch = (i + earlistCh ) % MaxRegChannel;
const int numCh = data[k]->GetNChannel();
for( int i = 0; i < numCh; i++){
int ch = (i + earlistCh ) % numCh;
if( chExhaused[bd][ch] ) continue;
if( loopIndex[bd][ch] * MaxNData + nextIndex[bd][ch] > data[bd]->LoopIndex[ch] * MaxNData + data[bd]->DataIndex[ch]) {
nExhaushedCh ++;
@ -234,7 +244,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
printf("%02d, %02d | %d | %5d %llu \n", bd, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp);
}
if( nExhaushedCh == nData * MaxRegChannel ) {
if( nExhaushedCh == nData * MaxNChannels ) {
printf("######################### no more event to be built\n");
break;
}
@ -249,7 +259,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
break;
}
}while(nExhaushedCh < nData * MaxRegChannel);
}while(nExhaushedCh < nData * MaxNChannels);
}
@ -259,8 +269,9 @@ void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){
// remember the end of DataIndex, prevent over build
for( int k = 0; k < nData; k++){
for( int i = 0; i < MaxRegChannel; i++){
for( int i = 0; i < data[i]->GetNChannel(); i++){
nextIndex[k][i] = data[k]->DataIndex[i];
loopIndex[k][i] = data[k]->LoopIndex[i];
}
}
@ -281,8 +292,10 @@ void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){
for( int k = 0; k < nData; k++){
int bd = (k + latestDigi) % nData;
for( unsigned int i = 0; i < MaxRegChannel; i++){
int ch = (i + latestCh) % MaxRegChannel;
const int numCh = data[k]->GetNChannel();
for( int i = 0; i < numCh; i++){
int ch = (i + latestCh) % numCh;
if( chExhaused[bd][ch] ) continue;
//if( nextIndex[bd][ch] <= lastBackWardIndex[bd][ch] || nextIndex[bd][ch] < 0){
if( nextIndex[bd][ch] < 0){
@ -330,7 +343,7 @@ void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){
printf("%02d, %02d | %d | %5d %llu \n", bd, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp);
}
if( nExhaushedCh == nData * MaxRegChannel ) {
if( nExhaushedCh == nData * MaxNChannels ) {
printf("######################### no more event to be built\n");
break;
}
@ -338,7 +351,7 @@ void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){
}
}while(nExhaushedCh < nData * MaxRegChannel && eventBuilt <= maxNumEvent);
}while(nExhaushedCh < nData * MaxNChannels && eventBuilt <= maxNumEvent);
// // remember the end of DataIndex, prevent over build
// for( int k = 0; k < nData; k++){

View File

@ -70,11 +70,11 @@ private:
Data ** data; // assume all data has MaxNChannel (16)
unsigned short timeWindow;
int loopIndex[MaxNDigitizer][MaxRegChannel];
int nextIndex[MaxNDigitizer][MaxRegChannel];
int loopIndex[MaxNDigitizer][MaxNChannels];
int nextIndex[MaxNDigitizer][MaxNChannels];
int nExhaushedCh;
bool chExhaused[MaxNDigitizer][MaxRegChannel];
bool chExhaused[MaxNDigitizer][MaxNChannels];
void FindEarlistTimeAndCh(bool verbose = false); // search thtough the nextIndex
unsigned long long earlistTime;
@ -87,7 +87,7 @@ private:
void FindLatestTimeOfData(bool verbose = false);
int lastBackWardIndex[MaxNDigitizer][MaxRegChannel];
int lastBackWardIndex[MaxNDigitizer][MaxNChannels];
};