From 197a49f6781fe5d09b64821b7e949e65a8e38d11 Mon Sep 17 00:00:00 2001 From: splitPoleDAQ Date: Fri, 26 May 2023 13:12:00 -0400 Subject: [PATCH] tested OnlineEventBuilder.cpp --- .gitignore | 1 + DataGenerator.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++ Makefile_test | 6 +++++- OnlineEventBuilder.cpp | 42 +++++++++++++++++++------------------ OnlineEventBuilder.h | 2 +- 5 files changed, 76 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 282ecc3..1de8357 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ test test_indep programSettings.txt EventBuilder +DataGenerator data diff --git a/DataGenerator.cpp b/DataGenerator.cpp index 29df041..31b7ecf 100644 --- a/DataGenerator.cpp +++ b/DataGenerator.cpp @@ -1,4 +1,5 @@ #include +#include #include "macro.h" #include "ClassDigitizer.h" @@ -6,7 +7,53 @@ int main(){ + Digitizer * digi = new Digitizer(); + + Data * data = digi->GetData(); + + std::random_device rd; + std::mt19937 gen(rd()); + + std::uniform_int_distribution RanNext(0, 1); + std::uniform_int_distribution RanCh(1, 2); + std::uniform_int_distribution RanEnergy(1, 1000); + std::uniform_int_distribution RanTime(1, 50); + + int count = 0; + unsigned long long time = 0; + do{ + + int ch = RanCh(gen); + unsigned short energy = RanEnergy(gen); + + unsigned long long timestamp = time + RanTime(gen) + RanNext(gen)*100; + time = timestamp; + + count ++; + + data->DataIndex[ch] ++; + int index = data->DataIndex[ch]; + + if( ch == 2 && index > 2) { + data->DataIndex[ch] --; + continue; + } + data->Energy[ch][index] = energy; + data->Timestamp[ch][index] = timestamp; + + printf("%02d | %5d %10lld\n", ch, energy, time); + + }while( count < 50 ); + + data->PrintAllData(); + + printf("===================================\n"); + + OnlineEventBuilder * eb = new OnlineEventBuilder(digi); + + eb->BuildEvents(100); + delete digi; } \ No newline at end of file diff --git a/Makefile_test b/Makefile_test index df50339..e2faead 100644 --- a/Makefile_test +++ b/Makefile_test @@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs` OBJS = ClassDigitizer.o OnlineEventBuilder.o -ALL = test test_indep EventBuilder +ALL = test test_indep EventBuilder DataGenerator ######################################################################### @@ -40,3 +40,7 @@ test_indep : test_indep.cpp RegisterAddress.h macro.h EventBuilder : EventBuilder.cpp ClassData.h @echo "--------- making EventBuilder" $(CC) $(COPTS) -o EventBuilder EventBuilder.cpp $(CAENLIBS) $(ROOTLIBS) + +DataGenerator : DataGenerator.cpp ClassDigitizer.o OnlineEventBuilder.o + @echo "--------- making DataGenerator" + $(CC) $(COPTS) -o DataGenerator DataGenerator.cpp ClassDigitizer.o OnlineEventBuilder.o $(CAENLIBS) diff --git a/OnlineEventBuilder.cpp b/OnlineEventBuilder.cpp index c3ba564..c693011 100644 --- a/OnlineEventBuilder.cpp +++ b/OnlineEventBuilder.cpp @@ -1,5 +1,7 @@ #include "OnlineEventBuilder.h" +#include + OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){ data = digi->GetData(); @@ -29,10 +31,8 @@ OnlineEventBuilder::~OnlineEventBuilder(){ void OnlineEventBuilder::FindEarlistTimeAndCh(){ - if( isNeverBuild ){ - earlistTime = -1; - earlistCh = -1; - } + earlistTime = -1; + earlistCh = -1; nExhaushedCh = 0; for( int i = 0; i < MaxNChannels; i++ ){ @@ -53,14 +53,14 @@ void OnlineEventBuilder::FindEarlistTimeAndCh(){ if( time < earlistTime ) { earlistTime = time; earlistCh = ch; - printf("ch: %d , nextIndex : %d, %llu\n", ch, nextIndex[ch] , earlistTime); + //printf("ch: %d , nextIndex : %d, %llu\n", ch, nextIndex[ch] , earlistTime); } } } -void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){ +void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose = false){ this->timeWindow = timeWindow; @@ -109,33 +109,35 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){ } + isNeverBuild = false; - //===== print + std::sort(events[eventIndex].begin(), events[eventIndex].end(), [](const dataPoint& a, const dataPoint& b) { + return a.timeStamp < b.timeStamp; + }); - printf("######################################### Event ID : %ld\n", eventIndex); - for( int i = 0; i <(int) events[eventIndex].size(); i++){ - printf("%02d | %5d %llu \n", events[eventIndex][i].ch, events[eventIndex][i].energy, events[eventIndex][i].timeStamp); + if( verbose ){ + //===== print + printf("&&&&&&&&&&&&&&&&&&&&&&&&& Event ID : %ld\n", eventIndex); + for( int i = 0; i <(int) events[eventIndex].size(); i++){ + printf("%02d | %5d %llu \n", events[eventIndex][i].ch, events[eventIndex][i].energy, events[eventIndex][i].timeStamp); + } } ///Find the next earlist - earlistTime = data->Timestamp[dp.ch][nextIndex[dp.ch]]; FindEarlistTimeAndCh(); - if( nExhaushedCh == nCh ) { - printf("######################### no more eevent to be built\n"); - break; + if( verbose ){ + if( nExhaushedCh == nCh ) { + printf("######################### no more eevent to be built\n"); + break; + } + printf("----- next ch : %d, next earlist Time : %llu \n", earlistCh, earlistTime); } - - printf("----- next ch : %d, next earlist Time : %llu \n", earlistCh, earlistTime); }while(nExhaushedCh < nCh); - for( unsigned int i = 0; i < nCh; i ++ ) printf("%d | exhaushed ? %d \n", i, chExhaused[i] ); - printf("------ nExhaushedCh = %d \n", nExhaushedCh); - - //TODO ----- to speed up continue with data->DataIndex data->ClearData(); for( int i = 0 ; i < MaxNChannels; i++) nextIndex[i] = -1; diff --git a/OnlineEventBuilder.h b/OnlineEventBuilder.h index 589c839..fd90c60 100644 --- a/OnlineEventBuilder.h +++ b/OnlineEventBuilder.h @@ -28,7 +28,7 @@ public: OnlineEventBuilder(Digitizer * digi); ~OnlineEventBuilder(); - void BuildEvents(unsigned short timeWindow); + void BuildEvents(unsigned short timeWindow, bool verbose = false); long eventIndex; std::vector events[MaxNEvent]; // should be a cirular memory, store energy