From d42b5383c2a25b83c41dd104ebd536667b7a9b6c Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Wed, 19 Oct 2022 18:14:58 -0400 Subject: [PATCH] EventBuilder for sigle digitizer --- .gitignore | 2 + ClassData.h | 113 +++++++++++++-------- EventBuilder.cpp | 253 +++++++++++++++++++++++++++++++++++++++++++++++ FSUDAQ.cpp | 7 +- Makefile | 6 +- decode.C | 39 -------- test.cpp | 126 +++-------------------- 7 files changed, 348 insertions(+), 198 deletions(-) create mode 100644 EventBuilder.cpp delete mode 100644 decode.C diff --git a/.gitignore b/.gitignore index 04b9c19..6d25fe7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,9 @@ *.bin *.txt *.fsu +*.root test FSUDAQ test_indep +EventBuilder diff --git a/ClassData.h b/ClassData.h index b6c4e54..5c9aa62 100644 --- a/ClassData.h +++ b/ClassData.h @@ -19,29 +19,33 @@ class Data{ public: - int DPPType; + int DPPType; + unsigned short boardSN; float ch2ns; unsigned int nByte; /// number of byte char *buffer; /// readout buffer uint32_t AllocatedSize; uint32_t BufferSize; - unsigned short NumEvents[MaxNChannels]; double TriggerRate[MaxNChannels]; /// Hz unsigned long TotNumEvents[MaxNChannels]; - unsigned long long Timestamp[MaxNChannels][MaxNData]; - unsigned short fineTime[MaxNChannels][MaxNData]; /// 10 bits, in unit of ch2ns / 1000 = ps - unsigned short Energy[MaxNChannels][MaxNData]; - unsigned short Energy2[MaxNChannels][MaxNData]; /// in PSD, Energy = Qshort, Energy2 = Qlong + unsigned short NumEventsDecoded[MaxNChannels]; + + unsigned long long firstTimestamp[MaxNChannels]; + unsigned long long lastTimestamp[MaxNChannels]; + + /// stored Raw event + unsigned short NumEvents[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 + unsigned short Energy2[MaxNChannels][MaxNData]; /// 15 bit, in PSD, Energy = Qshort, Energy2 = Qlong std::vector Waveform1[MaxNChannels][MaxNData]; std::vector Waveform2[MaxNChannels][MaxNData]; - std::vector DigiWaveform1[MaxNChannels][MaxNData]; - std::vector DigiWaveform2[MaxNChannels][MaxNData]; - - ///CAEN_DGTZ_DPP_PHA_Event_t *Events[MaxNChannels]; /// events buffer - ///CAEN_DGTZ_DPP_PHA_Waveforms_t *Waveform[MaxNChannels]; /// waveforms buffer - + std::vector DigiWaveform1[MaxNChannels][MaxNData]; + std::vector DigiWaveform2[MaxNChannels][MaxNData]; + public: Data(); ~Data(); @@ -57,11 +61,13 @@ class Data{ void SaveBuffer(const char * fileName); unsigned int GetPresentFileSize() {return presentFileSizeByte;} - void PrintBuffer(); //Incorrect + void PrintBuffer() const; //Incorrect void DecodeBuffer(bool fastDecode, int verbose = 0); void DecodeBuffer(char * buffer, unsigned int size, bool fastDecode, int verbose = 0); // for outside data - void PrintStat(); + void PrintStat() const; + + void PrintData() const; protected: @@ -113,7 +119,12 @@ inline void Data::AllocateMemory(){ AllocateMemory( 10 * 1024 * 1024 ); /// 10 M Byte } -inline void Data::ClearTriggerRate(){ for( int i = 0 ; i < MaxNChannels; i++) TriggerRate[i] = 0.0; } +inline void Data::ClearTriggerRate(){ + for( int i = 0 ; i < MaxNChannels; i++) { + TriggerRate[i] = 0.0; + NumEventsDecoded[i] = 0; + } +} inline void Data::ClearData(){ nByte = 0; @@ -122,7 +133,8 @@ inline void Data::ClearData(){ for( int i = 0 ; i < MaxNChannels; i++){ NumEvents[i] = 0; - ///TriggerRate[i] = 0.0; + firstTimestamp[0] = -1; + lastTimestamp[0] = 0; for( int j = 0; j < MaxNData; j++){ Timestamp[i][j] = 0; fineTime[i][j] = 0; @@ -165,25 +177,31 @@ inline void Data::SaveBuffer(const char * fileName){ fclose(haha); } -inline void Data::PrintStat(){ - +inline void Data::PrintStat() const{ printf("%2s | %6s | %9s | %6s\n", "ch", "# Evt.", "Rate [Hz]", "Tot. Evt."); printf("---+--------+-----------+----------\n"); for(int ch = 0; ch < MaxNChannels; ch++){ - printf("%2d | %6d | %9.2f | %6lu\n", ch, NumEvents[ch], TriggerRate[ch], TotNumEvents[ch]); + printf("%2d | %6d | %9.2f | %6lu\n", ch, NumEventsDecoded[ch], TriggerRate[ch], TotNumEvents[ch]); } printf("---+--------+-----------+----------\n"); - } -inline void Data::PrintBuffer(){ - +inline void Data::PrintBuffer() const{ unsigned int length = sizeof(buffer); - for( int i = 0; i < length; i++){ printf("%3d | 0x%08x \n", i, buffer[i]); } - +} + +inline void Data::PrintData() const{ + printf("============================= Print Data\n"); + for( int ch = 0; ch < MaxNChannels ; ch++){ + if( NumEvents[ch] == 0 ) continue; + printf("------------ ch : %d \n", ch); + for( int ev = 0; ev < NumEvents[ch] ; ev++){ + printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); + } + } } //####################################################### Decode @@ -216,6 +234,8 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){ nw = 0; + ClearTriggerRate(); + do{ if( verbose >= 1 ) printf("######################################### Board Agg.\n"); unsigned int word = ReadBuffer(nw, verbose); @@ -235,7 +255,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){ for( int chMask = 0; chMask < MaxNChannels/2 ; chMask ++ ){ if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue; - if( verbose >= 2 ) printf("---------------------- Dual Channel Block, ch Mask : %d, nw : %d\n", chMask *2, nw); + if( verbose >= 2 ) printf("==================== Dual Channel Block, ch Mask : %d, nw : %d\n", chMask *2, nw); if( DPPType == V1730_DPP_PHA_CODE ) { if ( DecodePHADualChannelBlock(chMask, fastDecode, verbose) < 0 ) break; @@ -245,18 +265,21 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){ } } }else{ - if( verbose >= 2 ) printf("incorrect buffer header. \n"); + if( verbose >= 4 ) printf("incorrect buffer header. \n"); break; } nw++; }while(true); - ///Calculate trigger rate + ///Calculate trigger rate and first and last Timestamp for(int ch = 0; ch < MaxNChannels; ch++){ - unsigned long long dTime = Timestamp[ch][NumEvents[ch]-1] - Timestamp[ch][0]; + unsigned long long dTime = Timestamp[ch][NumEvents[ch]-1] - Timestamp[ch][NumEvents[ch] - NumEventsDecoded[ch]]; double sec = dTime * ch2ns / 1e9; - TriggerRate[ch] = NumEvents[ch]/sec; + TriggerRate[ch] = NumEventsDecoded[ch]/sec; + + firstTimestamp[ch] = Timestamp[ch][0]; + lastTimestamp[ch] = Timestamp[ch][NumEvents[ch]-1]; } } @@ -272,6 +295,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe unsigned int nSample = 0; /// wave form; unsigned int nEvents = 0; unsigned int extra2Option = 0; + bool hasExtra2 = false; bool hasDualTrace = 0 ; if( hasFormatInfo ){ nw = nw + 1; word = ReadBuffer(nw, verbose); @@ -283,7 +307,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe unsigned int analogProbe2 = ( (word >> 20 ) & 0x3 ); unsigned int analogProbe1 = ( (word >> 22 ) & 0x3 ); bool hasWaveForm = ( (word >> 27 ) & 0x1 ); - bool hasExtra2 = ( (word >> 28 ) & 0x1 ); + hasExtra2 = ( (word >> 28 ) & 0x1 ); bool hasTimeStamp = ( (word >> 29 ) & 0x1 ); bool hasEnergy = ( (word >> 30 ) & 0x1 ); hasDualTrace = ( (word >> 31 ) & 0x1 ); @@ -339,7 +363,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe } } nEvents = aggSize / (nSample/2 + 2 + hasExtra2 ); - if( verbose >= 2 ) printf("=========== nEvents : %d \n", nEvents); + if( verbose >= 2 ) printf("-------------------nEvents : %d \n", nEvents); }else{ if( verbose >= 2 ) printf("does not has format info. unable to read buffer.\n"); return 0; @@ -347,7 +371,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe ///========== decode an event for( int ev = 0; ev < nEvents ; ev++){ - if( verbose >= 2 ) printf("=================================== event : %d\n", ev); + if( verbose >= 2 ) printf("------ event : %d\n", ev); nw = nw +1 ; word = ReadBuffer(nw, verbose); bool channelTag = ((word >> 31) & 0x1); unsigned int timeStamp0 = (word & 0x7FFFFFFF); @@ -404,15 +428,18 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe DigiWaveform1[channel][NumEvents[channel]] = tempDigiWaveform1; } - nw = nw +1 ; word = ReadBuffer(nw, verbose); - unsigned int extra2 = word; unsigned long long extTimeStamp = 0; - if( extra2Option == 0 || extra2Option == 2 ) extTimeStamp = (extra2 >> 16); - + unsigned int extra2 = 0; + if( hasExtra2 ){ + nw = nw +1 ; word = ReadBuffer(nw, verbose); + extra2 = word; + if( extra2Option == 0 || extra2Option == 2 ) extTimeStamp = (extra2 >> 16); + } + unsigned long long timeStamp = (extTimeStamp << 31) ; timeStamp = timeStamp + timeStamp0; - if( verbose >= 2) printf("TimeStamp : %llu\n", timeStamp); + if( verbose >= 2) printf("extra2 : 0x%0X, TimeStamp : %llu\n", extra2, timeStamp); nw = nw +1 ; word = ReadBuffer(nw, verbose); unsigned int extra = (( word >> 16) & 0x3FF); unsigned int energy = (word & 0x7FFF); @@ -433,7 +460,6 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe printf(" not coin. : %d \n", ((extra >> 8) & 0x1) ); printf(" pile-up : %d \n", ((extra >> 9) & 0x1) ); printf(" trapezoid sat. : %d \n", ((extra >> 10) & 0x1) ); - } if( rollOver == 0 ) { @@ -441,10 +467,11 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe Timestamp[channel][NumEvents[channel]] = timeStamp; if(extra2Option == 0 || extra2Option == 2 ) fineTime[channel][NumEvents[channel]] = (extra2 & 0x07FF ); NumEvents[channel] ++; + NumEventsDecoded[channel] ++; TotNumEvents[channel] ++; } - if( verbose >= 1 ) printf("%4d | ch : %2d, PileUp : %d , energy : %5d, roll-Over: %d, timestamp : %10llu, triggerAt : %d, nSample : %d, %f sec\n", + if( verbose >= 1 ) printf("%4d | ch : %2d, PileUp : %d , energy : %5d, rollOver: %d, timestamp : %10llu, triggerAt : %d, nSample : %d, %f sec\n", NumEvents[channel], channel, pileUp, energy, rollOver, timeStamp, triggerAtSample, nSample , timeStamp * 4. / 1e9); } @@ -452,8 +479,7 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe ///=========== Key information /// ch, energy, timestamp /// trace - - + return nw; } @@ -535,11 +561,11 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe } nEvents = aggSize / (nSample/2 + 2 + hasExtra ); - if( verbose >= 2 ) printf("=========== nEvents : %d \n", nEvents); + if( verbose >= 2 ) printf("----------------- nEvents : %d \n", nEvents); ///========= Decode an event for( int ev = 0; ev < nEvents ; ev++){ - if( verbose >= 2 ) printf("=================================== event : %d\n", ev); + if( verbose >= 2 ) printf("--------------------------- event : %d\n", ev); nw = nw +1 ; word = ReadBuffer(nw, verbose); bool channelTag = ((word >> 31) & 0x1); unsigned int timeStamp0 = (word & 0x7FFFFFFF); @@ -610,6 +636,7 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe if( isEnergyCorrect == 1 ) { NumEvents[channel] ++; + NumEventsDecoded[channel] ++; TotNumEvents[channel] ++; } diff --git a/EventBuilder.cpp b/EventBuilder.cpp new file mode 100644 index 0000000..605596e --- /dev/null +++ b/EventBuilder.cpp @@ -0,0 +1,253 @@ +#include "ClassData.h" + +#include "TROOT.h" +#include "TSystem.h" +#include "TApplication.h" +#include "TCanvas.h" +#include "TGraph.h" +#include "TH1.h" +#include "TFile.h" +#include "TTree.h" + +#define MAX_MULTI 100 +#define NTimeWinForBuffer 3 + +unsigned long get_time(){ + unsigned long time_us; + struct timeval t1; + struct timezone tz; + gettimeofday(&t1, &tz); + time_us = (t1.tv_sec) * 1000000 + t1.tv_usec; + return time_us; +} + +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 +//TODO std::vector wave[MAX_ID]; /// waveform + +void EventBuilder(Data * data, const unsigned short timeWin, bool isLastData = false){ + + ///printf("============= build Event\n"); + + ///data->PrintData(); + + /// find the last event timestamp; + unsigned long long firstTimeStamp = -1; + unsigned long long lastTimeStamp = 0; + unsigned long long smallestLastTimeStamp = -1; + for( int chI = 0; chI < MaxNChannels ; chI ++){ + if( data->Timestamp[chI][0] > 0 && data->Timestamp[chI][0] < firstTimeStamp ) { + firstTimeStamp = data->Timestamp[chI][0]; + } + + unsigned short ev = data->NumEvents[chI]-1; + if( data->Timestamp[chI][ev] > 0 && data->Timestamp[chI][ev] > lastTimeStamp ) { + lastTimeStamp = data->Timestamp[chI][ev]; + } + + if( data->Timestamp[chI][ev] > 0 && data->Timestamp[chI][ev] < smallestLastTimeStamp ){ + smallestLastTimeStamp = data->Timestamp[chI][ev]; + } + + } + + ///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; + + do { + + exhaustedCh = 0; + bool breakFlag = false; + /// find the 1st event + int ch1st = -1; + unsigned long long time1st = -1; + for( int chI = 0; chI < MaxNChannels ; chI ++){ + if( data->Timestamp[chI][lastEv[chI]] == 0 ) { + exhaustedCh ++; + continue; + } + if( data->NumEvents[chI] <= lastEv[chI] ) { + breakFlag = true; + exhaustedCh ++; + break; + } + if( data->Timestamp[chI][lastEv[chI]] < time1st ) { + time1st = data->Timestamp[chI][lastEv[chI]]; + ch1st = chI; + } + } + + if( !isLastData && ((smallestLastTimeStamp - time1st) < NTimeWinForBuffer * timeWin) ) 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]]; + lastEv[ch1st] ++; + + /// build event + for( int chI = ch1st; chI < ch1st + MaxNChannels; chI ++){ + unsigned short chX = chI % MaxNChannels; + if( data->NumEvents[chX] == 0 ) continue; + if( data->NumEvents[chX] <= lastEv[chX] ) continue; + for( int ev = lastEv[chX]; ev < data->NumEvents[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]; + lastEv[chX] = ev + 1; + + if( lastEv[chX] == data->NumEvents[chX] ) exhaustedCh ++; + } + } + } + + ///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 \n", chI, lastEv[chI]); + ///} + + ///========== Quick Sort the timestamp + + /// fill Tree + outRootFile->cd(); + tree->Fill(); + evID++; + + /// clear + multi = 0; + + }while( exhaustedCh < MaxNChannels - 1 ); + + ///========== clear built data + /// move the last data to the top, + for( int chI = 0; chI < MaxNChannels; chI++){ + if( data->NumEvents[chI] == 0 ) continue; + int count = 0; + for( int ev = lastEv[chI] ; ev < data->NumEvents[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++; + } + data->NumEvents[chI] = data->NumEvents[chI] - lastEv[chI]; + } + +} + +int main(int argc, char **argv) { + + printf("=====================================\n"); + printf("=== *.fsu Events Builder ===\n"); + printf("=====================================\n"); + // Check that the corrent number of arguments were provided. + if (argc <= 2) { + printf("Incorrect number of arguments:\n"); + printf("%s [outFile] [timeWindow] [inFile1] [inFile2] .... \n", argv[0]); + printf(" outFile : output root file name\n"); + printf(" timeWindow : number of tick, 1 tick. default = 100 \n"); + return 1; + } + + TString outFileName = argv[1]; + unsigned short timeWindow = atoi(argv[2]); + int nFile = argc - 3; + TString inFileName[nFile]; + for( int i = 0 ; i < nFile ; i++){ + inFileName[i] = argv[i+3]; + } + + /// Open input Files + FILE * haha = fopen(inFileName[0], "r"); + fseek(haha, 0L, SEEK_END); + const size_t inFileSize = ftell(haha); + printf("file size : %d Byte = %.2f MB\n", (int) inFileSize, inFileSize/1024./1024.); + fclose(haha); + + Data * data = new Data(); + data->DPPType = V1730_DPP_PHA_CODE; + data->boardSN = 323; + data->SetSaveWaveToMemory(true); + + + ///============= 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"); + + ///============= Main Loop + haha = fopen(inFileName[0], "r"); + int countBdAgg = 0; + + unsigned long currentTime = 0; + unsigned long oldTime = 0; + do{ + + ///========== Get 1 aggreration + oldTime = get_time(); + ///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); + + unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte + short header = ((word[0] >> 28 ) & 0xF); + if( header != 0xA ) break; + ///printf("Board Agg. has %d word = %d bytes\n", aggSize/4, aggSize); + countBdAgg ++; + + char * buffer = new char[aggSize]; + dump = fread(buffer, aggSize, 1, haha); + + data->DecodeBuffer(buffer, aggSize, false, 0); + + currentTime = get_time(); + + ///printf("~~~~~~~~~~~~~~~~ time used : %lu \n", currentTime - oldTime); + ///data->PrintStat(); + + EventBuilder(data, timeWindow); + + }while(!feof(haha) && ftell(haha) <= inFileSize); + + fclose(haha); + + ///printf("==================== end of loop \n"); + + EventBuilder(data, timeWindow, true); + + tree->Write(); + outRootFile->Close(); + + printf("========================= finsihed.\n"); + printf("total events built = %llu \n", evID); + +} diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index 758700e..6f92d94 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -221,9 +221,9 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { triggerSummary = NULL; programSetting = NULL; + LogMsg((char*)"The LogMsg is not complete for all actions. [update later]"); LogMsg((char*)"Please \"Open Digitizers\" to start."); - //HandleMenu(M_DIGITIZER_OPEN); //HandleMenu(M_BOARD_SETTINGS); //HandleMenu(M_CH_SETTING_PHA); @@ -755,7 +755,10 @@ void * MainWindow::RunThread(void * ptr){ if( cbMode->GetSelected() == Mode_DataRun ){ // Rate graph? data->SaveBuffer(dataFileName.Data()); - LogMsg((char *) Form("File Size : %.2f MB", data->GetPresentFileSize() / 1024./1024. ); + std::string msg = Form("File Size : %.2f MB", data->GetPresentFileSize() / 1024./1024. ); + teLog->AddLine(msg.c_str()); + teLog->LineDown(); + teLog->ShowBottom(); }else{ diff --git a/Makefile b/Makefile index dbcf712..212e605 100755 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ OBJS = programSetting.o triggerSummary.o registerSetting.o channelSettingPSD.o c ######################################################################### -all : test FSUDAQ test_indep +all : test FSUDAQ test_indep EventBuilder clean : /bin/rm -f $(OBJS) test FSUDAQ FSUDAQDict.cxx *.pcm @@ -27,6 +27,10 @@ test : test.cpp ClassDigitizer.o @echo "--------- making test" $(CC) $(COPTS) -o test test.cpp ClassDigitizer.o $(CAENLIBS) $(ROOTLIBS) +EventBuilder : EventBuilder.cpp ClassData.h + @echo "--------- making EventBuilder" + $(CC) $(COPTS) -o EventBuilder EventBuilder.cpp $(ROOTLIBS) + test_indep : test_indep.cpp RegisterAddress.h macro.h @echo "--------- making test_indep" $(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS) diff --git a/decode.C b/decode.C deleted file mode 100644 index 75dce6d..0000000 --- a/decode.C +++ /dev/null @@ -1,39 +0,0 @@ -#include "ClassData.h" - -void decode() { - - FILE * haha = fopen("ExpName_run000_323_000.fsu", "r"); - fseek(haha, 0L, SEEK_END); - size_t inFileSize = ftell(haha); - printf("file size : %d Byte\n", (int) inFileSize); - fclose(haha); - - - Data * data = new Data(); - data->DPPType = V1730_DPP_PHA_CODE; - - haha = fopen("ExpName_run000_323_000.fsu", "r"); - printf("pos : %d \n", (int) ftell(haha)); - - do{ - unsigned int word[1]; /// 4 bytes - size_t dump = fread(word, 4, 1, haha); - fseek(haha, -4, SEEK_CUR); - unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte - short header = ((word[0] >> 28 ) & 0xF); - if( header != 10 ) break; - - printf("-------- %7d word = %d bytes\n", aggSize/4, aggSize); - char * buffer = new char[aggSize]; - dump = fread(buffer, aggSize, 1, haha); - - data->DecodeBuffer(buffer, aggSize, 0, 2); - - if( ftell(haha) >= 12046*10 ) break; - - }while(!feof(haha) ); - - - fclose(haha); - -} diff --git a/test.cpp b/test.cpp index 3644e28..7c1523f 100644 --- a/test.cpp +++ b/test.cpp @@ -7,6 +7,8 @@ #include "TCanvas.h" #include "TGraph.h" #include "TH1.h" +#include "TFile.h" +#include "TTree.h" #include /** struct timeval, select() */ #include /** tcgetattr(), tcsetattr() */ @@ -68,18 +70,18 @@ int getch(void){ } -long get_time(){ - long time_ms; +unsigned long get_time(){ + unsigned long time_us; struct timeval t1; struct timezone tz; gettimeofday(&t1, &tz); - time_ms = (t1.tv_sec) * 1000 + t1.tv_usec / 1000; - return time_ms; + time_us = (t1.tv_sec) * 1000000 + t1.tv_usec; + return time_us; } int main(int argc, char* argv[]){ - //##################### Demo for loading and change setting without open a digitizer + /**##################### Demo for loading and change setting without open a digitizer Digitizer dig; dig.LoadSettingBinary("setting_323.bin"); @@ -99,13 +101,11 @@ int main(int argc, char* argv[]){ printf("Buffer Size : %u byte = %.2f MB \n", bSize, bSize/1024./1024.); Reg haha = dig.FindRegister(Register::DPP::RecordLength_G); - haha.Print(); + /**///##################### test with 2 digitizers - //##################### - - /* + /** const int nBoard = 2; Digitizer **dig = new Digitizer *[nBoard]; @@ -113,77 +113,17 @@ int main(int argc, char* argv[]){ int board = i % 3; int port = i/3; dig[i] = new Digitizer(board, port, false, true); - //dig[i]->OpenSettingBinary("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin"); + dig[i]->OpenSettingBinary("setting_" + to_string(dig[i]->GetSerialNumber()) + ".bin"); + dig[i]->LoadSettingBinary("setting_" + to_string(dig[0]->GetSerialNumber()) + ".bin"); } - //dig[0]->LoadSettingBinary("setting_" + to_string(dig[0]->GetSerialNumber()) + ".bin"); - - //dig[0]->Reset(); - //dig[0]->ProgramPHABoard(); - //dig[0]->WriteRegister(Register::DPP::BoardConfiguration, 0x84F8115); /// enable wave form, pileup - - unsigned int waveFormLength = 2000; - unsigned int ch2ns = (unsigned int) dig[0]->GetCh2ns(); - - - - //dig[0]->WriteRegister(Register::DPP::RecordLength_G, waveFormLength/ch2ns, 0); - //dig[0]->WriteRegister(Register::DPP::RecordLength_G, waveFormLength/ch2ns + 10, 3); - //dig[0]->WriteRegister(Register::DPP::DPPAlgorithmControl, 0xe30200e); - //dig[0]->WriteRegister(Register::DPP::TriggerValidationMask_G, 0x500, 1); - //dig[0]->WriteRegister(Register::DPP::TriggerValidationMask_G, 0x600, 3); - //dig[0]->WriteRegister(Register::DPP::Scratch, 0x12345678); - - for( int i = 0; i < 16; i++) printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::PHA::TriggerThreshold, i)); - - - for( int i = 0; i < 16; i++) dig[0]->ReadRegister(Register::DPP::PHA::TriggerThreshold, i, "A0"); - - //dig[0]->ReadRegister(Register::DPP::RecordLength_G, 0, "A0"); - //dig[0]->ReadRegister(Register::DPP::RecordLength_G, 3, "A0"); - //dig[0]->ReadRegister(Register::DPP::DPPAlgorithmControl, 0, "A1"); - //dig[0]->ReadRegister(Register::DPP::DPPAlgorithmControl, -1, "A1"); - //dig[0]->ReadRegister(Register::DPP::TriggerValidationMask_G, 1, "A3"); - //dig[0]->ReadRegister(Register::DPP::TriggerValidationMask_G, 3, "A3"); - //dig[0]->ReadRegister(Register::DPP::Scratch); - - //printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::RecordLength_G, 0)); - //printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::RecordLength_G, 3)); - //printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::DPPAlgorithmControl, 0)); - //printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::TriggerValidationMask_G, 1)); - //printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::TriggerValidationMask_G, 2)); - //printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::TriggerValidationMask_G, 3)); - //printf(" ======== %u \n", dig[0]->GetSettingFromMemory(Register::DPP::Scratch)); - - //printf("////// %u \n", dig[0]->ReadSettingFromFile(Register::DPP::RecordLength_G, 0)); - //printf("////// %u \n", dig[0]->ReadSettingFromFile(Register::DPP::RecordLength_G, 3)); - //dig[0]->ReadSettingFromFile(Register::DPP::DPPAlgorithmControl, 0); - //dig[0]->ReadSettingFromFile(Register::DPP::TriggerValidationMask_G, 1); - //dig[0]->ReadSettingFromFile(Register::DPP::TriggerValidationMask_G, 2); - //dig[0]->ReadSettingFromFile(Register::DPP::TriggerValidationMask_G, 3); - //dig[0]->ReadSettingFromFile(Register::DPP::Scratch); - - //dig[0]->PrintSettingFromMemory(); - dig[0]->SaveSettingAsText("haha.txt"); - - printf("============================== other dig\n"); - dig[1]->LoadSettingBinary("setting_323.bin"); - printf(" ======== %u \n", dig[1]->GetSettingFromMemory(Register::DPP::PHA::TriggerThreshold, 0)); - printf(" ======== %u \n", dig[1]->GetSettingFromMemory(Register::DPP::RecordLength_G, 0)); - printf(" ======== %u \n", dig[1]->GetSettingFromMemory(Register::DPP::RecordLength_G, 3)); - printf("////// %u \n", dig[1]->ReadSettingFromFile(Register::DPP::PHA::TriggerThreshold, 0)); - printf("////// %u \n", dig[1]->ReadSettingFromFile(Register::DPP::RecordLength_G, 0)); - printf("////// %u \n", dig[1]->ReadSettingFromFile(Register::DPP::RecordLength_G, 3)); + delete dig[0]; + delete dig[1]; - for( int i = 0; i < 16 ; i++){ - dig[1]->SaveSettingToFile(Register::DPP::PHA::TriggerThreshold, 1000*i + 123, i); - } - /** - ///============================ Get Data TApplication * app = new TApplication("app", &argc, argv); TCanvas * canvas = new TCanvas("c", "haha", 1200, 400); canvas->Divide(3, 1); @@ -273,45 +213,5 @@ int main(int argc, char* argv[]){ /*********************/ - - ///********************* method for using Data Class for decoding bin file - /** - FILE * haha = fopen("output.bin", "r"); - fseek(haha, 0L, SEEK_END); - size_t inFileSize = ftell(haha); - printf("file size : %d Byte\n", (int) inFileSize); - fclose(haha); - - Data * data = new Data(); - data->DPPType = V1730_DPP_PHA_CODE; - - haha = fopen("output.bin", "r"); - printf("pos : %d \n", (int) ftell(haha)); - - do{ - unsigned int word[1]; /// 4 bytes - size_t dump = fread(word, 4, 1, haha); - fseek(haha, -4, SEEK_CUR); - unsigned int aggSize = (word[0] & 0x0FFFFFFF) * 4; ///byte - short header = ((word[0] >> 28 ) & 0xF); - if( header != 10 ) break; - - printf("-------- %d word = %d bytes\n", aggSize/4, aggSize); - char * buffer = new char[aggSize]; - dump = fread(buffer, aggSize, 1, haha); - - data->DecodeBuffer(buffer, 1); - - if( ftell(haha) >= inFileSize ) break; - - }while(!feof(haha) ); - - - fclose(haha); - */ - - - //dig[0]->CloseDigitizer(); - return 0; }