Skip to content

Commit

Permalink
Add online task R3BOnlineSyncCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerii Panin committed Oct 27, 2023
1 parent d67a4f3 commit 33dae92
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 1 deletion.
1 change: 1 addition & 0 deletions analysis/AnaLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions analysis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
159 changes: 159 additions & 0 deletions analysis/online/R3BOnlineSyncCheck.cxx
Original file line number Diff line number Diff line change
@@ -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)

Check warning on line 37 in analysis/online/R3BOnlineSyncCheck.cxx

View workflow job for this annotation

GitHub Actions / clang-tidy

use nullptr [modernize-use-nullptr]
, header(nullptr)
, fTpat(-1)
, fTrig(-1)
, canvas(nullptr)
, fh2_array()

Check warning on line 42 in analysis/online/R3BOnlineSyncCheck.cxx

View workflow job for this annotation

GitHub Actions / clang-tidy

initializer for member 'fh2_array' is redundant [readability-redundant-member-init]
{
}

TString R3BOnlineSyncCheck::EnumName(int value)
{
switch (value)
{
case MASTER_SC:
return TString("MASTER");

Check warning on line 51 in analysis/online/R3BOnlineSyncCheck.cxx

View workflow job for this annotation

GitHub Actions / clang-tidy

avoid repeating the return type from the declaration; use a braced initializer list instead [modernize-return-braced-init-list]
case MASTERREF_SC:
return TString("MASTER_REF");

Check warning on line 53 in analysis/online/R3BOnlineSyncCheck.cxx

View workflow job for this annotation

GitHub Actions / clang-tidy

avoid repeating the return type from the declaration; use a braced initializer list instead [modernize-return-braced-init-list]
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<R3BEventHeader*>(mgr->GetObject("EventHeader."));
R3BLOG_IF(fatal, !header, "Branch EventHeader. not found");

fCA = dynamic_cast<TClonesArray*>(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<R3BSyncCheckData*>(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);
71 changes: 71 additions & 0 deletions analysis/online/R3BOnlineSyncCheck.h
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 15 in analysis/online/R3BOnlineSyncCheck.h

View workflow job for this annotation

GitHub Actions / clang-tidy

macro 'R3BOnlineSyncCheck_H' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]

#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);

Check warning on line 29 in analysis/online/R3BOnlineSyncCheck.h

View workflow job for this annotation

GitHub Actions / clang-tidy

constructors that are callable with a single argument must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor,hicpp-explicit-conversions]
InitStatus Init();

Check warning on line 30 in analysis/online/R3BOnlineSyncCheck.h

View workflow job for this annotation

GitHub Actions / clang-tidy

annotate this function with 'override' or (rarely) 'final' [cppcoreguidelines-explicit-virtual-functions,hicpp-use-override,modernize-use-override]
void Exec(Option_t* option);

Check warning on line 31 in analysis/online/R3BOnlineSyncCheck.h

View workflow job for this annotation

GitHub Actions / clang-tidy

annotate this function with 'override' or (rarely) 'final' [cppcoreguidelines-explicit-virtual-functions,hicpp-use-override,modernize-use-override]
void FinishEvent();

Check warning on line 32 in analysis/online/R3BOnlineSyncCheck.h

View workflow job for this annotation

GitHub Actions / clang-tidy

annotate this function with 'override' or (rarely) 'final' [cppcoreguidelines-explicit-virtual-functions,hicpp-use-override,modernize-use-override]
void FinishTask();

Check warning on line 33 in analysis/online/R3BOnlineSyncCheck.h

View workflow job for this annotation

GitHub Actions / clang-tidy

annotate this function with 'override' or (rarely) 'final' [cppcoreguidelines-explicit-virtual-functions,hicpp-use-override,modernize-use-override]
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<TH2F*> 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 */
2 changes: 1 addition & 1 deletion r3bsource/sync_check/R3BSyncCheckReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 33dae92

Please sign in to comment.