GRSISort "v4.1.1.0"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TGRSIHelper.h
Go to the documentation of this file.
1#ifndef TGRSIHELPER_H
2#define TGRSIHELPER_H
3#include <utility>
4
5#include "RVersion.h" // IWYU pragma: keep
6#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 14, 0)
7#include "ROOT/RDataFrame.hxx"
8#include "TObject.h"
9#include "TList.h"
10#include "TH1.h"
11#include "TH2.h"
12#include "TH3.h"
13#include "TTree.h"
14#include "TCutG.h"
15
16#include "GHSym.h"
17#include "GCube.h"
18#include "TPPG.h"
19#include "TRunInfo.h"
20#include "TGRSIMap.h"
21#include "TUserSettings.h"
22#include "TMnemonic.h" // IWYU pragma: keep
23
24////////////////////////////////////////////////////////////////////////////////
25///
26/// \class TGRSIHelper
27///
28/// Base class for all helpers used in grsiframe.
29/// It provides some general members that are set from the input list, like
30/// TPPG, run info, and user settings. It also loads settings from the input
31/// list into general GRSISort variables, like the analysis options, g-value
32/// files, cut files, or calibration files.
33///
34////////////////////////////////////////////////////////////////////////////////
35
36class TGRSIHelper : public TObject {
37public:
38 std::string& Prefix() { return fPrefix; }
39 void ColumnNames(ROOT::RDF::ColumnNames_t names) { fColumnNames = std::move(names); }
40 ROOT::RDF::ColumnNames_t ColumnNames() const { return fColumnNames; }
41
42protected:
43 TPPG* Ppg() { return fPpg; }
44 TRunInfo* RunInfo() { return fRunInfo; }
46
47 std::vector<std::shared_ptr<std::map<std::string, TList>>> fLists; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! one map of lists and directories per data processing slot to hold all output objects
48 std::vector<TGRSIMap<std::string, TH1*>> fH1; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! one map per data processing slot for 1D histograms
49 std::vector<TGRSIMap<std::string, TH2*>> fH2; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! one map per data processing slot for 2D histograms
50 std::vector<TGRSIMap<std::string, TH3*>> fH3; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! one map per data processing slot for 3D histograms
51 std::vector<TGRSIMap<std::string, GHSym*>> fSym; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! one map per data processing slot for GRSISort's symmectric 2D histograms
52 std::vector<TGRSIMap<std::string, GCube*>> fCube; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! one map per data processing slot for GRSISort's 3D histograms
53 std::vector<TGRSIMap<std::string, TTree*>> fTree; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! one map per data processing slot for trees
54 std::vector<TGRSIMap<std::string, TObject*>> fObject; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! one map per data processing slot for any TObjects
55 std::map<std::string, TCutG*> fCuts; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! map of cuts
56 TPPG* fPpg{nullptr}; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! pointer to the PPG
57 TRunInfo* fRunInfo{nullptr}; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! pointer to the run info
58 TUserSettings* fUserSettings{nullptr}; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! pointer to the user settings
59 std::string fPrefix{"TGRSIHelper"}; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! name of this action (used as prefix)
60 ROOT::RDF::ColumnNames_t fColumnNames; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) //!<! vector of names of available columns
61
62private:
63 static constexpr int fSizeLimit = 1073741822; //!<! 1 GiB size limit for objects in ROOT
64 void CheckSizes(unsigned int slot, const char* usage);
65
66public:
67 /// This type is a requirement for every helper.
68 using Result_t = std::map<std::string, TList>;
69
70 explicit TGRSIHelper(TList* input);
71
72 /// This function builds the vectors of TLists and maps for 1D- and 2D-histograms.
73 /// It calls the overloaded CreateHistograms functions in which the user can define
74 /// their histograms. Then it adds all those histograms to the list of the corresponding slot.
75 virtual void Setup();
76 /// Virtual helper function that the user uses to create their histograms
77 virtual void CreateHistograms(unsigned int)
78 {
79 std::cout << this << " - " << __PRETTY_FUNCTION__ << ", " << Prefix() << ": This function should not get called, the user's code should replace it. Not creating any histograms!" << std::endl; // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
80 }
81 /// This method will call the Book action on the provided dataframe
82 virtual ROOT::RDF::RResultPtr<std::map<std::string, TList>> Book(ROOT::RDataFrame*)
83 {
84 std::cout << this << " - " << __PRETTY_FUNCTION__ << ", " << Prefix() << ": This function should not get called, the user's code should replace it. Returning empty list!" << std::endl; // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay)
85 return {};
86 }
87
88 TGRSIHelper(const TGRSIHelper&) = delete;
92 ~TGRSIHelper() = default;
93 std::shared_ptr<std::map<std::string, TList>> GetResultPtr() const { return fLists[0]; }
94 void InitTask(TTreeReader*, unsigned int) {}
95 void Initialize() {} // required method, gets called once before starting the event loop
96 /// This required method is called at the end of the event loop. It is used to merge all the internal TLists which
97 /// were used in each of the data processing slots.
98 void Finalize();
99
100 /// This method gets called at the end of Finalize()
101 virtual void EndOfSort(std::shared_ptr<std::map<std::string, TList>>&) {}
102
103 std::string Prefix() const { return fPrefix; }
104 void Prefix(const std::string& val) { fPrefix = val; }
105 std::string GetActionName() const { return Prefix(); } // apparently a required function (not documented but doesn't compile w/o it)
106};
107
108#endif
109#endif
TUserSettings * UserSettings()
Definition TGRSIHelper.h:45
std::vector< TGRSIMap< std::string, TTree * > > fTree
Definition TGRSIHelper.h:53
std::map< std::string, TCutG * > fCuts
Definition TGRSIHelper.h:55
std::vector< TGRSIMap< std::string, GCube * > > fCube
Definition TGRSIHelper.h:52
std::vector< TGRSIMap< std::string, GHSym * > > fSym
Definition TGRSIHelper.h:51
std::shared_ptr< std::map< std::string, TList > > GetResultPtr() const
Definition TGRSIHelper.h:93
std::vector< TGRSIMap< std::string, TH2 * > > fH2
Definition TGRSIHelper.h:49
void Prefix(const std::string &val)
void ColumnNames(ROOT::RDF::ColumnNames_t names)
Definition TGRSIHelper.h:39
std::string Prefix() const
void CheckSizes(unsigned int slot, const char *usage)
TGRSIHelper & operator=(TGRSIHelper &&)=default
std::vector< TGRSIMap< std::string, TObject * > > fObject
Definition TGRSIHelper.h:54
TUserSettings * fUserSettings
Definition TGRSIHelper.h:58
std::map< std::string, TList > Result_t
This type is a requirement for every helper.
Definition TGRSIHelper.h:68
std::string fPrefix
Definition TGRSIHelper.h:59
void Initialize()
Definition TGRSIHelper.h:95
TRunInfo * RunInfo()
Definition TGRSIHelper.h:44
virtual ROOT::RDF::RResultPtr< std::map< std::string, TList > > Book(ROOT::RDataFrame *)
This method will call the Book action on the provided dataframe.
Definition TGRSIHelper.h:82
std::vector< TGRSIMap< std::string, TH1 * > > fH1
Definition TGRSIHelper.h:48
virtual void CreateHistograms(unsigned int)
Virtual helper function that the user uses to create their histograms.
Definition TGRSIHelper.h:77
virtual void EndOfSort(std::shared_ptr< std::map< std::string, TList > > &)
This method gets called at the end of Finalize()
std::string & Prefix()
Definition TGRSIHelper.h:38
std::vector< std::shared_ptr< std::map< std::string, TList > > > fLists
Definition TGRSIHelper.h:47
TGRSIHelper(const TGRSIHelper &)=delete
TPPG * fPpg
Definition TGRSIHelper.h:56
void InitTask(TTreeReader *, unsigned int)
Definition TGRSIHelper.h:94
TGRSIHelper(TGRSIHelper &&)=default
TGRSIHelper(TList *input)
ROOT::RDF::ColumnNames_t ColumnNames() const
Definition TGRSIHelper.h:40
ROOT::RDF::ColumnNames_t fColumnNames
Definition TGRSIHelper.h:60
static constexpr int fSizeLimit
! 1 GiB size limit for objects in ROOT
Definition TGRSIHelper.h:63
std::string GetActionName() const
TPPG * Ppg()
Definition TGRSIHelper.h:43
virtual void Setup()
TRunInfo * fRunInfo
Definition TGRSIHelper.h:57
~TGRSIHelper()=default
std::vector< TGRSIMap< std::string, TH3 * > > fH3
Definition TGRSIHelper.h:50
TGRSIHelper & operator=(const TGRSIHelper &)=delete
Definition TPPG.h:130