added OnlineEventBuilder.cpp and DataGenerator.cpp
This commit is contained in:
parent
5719171bdc
commit
367512ae06
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -44,4 +44,5 @@ Thumbs.db
|
|||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
/.qmake.stash
|
||||
*.gdb_history
|
|
@ -107,7 +107,7 @@ void Canvas::UpdateCanvas(){
|
|||
|
||||
digiMTX[i].lock();
|
||||
for( int ch = 0; ch < digi[i]->GetNChannels(); ch ++ ){
|
||||
int lastIndex = digi[i]->GetData()->EventIndex[ch];
|
||||
int lastIndex = digi[i]->GetData()->DataIndex[ch];
|
||||
int nDecoded = digi[i]->GetData()->NumEventsDecoded[ch];
|
||||
|
||||
for( int j = lastIndex - nDecoded + 1; j <= lastIndex; j ++){
|
||||
|
|
76
ClassData.h
76
ClassData.h
|
@ -35,9 +35,10 @@ class Data{
|
|||
unsigned short NumNonPileUpDecoded[MaxNChannels]; /// reset at every decode
|
||||
|
||||
/// store data for event building and deduce the trigger rate.
|
||||
//TODO... make it a circular memory
|
||||
//it is a circular memory
|
||||
bool IsNotRollOverFakeAgg;
|
||||
int EventIndex[MaxNChannels];
|
||||
int LoopIndex[MaxNChannels]; /// number of loop in the circular memory
|
||||
int DataIndex[MaxNChannels];
|
||||
unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit
|
||||
unsigned short fineTime[MaxNChannels][MaxNData]; /// 10 bits, in unit of ch2ns / 1000 = ps
|
||||
unsigned short Energy[MaxNChannels][MaxNData]; /// 15 bit
|
||||
|
@ -162,7 +163,8 @@ inline void Data::ClearData(){
|
|||
AllocatedSize = 0;
|
||||
IsNotRollOverFakeAgg = false;
|
||||
for( int ch = 0 ; ch < MaxNChannels; ch++){
|
||||
EventIndex[ch] = -1;
|
||||
LoopIndex[ch] = 0;
|
||||
DataIndex[ch] = -1;
|
||||
for( int j = 0; j < MaxNData; j++){
|
||||
Timestamp[ch][j] = 0;
|
||||
fineTime[ch][j] = 0;
|
||||
|
@ -269,9 +271,9 @@ inline void Data::PrintStat() const{
|
|||
inline void Data::PrintAllData() const{
|
||||
printf("============================= Print Data\n");
|
||||
for( int ch = 0; ch < MaxNChannels ; ch++){
|
||||
if( EventIndex[ch] < 0 ) continue;
|
||||
printf("------------ ch : %d, %d \n", ch, EventIndex[ch]);
|
||||
for( int ev = 0; ev <= EventIndex[ch] ; ev++){
|
||||
if( DataIndex[ch] < 0 ) continue;
|
||||
printf("------------ ch : %d, %d \n", ch, DataIndex[ch]);
|
||||
for( int ev = 0; ev <= 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_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
|
||||
}
|
||||
|
@ -368,7 +370,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
continue;
|
||||
}
|
||||
|
||||
if( EventIndex[ch] < 0 ){
|
||||
if( DataIndex[ch] < 0 ){
|
||||
TriggerRate[ch] = 0;
|
||||
NonPileUpRate[ch] = 0;
|
||||
continue;
|
||||
|
@ -377,12 +379,12 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
//TODO ====== when NumEventsDecoded is too small, the trigger rate is not reliable?
|
||||
if( NumEventsDecoded[ch] > 4 ){
|
||||
|
||||
int indexStart = EventIndex[ch] - NumEventsDecoded[ch] + 1;
|
||||
int indexStart = DataIndex[ch] - NumEventsDecoded[ch] + 1;
|
||||
if( indexStart < 0 ) indexStart += MaxNData;
|
||||
|
||||
//printf("%d %d| %d %d \n", EventIndex[ch], NumEventsDecoded[ch], indexStart, EventIndex[ch] );
|
||||
//printf("%d %d| %d %d \n", DataIndex[ch], NumEventsDecoded[ch], indexStart, DataIndex[ch] );
|
||||
|
||||
unsigned long long dTime = Timestamp[ch][EventIndex[ch]] - Timestamp[ch][indexStart];
|
||||
unsigned long long dTime = Timestamp[ch][DataIndex[ch]] - Timestamp[ch][indexStart];
|
||||
double sec = dTime * ch2ns / 1e9;
|
||||
|
||||
TriggerRate[ch] = NumEventsDecoded[ch]/sec;
|
||||
|
@ -391,7 +393,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
|
|||
}else{ // look in to the data in the memory, not just this agg.
|
||||
|
||||
if( calIndexes[ch][0] == -1 ) calIndexes[ch][0] = 0;
|
||||
if( calIndexes[ch][0] > -1 && calIndexes[ch][1] == -1 ) calIndexes[ch][1] = EventIndex[ch];
|
||||
if( calIndexes[ch][0] > -1 && calIndexes[ch][1] == -1 ) calIndexes[ch][1] = DataIndex[ch];
|
||||
|
||||
short nEvent = calIndexes[ch][1] - calIndexes[ch][0] ;
|
||||
if( nEvent < 0 ) nEvent += MaxNData;
|
||||
|
@ -622,13 +624,16 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
|
||||
|
||||
if( rollOver == 0 ) { // non-time roll over fake event
|
||||
EventIndex[channel] ++;
|
||||
if( EventIndex[channel] > MaxNData ) EventIndex[channel] = 0;
|
||||
DataIndex[channel] ++;
|
||||
if( DataIndex[channel] > MaxNData ) {
|
||||
LoopIndex[channel] ++;
|
||||
DataIndex[channel] = 0;
|
||||
}
|
||||
|
||||
Energy[channel][EventIndex[channel]] = energy;
|
||||
Timestamp[channel][EventIndex[channel]] = timeStamp;
|
||||
if(extra2Option == 0 || extra2Option == 2 ) fineTime[channel][EventIndex[channel]] = (extra2 & 0x07FF );
|
||||
PileUp[channel][EventIndex[channel]] = pileUp;
|
||||
Energy[channel][DataIndex[channel]] = energy;
|
||||
Timestamp[channel][DataIndex[channel]] = timeStamp;
|
||||
if(extra2Option == 0 || extra2Option == 2 ) fineTime[channel][DataIndex[channel]] = (extra2 & 0x07FF );
|
||||
PileUp[channel][DataIndex[channel]] = pileUp;
|
||||
NumEventsDecoded[channel] ++;
|
||||
TotNumEvents[channel] ++;
|
||||
|
||||
|
@ -638,19 +643,19 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
|
||||
if( SaveWaveToMemory ) {
|
||||
if( hasDualTrace ){
|
||||
Waveform1[channel][EventIndex[channel]] = tempWaveform1;
|
||||
Waveform2[channel][EventIndex[channel]] = tempWaveform2;
|
||||
Waveform1[channel][DataIndex[channel]] = tempWaveform1;
|
||||
Waveform2[channel][DataIndex[channel]] = tempWaveform2;
|
||||
}else{
|
||||
Waveform1[channel][EventIndex[channel]] = tempWaveform1;
|
||||
Waveform1[channel][DataIndex[channel]] = tempWaveform1;
|
||||
}
|
||||
DigiWaveform1[channel][EventIndex[channel]] = tempDigiWaveform1;
|
||||
DigiWaveform1[channel][DataIndex[channel]] = tempDigiWaveform1;
|
||||
}
|
||||
}
|
||||
|
||||
//if( EventIndex[channel] > MaxNData ) ClearData(); // if any channel has more data then MaxNData, clear all stored data
|
||||
//if( DataIndex[channel] > MaxNData ) ClearData(); // if any channel has more data then MaxNData, clear all stored data
|
||||
|
||||
if( verbose >= 1 ) printf("evt %4d | ch : %2d, PileUp : %d , energy : %5d, rollOver: %d, timestamp : %10llu, triggerAt : %d, nSample : %d, %f sec\n",
|
||||
EventIndex[channel], channel, pileUp, energy, rollOver, timeStamp, triggerAtSample, nSample , timeStamp * 4. / 1e9);
|
||||
DataIndex[channel], channel, pileUp, energy, rollOver, timeStamp, triggerAtSample, nSample , timeStamp * 4. / 1e9);
|
||||
|
||||
}
|
||||
|
||||
|
@ -808,32 +813,35 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
|
|||
bool isEnergyCorrect = ((word >> 15) & 0x1); // the PUR, either pileup or saturated
|
||||
|
||||
if( isEnergyCorrect == 0 ) {
|
||||
EventIndex[channel] ++;
|
||||
if( EventIndex[channel] > MaxNData ) EventIndex[channel] = 0;
|
||||
DataIndex[channel] ++;
|
||||
if( DataIndex[channel] > MaxNData ) {
|
||||
LoopIndex[channel] ++;
|
||||
DataIndex[channel] = 0;
|
||||
}
|
||||
|
||||
NumEventsDecoded[channel] ++;
|
||||
NumNonPileUpDecoded[channel] ++;
|
||||
TotNumEvents[channel] ++;
|
||||
|
||||
Energy[channel][EventIndex[channel]] = Qshort;
|
||||
Energy2[channel][EventIndex[channel]] = Qlong;
|
||||
Timestamp[channel][EventIndex[channel]] = timeStamp;
|
||||
Energy[channel][DataIndex[channel]] = Qshort;
|
||||
Energy2[channel][DataIndex[channel]] = Qlong;
|
||||
Timestamp[channel][DataIndex[channel]] = timeStamp;
|
||||
|
||||
if( SaveWaveToMemory ) {
|
||||
if( hasDualTrace ){
|
||||
Waveform1[channel][EventIndex[channel]] = tempWaveform1;
|
||||
Waveform2[channel][EventIndex[channel]] = tempWaveform2;
|
||||
Waveform1[channel][DataIndex[channel]] = tempWaveform1;
|
||||
Waveform2[channel][DataIndex[channel]] = tempWaveform2;
|
||||
}else{
|
||||
Waveform1[channel][EventIndex[channel]] = tempWaveform1;
|
||||
Waveform1[channel][DataIndex[channel]] = tempWaveform1;
|
||||
}
|
||||
DigiWaveform1[channel][EventIndex[channel]] = tempDigiWaveform1;
|
||||
DigiWaveform2[channel][EventIndex[channel]] = tempDigiWaveform2;
|
||||
DigiWaveform1[channel][DataIndex[channel]] = tempDigiWaveform1;
|
||||
DigiWaveform2[channel][DataIndex[channel]] = tempDigiWaveform2;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//if( EventIndex[channel] >= MaxNData ) ClearData();
|
||||
//if( DataIndex[channel] >= MaxNData ) ClearData();
|
||||
|
||||
if( verbose >= 2 ) printf("extra : 0x%08x, Qshort : %d, Qlong : %d \n", extra, Qshort, Qlong);
|
||||
|
||||
|
|
12
DataGenerator.cpp
Normal file
12
DataGenerator.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <cstdio>
|
||||
|
||||
#include "macro.h"
|
||||
#include "ClassDigitizer.h"
|
||||
#include "OnlineEventBuilder.h"
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -261,12 +261,12 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
|
|||
unsigned long long smallestLastTimeStamp = -1;
|
||||
unsigned int maxNumEvent = 0;
|
||||
for( int chI = 0; chI < MaxNChannels ; chI ++){
|
||||
if( data->EventIndex[chI] == 0 ) continue;
|
||||
if( data->DataIndex[chI] == 0 ) continue;
|
||||
|
||||
if( data->Timestamp[chI][0] < firstTimeStamp ) {
|
||||
firstTimeStamp = data->Timestamp[chI][0];
|
||||
}
|
||||
unsigned short ev = data->EventIndex[chI]-1;
|
||||
unsigned short ev = data->DataIndex[chI]-1;
|
||||
if( data->Timestamp[chI][ev] > lastTimeStamp ) {
|
||||
lastTimeStamp = data->Timestamp[chI][ev];
|
||||
}
|
||||
|
@ -289,8 +289,8 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
|
|||
int ch1st = -1;
|
||||
unsigned long long time1st = -1;
|
||||
for( int chI = 0; chI < MaxNChannels ; chI ++){
|
||||
if( data->EventIndex[chI] == 0 ) continue;
|
||||
if( data->EventIndex[chI] <= lastEv[chI] ) continue;
|
||||
if( data->DataIndex[chI] == 0 ) continue;
|
||||
if( data->DataIndex[chI] <= lastEv[chI] ) continue;
|
||||
if( data->Timestamp[chI][lastEv[chI]] < time1st ) {
|
||||
time1st = data->Timestamp[chI][lastEv[chI]];
|
||||
ch1st = chI;
|
||||
|
@ -323,17 +323,17 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
|
|||
singleChannelExhaustedFlag = false;
|
||||
for( int chI = ch1st; chI < ch1st + MaxNChannels; chI ++){
|
||||
unsigned short chX = chI % MaxNChannels;
|
||||
if( data->EventIndex[chX] == 0 ) {
|
||||
if( data->DataIndex[chX] == 0 ) {
|
||||
exhaustedCh ++;
|
||||
continue;
|
||||
}
|
||||
if( data->EventIndex[chX] <= lastEv[chX] ) {
|
||||
if( data->DataIndex[chX] <= lastEv[chX] ) {
|
||||
exhaustedCh ++;
|
||||
singleChannelExhaustedFlag = true;
|
||||
continue;
|
||||
}
|
||||
if( timeWin == 0 ) continue;
|
||||
for( int ev = lastEv[chX]; ev < data->EventIndex[chX] ; ev++){
|
||||
for( int ev = lastEv[chX]; ev < data->DataIndex[chX] ; ev++){
|
||||
if( data->Timestamp[chX][ev] > 0 && (data->Timestamp[chX][ev] - e_t[0] ) < timeWin ) {
|
||||
multi ++;
|
||||
bd[multi-1] = data->boardSN;
|
||||
|
@ -350,7 +350,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
|
|||
}
|
||||
}
|
||||
lastEv[chX] = ev + 1;
|
||||
if( lastEv[chX] == data->EventIndex[chX] ) exhaustedCh ++;
|
||||
if( lastEv[chX] == data->DataIndex[chX] ) exhaustedCh ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
|
|||
printf("=============== Last Ev , exhaustedCh %d \n", exhaustedCh);
|
||||
for( int chI = 0; chI < MaxNChannels ; chI++){
|
||||
if( lastEv[chI] == 0 ) continue;
|
||||
printf("%2d, %d %d\n", chI, lastEv[chI], data->EventIndex[chI]);
|
||||
printf("%2d, %d %d\n", chI, lastEv[chI], data->DataIndex[chI]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,16 +379,16 @@ void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool is
|
|||
///========== clear built data
|
||||
/// move the last data to the top,
|
||||
for( int chI = 0; chI < MaxNChannels; chI++){
|
||||
if( data->EventIndex[chI] == 0 ) continue;
|
||||
if( data->DataIndex[chI] == 0 ) continue;
|
||||
int count = 0;
|
||||
for( int ev = lastEv[chI] ; ev < data->EventIndex[chI] ; ev++){
|
||||
for( int ev = lastEv[chI] ; ev < data->DataIndex[chI] ; ev++){
|
||||
data->Energy[chI][count] = data->Energy[chI][ev];
|
||||
data->Timestamp[chI][count] = data->Timestamp[chI][ev];
|
||||
data->fineTime[chI][count] = data->fineTime[chI][ev];
|
||||
count++;
|
||||
}
|
||||
int lala = data->EventIndex[chI] - lastEv[chI];
|
||||
data->EventIndex[chI] = (lala >= 0 ? lala: 0);
|
||||
int lala = data->DataIndex[chI] - lastEv[chI];
|
||||
data->DataIndex[chI] = (lala >= 0 ? lala: 0);
|
||||
}
|
||||
|
||||
if( verbose > 0 ) {
|
||||
|
|
10
FSUDAQ.cpp
10
FSUDAQ.cpp
|
@ -53,6 +53,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
|
|||
layout->addWidget(bnOpenScope, 1, 1);
|
||||
connect(bnOpenScope, &QPushButton::clicked, this, &MainWindow::OpenScope);
|
||||
|
||||
bnAnalyzer = new QPushButton("Online Analyzer", this);
|
||||
layout->addWidget(bnAnalyzer, 0, 2);
|
||||
connect(bnAnalyzer, &QPushButton::clicked, this, &MainWindow::OpenScope);
|
||||
bnAnalyzer->setEnabled(false);
|
||||
|
||||
bnCanvas = new QPushButton("Online 1D Histograms", this);
|
||||
layout->addWidget(bnCanvas, 1, 2);
|
||||
connect(bnCanvas, &QPushButton::clicked, this, &MainWindow::OpenCanvas);
|
||||
|
@ -773,7 +778,10 @@ void MainWindow::UpdateScalar(){
|
|||
}
|
||||
|
||||
if( influx ){
|
||||
if( chkSaveData->isChecked() ) influx->AddDataPoint("FileSize value=" + std::to_string(totalFileSize));
|
||||
if( chkSaveData->isChecked() ) {
|
||||
influx->AddDataPoint("RunID value=" + std::to_string(runID));
|
||||
influx->AddDataPoint("FileSize value=" + std::to_string(totalFileSize));
|
||||
}
|
||||
influx->WriteData(dataBaseName.toStdString());
|
||||
influx->ClearDataPointsBuffer();
|
||||
}
|
||||
|
|
1
FSUDAQ.h
1
FSUDAQ.h
|
@ -85,6 +85,7 @@ private:
|
|||
QPushButton * bnCloseDigitizers;
|
||||
QPushButton * bnOpenScope;
|
||||
QPushButton * bnDigiSettings;
|
||||
QPushButton * bnAnalyzer;
|
||||
|
||||
QPushButton * bnOpenScaler;
|
||||
QPushButton * bnStartACQ;
|
||||
|
|
|
@ -32,11 +32,13 @@ HEADERS += ClassData.h \
|
|||
RegisterAddress.h \
|
||||
influxdb.h\
|
||||
Scope.h \
|
||||
CanvasClass.h
|
||||
CanvasClass.h \
|
||||
OnlineEventBuilder.h
|
||||
SOURCES += ClassDigitizer.cpp \
|
||||
DigiSettingsPanel.cpp \
|
||||
FSUDAQ.cpp \
|
||||
main.cpp \
|
||||
influxdb.cpp\
|
||||
Scope.cpp \
|
||||
CanvasClass.cpp
|
||||
CanvasClass.cpp \
|
||||
OnlineEventBuilder.cpp \
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
CC = g++
|
||||
|
||||
#COPTS = -fPIC -DLINUX -O2 -std=c++17 -lpthread
|
||||
COPTS = -fPIC -DLINUX -g -std=c++17 -lpthread
|
||||
COPTS = -fPIC -DLINUX -g -O2 -Wall -std=c++17 -lpthread
|
||||
|
||||
CAENLIBS = -lCAENDigitizer
|
||||
|
||||
ROOTLIBS = `root-config --cflags --glibs`
|
||||
|
||||
OBJS = ClassDigitizer.o
|
||||
OBJS = ClassDigitizer.o OnlineEventBuilder.o
|
||||
|
||||
ALL = test test_indep EventBuilder
|
||||
|
||||
|
@ -23,12 +23,15 @@ all : $(ALL)
|
|||
clean :
|
||||
/bin/rm -f $(OBJS) $(ALL)
|
||||
|
||||
OnlineEventBuilder.o : OnlineEventBuilder.cpp OnlineEventBuilder.h
|
||||
$(CC) $(COPTS) -c OnlineEventBuilder.cpp
|
||||
|
||||
ClassDigitizer.o : ClassDigitizer.cpp ClassDigitizer.h RegisterAddress.h macro.h ClassData.h
|
||||
$(CC) $(COPTS) -c ClassDigitizer.cpp
|
||||
|
||||
test : test.cpp ClassDigitizer.o
|
||||
test : test.cpp ClassDigitizer.o OnlineEventBuilder.o
|
||||
@echo "--------- making test"
|
||||
$(CC) $(COPTS) -o test test.cpp ClassDigitizer.o $(CAENLIBS) $(ROOTLIBS)
|
||||
$(CC) $(COPTS) -o test test.cpp ClassDigitizer.o OnlineEventBuilder.o $(CAENLIBS) $(ROOTLIBS)
|
||||
|
||||
test_indep : test_indep.cpp RegisterAddress.h macro.h
|
||||
@echo "--------- making test_indep"
|
||||
|
|
143
OnlineEventBuilder.cpp
Normal file
143
OnlineEventBuilder.cpp
Normal file
|
@ -0,0 +1,143 @@
|
|||
#include "OnlineEventBuilder.h"
|
||||
|
||||
OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){
|
||||
|
||||
data = digi->GetData();
|
||||
nCh = digi->GetNChannels();
|
||||
|
||||
eventIndex = -1;
|
||||
isNeverBuild = true;
|
||||
for( int i = 0; i < MaxNEvent; i++ ) events[i].clear();
|
||||
|
||||
for( int i = 0; i < MaxNChannels; i++ ){
|
||||
nextIndex[i] = -1;
|
||||
chExhaused[i] = false;
|
||||
}
|
||||
|
||||
earlistTime = -1;
|
||||
earlistCh = -1;
|
||||
|
||||
nExhaushedCh = 0;
|
||||
|
||||
}
|
||||
|
||||
OnlineEventBuilder::~OnlineEventBuilder(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OnlineEventBuilder::FindEarlistTimeAndCh(){
|
||||
|
||||
if( isNeverBuild ){
|
||||
earlistTime = -1;
|
||||
earlistCh = -1;
|
||||
}
|
||||
|
||||
nExhaushedCh = 0;
|
||||
for( int i = 0; i < MaxNChannels; i++ ){
|
||||
chExhaused[i] = false;
|
||||
}
|
||||
|
||||
for(unsigned int ch = 0; ch < nCh; ch ++){
|
||||
if( data->DataIndex[ch] == -1 || nextIndex[ch] > data->DataIndex[ch]) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[ch] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( isNeverBuild || nextIndex[ch] == -1 ) nextIndex[ch] = 0;
|
||||
|
||||
unsigned long long time = data->Timestamp[ch][nextIndex[ch]];
|
||||
|
||||
if( time < earlistTime ) {
|
||||
earlistTime = time;
|
||||
earlistCh = ch;
|
||||
printf("ch: %d , nextIndex : %d, %llu\n", ch, nextIndex[ch] , earlistTime);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OnlineEventBuilder::BuildEvents(unsigned short timeWindow){
|
||||
|
||||
this->timeWindow = timeWindow;
|
||||
|
||||
//======= Find the earlist time and ch
|
||||
FindEarlistTimeAndCh();
|
||||
|
||||
if( earlistCh == -1 ) { /// no data
|
||||
return;
|
||||
}
|
||||
|
||||
//======= Start bilding event
|
||||
|
||||
do{
|
||||
|
||||
eventIndex ++;
|
||||
if( eventIndex >= MaxNEvent ) eventIndex = 0;
|
||||
|
||||
unsigned long long dT =0;
|
||||
dataPoint dp = {0, 0, 0};
|
||||
for( unsigned int i = 0; i < nCh; i++){
|
||||
int ch = (i + earlistCh ) % nCh;
|
||||
|
||||
if( chExhaused[ch] ) continue;
|
||||
if( nextIndex[ch] > data->DataIndex[ch]) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[ch] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
dT = data->Timestamp[ch][nextIndex[ch]] - earlistTime;
|
||||
|
||||
if( dT < timeWindow ){
|
||||
dp.ch = ch;
|
||||
dp.energy = data->Energy[ch][nextIndex[ch]];
|
||||
dp.timeStamp = data->Timestamp[ch][nextIndex[ch]];
|
||||
|
||||
events[eventIndex].push_back(dp);
|
||||
nextIndex[ch]++;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
|
||||
}while( dT < timeWindow);
|
||||
|
||||
}
|
||||
|
||||
isNeverBuild = false;
|
||||
|
||||
//===== 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
55
OnlineEventBuilder.h
Normal file
55
OnlineEventBuilder.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
#ifndef ONLINE_EVENT_BUILDER_H
|
||||
#define ONLINE_EVENT_BUILDER_H
|
||||
|
||||
/**********************************************
|
||||
|
||||
This is an online event builder for single digitizer
|
||||
|
||||
In principle, it can be merged into the digitizer Class.
|
||||
But for clarity and separate the memory for an event.
|
||||
Use another class to hold the event data and methods.
|
||||
|
||||
************************************************/
|
||||
|
||||
#include "macro.h"
|
||||
#include "ClassDigitizer.h"
|
||||
|
||||
#define MaxNEvent 10000
|
||||
|
||||
struct dataPoint{
|
||||
unsigned short ch;
|
||||
unsigned short energy;
|
||||
unsigned long long timeStamp;
|
||||
};
|
||||
|
||||
class OnlineEventBuilder {
|
||||
|
||||
public:
|
||||
OnlineEventBuilder(Digitizer * digi);
|
||||
~OnlineEventBuilder();
|
||||
|
||||
void BuildEvents(unsigned short timeWindow);
|
||||
|
||||
long eventIndex;
|
||||
std::vector<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy
|
||||
|
||||
unsigned short GetTimeWindow() const { return timeWindow;}
|
||||
|
||||
private:
|
||||
|
||||
unsigned short nCh;
|
||||
Data * data;
|
||||
|
||||
unsigned short timeWindow;
|
||||
bool isNeverBuild;
|
||||
int nextIndex[MaxNChannels];
|
||||
|
||||
int nExhaushedCh;
|
||||
bool chExhaused[MaxNChannels];
|
||||
unsigned long long earlistTime;
|
||||
int earlistCh;
|
||||
void FindEarlistTimeAndCh();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -312,7 +312,7 @@ void Scope::UpdateScope(){
|
|||
//leTriggerRate->setText(QString::number(data->TriggerRate[ch]) + " [" + QString::number(data->NumEventsDecoded[ch]) + "]");
|
||||
leTriggerRate->setText(QString::number(data->TriggerRate[ch]));
|
||||
|
||||
unsigned short index = data->EventIndex[ch];
|
||||
unsigned short index = data->DataIndex[ch];
|
||||
unsigned short traceLength = data->Waveform1[ch][index].size();
|
||||
|
||||
if( data->TriggerRate[ch] > 0 ){
|
||||
|
|
27
test.cpp
27
test.cpp
|
@ -2,6 +2,8 @@
|
|||
#include "ClassData.h"
|
||||
#include "ClassDigitizer.h"
|
||||
|
||||
#include "OnlineEventBuilder.h"
|
||||
|
||||
#include <TROOT.h>
|
||||
#include <TSystem.h>
|
||||
#include <TApplication.h>
|
||||
|
@ -35,8 +37,15 @@ int main(int argc, char* argv[]){
|
|||
dig[i] = new Digitizer(board, port, false, true);
|
||||
}
|
||||
|
||||
const float ch2ns = dig[0]->GetCh2ns();
|
||||
dig[0]->StopACQ();
|
||||
// dig[0]->WriteRegister(DPP::SoftwareClear_W, 1);
|
||||
|
||||
// dig[0]->ProgramBoard();
|
||||
// dig[0]->ProgramPSDBoard();
|
||||
|
||||
// const float ch2ns = dig[0]->GetCh2ns();
|
||||
|
||||
OnlineEventBuilder * eb = new OnlineEventBuilder( dig[0] );
|
||||
|
||||
Data * data = dig[0]->GetData();
|
||||
|
||||
|
@ -46,16 +55,18 @@ int main(int argc, char* argv[]){
|
|||
|
||||
dig[0]->StartACQ();
|
||||
|
||||
for( int i = 0; i < 5; i ++ ){
|
||||
for( int i = 0; i < 3; i ++ ){
|
||||
usleep(100*1000);
|
||||
dig[0]->ReadData();
|
||||
data->DecodeBuffer(false, 5);
|
||||
data->DecodeBuffer(false, 1);
|
||||
data->PrintStat();
|
||||
|
||||
data->SaveData();
|
||||
|
||||
int index = data->NumEventsDecoded[0];
|
||||
printf("-------------- %ld \n", data->Waveform1[0][index].size());
|
||||
// int index = data->NumEventsDecoded[0];
|
||||
// printf("-------------- %ld \n", data->Waveform1[0][index].size());
|
||||
|
||||
eb->BuildEvents(100);
|
||||
|
||||
}
|
||||
|
||||
|
@ -108,7 +119,7 @@ int main(int argc, char* argv[]){
|
|||
data->SaveBuffer("test");
|
||||
data->DecodeBuffer(0);
|
||||
|
||||
unsigned short nData = data->EventIndex[0]; //channel-0
|
||||
unsigned short nData = data->DataIndex[0]; //channel-0
|
||||
haha = data->Waveform1[0][nData-1];
|
||||
for( int i = 0; i < waveFormLength; i++) g1->SetPoint(i, i*ch2ns, haha[i]);
|
||||
|
||||
|
@ -128,10 +139,10 @@ int main(int argc, char* argv[]){
|
|||
data->PrintStat();
|
||||
|
||||
for(int i = 0; i < dig[0]->GetNChannel(); i++){
|
||||
h1->Fill(i, data->EventIndex[i]);
|
||||
h1->Fill(i, data->DataIndex[i]);
|
||||
}
|
||||
|
||||
for( int i = 0; i < data->EventIndex[0]; i++){
|
||||
for( int i = 0; i < data->DataIndex[0]; i++){
|
||||
h2->Fill( data->Energy[0][i]);
|
||||
}
|
||||
data->ClearData();
|
||||
|
|
|
@ -292,7 +292,7 @@ int main(int argc, char* argv[]){
|
|||
|
||||
int Nb; /// number of byte
|
||||
char *buffer = NULL; /// readout buffer
|
||||
uint32_t EventIndex[MaxNChannels];
|
||||
uint32_t DataIndex[MaxNChannels];
|
||||
uint32_t AllocatedSize, BufferSize;
|
||||
CAEN_DGTZ_DPP_PHA_Event_t *Events[MaxNChannels]; /// events buffer
|
||||
CAEN_DGTZ_DPP_PHA_Waveforms_t *Waveform[MaxNChannels]; /// waveforms buffer
|
||||
|
@ -327,15 +327,15 @@ int main(int argc, char* argv[]){
|
|||
if (Nb == 0 || ret) {
|
||||
return 0;
|
||||
}
|
||||
ret |= (CAEN_DGTZ_ErrorCode) CAEN_DGTZ_GetDPPEvents(handle, buffer, BufferSize, reinterpret_cast<void**>(&Events), EventIndex);
|
||||
ret |= (CAEN_DGTZ_ErrorCode) CAEN_DGTZ_GetDPPEvents(handle, buffer, BufferSize, reinterpret_cast<void**>(&Events), DataIndex);
|
||||
if (ret) {
|
||||
printf("Error when getting events from data %d\n", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int ch = 0; ch < NChannel; ch++) {
|
||||
if( EventIndex[ch] > 0 ) printf("------------------------ %d, %d\n", ch, EventIndex[ch]);
|
||||
for (int ev = 0; ev < EventIndex[ch]; ev++) {
|
||||
if( DataIndex[ch] > 0 ) printf("------------------------ %d, %d\n", ch, DataIndex[ch]);
|
||||
for (int ev = 0; ev < DataIndex[ch]; ev++) {
|
||||
///TrgCnt[ch]++;
|
||||
|
||||
if( ev == 0 ){
|
||||
|
|
Loading…
Reference in New Issue
Block a user