fixed online event builder, but rebining histogram2D during run will seg fault

This commit is contained in:
splitPoleDAQ 2023-06-09 16:36:43 -04:00
parent d9034fd8b1
commit 21f19b6ff7
6 changed files with 44 additions and 28 deletions

View File

@ -51,10 +51,10 @@ void Analyzer::SetUpCanvas(){
setGeometry(0, 0, 1600, 800); setGeometry(0, 0, 1600, 800);
h2 = new Histogram2D("testing", "x", "y", 400, 0, 4000, 400, 0, 4000, this); h2 = new Histogram2D("testing", "x", "y", 400, 0, 10000, 400, 0, 10000, this);
layout->addWidget(h2, 0, 0); layout->addWidget(h2, 0, 0);
h1 = new Histogram1D("testing", "x", 400, 0, 4000, this); h1 = new Histogram1D("testing", "x", 400, 0, 10000, this);
layout->addWidget(h1, 0, 1); layout->addWidget(h1, 0, 1);
// std::random_device rd; // std::random_device rd;
@ -74,11 +74,13 @@ void Analyzer::UpdateHistograms(){
//Set with digitizer to be event build //Set with digitizer to be event build
digiMTX[0].lock(); digiMTX[0].lock();
oeb[0]->BuildEvents(100, true); oeb[0]->BuildEvents(100, false);
digiMTX[0].unlock(); digiMTX[0].unlock();
oeb[0]->PrintStat();
//============ Get events, and do analysis //============ Get events, and do analysis
long eventBuilt = oeb[0]->eventbuilt; long eventBuilt = oeb[0]->eventBuilt;
if( eventBuilt == 0 ) return; if( eventBuilt == 0 ) return;
long eventIndex = oeb[0]->eventIndex; long eventIndex = oeb[0]->eventIndex;

View File

@ -283,7 +283,7 @@ inline void Data::PrintAllData(bool tableMode) const{
if( DataIndex[ch] > MaxEntry ) MaxEntry = DataIndex[ch]; if( DataIndex[ch] > MaxEntry ) MaxEntry = DataIndex[ch];
} }
if( DataIndex[ch] < 0 ) continue; if( DataIndex[ch] < 0 ) continue;
printf(" %5s-%02d,%-9d |", "ch", ch, DataIndex[ch]); printf(" %5s-%02d,%2d,%-6d |", "ch", ch, LoopIndex[ch], DataIndex[ch]);
} }
printf("\n"); printf("\n");

View File

@ -766,7 +766,7 @@ void MainWindow::UpdateScalar(){
if( scalar == nullptr ) return; if( scalar == nullptr ) return;
//if( !scalar->isVisible() ) return; //if( !scalar->isVisible() ) return;
digi[0]->GetData()->PrintAllData(); // digi[0]->GetData()->PrintAllData();
lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss")); lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));

View File

@ -12,15 +12,16 @@ OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){
OnlineEventBuilder::~OnlineEventBuilder(){ OnlineEventBuilder::~OnlineEventBuilder(){
} }
void OnlineEventBuilder::ClearEvents(){ void OnlineEventBuilder::ClearEvents(){
eventIndex = -1; eventIndex = -1;
totalEventBuilt = 0;
for( int i = 0; i < MaxNEvent; i++ ) events[i].clear(); for( int i = 0; i < MaxNEvent; i++ ) events[i].clear();
for( int i = 0; i < MaxNChannels; i++ ){ for( int i = 0; i < MaxNChannels; i++ ){
nextIndex[i] = -1; nextIndex[i] = -1;
loopIndex[i] = 0;
chExhaused[i] = false; chExhaused[i] = false;
} }
@ -30,6 +31,11 @@ void OnlineEventBuilder::ClearEvents(){
nExhaushedCh = 0; nExhaushedCh = 0;
} }
void OnlineEventBuilder::PrintStat(){
printf("========= Total Event built : %lu, last built : %lu, index: %lu \n", totalEventBuilt, eventBuilt, eventIndex);
}
void OnlineEventBuilder::FindEarlistTimeAndCh(){ void OnlineEventBuilder::FindEarlistTimeAndCh(){
earlistTime = -1; earlistTime = -1;
@ -41,7 +47,7 @@ void OnlineEventBuilder::FindEarlistTimeAndCh(){
} }
for(unsigned int ch = 0; ch < nCh; ch ++){ for(unsigned int ch = 0; ch < nCh; ch ++){
if( data->DataIndex[ch] == -1 || nextIndex[ch] > data->DataIndex[ch]) { if( data->DataIndex[ch] == -1 || loopIndex[ch] * MaxNData + nextIndex[ch] > data->LoopIndex[ch] * MaxNData + data->DataIndex[ch]) {
nExhaushedCh ++; nExhaushedCh ++;
chExhaused[ch] = true; chExhaused[ch] = true;
continue; continue;
@ -57,50 +63,51 @@ void OnlineEventBuilder::FindEarlistTimeAndCh(){
} }
} }
// printf("%s | ch : %d, %llu\n", __func__, earlistCh, earlistTime);
} }
void OnlineEventBuilder::FindLatestTime(){ void OnlineEventBuilder::FindLatestTime(){
latestTime = 0; latestTime = 0;
// int latestCh = -1;
for( unsigned ch = 0; ch < nCh; ch++ ){ for( unsigned ch = 0; ch < nCh; ch++ ){
int index = data->DataIndex[ch]; int index = data->DataIndex[ch];
if( index == -1 ) continue; if( index == -1 ) continue;
if( data->Timestamp[ch][index] > latestTime ) { if( data->Timestamp[ch][index] > latestTime ) {
latestTime = data->Timestamp[ch][index]; latestTime = data->Timestamp[ch][index];
//latestCh = ch;
} }
} }
//printf("--- latest time %lld \n", latestTime); // printf("%s | ch : %d, %lld \n", __func__, latestCh, latestTime);
} }
void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
this->timeWindow = timeWindow; this->timeWindow = timeWindow;
if( verbose ) data->PrintAllData();
FindLatestTime(); FindLatestTime();
FindEarlistTimeAndCh(); FindEarlistTimeAndCh();
if( earlistCh == -1 || nExhaushedCh == nCh) return; /// no data if( earlistCh == -1 || nExhaushedCh == nCh) return; /// no data
eventbuilt = 0; eventBuilt = 0;
data->PrintAllData();
//======= Start building event //======= Start building event
do{ do{
eventIndex ++; eventIndex ++;
if( eventIndex >= MaxNEvent ) eventIndex = 0; if( eventIndex >= MaxNEvent ) eventIndex = 0;
events[eventIndex].clear(); events[eventIndex].clear();
eventbuilt ++; eventBuilt ++;
totalEventBuilt ++;
unsigned long long dT =0;
unsigned long long dT = 0;
dataPoint dp = {0, 0, 0}; dataPoint dp = {0, 0, 0};
for( unsigned int i = 0; i < nCh; i++){ for( unsigned int i = 0; i < nCh; i++){
int ch = (i + earlistCh ) % nCh; int ch = (i + earlistCh ) % nCh;
//printf("------ %d | %d | %d | %d\n", ch, data->DataIndex[ch], nextIndex[ch], chExhaused[ch]);
if( chExhaused[ch] ) continue; if( chExhaused[ch] ) continue;
if( nextIndex[ch] > data->DataIndex[ch]) { if( loopIndex[ch] * MaxNData + nextIndex[ch] > data->LoopIndex[ch] * MaxNData + data->DataIndex[ch]) {
nExhaushedCh ++; nExhaushedCh ++;
chExhaused[ch] = true; chExhaused[ch] = true;
continue; continue;
@ -117,7 +124,10 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
events[eventIndex].push_back(dp); events[eventIndex].push_back(dp);
nextIndex[ch]++; nextIndex[ch]++;
if( nextIndex[ch] >= MaxNData) nextIndex[ch] = 0; if( nextIndex[ch] >= MaxNData) {
loopIndex[ch] ++;
nextIndex[ch] = 0;
}
}else{ }else{
break; break;
} }
@ -134,7 +144,7 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
FindEarlistTimeAndCh(); FindEarlistTimeAndCh();
if( verbose ){ if( verbose ){
printf(">>>>>>>>>>>>>>>>>>>>>>>>> Event ID : %ld, multiplicity : %ld\n", eventIndex, events[eventIndex].size()); printf(">>>>>>>>>>>>>>>>> Event ID : %ld, total built: %ld, multiplicity : %ld\n", eventIndex, totalEventBuilt, events[eventIndex].size());
for( int i = 0; i <(int) events[eventIndex].size(); i++){ for( int i = 0; i <(int) events[eventIndex].size(); i++){
int chxxx = events[eventIndex][i].ch; int chxxx = events[eventIndex][i].ch;
printf("%02d | %d | %5d %llu \n", chxxx, nextIndex[chxxx], events[eventIndex][i].energy, events[eventIndex][i].timeStamp); printf("%02d | %d | %5d %llu \n", chxxx, nextIndex[chxxx], events[eventIndex][i].energy, events[eventIndex][i].timeStamp);

View File

@ -32,17 +32,21 @@ public:
void BuildEvents(unsigned short timeWindow, bool verbose = false); void BuildEvents(unsigned short timeWindow, bool verbose = false);
long eventIndex; long eventIndex;
long eventbuilt; long eventBuilt; // reset once call BuildEvents()
long totalEventBuilt;
std::vector<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy std::vector<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy
unsigned short GetTimeWindow() const { return timeWindow;} unsigned short GetTimeWindow() const { return timeWindow;}
void PrintStat();
private: private:
unsigned short nCh; unsigned short nCh;
Data * data; Data * data;
unsigned short timeWindow; unsigned short timeWindow;
int loopIndex[MaxNChannels];
int nextIndex[MaxNChannels]; int nextIndex[MaxNChannels];
int nExhaushedCh; int nExhaushedCh;

View File

@ -56,19 +56,19 @@ int main(int argc, char* argv[]){
dig[0]->StartACQ(); dig[0]->StartACQ();
for( int i = 0; i < 3; i ++ ){ for( int i = 0; i < 9; i ++ ){
usleep(100*1000); usleep(1000*1000);
dig[0]->ReadData(); dig[0]->ReadData();
data->DecodeBuffer(false, 1); data->DecodeBuffer(false, 0);
data->PrintStat(); //data->PrintStat();
data->SaveData(); //data->SaveData();
// int index = data->NumEventsDecoded[0]; // int index = data->NumEventsDecoded[0];
// printf("-------------- %ld \n", data->Waveform1[0][index].size()); // printf("-------------- %ld \n", data->Waveform1[0][index].size());
data->PrintAllData(); //data->PrintAllData();
eb->BuildEvents(100); eb->BuildEvents(100, false);
} }