clean up, remove EventBuilder and OnlineEventBuilder
This commit is contained in:
parent
0611cbe0ea
commit
73df2edb80
13
Analyser.cpp
13
Analyser.cpp
|
@ -11,9 +11,6 @@ Analyzer::Analyzer(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent )
|
|||
setWindowTitle("Online Analyzer");
|
||||
setGeometry(0, 0, 1000, 800);
|
||||
|
||||
//oeb = new OnlineEventBuilder * [nDigi];
|
||||
//for( unsigned int i = 0; i < nDigi; i++ ) oeb[i] = new OnlineEventBuilder(digi[i]);
|
||||
|
||||
mb = new MultiBuilder(digi, nDigi);
|
||||
|
||||
buildTimerThread = new TimingThread(this);
|
||||
|
@ -31,16 +28,11 @@ Analyzer::Analyzer(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent )
|
|||
}
|
||||
|
||||
Analyzer::~Analyzer(){
|
||||
// for( unsigned int i = 0; i < nDigi; i++ ) delete oeb[i];
|
||||
// delete [] oeb;
|
||||
|
||||
delete mb;
|
||||
}
|
||||
|
||||
void Analyzer::StartThread(){
|
||||
// printf("%s\n", __func__);
|
||||
//for( unsigned int i = 0; i < nDigi; i++) oeb[i]->ClearEvents();
|
||||
|
||||
mb->ClearEvents();
|
||||
buildTimerThread->start();
|
||||
}
|
||||
|
@ -54,11 +46,6 @@ void Analyzer::StopThread(){
|
|||
|
||||
void Analyzer::BuildEvents(){
|
||||
|
||||
//Set with digitizer to be event build
|
||||
// digiMTX[digiID].lock();
|
||||
// oeb[digiID]->BuildEvents(100, false);
|
||||
// digiMTX[digiID].unlock();
|
||||
|
||||
for( unsigned int i = 0; i < nDigi; i++ ) digiMTX[digiID].lock();
|
||||
mb->BuildEvents(0, 0, 0);
|
||||
for( unsigned int i = 0; i < nDigi; i++ ) digiMTX[digiID].unlock();
|
||||
|
|
|
@ -43,8 +43,6 @@ public:
|
|||
|
||||
virtual void SetUpCanvas();
|
||||
|
||||
//OnlineEventBuilder * GetEventBuilder() {return oeb[digiID];}
|
||||
|
||||
MultiBuilder * GetEventBuilder() { return mb;}
|
||||
|
||||
|
||||
|
@ -69,8 +67,6 @@ private:
|
|||
int digiID; // the digi that will event
|
||||
double waitTimeinSec;
|
||||
|
||||
//OnlineEventBuilder ** oeb;
|
||||
|
||||
MultiBuilder * mb;
|
||||
|
||||
TimingThread * buildTimerThread;
|
||||
|
|
445
EventBuilder.cpp
445
EventBuilder.cpp
|
@ -1,445 +0,0 @@
|
|||
#include "ClassData.h"
|
||||
|
||||
#include "TROOT.h"
|
||||
#include "TSystem.h"
|
||||
#include "TClonesArray.h"
|
||||
#include "TGraph.h"
|
||||
#include "TFile.h"
|
||||
#include "TTree.h"
|
||||
|
||||
#define MAX_MULTI 100
|
||||
#define NTimeWinForBuffer 3
|
||||
|
||||
TFile * outRootFile = NULL;
|
||||
TTree * tree = NULL;
|
||||
|
||||
unsigned long long evID = 0;
|
||||
unsigned short multi = 0;
|
||||
unsigned short bd[MAX_MULTI] = {0}; /// boardID
|
||||
unsigned short ch[MAX_MULTI] = {0}; /// chID
|
||||
unsigned short e[MAX_MULTI] = {0}; /// 15 bit
|
||||
unsigned long long e_t[MAX_MULTI] = {0}; /// timestamp 47 bit
|
||||
unsigned short e_f[MAX_MULTI] = {0}; /// fine time 10 bit
|
||||
|
||||
|
||||
class Trace{
|
||||
public:
|
||||
Trace() {trace.clear(); }
|
||||
~Trace();
|
||||
void Clear() { trace.clear(); };
|
||||
Trace operator = (std::vector<unsigned short> v){
|
||||
Trace tt;
|
||||
for( int i = 0 ; i < (int) v.size() ; i++){
|
||||
trace.push_back(v[i]);
|
||||
}
|
||||
return tt;
|
||||
}
|
||||
std::vector<unsigned short> trace;
|
||||
};
|
||||
|
||||
/// using TClonesArray to hold the trace in TGraph
|
||||
TClonesArray * arrayTrace = NULL;
|
||||
unsigned short traceLength[MAX_MULTI] = {0};
|
||||
TGraph * trace = NULL;
|
||||
|
||||
template<typename T> void swap(T * a, T *b );
|
||||
int partition(int arr[], int kaka[], TString file[], int start, int end);
|
||||
void quickSort(int arr[], int kaka[], TString file[], int start, int end);
|
||||
void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn = false, bool isLastData = false, unsigned int verbose = 0);
|
||||
|
||||
//*#############################################################
|
||||
//*#############################################################
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
printf("=====================================\n");
|
||||
printf("=== *.fsu Events Builder ===\n");
|
||||
printf("=====================================\n");
|
||||
if (argc <= 3) {
|
||||
printf("Incorrect number of arguments:\n");
|
||||
printf("%s [timeWindow] [traceOn/Off] [verbose] [inFile1] [inFile2] .... \n", argv[0]);
|
||||
printf(" timeWindow : number of tick, 1 tick. default = 100 \n");
|
||||
printf(" traceOn/Off : is traces stored \n");
|
||||
printf(" verbose : > 0 for debug \n");
|
||||
printf(" Output file name is contructed from inFile1 \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// File format must be YYY...Y_runXXX_AAA_BBB_CCC.fsu
|
||||
/// YYY...Y = prefix
|
||||
/// XXX = runID, 3 digits
|
||||
/// AAA = board Serial Number, 3 digits
|
||||
/// BBB = DPPtype, 3 digits
|
||||
/// CCC = over size index, 3 digits
|
||||
|
||||
///============= read input
|
||||
unsigned int timeWindow = atoi(argv[1]);
|
||||
bool traceOn = atoi(argv[2]);
|
||||
unsigned int debug = atoi(argv[3]);
|
||||
int nFile = argc - 4;
|
||||
TString inFileName[nFile];
|
||||
for( int i = 0 ; i < nFile ; i++){
|
||||
inFileName[i] = argv[i+4];
|
||||
}
|
||||
|
||||
/// Form outFileName;
|
||||
TString outFileName = inFileName[0];
|
||||
int pos = outFileName.Index("_");
|
||||
pos = outFileName.Index("_", pos+1);
|
||||
outFileName.Remove(pos);
|
||||
outFileName += ".root";
|
||||
printf("-------> Out file name : %s \n", outFileName.Data());
|
||||
|
||||
|
||||
printf(" Number of Files : %d \n", nFile);
|
||||
for( int i = 0; i < nFile; i++) printf("%2d | %s \n", i, inFileName[i].Data());
|
||||
printf("=====================================\n");
|
||||
printf(" Time Window = %u \n", timeWindow);
|
||||
printf("=====================================\n");
|
||||
|
||||
///============= sorting file by the serial number & order
|
||||
int ID[nFile]; /// serial+ order*1000;
|
||||
int type[nFile];
|
||||
for( int i = 0; i < nFile; i++){
|
||||
int snPos = inFileName[i].Index("_"); // first "_"
|
||||
//snPos = inFileName[i].Index("_", snPos + 1);
|
||||
int sn = atoi(&inFileName[i][snPos+5]);
|
||||
TString typeStr = &inFileName[i][snPos+9];
|
||||
typeStr.Resize(3);
|
||||
|
||||
if( typeStr == "PHA" ) type[i] = V1730_DPP_PHA_CODE;
|
||||
if( typeStr == "PSD" ) type[i] = V1730_DPP_PSD_CODE;
|
||||
|
||||
int order = atoi(&inFileName[i][snPos+13]);
|
||||
ID[i] = sn + order * 1000;
|
||||
|
||||
//printf("sn:%d, type:%d (%s), order:%d \n", sn, type[i], typeStr.Data(), order);
|
||||
|
||||
}
|
||||
quickSort(&(ID[0]), &(type[0]), &(inFileName[0]), 0, nFile-1);
|
||||
for( int i = 0 ; i < nFile; i++){
|
||||
printf("%d | %6d | %3d | %s \n", i, ID[i], type[i], inFileName[i].Data());
|
||||
}
|
||||
|
||||
///=============== Seperate files
|
||||
std::vector<int> idCat;
|
||||
std::vector<std::vector<int>> typeCat;
|
||||
std::vector<std::vector<TString>> fileCat;
|
||||
for( int i = 0; i < nFile; i++){
|
||||
if( ID[i] / 1000 == 0 ) {
|
||||
std::vector<TString> temp = {inFileName[i]};
|
||||
std::vector<int> temp2 = {type[i]};
|
||||
fileCat.push_back(temp);
|
||||
typeCat.push_back(temp2);
|
||||
idCat.push_back(ID[i]%1000);
|
||||
}else{
|
||||
for( int p = 0; p < (int) idCat.size(); p++){
|
||||
if( (ID[i] % 1000) == idCat[p] ) {
|
||||
fileCat[p].push_back(inFileName[i]);
|
||||
typeCat[p].push_back(type[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("=====================================\n");
|
||||
for( int i = 0; i < (int) idCat.size(); i++){
|
||||
printf("............ %d \n", idCat[i]);
|
||||
for( int j = 0; j< (int) fileCat[i].size(); j++){
|
||||
printf("%s | %d\n", fileCat[i][j].Data(), typeCat[i][j]);
|
||||
}
|
||||
}
|
||||
|
||||
///============= Set Root Tree
|
||||
outRootFile = new TFile(outFileName, "recreate");
|
||||
tree = new TTree("tree", outFileName);
|
||||
tree->Branch("evID", &evID, "event_ID/l");
|
||||
tree->Branch("multi", &multi, "multi/s");
|
||||
tree->Branch("bd", bd, "bd[multi]/s");
|
||||
tree->Branch("ch", ch, "ch[multi]/s");
|
||||
tree->Branch("e", e, "e[multi]/s");
|
||||
tree->Branch("e_t", e_t, "e_timestamp[multi]/l");
|
||||
tree->Branch("e_f", e_f, "e_timestamp[multi]/s");
|
||||
|
||||
if( traceOn ) {
|
||||
arrayTrace = new TClonesArray("TGraph");
|
||||
tree->Branch("traceLength", traceLength, "traceLength[multi]/s");
|
||||
tree->Branch("trace", arrayTrace, 2560000);
|
||||
arrayTrace->BypassStreamer();
|
||||
}
|
||||
|
||||
///============= Open input Files
|
||||
printf("##############################################\n");
|
||||
FILE * haha = fopen(fileCat[0][0], "r");
|
||||
if( haha == NULL ){
|
||||
printf("#### Cannot open file : %s. Abort.\n", fileCat[0][0].Data());
|
||||
return -1;
|
||||
}
|
||||
fseek(haha, 0L, SEEK_END);
|
||||
const size_t inFileSize = ftell(haha);
|
||||
printf("%s | file size : %d Byte = %.2f MB\n", fileCat[0][0].Data(), (int) inFileSize, inFileSize/1024./1024.);
|
||||
fclose(haha);
|
||||
|
||||
|
||||
Data * data = new Data();
|
||||
data->DPPType = typeCat[0][0];
|
||||
data->boardSN = idCat[0];
|
||||
|
||||
///============= Main Loop
|
||||
haha = fopen(inFileName[0], "r");
|
||||
int countBdAgg = 0;
|
||||
|
||||
unsigned long currentTime = 0;
|
||||
unsigned long oldTime = 0;
|
||||
|
||||
char * buffer = NULL;
|
||||
do{
|
||||
|
||||
///========== Get 1 aggreration
|
||||
oldTime = get_time();
|
||||
if( debug) printf("*********************** file pos : %d, %lu\n", (int) ftell(haha), oldTime);
|
||||
unsigned int word[1]; /// 4 bytes
|
||||
size_t dump = fread(word, 4, 1, haha);
|
||||
fseek(haha, -4, SEEK_CUR);
|
||||
|
||||
short header = ((word[0] >> 28 ) & 0xF);
|
||||
if( header != 0xA ) break;
|
||||
|
||||
unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte
|
||||
|
||||
if( debug) printf("Board Agg. has %d word = %d bytes\n", aggSize/4, aggSize);
|
||||
|
||||
buffer = new char[aggSize];
|
||||
dump = fread(buffer, aggSize, 1, haha);
|
||||
countBdAgg ++;
|
||||
if( debug) printf("==================== %d Agg\n", countBdAgg);
|
||||
|
||||
data->DecodeBuffer(buffer, aggSize, false, 0);
|
||||
data->ClearBuffer();
|
||||
if( !data->IsNotRollOverFakeAgg ) continue;
|
||||
|
||||
currentTime = get_time();
|
||||
|
||||
if( debug) {
|
||||
printf("~~~~~~~~~~~~~~~~ time used : %lu usec\n", currentTime - oldTime);
|
||||
data->PrintStat();
|
||||
}
|
||||
|
||||
EventBuilder(data, timeWindow, traceOn, false, debug);
|
||||
|
||||
if( debug) printf("---------- event built : %llu \n", evID);
|
||||
|
||||
//if( countBdAgg > 74) break;
|
||||
|
||||
}while(!feof(haha) && ftell(haha) < inFileSize);
|
||||
|
||||
fclose(haha);
|
||||
|
||||
printf("=======@@@@@@@@###############============= end of loop \n");
|
||||
EventBuilder(data, timeWindow, traceOn, true, debug);
|
||||
|
||||
|
||||
tree->Write();
|
||||
outRootFile->Close();
|
||||
|
||||
printf("========================= finsihed.\n");
|
||||
printf("total events built = %llu \n", evID);
|
||||
printf("=======> saved to %s \n", outFileName.Data());
|
||||
|
||||
}
|
||||
|
||||
void EventBuilder(Data * data, const unsigned int timeWin, bool traceOn, bool isLastData, unsigned int verbose){
|
||||
|
||||
if( verbose) {
|
||||
printf("======================== Event Builder \n");
|
||||
data->PrintAllData();
|
||||
}
|
||||
|
||||
/// find the last event timestamp;
|
||||
unsigned long long firstTimeStamp = -1;
|
||||
unsigned long long lastTimeStamp = 0;
|
||||
unsigned long long smallestLastTimeStamp = -1;
|
||||
unsigned int maxNumEvent = 0;
|
||||
for( int chI = 0; chI < MaxNChannels ; chI ++){
|
||||
if( data->DataIndex[chI] == 0 ) continue;
|
||||
|
||||
if( data->Timestamp[chI][0] < firstTimeStamp ) {
|
||||
firstTimeStamp = data->Timestamp[chI][0];
|
||||
}
|
||||
unsigned short ev = data->DataIndex[chI]-1;
|
||||
if( data->Timestamp[chI][ev] > lastTimeStamp ) {
|
||||
lastTimeStamp = data->Timestamp[chI][ev];
|
||||
}
|
||||
if( ev + 1 > maxNumEvent ) maxNumEvent = ev + 1;
|
||||
if( data->Timestamp[chI][ev] < smallestLastTimeStamp ){
|
||||
smallestLastTimeStamp = data->Timestamp[chI][ev];
|
||||
}
|
||||
}
|
||||
|
||||
if( maxNumEvent == 0 ) return;
|
||||
|
||||
if( verbose) printf("================ time range : %llu - %llu, smallest Last %llu\n", firstTimeStamp, lastTimeStamp, smallestLastTimeStamp );
|
||||
unsigned short lastEv[MaxNChannels] = {0}; /// store the last event number for each ch
|
||||
unsigned short exhaustedCh = 0; /// when exhaustedCh == MaxNChannels ==> stop
|
||||
bool singleChannelExhaustedFlag = false; /// when a single ch has data but exhaused ==> stop
|
||||
|
||||
do {
|
||||
|
||||
/// find the 1st event
|
||||
int ch1st = -1;
|
||||
unsigned long long time1st = -1;
|
||||
for( int chI = 0; chI < MaxNChannels ; chI ++){
|
||||
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;
|
||||
}
|
||||
}
|
||||
if( !isLastData && ((smallestLastTimeStamp - time1st) < NTimeWinForBuffer * timeWin) && maxNumEvent < MaxNData * 0.6 ) break;
|
||||
if( ch1st > MaxNChannels ) break;
|
||||
|
||||
multi ++;
|
||||
bd[multi-1] = data->boardSN;
|
||||
ch[multi-1] = ch1st;
|
||||
e[multi-1] = data->Energy[ch1st][lastEv[ch1st]];
|
||||
e_t[multi-1] = data->Timestamp[ch1st][lastEv[ch1st]];
|
||||
e_f[multi-1] = data->fineTime[ch1st][lastEv[ch1st]];
|
||||
if( traceOn ){
|
||||
arrayTrace->Clear("C");
|
||||
traceLength[multi-1] = (unsigned short) data->Waveform1[ch1st][lastEv[ch1st]].size();
|
||||
///if( verbose )printf("------- trace Length : %u \n", traceLength[multi-1]);
|
||||
trace = (TGraph *) arrayTrace->ConstructedAt(multi-1, "C");
|
||||
trace->Clear();
|
||||
for( int hh = 0; hh < traceLength[multi-1]; hh++){
|
||||
trace->SetPoint(hh, hh, data->Waveform1[ch1st][lastEv[ch1st]][hh]);
|
||||
///if( verbose )if( hh % 200 == 0 ) printf("%3d | %u \n", hh, data->Waveform1[ch1st][lastEv[ch1st]][hh]);
|
||||
}
|
||||
}
|
||||
lastEv[ch1st] ++;
|
||||
|
||||
/// build the rest of the event
|
||||
exhaustedCh = 0;
|
||||
singleChannelExhaustedFlag = false;
|
||||
for( int chI = ch1st; chI < ch1st + MaxNChannels; chI ++){
|
||||
unsigned short chX = chI % MaxNChannels;
|
||||
if( data->DataIndex[chX] == 0 ) {
|
||||
exhaustedCh ++;
|
||||
continue;
|
||||
}
|
||||
if( data->DataIndex[chX] <= lastEv[chX] ) {
|
||||
exhaustedCh ++;
|
||||
singleChannelExhaustedFlag = true;
|
||||
continue;
|
||||
}
|
||||
if( timeWin == 0 ) continue;
|
||||
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;
|
||||
ch[multi-1] = chX;
|
||||
e[multi-1] = data->Energy[chX][ev];
|
||||
e_t[multi-1] = data->Timestamp[chX][ev];
|
||||
e_f[multi-1] = data->fineTime[chX][ev];
|
||||
if( traceOn ){
|
||||
traceLength[multi-1] = (unsigned short) data->Waveform1[chX][ev].size();
|
||||
trace = (TGraph *) arrayTrace->ConstructedAt(multi-1, "C");
|
||||
trace->Clear();
|
||||
for( int hh = 0; hh < traceLength[multi-1]; hh++){
|
||||
trace->SetPoint(hh, hh, data->Waveform1[chX][ev][hh]);
|
||||
}
|
||||
}
|
||||
lastEv[chX] = ev + 1;
|
||||
if( lastEv[chX] == data->DataIndex[chX] ) exhaustedCh ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose) {
|
||||
printf("=============== multi : %d , ev : %llu\n", multi, evID);
|
||||
for( int ev = 0; ev < multi; ev++){
|
||||
printf("%3d, ch : %2d, %u, %llu \n", ev, ch[ev], e[ev], e_t[ev]);
|
||||
}
|
||||
|
||||
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->DataIndex[chI]);
|
||||
}
|
||||
}
|
||||
|
||||
/// fill Tree
|
||||
outRootFile->cd();
|
||||
tree->Fill();
|
||||
evID++;
|
||||
multi = 0;
|
||||
|
||||
}while( !singleChannelExhaustedFlag || (exhaustedCh < MaxNChannels) );
|
||||
|
||||
///========== clear built data
|
||||
/// move the last data to the top,
|
||||
for( int chI = 0; chI < MaxNChannels; chI++){
|
||||
if( data->DataIndex[chI] == 0 ) continue;
|
||||
int count = 0;
|
||||
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->DataIndex[chI] - lastEv[chI];
|
||||
data->DataIndex[chI] = (lala >= 0 ? lala: 0);
|
||||
}
|
||||
|
||||
if( verbose > 0 ) {
|
||||
printf("&&&&&&&&&&&&&&&&&&&&&&&&&& end of one event build loop\n");
|
||||
data->PrintAllData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*#############################################################
|
||||
//*#############################################################
|
||||
template<typename T> void swap(T * a, T *b ){
|
||||
T temp = * b;
|
||||
*b = *a;
|
||||
*a = temp;
|
||||
}
|
||||
|
||||
int partition(int arr[], int kaka[], TString file[], int start, int end){
|
||||
int pivot = arr[start];
|
||||
int count = 0;
|
||||
for (int i = start + 1; i <= end; i++) {
|
||||
if (arr[i] <= pivot) count++;
|
||||
}
|
||||
/// Giving pivot element its correct position
|
||||
int pivotIndex = start + count;
|
||||
swap(&arr[pivotIndex], &arr[start]);
|
||||
swap(&file[pivotIndex], &file[start]);
|
||||
swap(&kaka[pivotIndex], &kaka[start]);
|
||||
|
||||
/// Sorting left and right parts of the pivot element
|
||||
int i = start, j = end;
|
||||
while (i < pivotIndex && j > pivotIndex) {
|
||||
while (arr[i] <= pivot) {i++;}
|
||||
while (arr[j] > pivot) {j--;}
|
||||
if (i < pivotIndex && j > pivotIndex) {
|
||||
int ip = i++;
|
||||
int jm = j--;
|
||||
swap( &arr[ip], &arr[jm]);
|
||||
swap(&file[ip], &file[jm]);
|
||||
swap(&kaka[ip], &kaka[jm]);
|
||||
}
|
||||
}
|
||||
return pivotIndex;
|
||||
}
|
||||
|
||||
void quickSort(int arr[], int kaka[], TString file[], int start, int end){
|
||||
/// base case
|
||||
if (start >= end) return;
|
||||
/// partitioning the array
|
||||
int p = partition(arr, kaka, file, start, end);
|
||||
/// Sorting the left part
|
||||
quickSort(arr, kaka, file, start, p - 1);
|
||||
/// Sorting the right part
|
||||
quickSort(arr, kaka, file, p + 1, end);
|
||||
}
|
|
@ -35,7 +35,6 @@ HEADERS += ClassData.h \
|
|||
influxdb.h\
|
||||
Scope.h \
|
||||
SingleSpectra.h \
|
||||
OnlineEventBuilder.h \
|
||||
MultiBuilder.h \
|
||||
Analyser.h \
|
||||
qcustomplot.h \
|
||||
|
@ -47,7 +46,6 @@ SOURCES += ClassDigitizer.cpp \
|
|||
influxdb.cpp\
|
||||
Scope.cpp \
|
||||
SingleSpectra.cpp \
|
||||
OnlineEventBuilder.cpp \
|
||||
MultiBuilder.cpp \
|
||||
Analyser.cpp \
|
||||
qcustomplot.cpp
|
||||
|
|
|
@ -14,7 +14,7 @@ ROOTLIBS = `root-config --cflags --glibs`
|
|||
|
||||
OBJS = ClassDigitizer.o OnlineEventBuilder.o MultiBuilder.o
|
||||
|
||||
ALL = test test_indep EventBuilder DataGenerator EventKenshikushi
|
||||
ALL = test test_indep DataGenerator EventKenshikushi
|
||||
|
||||
#########################################################################
|
||||
|
||||
|
@ -40,10 +40,6 @@ test_indep : test_indep.cpp RegisterAddress.h macro.h
|
|||
@echo "--------- making test_indep"
|
||||
$(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS)
|
||||
|
||||
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)
|
||||
|
|
|
@ -1,170 +0,0 @@
|
|||
#include "OnlineEventBuilder.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
OnlineEventBuilder::OnlineEventBuilder(Digitizer * digi){
|
||||
|
||||
data = digi->GetData();
|
||||
nCh = digi->GetNChannels();
|
||||
|
||||
ClearEvents();
|
||||
}
|
||||
|
||||
OnlineEventBuilder::~OnlineEventBuilder(){
|
||||
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::ClearEvents(){
|
||||
eventIndex = -1;
|
||||
totalEventBuilt = 0;
|
||||
for( int i = 0; i < MaxNEvent; i++ ) events[i].clear();
|
||||
|
||||
for( int i = 0; i < MaxNChannels; i++ ){
|
||||
nextIndex[i] = -1;
|
||||
loopIndex[i] = 0;
|
||||
chExhaused[i] = false;
|
||||
}
|
||||
|
||||
earlistTime = -1;
|
||||
earlistCh = -1;
|
||||
|
||||
nExhaushedCh = 0;
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::PrintStat(){
|
||||
|
||||
printf("========= Total Event built : %lu, last built : %lu, index: %lu \n", totalEventBuilt, eventBuilt, eventIndex);
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::FindEarlistTimeAndCh(){
|
||||
|
||||
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 || loopIndex[ch] * MaxNData + nextIndex[ch] > data->LoopIndex[ch] * MaxNData + data->DataIndex[ch]) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[ch] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if( 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);
|
||||
}
|
||||
}
|
||||
|
||||
// printf("%s | ch : %d, %llu\n", __func__, earlistCh, earlistTime);
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::FindLatestTime(){
|
||||
latestTime = 0;
|
||||
// int latestCh = -1;
|
||||
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];
|
||||
//latestCh = ch;
|
||||
}
|
||||
}
|
||||
// printf("%s | ch : %d, %lld \n", __func__, latestCh, latestTime);
|
||||
}
|
||||
|
||||
void OnlineEventBuilder::BuildEvents(unsigned short timeWindow, bool verbose){
|
||||
|
||||
this->timeWindow = timeWindow;
|
||||
if( verbose ) data->PrintAllData();
|
||||
|
||||
FindLatestTime();
|
||||
FindEarlistTimeAndCh();
|
||||
|
||||
if( earlistCh == -1 || nExhaushedCh == nCh) return; /// no data
|
||||
|
||||
eventBuilt = 0;
|
||||
|
||||
//======= Start building event
|
||||
do{
|
||||
|
||||
eventIndex ++;
|
||||
if( eventIndex >= MaxNEvent ) eventIndex = 0;
|
||||
events[eventIndex].clear();
|
||||
|
||||
eventBuilt ++;
|
||||
totalEventBuilt ++;
|
||||
|
||||
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( loopIndex[ch] * MaxNData + nextIndex[ch] > data->LoopIndex[ch] * MaxNData + data->DataIndex[ch]) {
|
||||
nExhaushedCh ++;
|
||||
chExhaused[ch] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
unsigned long long time = data->Timestamp[ch][nextIndex[ch]];
|
||||
|
||||
if( time >= earlistTime && (time - earlistTime < timeWindow) ){
|
||||
dp.ch = ch;
|
||||
dp.energy = data->Energy[ch][nextIndex[ch]];
|
||||
dp.timeStamp = time;
|
||||
|
||||
events[eventIndex].push_back(dp);
|
||||
nextIndex[ch]++;
|
||||
if( nextIndex[ch] >= MaxNData) {
|
||||
loopIndex[ch] ++;
|
||||
nextIndex[ch] = 0;
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
|
||||
}while( dT < timeWindow);
|
||||
|
||||
}
|
||||
|
||||
std::sort(events[eventIndex].begin(), events[eventIndex].end(), [](const dataPoint& a, const dataPoint& b) {
|
||||
return a.timeStamp < b.timeStamp;
|
||||
});
|
||||
|
||||
///Find the next earlist
|
||||
FindEarlistTimeAndCh();
|
||||
|
||||
if( verbose ){
|
||||
printf(">>>>>>>>>>>>>>>>> Event ID : %ld, total built: %ld, multiplicity : %ld\n", eventIndex, totalEventBuilt, events[eventIndex].size());
|
||||
for( int i = 0; i <(int) events[eventIndex].size(); i++){
|
||||
int chxxx = events[eventIndex][i].ch;
|
||||
printf("%02d | %d | %5d %llu \n", chxxx, nextIndex[chxxx], 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, latesTime : %llu.\n", latestTime);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}while(nExhaushedCh < nCh);
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
#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 5000
|
||||
|
||||
struct dataPoint{
|
||||
unsigned short ch;
|
||||
unsigned short energy;
|
||||
unsigned long long timeStamp;
|
||||
};
|
||||
|
||||
class OnlineEventBuilder {
|
||||
|
||||
public:
|
||||
OnlineEventBuilder(Digitizer * digi);
|
||||
~OnlineEventBuilder();
|
||||
|
||||
void ClearEvents();
|
||||
void BuildEvents(unsigned short timeWindow, bool verbose = false);
|
||||
|
||||
long eventIndex;
|
||||
long eventBuilt; // reset once call BuildEvents()
|
||||
long totalEventBuilt;
|
||||
std::vector<dataPoint> events[MaxNEvent]; // should be a cirular memory, store energy
|
||||
|
||||
unsigned short GetTimeWindow() const { return timeWindow;}
|
||||
|
||||
void PrintStat();
|
||||
|
||||
private:
|
||||
|
||||
unsigned short nCh;
|
||||
Data * data;
|
||||
|
||||
unsigned short timeWindow;
|
||||
int loopIndex[MaxNChannels];
|
||||
int nextIndex[MaxNChannels];
|
||||
|
||||
int nExhaushedCh;
|
||||
bool chExhaused[MaxNChannels];
|
||||
unsigned long long earlistTime;
|
||||
int earlistCh;
|
||||
void FindEarlistTimeAndCh();
|
||||
unsigned long long latestTime;
|
||||
void FindLatestTime();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
|
@ -27,7 +27,6 @@ public:
|
|||
SetDigiID(0); // define which digitizer to build event
|
||||
SetUpdateTimeInSec(1.0);
|
||||
|
||||
//evtbder = GetEventBuilder(); // get the event builder pointer from mother class;
|
||||
evtbder = GetEventBuilder();
|
||||
|
||||
SetUpCanvas();
|
||||
|
@ -42,7 +41,6 @@ public slots:
|
|||
|
||||
private:
|
||||
|
||||
//OnlineEventBuilder * evtbder;
|
||||
MultiBuilder *evtbder;
|
||||
|
||||
// declaie histograms
|
||||
|
@ -70,8 +68,6 @@ inline void SplitPole::UpdateHistograms(){
|
|||
|
||||
BuildEvents(); // call the event builder to build events
|
||||
|
||||
//oeb->PrintStat();
|
||||
|
||||
//============ Get events, and do analysis
|
||||
long eventBuilt = evtbder->eventBuilt;
|
||||
if( eventBuilt == 0 ) return;
|
||||
|
@ -84,7 +80,6 @@ inline void SplitPole::UpdateHistograms(){
|
|||
unsigned short e1 = 0, e2 = 0;
|
||||
|
||||
for( long i = eventStart ; i <= eventIndex; i ++ ){
|
||||
//std::vector<dataPoint> event = evtbder->events[i];
|
||||
std::vector<EventMember> event = evtbder->events[i];
|
||||
|
||||
for( int k = 0; k < (int) event.size(); k++ ){
|
||||
|
|
Loading…
Reference in New Issue
Block a user