R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandCalibrationTask.h
Go to the documentation of this file.
1#pragma once
2/******************************************************************************
3 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
4 * Copyright (C) 2019-2023 Members of R3B Collaboration *
5 * *
6 * This software is distributed under the terms of the *
7 * GNU General Public Licence (GPL) version 3, *
8 * copied verbatim in the file "LICENSE". *
9 * *
10 * In applying this license GSI does not waive the privileges and immunities *
11 * granted to it by virtue of its status as an Intergovernmental Organization *
12 * or submit itself to any jurisdiction. *
13 ******************************************************************************/
14
15#include "R3BDataMonitor.h"
16#include "R3BException.h"
17#include "R3BNeulandBasePar.h"
19#include <FairRun.h>
20#include <FairRuntimeDb.h>
21#include <FairTask.h>
22#include <R3BEventHeader.h>
23#include <RtypesCore.h>
24#include <TH1.h>
25#include <cstdint>
26#include <string_view>
27#include <vector>
28
29class FairParSet;
30
31namespace R3B::Neuland
32{
33 class CalibrationTask : public FairTask
34 {
35 public:
37 explicit CalibrationTask(std::string_view name, int iVerbose = 1);
38
39 // Getters:
40 [[nodiscard]] auto GetEventHeader() const -> auto* { return eventHeader_; }
41 [[nodiscard]] auto GetHistMonitor() -> DataMonitor& { return histograms_; }
42 [[nodiscard]] auto IsHistDisabled() const -> bool { return is_hist_disabled_; }
43
45 void SetDisableHist(bool is_hist_disabled = true) { is_hist_disabled_ = is_hist_disabled; }
46 void SetDisableHistWrite(bool is_write_hist_disabled = true)
47 {
48 is_write_hist_disabled_ = is_write_hist_disabled;
49 }
50
51 auto GetBasePar() -> auto* { return base_par_; }
52 // void SetOnline()
53
54 protected:
55 template <typename ParType>
56 auto InputPar(std::string_view par_name, FairRuntimeDb* rtdb = FairRuntimeDb::instance()) -> ParType*
57 {
58 return add_par<ParType>(par_name, input_pars_, rtdb);
59 }
60
61 template <typename ParType>
62 auto OutputPar(std::string_view par_name, FairRuntimeDb* rtdb = FairRuntimeDb::instance()) -> ParType*
63 {
64 return add_par<ParType>(par_name, output_pars_, rtdb);
65 }
66
67 private:
68 bool is_hist_disabled_ = false;
74 std::vector<FairParSet*> input_pars_;
75 std::vector<FairParSet*> output_pars_;
76
78 TH1I* hist_trig_check_ = nullptr;
79 TH1I* hist_condition_check_ = nullptr;
80
81 // helpers:
83
84 // virtual functions:
85 virtual void HistogramInit(DataMonitor& histograms) {}
86 virtual void ExtraInit(FairRootManager* rootMan) {}
87 virtual void SetExtraPar(FairRuntimeDb* rtdb) {}
88 virtual void BeginOfEvent() {};
89 virtual void TriggeredExec() = 0;
90 virtual void EndOfTask() {};
91 [[nodiscard]] virtual auto CheckConditions() const -> bool { return true; }
92
93 // overriden functions:
94 auto Init() -> InitStatus override;
95 void SetParContainers() override;
96 void Exec(Option_t* option) override;
97 void FinishTask() override;
98
99 // private functions:
100 void init_histogram();
101 void check_input_par();
102 void execute_no_hist();
103 void execute_with_hist();
104 void reset();
105
106 [[nodiscard]] auto check_trigger() const -> bool;
107 template <typename ParType>
108 [[nodiscard]] auto add_par(std::string_view par_name,
109 std::vector<FairParSet*>& pars,
110 FairRuntimeDb* rtdb) -> ParType*;
111 };
112
113 template <typename ParType>
114 auto CalibrationTask::add_par(std::string_view par_name,
115 std::vector<FairParSet*>& pars,
116 FairRuntimeDb* rtdb) -> ParType*
117 {
118 auto* par = dynamic_cast<ParType*>(rtdb->findContainer(par_name.data()));
119 if (par == nullptr)
120 {
121 par = std::make_unique<ParType>(par_name.data()).release();
122 if (rtdb->addContainer(par); par == nullptr)
123 {
124 throw R3B::runtime_error("Calibration parameter becomes nullptr!");
125 }
126 }
127 pars.push_back(par);
128 return par;
129 }
130
131}; // namespace R3B::Neuland
virtual void SetExtraPar(FairRuntimeDb *rtdb)
virtual void ExtraInit(FairRootManager *rootMan)
virtual auto CheckConditions() const -> bool
virtual void HistogramInit(DataMonitor &histograms)
auto Init() -> InitStatus override
auto add_par(std::string_view par_name, std::vector< FairParSet * > &pars, FairRuntimeDb *rtdb) -> ParType *
void SetDisableHist(bool is_hist_disabled=true)
virtual void TriggeredExec()=0
auto InputPar(std::string_view par_name, FairRuntimeDb *rtdb=FairRuntimeDb::instance()) -> ParType *
auto OutputPar(std::string_view par_name, FairRuntimeDb *rtdb=FairRuntimeDb::instance()) -> ParType *
void Exec(Option_t *option) override
void SetDisableHistWrite(bool is_write_hist_disabled=true)
std::vector< FairParSet * > output_pars_
std::vector< FairParSet * > input_pars_
Simulation of NeuLAND Bar/Paddle.