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