better data encaptule for ClassData.h

This commit is contained in:
carina@hades 2024-01-26 14:53:52 -05:00
parent 99bb47c25e
commit 0927cca571
8 changed files with 55 additions and 109 deletions

View File

@ -1,61 +0,0 @@
#include <cstdio>
#include <random>
#include "../macro.h"
#include "../ClassDigitizer.h"
int main(){
//Digitizer * digi = new Digitizer();
Data * data = new Data(16);
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);
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] > data->GetDataSize() ) {
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");
}
delete data;
}

View File

@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs`
OBJS = ClassDigitizer.o MultiBuilder.o
ALL = test test_indep DataGenerator EventBuilder EventBuilderNoTrace DataReader DumpFSU2ROOT SettingsExplorer
ALL = test test_indep EventBuilder EventBuilderNoTrace DataReader DumpFSU2ROOT SettingsExplorer
#########################################################################
@ -37,10 +37,6 @@ test_indep : test_indep.cpp ../RegisterAddress.h ../macro.h
@echo "--------- making test_indep"
$(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS)
DataGenerator : DataGenerator.cpp ../ClassDigitizer.o
@echo "--------- making DataGenerator"
$(CC) $(COPTS) -o DataGenerator DataGenerator.cpp ../ClassDigitizer.o $(CAENLIBS)
DataReader : DataReaderScript.cpp ../ClassData.h MultiBuilder.o
@echo "--------- making DataReader"
$(CC) $(COPTS) -o DataReader DataReaderScript.cpp ../ClassData.h MultiBuilder.o

View File

@ -279,7 +279,7 @@ inline int FSUReader::ReadNextBlock(bool traceON, int verbose, uShort saveData){
hitCount += data->NumEventsDecoded[ch];
if( saveData ){
int start = data->DataIndex[ch] - data->NumEventsDecoded[ch] + 1;
int start = data->GetDataIndex(ch) - data->NumEventsDecoded[ch] + 1;
if( start < 0 ) start = start + data->GetDataSize();
for( int i = start; i < start + data->NumEventsDecoded[ch]; i++ ){
@ -287,11 +287,11 @@ inline int FSUReader::ReadNextBlock(bool traceON, int verbose, uShort saveData){
temp.sn = sn;
temp.ch = ch;
temp.energy = data->Energy[ch][k];
temp.energy2 = data->Energy2[ch][k];
temp.timestamp = data->Timestamp[ch][k];
temp.fineTime = data->fineTime[ch][k];
temp.pileUp = data->PileUp[ch][k];
temp.energy = data->GetEnergy(ch, k);
temp.energy2 = data->GetEnergy2(ch, k);
temp.timestamp = data->GetTimestamp(ch, k);
temp.fineTime = data->GetFineTime(ch, k);
temp.pileUp = data->GetPileUp(ch, k);
if( saveData > 1 ) {
temp.traceLength = data->Waveform1[ch][k].size();
temp.trace = data->Waveform1[ch][k];

View File

@ -28,7 +28,7 @@ enum DPPType{
class Data{
public:
char *buffer; /// readout buffer
char * buffer; /// readout buffer
int DPPType;
std::string DPPTypeStr; /// only for saving fiel name
unsigned short boardSN;
@ -49,15 +49,16 @@ class Data{
//it is a circular memory
bool IsNotRollOverFakeAgg;
int LoopIndex[MaxNChannels]; /// number of loop in the circular memory
int DataIndex[MaxNChannels];
int GetLoopIndex(unsigned short ch) const {return LoopIndex[ch];}
int GetDataIndex(unsigned short ch) const {return DataIndex[ch];}
uShort GetDataSize() const {return dataSize;}
ullong ** Timestamp; /// 47 bit
uShort ** fineTime; /// 10 bits, in unit of tick2ns / 1000 = ps
uShort ** Energy ; /// 15 bit
uShort ** Energy2 ; /// 15 bit, in PSD, Energy = Qshort, Energy2 = Qlong
bool ** PileUp ; /// pile up flag
ullong GetTimestamp(unsigned short ch, unsigned int index) const {return Timestamp[ch][index];}
uShort GetFineTime(unsigned short ch, unsigned int index) const {return fineTime[ch][index];}
uShort GetEnergy(unsigned short ch, unsigned int index) const {return Energy[ch][index];}
uShort GetEnergy2(unsigned short ch, unsigned int index) const {return Energy2[ch][index];}
bool GetPileUp(unsigned short ch, unsigned int index) const {return PileUp[ch][index];}
std::vector<short> ** Waveform1 ; // used at least 14 MB
std::vector<short> ** Waveform2 ;
@ -108,6 +109,15 @@ class Data{
uShort dataSize;
int LoopIndex[MaxNChannels]; /// number of loop in the circular memory
int DataIndex[MaxNChannels];
ullong ** Timestamp; /// 47 bit
uShort ** fineTime; /// 10 bits, in unit of tick2ns / 1000 = ps
uShort ** Energy ; /// 15 bit
uShort ** Energy2 ; /// 15 bit, in PSD, Energy = Qshort, Energy2 = Qlong
bool ** PileUp ; /// pile up flag
///for temperary
std::vector<short> tempWaveform1;
std::vector<short> tempWaveform2;

View File

@ -36,6 +36,7 @@ HEADERS += ClassData.h \
influxdb.h\
Scope.h \
SingleSpectra.h \
Hit.h \
MultiBuilder.h \
qcustomplot.h \
analyzers/Isotope.h \

View File

@ -109,9 +109,9 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
continue;
}
if( data[i]->Timestamp[ch][data[i]->DataIndex[ch]] == 0 ||
data[i]->DataIndex[ch] == -1 ||
loopIndex[i][ch] * dataSize[i] > data[i]->LoopIndex[ch] * dataSize[i] + data[i]->DataIndex[ch]) {
if( data[i]->GetTimestamp(ch, data[i]->GetDataIndex(ch)) == 0 ||
data[i]->GetDataIndex(ch) == -1 ||
loopIndex[i][ch] * dataSize[i] > data[i]->GetLoopIndex(ch) * dataSize[i] + data[i]->GetDataIndex(ch)) {
nExhaushedCh ++;
chExhaused[i][ch] = true;
continue;
@ -119,7 +119,7 @@ void MultiBuilder::FindEarlistTimeAndCh(bool verbose){
if( nextIndex[i][ch] == -1 ) nextIndex[i][ch] = 0;
unsigned long long time = data[i]->Timestamp[ch][nextIndex[i][ch]];
unsigned long long time = data[i]->GetTimestamp(ch, nextIndex[i][ch]);
if( time < earlistTime ) {
earlistTime = time;
earlistDigi = i;
@ -156,7 +156,7 @@ void MultiBuilder::FindLatestTimeAndCh(bool verbose){
continue;
}
unsigned long long time = data[i]->Timestamp[ch][nextIndex[i][ch]];
unsigned long long time = data[i]->GetTimestamp(ch, nextIndex[i][ch]);
// printf(", time : %llu\n", time );
if( time > latestTime ) {
latestTime = time;
@ -177,10 +177,10 @@ void MultiBuilder::FindEarlistTimeAmongLastData(bool verbose){
for( int i = 0; i < nData; i++){
for( unsigned ch = 0; ch < data[i]->GetNChannel(); ch++ ){
if( chExhaused[i][ch] ) continue;
int index = data[i]->DataIndex[ch];
int index = data[i]->GetDataIndex(ch);
if( index == -1 ) continue;
if( data[i]->Timestamp[ch][index] < latestTime ) {
latestTime = data[i]->Timestamp[ch][index];
if( data[i]->GetTimestamp(ch, index) < latestTime ) {
latestTime = data[i]->GetTimestamp(ch, index);
latestCh = ch;
latestDigi = i;
}
@ -195,10 +195,10 @@ void MultiBuilder::FindLatestTimeOfData(bool verbose){
latestDigi = -1;
for( int i = 0; i < nData; i++){
for( unsigned ch = 0; ch < data[i]->GetNChannel(); ch++ ){
int index = data[i]->DataIndex[ch];
int index = data[i]->GetDataIndex(ch);
if( index == -1 ) continue;
if( data[i]->Timestamp[ch][index] > latestTime ) {
latestTime = data[i]->Timestamp[ch][index];
if( data[i]->GetTimestamp(ch, index) > latestTime ) {
latestTime = data[i]->GetTimestamp(ch, index);
latestCh = ch;
latestDigi = i;
}
@ -240,7 +240,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
int ch = (i + earlistCh ) % numCh;
// printf("ch : %d | exhaused ? %s \n", ch, chExhaused[bd][ch] ? "Yes" : "No");
if( chExhaused[bd][ch] ) continue;
if( loopIndex[bd][ch] * dataSize[bd] + nextIndex[bd][ch] > data[bd]->LoopIndex[ch] * dataSize[bd] + data[bd]->DataIndex[ch]) {
if( loopIndex[bd][ch] * dataSize[bd] + nextIndex[bd][ch] > data[bd]->GetLoopIndex(ch) * dataSize[bd] + data[bd]->GetDataIndex(ch)) {
nExhaushedCh ++;
chExhaused[bd][ch] = true;
continue;
@ -248,19 +248,19 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){
do {
unsigned long long time = data[bd]->Timestamp[ch][nextIndex[bd][ch]];
unsigned long long time = data[bd]->GetTimestamp(ch, nextIndex[bd][ch]);
//printf("%6ld, sn: %5d, ch: %2d, timestamp : %16llu | earlistTime : %16llu | timeWindow : %u \n", eventIndex, data[bd]->boardSN, ch, time, earlistTime, timeWindow);
if( time >= earlistTime && (time - earlistTime <= timeWindow) ){
em.sn = snList[bd];
em.bd = bd;
em.ch = ch;
em.energy = data[bd]->Energy[ch][nextIndex[bd][ch]];
em.energy = data[bd]->GetEnergy(ch, nextIndex[bd][ch]);
em.timestamp = time;
em.fineTime = data[bd]->fineTime[ch][nextIndex[bd][ch]];
em.fineTime = data[bd]->GetFineTime(ch, nextIndex[bd][ch]);
if( !skipTrace ) em.trace = data[bd]->Waveform1[ch][nextIndex[bd][ch]];
if( typeList[bd] == DPPType::DPP_PSD_CODE ) em.energy2 = data[bd]->Energy2[ch][nextIndex[bd][ch]];
if( typeList[bd] == DPPType::DPP_PSD_CODE ) em.energy2 = data[bd]->GetEnergy2(ch, nextIndex[bd][ch]);
events[eventIndex].push_back(em);
nextIndex[bd][ch]++;
@ -338,8 +338,8 @@ void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){
// remember the end of DataIndex, prevent over build
for( int k = 0; k < nData; k++){
for( int i = 0; i < data[k]->GetNChannel(); i++){
nextIndex[k][i] = data[k]->DataIndex[i];
loopIndex[k][i] = data[k]->LoopIndex[i];
nextIndex[k][i] = data[k]->GetDataIndex(i);
loopIndex[k][i] = data[k]->GetLoopIndex(i);
}
}
@ -374,18 +374,18 @@ void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){
do{
unsigned long long time = data[bd]->Timestamp[ch][nextIndex[bd][ch]];
unsigned long long time = data[bd]->GetTimestamp(ch, nextIndex[bd][ch]);
if( time <= latestTime && (latestTime - time <= timeWindow)){
em.sn = snList[bd];
em.bd = bd;
em.ch = ch;
em.energy = data[bd]->Energy[ch][nextIndex[bd][ch]];
em.energy = data[bd]->GetEnergy(ch, nextIndex[bd][ch]);
em.timestamp = time;
if( typeList[bd] == DPPType::DPP_PSD_CODE ) em.energy2 = data[bd]->Energy2[ch][nextIndex[bd][ch]];
if( typeList[bd] == DPPType::DPP_PSD_CODE ) em.energy2 = data[bd]->GetEnergy2(ch, nextIndex[bd][ch]);
events[eventIndex].push_back(em);
nextIndex[bd][ch]--;
if( nextIndex[bd][ch] < 0 && data[bd]->LoopIndex[ch] > 0 ) nextIndex[bd][ch] = dataSize[bd] - 1;
if( nextIndex[bd][ch] < 0 && data[bd]->GetLoopIndex(ch) > 0 ) nextIndex[bd][ch] = dataSize[bd] - 1;
}else{
break;

View File

@ -467,7 +467,7 @@ void Scope::UpdateScope(){
}
Data * data = digi[ID]->GetData();
int index = data->DataIndex[ch];
int index = data->GetDataIndex(ch);
int traceLength = data->Waveform1[ch][index].size();
if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) traceLength = data->DigiWaveform1[ch][index].size();
@ -481,8 +481,8 @@ void Scope::UpdateScope(){
if( traceLength * tick2ns > MaxDisplayTraceTimeLength) traceLength = MaxDisplayTraceTimeLength / tick2ns;
// printf("--- %s| %d, %d, %d | %d | %d, %d\n", __func__, ch, data->LoopIndex[ch], index, traceLength, factor, tick2ns );
if( index < 0 || data->TriggerRate[ch] > 0 ){
//printf("--- %s| %d, %d, %d | %d | %d, %d\n", __func__, ch, data->LoopIndex[ch], index, traceLength, factor, tick2ns );
if( index > 0 || data->TriggerRate[ch] > 0 ){
QVector<QPointF> points[5];
if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) {

View File

@ -205,8 +205,8 @@ void SingleSpectra::FillHistograms(){
digiMTX[i].lock();
for( int ch = 0; ch < digi[i]->GetNumInputCh(); ch ++ ){
int lastIndex = digi[i]->GetData()->DataIndex[ch];
int loopIndex = digi[i]->GetData()->LoopIndex[ch];
int lastIndex = digi[i]->GetData()->GetDataIndex(ch);
int loopIndex = digi[i]->GetData()->GetLoopIndex(ch);
int temp1 = lastIndex + loopIndex * digi[i]->GetData()->GetDataSize();
int temp2 = lastFilledIndex[i][ch] + loopFilledIndex[i][ch] * digi[i]->GetData()->GetDataSize();
@ -222,9 +222,9 @@ void SingleSpectra::FillHistograms(){
lastFilledIndex[i][ch] = 0;
loopFilledIndex[i][ch] ++;
}
hist[i][ch]->Fill( digi[i]->GetData()->Energy[ch][lastFilledIndex[i][ch]]);
hist[i][ch]->Fill( digi[i]->GetData()->GetEnergy(ch, lastFilledIndex[i][ch]));
hist2D[i]->Fill(ch, digi[i]->GetData()->Energy[ch][lastFilledIndex[i][ch]]);
hist2D[i]->Fill(ch, digi[i]->GetData()->GetEnergy(ch, lastFilledIndex[i][ch]));
}
if( histVisibility[i][ch] ) hist[i][ch]->UpdatePlot();