tested OnlineEventBuilder.cpp

This commit is contained in:
splitPoleDAQ 2023-05-26 13:12:00 -04:00
parent 367512ae06
commit 197a49f678
5 changed files with 76 additions and 22 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ test
test_indep
programSettings.txt
EventBuilder
DataGenerator
data

View File

@ -1,4 +1,5 @@
#include <cstdio>
#include <random>
#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<int> RanNext(0, 1);
std::uniform_int_distribution<int> RanCh(1, 2);
std::uniform_int_distribution<unsigned short> RanEnergy(1, 1000);
std::uniform_int_distribution<unsigned long long> 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;
}

View File

@ -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)

View File

@ -1,5 +1,7 @@
#include "OnlineEventBuilder.h"
#include <algorithm>
OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){
data = digi->GetData();
@ -29,10 +31,8 @@ OnlineEventBuilder::~OnlineEventBuilder(){
void OnlineEventBuilder::FindEarlistTimeAndCh(){
if( isNeverBuild ){
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);
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( verbose ){
if( nExhaushedCh == nCh ) {
printf("######################### no more eevent to be built\n");
break;
}
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;

View File

@ -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<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy