@@ -32,66 +32,31 @@ namespace o2
3232
3333namespace framework
3434{
35- // Most common histogram types
36- enum HistogramType {
37- kTH1D ,
38- kTH1F ,
39- kTH1I ,
40- kTH2D ,
41- kTH2F ,
42- kTH2I ,
43- kTH3D ,
44- kTH3F ,
45- kTH3I
46- };
47-
48- // / Description of a single histogram axis
49- struct AxisSpec {
50- AxisSpec (int nBins_, std::vector<double > bins_, std::string label_ = " " )
51- : nBins(nBins_),
52- bins (bins_),
53- binsEqual(false ),
54- label(label_)
55- {
56- }
57-
58- AxisSpec (int nBins_, double binMin_, double binMax_, std::string label_ = " " )
59- : nBins(nBins_),
60- bins({binMin_, binMax_}),
61- binsEqual(true ),
62- label(label_)
63- {
64- }
65-
66- AxisSpec () : nBins(1 ), binsEqual(false ), bins(), label(" " ) {}
67-
68- int nBins;
69- std::vector<double > bins;
70- bool binsEqual; // if true, then bins specify min and max for equidistant binning
71- std::string label;
72- };
73-
7435// / Data sctructure that will allow to construct a fully qualified TH* histogram
36+ // / Currently only supports TH1F
7537struct HistogramConfigSpec {
76- HistogramConfigSpec (HistogramType type_, std::vector<AxisSpec> axes_)
77- : type(type_),
78- axes (axes_),
79- binsEqual(axes.size() > 0 ? axes[0].binsEqual : false)
38+ HistogramConfigSpec (char const * const kind_, unsigned int nBins_, double xmin_, double xmax_)
39+ : kind(kind_),
40+ nBins (nBins_),
41+ xmin(xmin_),
42+ xmax(xmax_)
8043 {
8144 }
8245
8346 HistogramConfigSpec ()
84- : type(HistogramType::kTH1F ),
85- axes(),
86- binsEqual(false )
47+ : kind(" " ),
48+ nBins(1 ),
49+ xmin(0 ),
50+ xmax(1 )
8751 {
8852 }
8953 HistogramConfigSpec (HistogramConfigSpec const & other) = default;
9054 HistogramConfigSpec (HistogramConfigSpec&& other) = default;
9155
92- HistogramType type;
93- std::vector<AxisSpec> axes;
94- bool binsEqual;
56+ std::string kind;
57+ unsigned int nBins;
58+ double xmin;
59+ double xmax;
9560};
9661
9762// / Data structure containing histogram specification for the HistogramRegistry
@@ -121,80 +86,6 @@ struct HistogramSpec {
12186 HistogramConfigSpec config;
12287};
12388
124- class HistogramFactory
125- {
126- public:
127- static std::unique_ptr<TH1> create (HistogramSpec& spec)
128- {
129- const auto & it = lookup ().find (spec.config .type );
130- if (it == lookup ().end ()) {
131- return nullptr ;
132- }
133- return std::move (it->second ->createImpl (spec));
134- }
135-
136- protected:
137- static std::map<HistogramType, HistogramFactory*>& lookup ()
138- {
139- static std::map<HistogramType, HistogramFactory*> histMap;
140- return histMap;
141- }
142-
143- private:
144- virtual std::unique_ptr<TH1> createImpl (HistogramSpec const & spec) = 0;
145- };
146-
147- template <typename T>
148- class HistogramFactoryImpl : public HistogramFactory
149- {
150- public:
151- HistogramFactoryImpl (HistogramType type)
152- : position(this ->lookup ().insert(std::make_pair(type, this )).first)
153- {
154- }
155-
156- ~HistogramFactoryImpl ()
157- {
158- this ->lookup ().erase (position);
159- }
160-
161- private:
162- std::unique_ptr<TH1> createImpl (HistogramSpec const & spec) override
163- {
164- if (spec.config .axes .size () == 0 ) {
165- throw std::runtime_error (" No arguments available in spec to create a histogram" );
166- }
167- if constexpr (std::is_base_of_v<TH3, T>) {
168- if (spec.config .binsEqual ) {
169- return std::make_unique<T>(spec.name .data (), spec.readableName .data (), spec.config .axes [0 ].nBins , spec.config .axes [0 ].bins [0 ], spec.config .axes [0 ].bins [1 ], spec.config .axes [1 ].nBins , spec.config .axes [1 ].bins [0 ], spec.config .axes [1 ].bins [1 ], spec.config .axes [2 ].nBins , spec.config .axes [2 ].bins [0 ], spec.config .axes [2 ].bins [1 ]);
170- }
171- return std::make_unique<T>(spec.name .data (), spec.readableName .data (), spec.config .axes [0 ].nBins , spec.config .axes [0 ].bins .data (), spec.config .axes [1 ].nBins , spec.config .axes [1 ].bins .data (), spec.config .axes [2 ].nBins , spec.config .axes [2 ].bins .data ());
172- } else if constexpr (std::is_base_of_v<TH2, T>) {
173- if (spec.config .binsEqual ) {
174- return std::make_unique<T>(spec.name .data (), spec.readableName .data (), spec.config .axes [0 ].nBins , spec.config .axes [0 ].bins [0 ], spec.config .axes [0 ].bins [1 ], spec.config .axes [1 ].nBins , spec.config .axes [1 ].bins [0 ], spec.config .axes [1 ].bins [1 ]);
175- }
176- return std::make_unique<T>(spec.name .data (), spec.readableName .data (), spec.config .axes [0 ].nBins , spec.config .axes [0 ].bins .data (), spec.config .axes [1 ].nBins , spec.config .axes [1 ].bins .data ());
177- } else if constexpr (std::is_base_of_v<TH1, T>) {
178- if (spec.config .binsEqual ) {
179- return std::make_unique<T>(spec.name .data (), spec.readableName .data (), spec.config .axes [0 ].nBins , spec.config .axes [0 ].bins [0 ], spec.config .axes [0 ].bins [1 ]);
180- }
181- return std::make_unique<T>(spec.name .data (), spec.readableName .data (), spec.config .axes [0 ].nBins , spec.config .axes [0 ].bins .data ());
182- }
183- }
184-
185- typename std::map<HistogramType, HistogramFactory*>::iterator position;
186- };
187-
188- HistogramFactoryImpl<TH1D> const hf1d (HistogramType::kTH1D );
189- HistogramFactoryImpl<TH1F> const hf1f (HistogramType::kTH1F );
190- HistogramFactoryImpl<TH1I> const hf1i (HistogramType::kTH1I );
191- HistogramFactoryImpl<TH2D> const hf2d (HistogramType::kTH2D );
192- HistogramFactoryImpl<TH2F> const hf2f (HistogramType::kTH2F );
193- HistogramFactoryImpl<TH2I> const hf2i (HistogramType::kTH2I );
194- HistogramFactoryImpl<TH3D> const hf3d (HistogramType::kTH3D );
195- HistogramFactoryImpl<TH3F> const hf3f (HistogramType::kTH3F );
196- HistogramFactoryImpl<TH3I> const hf3i (HistogramType::kTH3I );
197-
19889// / Histogram registry for an analysis task that allows to define needed histograms
19990// / and serves as the container/wrapper to fill them
20091class HistogramRegistry
@@ -257,7 +148,7 @@ class HistogramRegistry
257148 for (auto j = 0u ; j < MAX_REGISTRY_SIZE; ++j) {
258149 if (mRegistryValue [imask (j + i)].get () == nullptr ) {
259150 mRegistryKey [imask (j + i)] = spec.id ;
260- mRegistryValue [imask (j + i)] = HistogramFactory::create (spec) ;
151+ mRegistryValue [imask (j + i)] = {std::make_unique<TH1F> (spec. name . data (), spec. readableName . data (), spec. config . nBins , spec. config . xmin , spec. config . xmax )} ;
261152 lookup += j;
262153 return ;
263154 }
0 commit comments