Compare commits

..

2 Commits

Author SHA1 Message Date
splitPoleDAQ 322cbca165 improve the online event builder. 2023-05-26 15:01:54 -04:00
splitPoleDAQ 197a49f678 tested OnlineEventBuilder.cpp 2023-05-26 13:12:00 -04:00
6 changed files with 113 additions and 46 deletions

1
.gitignore vendored
View File

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

View File

@ -14,7 +14,7 @@
#include "CAENDigitizerType.h" #include "CAENDigitizerType.h"
#include "macro.h" #include "macro.h"
#define MaxNData 10000 /// store 100k events per channels #define MaxNData 10000 /// store 10k events per channels
class Data{ class Data{
@ -272,8 +272,8 @@ inline void Data::PrintAllData() const{
printf("============================= Print Data\n"); printf("============================= Print Data\n");
for( int ch = 0; ch < MaxNChannels ; ch++){ for( int ch = 0; ch < MaxNChannels ; ch++){
if( DataIndex[ch] < 0 ) continue; if( DataIndex[ch] < 0 ) continue;
printf("------------ ch : %d, %d \n", ch, DataIndex[ch]); printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]);
for( int ev = 0; ev <= DataIndex[ch] ; ev++){ for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? MaxNData : DataIndex[ch]) ; ev++){
if( DPPType == V1730_DPP_PHA_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); if( DPPType == V1730_DPP_PHA_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
if( DPPType == V1730_DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); if( DPPType == V1730_DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
} }

View File

@ -1,4 +1,5 @@
#include <cstdio> #include <cstdio>
#include <random>
#include "macro.h" #include "macro.h"
#include "ClassDigitizer.h" #include "ClassDigitizer.h"
@ -6,7 +7,60 @@
int main(){ 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(0, 4);
std::uniform_int_distribution<unsigned short> RanEnergy(1, 1000);
std::uniform_int_distribution<unsigned long long> RanTime(1, 50);
OnlineEventBuilder * eb = new OnlineEventBuilder(digi);
unsigned long long time = 0;
for( int q = 0; q < 3; q ++ ){
int count = 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] ++;
if( data->DataIndex[ch] > MaxNData ) {
data->LoopIndex[ch] ++;
data->DataIndex[ch] = 0;
}
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 < 40 );
data->PrintAllData();
printf("===================================\n");
eb->BuildEvents(100, true);
}
delete eb;
delete digi;
} }

View File

@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs`
OBJS = ClassDigitizer.o OnlineEventBuilder.o 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 EventBuilder : EventBuilder.cpp ClassData.h
@echo "--------- making EventBuilder" @echo "--------- making EventBuilder"
$(CC) $(COPTS) -o EventBuilder EventBuilder.cpp $(CAENLIBS) $(ROOTLIBS) $(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,12 +1,13 @@
#include "OnlineEventBuilder.h" #include "OnlineEventBuilder.h"
#include <algorithm>
OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){ OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){
data = digi->GetData(); data = digi->GetData();
nCh = digi->GetNChannels(); nCh = digi->GetNChannels();
eventIndex = -1; eventIndex = -1;
isNeverBuild = true;
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++ ){
@ -29,10 +30,8 @@ OnlineEventBuilder::~OnlineEventBuilder(){
void OnlineEventBuilder::FindEarlistTimeAndCh(){ void OnlineEventBuilder::FindEarlistTimeAndCh(){
if( isNeverBuild ){ earlistTime = -1;
earlistTime = -1; earlistCh = -1;
earlistCh = -1;
}
nExhaushedCh = 0; nExhaushedCh = 0;
for( int i = 0; i < MaxNChannels; i++ ){ for( int i = 0; i < MaxNChannels; i++ ){
@ -46,33 +45,42 @@ void OnlineEventBuilder::FindEarlistTimeAndCh(){
continue; continue;
} }
if( isNeverBuild || nextIndex[ch] == -1 ) nextIndex[ch] = 0; if( nextIndex[ch] == -1 ) nextIndex[ch] = 0;
unsigned long long time = data->Timestamp[ch][nextIndex[ch]]; unsigned long long time = data->Timestamp[ch][nextIndex[ch]];
if( time < earlistTime ) { if( time < earlistTime ) {
earlistTime = time; earlistTime = time;
earlistCh = ch; 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::FindLatestTime(){
void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){ latestTime = 0;
for( unsigned ch = 0; ch < nCh; ch++ ){
int index = data->DataIndex[ch];
if( index == -1 ) continue;
if( data->Timestamp[ch][index] > latestTime ) {
latestTime = data->Timestamp[ch][index];
}
}
printf("--- latest time %lld \n", latestTime);
}
void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
this->timeWindow = timeWindow; this->timeWindow = timeWindow;
//======= Find the earlist time and ch FindLatestTime();
FindEarlistTimeAndCh(); FindEarlistTimeAndCh();
if( earlistCh == -1 ) { /// no data if( earlistCh == -1 || nExhaushedCh == nCh) return; /// no data
return;
}
//======= Start bilding event
//======= Start building event
do{ do{
eventIndex ++; eventIndex ++;
@ -92,15 +100,16 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){
do { do {
dT = data->Timestamp[ch][nextIndex[ch]] - earlistTime; unsigned long long time = data->Timestamp[ch][nextIndex[ch]];
if( dT < timeWindow ){ if( time - earlistTime < timeWindow ){
dp.ch = ch; dp.ch = ch;
dp.energy = data->Energy[ch][nextIndex[ch]]; dp.energy = data->Energy[ch][nextIndex[ch]];
dp.timeStamp = data->Timestamp[ch][nextIndex[ch]]; dp.timeStamp = time;
events[eventIndex].push_back(dp); events[eventIndex].push_back(dp);
nextIndex[ch]++; nextIndex[ch]++;
if( nextIndex[ch] >= MaxNData) nextIndex[ch] = 0;
}else{ }else{
break; break;
} }
@ -109,35 +118,33 @@ void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){
} }
isNeverBuild = false; std::sort(events[eventIndex].begin(), events[eventIndex].end(), [](const dataPoint& a, const dataPoint& b) {
return a.timeStamp < b.timeStamp;
//===== 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 ///Find the next earlist
earlistTime = data->Timestamp[dp.ch][nextIndex[dp.ch]];
FindEarlistTimeAndCh(); FindEarlistTimeAndCh();
if( nExhaushedCh == nCh ) { if( verbose ){
printf("######################### no more eevent to be built\n"); 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( nExhaushedCh == nCh ) {
printf("######################### no more event to be built\n");
break;
}
printf("----- next ch : %d, next earlist Time : %llu \n", earlistCh, earlistTime);
}
if( latestTime - earlistTime <= timeWindow ) {
if( verbose ) {
printf("######################### left over data for next build\n");
}
break; break;
} }
printf("----- next ch : %d, next earlist Time : %llu \n", earlistCh, earlistTime);
}while(nExhaushedCh < nCh); }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(Digitizer * digi);
~OnlineEventBuilder(); ~OnlineEventBuilder();
void BuildEvents(unsigned short timeWindow); void BuildEvents(unsigned short timeWindow, bool verbose = false);
long eventIndex; long eventIndex;
std::vector<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy std::vector<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy
@ -41,7 +41,6 @@ private:
Data * data; Data * data;
unsigned short timeWindow; unsigned short timeWindow;
bool isNeverBuild;
int nextIndex[MaxNChannels]; int nextIndex[MaxNChannels];
int nExhaushedCh; int nExhaushedCh;
@ -49,6 +48,8 @@ private:
unsigned long long earlistTime; unsigned long long earlistTime;
int earlistCh; int earlistCh;
void FindEarlistTimeAndCh(); void FindEarlistTimeAndCh();
unsigned long long latestTime;
void FindLatestTime();
}; };