From 33dae9206e96de8312c8ed0b6367b85d8ac294f3 Mon Sep 17 00:00:00 2001 From: Valerii Panin Date: Fri, 27 Oct 2023 17:28:40 +0200 Subject: [PATCH] Add online task R3BOnlineSyncCheck --- analysis/AnaLinkDef.h | 1 + analysis/CMakeLists.txt | 1 + analysis/online/R3BOnlineSyncCheck.cxx | 159 ++++++++++++++++++++ analysis/online/R3BOnlineSyncCheck.h | 71 +++++++++ r3bsource/sync_check/R3BSyncCheckReader.cxx | 2 +- 5 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 analysis/online/R3BOnlineSyncCheck.cxx create mode 100644 analysis/online/R3BOnlineSyncCheck.h diff --git a/analysis/AnaLinkDef.h b/analysis/AnaLinkDef.h index a726522b8..c78ac4f7d 100644 --- a/analysis/AnaLinkDef.h +++ b/analysis/AnaLinkDef.h @@ -47,5 +47,6 @@ #pragma link C++ class R3BFibervsTofDOnlineSpectra+; #pragma link C++ class R3BGeneralOnlineSpectra+; #pragma link C++ class R3BIncomingIDOnlineSpectra+; +#pragma link C++ class R3BOnlineSyncCheck+; #endif diff --git a/analysis/CMakeLists.txt b/analysis/CMakeLists.txt index 05a97c004..7157c2e38 100644 --- a/analysis/CMakeLists.txt +++ b/analysis/CMakeLists.txt @@ -75,6 +75,7 @@ ${R3BROOT_SOURCE_DIR}/r3bdata/frsData ${R3BROOT_SOURCE_DIR}/r3bdata/footData ${R3BROOT_SOURCE_DIR}/r3bdata/rpcData ${R3BROOT_SOURCE_DIR}/r3bdata/wrData +${R3BROOT_SOURCE_DIR}/r3bdata/synccheckData ${R3BROOT_SOURCE_DIR}/tracker_rene ${R3BROOT_SOURCE_DIR}/analysis ${R3BROOT_SOURCE_DIR}/analysis/pars diff --git a/analysis/online/R3BOnlineSyncCheck.cxx b/analysis/online/R3BOnlineSyncCheck.cxx new file mode 100644 index 000000000..462847cb3 --- /dev/null +++ b/analysis/online/R3BOnlineSyncCheck.cxx @@ -0,0 +1,159 @@ +/****************************************************************************** + * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * + * Copyright (C) 2019-2023 Members of R3B Collaboration * + * * + * This software is distributed under the terms of the * + * GNU General Public Licence (GPL) version 3, * + * copied verbatim in the file "LICENSE". * + * * + * In applying this license GSI does not waive the privileges and immunities * + * granted to it by virtue of its status as an Intergovernmental Organization * + * or submit itself to any jurisdiction. * + ******************************************************************************/ + +#include "R3BOnlineSyncCheck.h" +#include "R3BEventHeader.h" +#include "R3BLogger.h" +#include "R3BSyncCheckData.h" + +#include "FairLogger.h" +#include "FairRootManager.h" +#include "FairRunAna.h" +#include "FairRunOnline.h" +#include "FairRuntimeDb.h" +#include "TCanvas.h" +#include "TClonesArray.h" +#include "TFolder.h" +#include "TH2F.h" +#include "THttpServer.h" + +R3BOnlineSyncCheck::R3BOnlineSyncCheck() + : R3BOnlineSyncCheck("OnlineSyncCheck", 1) +{ +} + +R3BOnlineSyncCheck::R3BOnlineSyncCheck(const TString& name, Int_t iVerbose) + : FairTask(name, iVerbose) + , fCA(NULL) + , header(nullptr) + , fTpat(-1) + , fTrig(-1) + , canvas(nullptr) + , fh2_array() +{ +} + +TString R3BOnlineSyncCheck::EnumName(int value) +{ + switch (value) + { + case MASTER_SC: + return TString("MASTER"); + case MASTERREF_SC: + return TString("MASTER_REF"); + case MUSIC_SC: + return TString("MUSIC"); + case RPC_SC: + return TString("RPC"); + case S2_SC: + return TString("S2"); + case FOOT1_SC: + return TString("FOOT1"); + case FOOT2_SC: + return TString("FOOT2"); + default: + return TString("Invalid enum value"); + } +} + +InitStatus R3BOnlineSyncCheck::Init() +{ + R3BLOG(info, ""); + FairRootManager* mgr = FairRootManager::Instance(); + R3BLOG_IF(fatal, NULL == mgr, "FairRootManager not found"); + + FairRunOnline* run = FairRunOnline::Instance(); + run->GetHttpServer()->Register("", this); + + header = dynamic_cast(mgr->GetObject("EventHeader.")); + R3BLOG_IF(fatal, !header, "Branch EventHeader. not found"); + + fCA = dynamic_cast(mgr->GetObject("SyncCheckData")); + R3BLOG_IF(fatal, !fCA, "Branch SyncCheckData not found"); + + canvas = new TCanvas("Sync check", "Sync check"); + canvas->Divide(NXPADS, NYPADS); + + for (int i = 0; i < NUM_SC; ++i) + { + canvas->cd(i + 1); + TString hname = EnumName(i); + auto* fh2 = new TH2F(hname.Data(), hname.Data(), XBINS, XMIN, XMAX, YBINS, YMIN, YMAX); + fh2->GetXaxis()->SetTitle(EnumName(MASTER_SC).Data()); + fh2->GetYaxis()->SetTitle(EnumName(i).Data()); + fh2->GetXaxis()->CenterTitle(true); + fh2->GetYaxis()->CenterTitle(true); + fh2->Draw("colz"); + fh2_array.push_back(fh2); + } + TFolder* mainfol = new TFolder("SYNC_CHECK", "SYNC_CHECK"); + mainfol->Add(canvas); + run->AddObject(mainfol); + run->GetHttpServer()->RegisterCommand("Reset_Sync_Check", Form("/Objects/%s/->Reset_Histo()", GetName())); + return kSUCCESS; +} + +void R3BOnlineSyncCheck::Reset_Histo() +{ + R3BLOG(info, ""); + for (const auto& hist : fh2_array) + { + hist->Reset(); + } +} + +void R3BOnlineSyncCheck::Exec(Option_t* option) +{ + if (fTpat >= 0 && header && ((header->GetTpat() & fTpat) != fTpat)) + return; + if (fTrig >= 0 && header && (header->GetTrigger() != fTrig)) + return; + if (fCA->GetEntriesFast() == 0) + return; + + R3BSyncCheckData* sdata = dynamic_cast(fCA->At(0)); + R3BLOG_IF(fatal, !sdata, "Sync check data is empty!"); + + uint32_t val = 0; + for (int i = 0; i < NUM_SC; ++i) + { + switch (i) + { + case MUSIC_SC: + val = sdata->GetMusic(); + break; + case RPC_SC: + val = sdata->GetRpc(); + break; + case S2_SC: + val = sdata->GetS2(); + break; + case FOOT1_SC: + val = sdata->GetFoot1(); + break; + case FOOT2_SC: + val = sdata->GetFoot2(); + break; + default: + val = 0; + break; + } + fh2_array.at(i)->Fill(sdata->GetMaster(), val); + } +} + +void R3BOnlineSyncCheck::FinishEvent() { fCA->Clear(); } + +void R3BOnlineSyncCheck::FinishTask() { canvas->Write(); } + +ClassImp(R3BOnlineSyncCheck); diff --git a/analysis/online/R3BOnlineSyncCheck.h b/analysis/online/R3BOnlineSyncCheck.h new file mode 100644 index 000000000..386c698aa --- /dev/null +++ b/analysis/online/R3BOnlineSyncCheck.h @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH * + * Copyright (C) 2019-2023 Members of R3B Collaboration * + * * + * This software is distributed under the terms of the * + * GNU General Public Licence (GPL) version 3, * + * copied verbatim in the file "LICENSE". * + * * + * In applying this license GSI does not waive the privileges and immunities * + * granted to it by virtue of its status as an Intergovernmental Organization * + * or submit itself to any jurisdiction. * + ******************************************************************************/ + +#ifndef R3BOnlineSyncCheck_H +#define R3BOnlineSyncCheck_H 1 + +#include "FairTask.h" + +class TClonesArray; +class R3BEventHeader; +class TCanvas; +class TH1F; +class TH2F; + +class R3BOnlineSyncCheck : public FairTask +{ + public: + R3BOnlineSyncCheck(); + R3BOnlineSyncCheck(const TString& name, Int_t iVerbose = 1); + InitStatus Init(); + void Exec(Option_t* option); + void FinishEvent(); + void FinishTask(); + void Reset_Histo(); + void SetTpat(Int_t tpat) { fTpat = tpat; } + void SetTrig(Int_t trig) { fTrig = trig; } + static TString EnumName(int val); + + private: + enum SyncValues + { + MUSIC_SC, + RPC_SC, + S2_SC, + FOOT1_SC, + FOOT2_SC, + NUM_SC, + MASTER_SC, + MASTERREF_SC + }; + + TClonesArray* fCA; + R3BEventHeader* header; + Int_t fTpat; + Int_t fTrig; + TCanvas* canvas; + std::vector fh2_array; + static constexpr auto XBINS = 20; + static constexpr auto YBINS = 50; + static constexpr auto XMIN = 0; + static constexpr auto XMAX = 20; + static constexpr auto YMIN = 0; + static constexpr auto YMAX = 500; + static constexpr auto NXPADS = 3; + static constexpr auto NYPADS = 3; + + public: + ClassDef(R3BOnlineSyncCheck, 1) +}; + +#endif /* R3BOnlineSyncCheck_H */ diff --git a/r3bsource/sync_check/R3BSyncCheckReader.cxx b/r3bsource/sync_check/R3BSyncCheckReader.cxx index 614c9175b..2e44017ea 100644 --- a/r3bsource/sync_check/R3BSyncCheckReader.cxx +++ b/r3bsource/sync_check/R3BSyncCheckReader.cxx @@ -54,7 +54,7 @@ Bool_t R3BSyncCheckReader::Init(ext_data_struct_info* a_struct_info) return kFALSE; } // Register output array in tree - FairRootManager::Instance()->Register("SyncCheckData", "SyncCheck", fArray, kTRUE); + FairRootManager::Instance()->Register("SyncCheckData", "SyncCheck", fArray, kFALSE); Reset(); memset(fData, 0, sizeof *fData); return kTRUE;