From 30a48743cb574308bf8d97d0275223f3b5f1fca8 Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Wed, 5 Oct 2022 14:28:55 -0400 Subject: [PATCH] added triggerSummary, next consider save a copy of setting in memory --- ClassData.h | 34 +++++----- FSUDAQ.cpp | 42 ++++++------ FSUDAQ.h | 10 ++- Makefile | 7 +- boardSetting.cpp | 11 ++-- registerSetting.cpp | 75 +++++++++++---------- registerSetting.h | 2 +- triggerSummary.cpp | 157 ++++++++++++++++++++++++++++++++++++++++++++ triggerSummary.h | 47 +++++++++++++ 9 files changed, 300 insertions(+), 85 deletions(-) create mode 100644 triggerSummary.cpp create mode 100644 triggerSummary.h diff --git a/ClassData.h b/ClassData.h index 29d5c83..ee4c688 100644 --- a/ClassData.h +++ b/ClassData.h @@ -27,6 +27,7 @@ class Data{ uint32_t BufferSize; unsigned short NumEvents[MaxNChannels]; + double TriggerRate[MaxNChannels]; /// Hz unsigned long TotNumEvents[MaxNChannels]; unsigned long long Timestamp[MaxNChannels][MaxNData]; unsigned short Energy[MaxNChannels][MaxNData]; @@ -45,18 +46,18 @@ class Data{ ~Data(); void AllocateMemory(); - void FreeMemory(); void SetSaveWaveformToMemory(bool OnOff) { this->SaveWaveformToMemory = OnOff; } void ClearData(); + void ClearTriggerRate(); void SaveBuffer(const char * fileName); void PrintBuffer(); //Incorrect void DecodeBuffer(int verbose = 0); void DecodeBuffer(char * buffer, int verbose = 0); // for outside data - + void PrintStat(); protected: @@ -87,18 +88,14 @@ inline Data::Data(){ buffer = NULL; for ( int i = 0; i < MaxNChannels; i++) TotNumEvents[i] = 0; ClearData(); + ClearTriggerRate(); SaveWaveformToMemory = true; nw = 0; saveFileIndex = 0; } inline Data::~Data(){ - FreeMemory(); - ///if( buffer != NULL ) delete buffer; - ///for( int i = 0 ; i < MaxNChannels; i++){ - /// delete Events [i]; - /// delete Waveform [i]; - ///} + delete buffer; } inline void Data::AllocateMemory(){ @@ -113,11 +110,7 @@ inline void Data::AllocateMemory(){ } - -inline void Data::FreeMemory(){ - printf("======= Free memory\n"); - //delete buffer; -} +inline void Data::ClearTriggerRate(){ for( int i = 0 ; i < MaxNChannels; i++) TriggerRate[i] = 0.0; } inline void Data::ClearData(){ @@ -127,6 +120,7 @@ inline void Data::ClearData(){ for( int i = 0 ; i < MaxNChannels; i++){ NumEvents[i] = 0; + ///TriggerRate[i] = 0.0; for( int j = 0; j < MaxNData; j++){ Timestamp[i][j] = 0; Energy[i][j] = 0; @@ -181,10 +175,7 @@ inline void Data::PrintStat(){ printf("%2s | %6s | %9s | %6s\n", "ch", "# Evt.", "Rate [Hz]", "Tot. Evt."); printf("---+--------+-----------+----------\n"); for(int ch = 0; ch < MaxNChannels; ch++){ - unsigned long long dTime = Timestamp[ch][NumEvents[ch]-1] - Timestamp[ch][0]; - double sec = dTime * ch2ns / 1e9; - - printf("%2d | %6d | %9.2f | %6lu\n", ch, NumEvents[ch], NumEvents[ch]/sec, TotNumEvents[ch]); + printf("%2d | %6d | %9.2f | %6lu\n", ch, NumEvents[ch], TriggerRate[ch], TotNumEvents[ch]); } printf("---+--------+-----------+----------\n"); @@ -253,6 +244,15 @@ inline void Data::DecodeBuffer(int verbose){ } nw++; }while(true); + + + ///Calculate trigger rate + for(int ch = 0; ch < MaxNChannels; ch++){ + unsigned long long dTime = Timestamp[ch][NumEvents[ch]-1] - Timestamp[ch][0]; + double sec = dTime * ch2ns / 1e9; + TriggerRate[ch] = NumEvents[ch]/sec; + } + } inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, int verbose){ diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index b574f5a..2e1345b 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -82,8 +82,8 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { fMain->Connect("CloseWindow()", "MainWindow", this, "GoodBye()"); {///======================= menu - fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame); - fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); + fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame); fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); + fMenuFile = new TGPopupMenu(gClient->GetRoot()); fMenuFile->AddEntry("&Open File", M_FILE_OPEN); fMenuFile->AddSeparator(); @@ -100,22 +100,20 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { fMenuDigitizers->AddEntry("&Channel Settings (PHA)", M_CH_SETTING_PHA); fMenuDigitizers->AddEntry("&Channel Settings (PSD)", M_CH_SETTING_PSD); fMenuDigitizers->AddEntry("&Register Setting", M_REGISTER_SETTING); - fMenuDigitizers->AddSeparator(); - fMenuDigitizers->AddEntry("&Program Settings", M_PROGRAM_SETTINGS); + //fMenuDigitizers->AddSeparator(); + //fMenuDigitizers->AddEntry("&Program Settings", M_PROGRAM_SETTINGS); fMenuDigitizers->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)"); - fMenuBar->AddPopup("&Digitizers", fMenuDigitizers, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0)); + fMenuBar->AddPopup("&Digitizers", fMenuDigitizers, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0)); - fMenuDigitizers->DisableEntry( M_TRIGGER_SUMMARY); - fMenuDigitizers->DisableEntry( M_LOAD_SETTINGS); - //fMenuDigitizers->DisableEntry( M_BOARD_SETTINGS); - //fMenuDigitizers->DisableEntry( M_CH_SETTING); + fMenuDigitizers->DisableEntry( M_REGISTER_SETTING); fMenuUtility = new TGPopupMenu(gClient->GetRoot()); fMenuUtility->AddEntry("Plot Channels Rate", M_SHOW_CHANNELS_RATE); fMenuDigitizers->AddSeparator(); fMenuUtility->AddEntry("Find &Peaks", M_FINDPEAKS); fMenuUtility->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)"); - fMenuBar->AddPopup("&Utility", fMenuUtility, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0)); + fMenuBar->AddPopup("&Utility", fMenuUtility, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0)); + } TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain); fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2)); @@ -224,7 +222,8 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { //HandleMenu(M_BOARD_SETTINGS); //HandleMenu(M_CH_SETTING_PHA); //HandleMenu(M_CH_SETTING_PSD); - HandleMenu(M_REGISTER_SETTING); + //HandleMenu(M_REGISTER_SETTING); + HandleMenu(M_TRIGGER_SUMMARY); gAnaTrace1 = new TGraph(); gAnaTrace2 = new TGraph(); @@ -262,7 +261,7 @@ MainWindow::~MainWindow() { delete channelSettingPSD; delete registerSetting; - //delete scalarPanel; + delete triggerSummary; //delete saveDataThread; delete fillHistThread; @@ -289,7 +288,6 @@ void MainWindow::HandleMenu(Int_t id){ OpenDigitizers(); - //fMenuDigitizers->EnableEntry( M_TRIGGER_SUMMARY); //fMenuDigitizers->EnableEntry( M_BOARD_SETTINGS); //fMenuDigitizers->EnableEntry( M_CH_SETTING); @@ -304,9 +302,9 @@ void MainWindow::HandleMenu(Int_t id){ ///========================= Exit case M_EXIT: GoodBye(); break; - ///========================= Channel setting summary + ///========================= Trigger summary case M_TRIGGER_SUMMARY: { - + triggerSummary = new TriggerSummary(gClient->GetRoot(), 600, 600, digi, nDigi); }break; ///========================= Channel setting @@ -403,8 +401,8 @@ void MainWindow::OpenDigitizers(){ } fMenuDigitizers->DisableEntry( M_DIGITIZER_OPEN); - fMenuDigitizers->EnableEntry( M_LOAD_SETTINGS); - fMenuDigitizers->EnableEntry( M_TRIGGER_SUMMARY); + fMenuDigitizers->EnableEntry( M_LOAD_SETTINGS); + fMenuDigitizers->EnableEntry( M_TRIGGER_SUMMARY); bOpenDigitizers->SetEnabled(false); bStartRun->SetEnabled(true); @@ -472,6 +470,11 @@ void MainWindow::StopRun(){ digi[0]->StopACQ(); + //Save last bit of buffer; + + ///===== clear data; + digi[0]->GetData()->ClearTriggerRate(); + bStartRun->SetEnabled(true); bStopRun->SetEnabled(false); dataPrefix->SetEnabled(true); @@ -487,8 +490,7 @@ void MainWindow::StopRun(){ } void MainWindow::OpenChannelSetting(Int_t boardID){ - - printf("#### %s \n", __func__); + if( digi == NULL ) return; if( digi[boardID]->GetDPPType() == V1730_DPP_PHA_CODE ){ channelSettingPHA = new ChannelSettingPHA(gClient->GetRoot(), 600, 600, digi, nDigi, boardID); @@ -714,7 +716,7 @@ void * MainWindow::FillHistogram(void * ptr){ ///Fill Channel Count for( int i = 0 ; i < digi[boardID]->GetNChannel(); i++){ - hChannel[boardID]->Fill(i, data->NumEvents[i]); + for( int j = 0; j < data->NumEvents[i]; j++) hChannel[boardID]->Fill(i); } ///Fill Energy histogram diff --git a/FSUDAQ.h b/FSUDAQ.h index 9e9b84d..1511ce4 100644 --- a/FSUDAQ.h +++ b/FSUDAQ.h @@ -12,7 +12,6 @@ #include #include - #include "CAENDigitizer.h" #include "macro.h" @@ -22,9 +21,8 @@ #include "channelSettingPHA.h" #include "channelSettingPSD.h" #include "registerSetting.h" +#include "triggerSummary.h" -///#include "settingsSummary.h" -///#include "scalarPanel.h" class TGWindow; class TGMainFrame; class TRootEmbeddedCanvas; @@ -63,9 +61,8 @@ private: ChannelSettingPHA * channelSettingPHA; ChannelSettingPSD * channelSettingPSD; RegisterSetting * registerSetting; - - //ScalarPanel * scalarPanel; - // + TriggerSummary * triggerSummary; + //TThread * saveDataThread; TThread * fillHistThread; @@ -101,4 +98,5 @@ public: void OpenChannelSetting(Int_t); void LogMsg(char * ); void GoodBye(); + }; diff --git a/Makefile b/Makefile index ab1f6f9..23ca7ea 100755 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ CAENLIBS = -lCAENDigitizer ROOTLIBS = `root-config --cflags --glibs` #OBJS = channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o DigitizerPHA.o DigitizerPSD.o FSUDAQ.o -OBJS = registerSetting.o channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o FSUDAQ.o +OBJS = triggerSummary.o registerSetting.o channelSettingPSD.o channelSettingPHA.o boardSetting.o ClassDigitizer.o FSUDAQ.o ######################################################################### @@ -44,7 +44,6 @@ FSUDAQ : FSUDAQDict.cxx $(OBJS) FSUDAQDict.cxx : FSUDAQ.h FSUDAQLinkDef.h @echo "----------- creating pcm and cxx for root" -# @rootcling -f FSUDAQDict.cxx -c FSUDAQ.h -p FSUDAQLinkDef.h $(CAENLIBS) @rootcling -f FSUDAQDict.cxx -c FSUDAQ.h -p FSUDAQLinkDef.h FSUDAQ.o : FSUDAQ.h FSUDAQ.cpp FSUDAQDict.cxx @@ -67,6 +66,10 @@ registerSetting.o : registerSetting.h registerSetting.cpp @echo "----------- creating registerSetting.o" $(CC) $(COPTS) -c registerSetting.cpp $(ROOTLIBS) +triggerSummary.o : triggerSummary.h triggerSummary.cpp + @echo "----------- creating triggerSummary.o" + $(CC) $(COPTS) -c triggerSummary.cpp $(ROOTLIBS) + #CutsCreator: $(OBJS3) src/CutsCreator.c # g++ -std=c++17 -pthread src/CutsCreator.c -o CutsCreator $(ROOTLIBS) diff --git a/boardSetting.cpp b/boardSetting.cpp index e8bc45b..a0b289b 100644 --- a/boardSetting.cpp +++ b/boardSetting.cpp @@ -669,8 +669,11 @@ BoardSetting::BoardSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** d ///===== LVSD - TGHorizontalFrame * hframeLVSD = new TGHorizontalFrame(vframe); vframe->AddFrame(hframeLVSD, new TGLayoutHints(kLHintsCenterY , 5,5,3,4)); - TGLabel * lbLVSD = new TGLabel(hframeLVSD, "LVSD Control is not impletmented."); hframeLVSD->AddFrame(lbLVSD, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 3, 2)); + TGHorizontalFrame * hframeNote1 = new TGHorizontalFrame(vframe); vframe->AddFrame(hframeNote1, new TGLayoutHints(kLHintsCenterY , 5,5,0,0)); + TGLabel * lbNote1 = new TGLabel(hframeNote1, "LVSD Control is not impletmented."); hframeNote1->AddFrame(lbNote1, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 0, 0)); + + TGHorizontalFrame * hframeNote2 = new TGHorizontalFrame(vframe); vframe->AddFrame(hframeNote2, new TGLayoutHints(kLHintsCenterY , 5,5,0,0)); + TGLabel * lbNote2 = new TGLabel(hframeNote2, "Trigger Validation Mask only for 0x8180."); hframeNote2->AddFrame(lbNote2, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 5, 0, 0)); ///==================== Read digitizer Setting ChangeBoard(); @@ -855,7 +858,7 @@ void BoardSetting::ChangeBoard(){ bGLBSoftwareTrigger->SetState( (( tempBits >> 31) & 0x1 ) == 0 ? kButtonUp : kButtonDown, false); /// Trigger Validation Mask - tempBits = digi[boardID]->ReadRegister(Register::DPP::TriggerValidationMask); + tempBits = digi[boardID]->ReadRegister(Register::DPP::TriggerValidationMask_G); for( int i = 0; i < 8; i++){ cbTRGValMskCh[i]->SetState( ((tempBits >> i ) & 0x1) == 0 ? kButtonUp : kButtonDown , false); } @@ -1222,7 +1225,7 @@ void BoardSetting::SetTriggerValidMask(){ /// same for PHA and PSD printf("bit : 0x%x \n", bit); - digi[boardID]->WriteRegister(Register::DPP::TriggerValidationMask, bit ); + digi[boardID]->WriteRegister(Register::DPP::TriggerValidationMask_G, bit ); } void BoardSetting::SetTRGOUTMask(){ /// same for PHA and PSD diff --git a/registerSetting.cpp b/registerSetting.cpp index 3ab2c09..d1556fc 100644 --- a/registerSetting.cpp +++ b/registerSetting.cpp @@ -60,7 +60,6 @@ RegisterSetting::RegisterSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitize } {///==================== Controls - TGHorizontalFrame *hframeAll = new TGHorizontalFrame(vframe, w, 50 ); vframe->AddFrame(hframeAll, layoutHints); bSetALLChannel = new TGCheckButton(hframeAll, "Set ALL Channels", 1); hframeAll->AddFrame(bSetALLChannel, haha); @@ -85,7 +84,7 @@ RegisterSetting::RegisterSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitize TGLabel * lbCh[MaxNChannels]; - for( int i = 0; i < digi[boardID]->GetNChannel(); i++){ + for( int i = 0; i < ( digi == NULL ? MaxNChannels : digi[boardID]->GetNChannel() ); i++){ lbCh[i] = new TGLabel(vframe0, Form("%02d", i)); vframe0->AddFrame(lbCh[i], new TGLayoutHints(kLHintsRight, 5,5,3,2)); @@ -139,15 +138,18 @@ RegisterSetting::~RegisterSetting(){ } void RegisterSetting::ChangeBoard(){ - if( digi == NULL ) return; - int boardID = boardIDEntry->GetNumber(); + int DPPType = V1730_DPP_PHA_CODE; + if( digi != NULL ){ + int boardID = boardIDEntry->GetNumber(); + DPPType = digi[boardID]->GetDPPType(); + } cbName->RemoveAll(); cbName->AddEntry("Address NOT Exist", 0); - if( digi[boardID]->GetDPPType() == V1730_DPP_PHA_CODE){ /// PHA + if( DPPType == V1730_DPP_PHA_CODE){ /// PHA cbName->AddEntry("DPP::PHA::DataFlush_W" , Register::DPP::PHA::DataFlush_W ); cbName->AddEntry("DPP::PHA::ChannelStopAcquisition" , Register::DPP::PHA::ChannelStopAcquisition ); cbName->AddEntry("DPP::PHA::RCCR2SmoothingFactor" , Register::DPP::PHA::RCCR2SmoothingFactor ); @@ -165,7 +167,7 @@ void RegisterSetting::ChangeBoard(){ cbName->AddEntry("DPP::PHA::FineGain" , Register::DPP::PHA::FineGain ); } - if( digi[boardID]->GetDPPType() == V1730_DPP_PSD_CODE){ /// PSD + if( DPPType == V1730_DPP_PSD_CODE){ /// PSD cbName->AddEntry("DPP::PSD::CFDSetting" , Register::DPP::PSD::CFDSetting ); cbName->AddEntry("DPP::PSD::ForcedDataFlush_W" , Register::DPP::PSD::ForcedDataFlush_W ); cbName->AddEntry("DPP::PSD::ChargeZeroSuppressionThreshold", Register::DPP::PSD::ChargeZeroSuppressionThreshold ); @@ -184,7 +186,7 @@ void RegisterSetting::ChangeBoard(){ } - if( digi[boardID]->GetDPPType() == V1730_DPP_PSD_CODE || digi[boardID]->GetDPPType() == V1730_DPP_PHA_CODE){ + if( DPPType == V1730_DPP_PSD_CODE || DPPType == V1730_DPP_PHA_CODE){ cbName->AddEntry("DPP::RecordLength_G" , Register::DPP::RecordLength_G ); cbName->AddEntry("DPP::InputDynamicRange" , Register::DPP::InputDynamicRange ); cbName->AddEntry("DPP::NumberEventsPerAggregate_G" , Register::DPP::NumberEventsPerAggregate_G ); @@ -289,13 +291,13 @@ std::string RegisterSetting::GetRegisterName(uint32_t address){ } void RegisterSetting::UpdateRegister(){ - if( digi == NULL ) return; - int boardID = boardIDEntry->GetNumber(); uint32_t address = cbName->GetSelected(); - txtAddress->SetText(Form("0x%04X", address), false); + if( digi == NULL ) return; + int boardID = boardIDEntry->GetNumber(); + ///check is the register readable std::string haha = cbName->GetSelectedEntry()->GetTitle(); int type = haha.back(); @@ -382,9 +384,6 @@ void RegisterSetting::SetTxtValueUnit(uint32_t address, int ch){ if( digi == NULL ) return; int boardID = boardIDEntry->GetNumber(); - std::string unit = ""; - float valueUnit = 0; - int ch2ns = (int) digi[boardID]->GetCh2ns(); txtValueUnit[ch]->SetText(""); @@ -430,27 +429,34 @@ void RegisterSetting::SetTxtValueUnit(uint32_t address, int ch){ } lbValueUnit->SetText("Value [ns]"); } - } if( digi[boardID]->GetDPPType() == V1730_DPP_PSD_CODE){ /// PSD - if( address == Register::DPP::PSD::CFDSetting ){ - - } - if( address == Register::DPP::PSD::ChargeZeroSuppressionThreshold ){ - } - if( address == Register::DPP::PSD::ShortGateWidth ){ - } - if( address == Register::DPP::PSD::LongGateWidth ){} - if( address == Register::DPP::PSD::GateOffset ){} - if( address == Register::DPP::PSD::TriggerThreshold ){} - if( address == Register::DPP::PSD::FixedBaseline ){} - if( address == Register::DPP::PSD::TriggerLatency ){} - if( address == Register::DPP::PSD::ShapedTriggerWidth ){} - if( address == Register::DPP::PSD::TriggerHoldOffWidth ){} - if( address == Register::DPP::PSD::ThresholdForPSDCut ){} - if( address == Register::DPP::PSD::PurGapThreshold ){} - if( address == Register::DPP::PSD::EarlyBaselineFreeze ){} + if( address == Register::DPP::PSD::ChargeZeroSuppressionThreshold || + address == Register::DPP::PSD::TriggerThreshold || + address == Register::DPP::PSD::FixedBaseline + ){ + txtValueUnit[ch]->SetText(Form("%d", value[ch])); + lbValueUnit->SetText("Value [LSB]"); + } + if( address == Register::DPP::PSD::ShortGateWidth || + address == Register::DPP::PSD::LongGateWidth || + address == Register::DPP::PSD::GateOffset + ){ + txtValueUnit[ch]->SetText(Form("%d", ch2ns * value[ch])); + lbValueUnit->SetText("Value [ns]"); + } + if( address == Register::DPP::PSD::TriggerLatency || + address == Register::DPP::PSD::ShapedTriggerWidth || + address == Register::DPP::PSD::TriggerHoldOffWidth || + address == Register::DPP::PSD::EarlyBaselineFreeze + ){ + txtValueUnit[ch]->SetText(Form("%d", 4* ch2ns * value[ch])); + lbValueUnit->SetText("Value [ns]"); + } + if( address == Register::DPP::PSD::PurGapThreshold ){ + //TODO + } } @@ -479,9 +485,6 @@ void RegisterSetting::SetTxtValueUnit(uint32_t address, int ch){ lbValueUnit->SetText("Value [%]"); } } - - - } unsigned int RegisterSetting::ConvertHexToDec(const char * text){ @@ -507,7 +510,6 @@ void RegisterSetting::TypeRegisterAddress(){ } } - void RegisterSetting::ChangeValue(){ printf("=============%s\n", __func__); @@ -578,3 +580,6 @@ void RegisterSetting::SendChangeSignal(){ Emit("SendChangeSignal()"); } +void RegisterSetting::LogMsg(TString msg){ + Emit("LogMsg(char*)", msg.Data()); +} diff --git a/registerSetting.h b/registerSetting.h index 090373c..a527818 100644 --- a/registerSetting.h +++ b/registerSetting.h @@ -60,7 +60,7 @@ class RegisterSetting{ void SetAllChannels(); void SendChangeSignal(); // *SIGNAL* - + void LogMsg(TString msg); // *SIGNAL* }; diff --git a/triggerSummary.cpp b/triggerSummary.cpp new file mode 100644 index 0000000..14ff386 --- /dev/null +++ b/triggerSummary.cpp @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "triggerSummary.h" + +Digitizer ** TriggerSummary::digi = NULL; +int TriggerSummary::nDigi = 0; +bool TriggerSummary::updateFlag = true; +TGTextEntry * TriggerSummary::txtTrigger[MaxNBoards][MaxNChannels] = {NULL}; +TGTextEntry * TriggerSummary::txtThreshold[MaxNBoards][MaxNChannels] = {NULL}; +TGNumberEntry * TriggerSummary::numUpdateTime = NULL; + +TriggerSummary::TriggerSummary(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** digi, int nBoard){ + + this->nDigi = nBoard; + this->digi = digi; + + fMain = new TGMainFrame(p,w,h); + fMain->SetWindowName("Scalar Panel"); + fMain->Connect("CloseWindow()", "TriggerSummary", this, "CloseWindow()"); + + TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain); fMain->AddFrame(hframe); + + TGLayoutHints * kaka = new TGLayoutHints(kLHintsLeft, 0,0,0,0); /// left, right, top, bottom + + TGGroupFrame * gBD[nDigi]; + TGLabel * lbCh[nDigi][MaxNChannels]; + + for( int bd = 0; bd < nDigi; bd++){ + + gBD[bd] = new TGGroupFrame(hframe, Form("Board-%02d", bd), kHorizontalFrame); hframe->AddFrame(gBD[bd], new TGLayoutHints( kLHintsExpandY, 5, 0, 5, 5)); + + TGVerticalFrame * vframe0 = new TGVerticalFrame(gBD[bd]); gBD[bd]->AddFrame(vframe0, new TGLayoutHints(kLHintsCenterX, 0, 0, 0, 0)); + TGVerticalFrame * vframe1 = new TGVerticalFrame(gBD[bd]); gBD[bd]->AddFrame(vframe1, new TGLayoutHints(kLHintsCenterX, 0, 0, 0, 0)); + TGVerticalFrame * vframe2 = new TGVerticalFrame(gBD[bd]); gBD[bd]->AddFrame(vframe2, new TGLayoutHints(kLHintsCenterX, 0, 0, 0, 0)); + + TGLabel * lbCh0 = new TGLabel(vframe0, "ch"); vframe0->AddFrame(lbCh0, new TGLayoutHints(kLHintsCenterY, 0,5,3,2)); + TGLabel * lbTrigger = new TGLabel(vframe1, "Trig.[Hz]"); vframe1->AddFrame(lbTrigger, new TGLayoutHints(kLHintsCenterY, 5,5,3,2)); + TGLabel * lbThreshold = new TGLabel(vframe2, "Thres."); vframe2->AddFrame(lbThreshold, new TGLayoutHints(kLHintsCenterY, 5,5,3,2)); + + for( int ch = 0; ch < (digi == NULL ? MaxNChannels: digi[bd]->GetNChannel()); ch++){ + lbCh[bd][ch] = new TGLabel(vframe0, Form("%02d", ch)); vframe0->AddFrame(lbCh[bd][ch], new TGLayoutHints(kLHintsCenterY, 0,5,3,2)); + + txtTrigger[bd][ch] = new TGTextEntry(vframe1, ""); vframe1->AddFrame(txtTrigger[bd][ch], kaka); + txtTrigger[bd][ch]->Resize(50,20); + txtTrigger[bd][ch]->SetEnabled(false); + txtTrigger[bd][ch]->SetAlignment(kTextRight); + + txtThreshold[bd][ch] = new TGTextEntry(vframe2, ""); vframe2->AddFrame(txtThreshold[bd][ch], kaka); + txtThreshold[bd][ch]->Resize(50,20); + txtThreshold[bd][ch]->SetAlignment(kTextRight); + txtThreshold[bd][ch]->Connect("ReturnPressed()", "TriggerSummary", this, "SetThreshold()"); + + value[bd][ch] = 0; + + if( digi != NULL ){ + if( digi[bd]->GetDPPType() == V1730_DPP_PSD_CODE ) value[bd][ch] = digi[bd]->ReadRegister(Register::DPP::PSD::TriggerThreshold, ch); + if( digi[bd]->GetDPPType() == V1730_DPP_PHA_CODE ) value[bd][ch] = digi[bd]->ReadRegister(Register::DPP::PHA::TriggerThreshold, ch); + } + txtThreshold[bd][ch]->SetText(Form("%d", value[bd][ch]), false); + } + } + + TGHorizontalFrame * hframeSetting = new TGHorizontalFrame(fMain); fMain->AddFrame(hframeSetting, new TGLayoutHints(kLHintsExpandX)); + + TGLabel * lbUpDateTime = new TGLabel(hframeSetting, "Update Period [msec]:"); + hframeSetting->AddFrame(lbUpDateTime, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); + + numUpdateTime = new TGNumberEntry(hframeSetting, 500, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); + hframeSetting->AddFrame(numUpdateTime, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); + numUpdateTime->Resize(50, 20); + + fMain->MapSubwindows(); + fMain->Resize(fMain->GetDefaultSize()); + fMain->MapWindow(); + + updateFlag = true; + + if( digi != NULL ){ + printf("-------- %s thread\n", __func__); + thread = new TThread("hahaha", UpdateTriggerRate, (void *) 0); + thread->Run(); + } +} + +TriggerSummary::~TriggerSummary(){ + + printf("Close %s \n", __func__); + + for(int i = 0; i < nDigi; i++){ + for(int j = 0; j < MaxNChannels; j++){ + delete txtTrigger[i][j]; + delete txtThreshold[i][j]; + } + } + + delete numUpdateTime; + + updateFlag = false; + usleep(1000 * 1000); + + ///delete thread; /// Don;t delete the thread, otherwise, thread will not run after close and reopen. + + fMain->Cleanup(); + delete fMain; +} + +void * TriggerSummary::UpdateTriggerRate(void * ptr){ + + while( updateFlag){ + + for( int bd = 0; bd < nDigi; bd++){ + for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){ + txtTrigger[bd][ch]->SetText(Form("%.2f", digi[bd]->GetData()->TriggerRate[ch])); + } + } + + usleep(numUpdateTime->GetNumber() * 1000); + } +} + +void TriggerSummary::SetThreshold(){ + if( digi == NULL ) return; + + for( int bd = 0; bd < nDigi; bd++){ + for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){ + + unsigned short haha = atoi( txtThreshold[bd][ch]->GetText()); + + if( value[bd][ch] != haha ){ + if( digi[bd]->GetDPPType() == V1730_DPP_PSD_CODE ) { + + + digi[bd]->WriteRegister(Register::DPP::PSD::TriggerThreshold, haha, ch); + + value[bd][ch] = digi[bd]->ReadRegister(Register::DPP::PSD::TriggerThreshold, ch); + + } + if( digi[bd]->GetDPPType() == V1730_DPP_PHA_CODE ) { + digi[bd]->WriteRegister(Register::DPP::PHA::TriggerThreshold, haha, ch); + + value[bd][ch] = digi[bd]->ReadRegister(Register::DPP::PHA::TriggerThreshold, ch); + + } + + txtThreshold[bd][ch]->SetText(Form("%d", value[bd][ch]), false); + } + } + } + +} diff --git a/triggerSummary.h b/triggerSummary.h new file mode 100644 index 0000000..abc35da --- /dev/null +++ b/triggerSummary.h @@ -0,0 +1,47 @@ +#ifndef TRIGGER_SUMMARY_H +#define TRIGGER_SUMMARY_H + +#include +#include +#include +#include +#include +#include +#include +#include "ClassDigitizer.h" +#include "macro.h" + +class TGWindow; +class TGMainFrame; + +class TriggerSummary{ + RQ_OBJECT("TriggerSummary") + private: + TGMainFrame * fMain; + + static int nDigi; + static Digitizer ** digi; + + static TGTextEntry * txtTrigger[MaxNBoards][MaxNChannels]; + static TGTextEntry * txtThreshold[MaxNBoards][MaxNChannels]; + + TThread * thread; + static bool updateFlag; + static TGNumberEntry * numUpdateTime; + + unsigned short value[MaxNBoards][MaxNChannels]; + + public: + TriggerSummary(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** digi, int nBoard); + virtual ~TriggerSummary(); + + void CloseWindow() { delete this;} + + static void * UpdateTriggerRate(void *ptr); + + void SetThreshold(); + void SetThreshold(int boardID, int ch, unsigned short val) { value[boardID][ch] = val; } +}; + + +#endif