MarlinMT  0.1.0
ROOTv7.h
Go to the documentation of this file.
1 #ifndef MARLINMT_BOOK_CONFIG
2 #define MARLINMT_BOOK_CONFIG
3 #else
4 #error No mutiple binding of MarlinConfig.
5 #endif
6 
8 
9 // -- ROOT includes
10 #include "RVersion.h"
11 
12 // -- ROOT Files includes
13 #include "ROOT/RDirectory.hxx"
14 #include "ROOT/RFile.hxx"
15 
16 // -- ROOT Histogram includes
17 #include "ROOT/RHist.hxx"
18 #include "ROOT/RHistConcurrentFill.hxx"
19 #include "ROOT/RHistData.hxx"
20 #include "ROOT/RSpan.hxx"
21 
22 // -- histogram conversion include
24 
25 namespace marlinmt {
26  namespace book {
27  namespace types {
28 
29 
30  template<typename T = double>
31  class AxisConfig;
32 
33 #ifndef MARLIN_HIST_FILLER_BUFFER_SIZE
34 # define MARLIN_HIST_FILLER_BUFFER_SIZE 1024
35 #endif
36 
43  constexpr std::size_t HistogramFillerBufferSize
45 
46 #define HistConfig_ROOT(Alias, Impl, Weight, Dim) \
47  template<>\
48  struct HistConfig<double, Weight, Dim> {\
49  using Weight_t = Weight;\
50  using Precision_t = double;\
51  using Impl_t = Impl;\
52  using ConcurrentFiller_t \
53  = ROOT::Experimental::RHistConcurrentFiller<Impl, HistogramFillerBufferSize>;\
54  using ConcurrentManager_t \
55  = ROOT::Experimental::RHistConcurrentFillManager<Impl, HistogramFillerBufferSize>;\
56  static constexpr std::size_t Dimension = static_cast<std::size_t>(Dim);\
57  };\
58  using Alias = HistT<HistConfig<double, Weight, (Dim)>>
59 
60  HistConfig_ROOT(H1F, ROOT::Experimental::RH1F, float, 1);
61  HistConfig_ROOT(H1D, ROOT::Experimental::RH1D, double, 1);
62  HistConfig_ROOT(H1I, ROOT::Experimental::RH1I, int, 1);
63  HistConfig_ROOT(H2F, ROOT::Experimental::RH2F, float, 2);
64  HistConfig_ROOT(H2D, ROOT::Experimental::RH2D, double, 2);
65  HistConfig_ROOT(H2I, ROOT::Experimental::RH2I, int, 2);
66  HistConfig_ROOT(H3F, ROOT::Experimental::RH3F, float, 3);
67  HistConfig_ROOT(H3D, ROOT::Experimental::RH3D, double, 3);
68  HistConfig_ROOT(H3I, ROOT::Experimental::RH3I, int, 3);
69 
70 
71  template<typename Config>
73  const std::string_view& title,
74  const AxisConfig<typename Config::Precision_t>& axis)
75  : _impl(
76  title,
77  ROOT::Experimental::RAxisConfig(
78  axis.title(),
79  details::safe_cast<std::size_t, int>(axis.bins()),
80  axis.min(),
81  axis.max()))
82  {
83  static_assert(std::is_same_v<typename Config::Precision_t, double>);
84  static_assert(Dimension == 1);
85  }
86 
87  template<typename Config>
89  const std::string_view& title,
90  const AxisConfig<typename Config::Precision_t>& axisA,
91  const AxisConfig<typename Config::Precision_t>& axisB)
92  : _impl(
93  title,
94  ROOT::Experimental::RAxisConfig(
95  axisA.title(),
96  details::safe_cast<std::size_t, int>(axisA.bins()),
97  axisA.min(),
98  axisA.max()),
99  ROOT::Experimental::RAxisConfig(
100  axisB.title(),
101  details::safe_cast<std::size_t, int>(axisB.bins()),
102  axisB.min(),
103  axisB.max()
104  ))
105  {
106  static_assert(std::is_same_v<typename Config::Precision_t, double>);
107  static_assert(Dimension == 2);
108  }
109 
110  template<typename Config>
112  const std::string_view& title,
113  const AxisConfig<typename Config::Precision_t>& axisA,
114  const AxisConfig<typename Config::Precision_t>& axisB,
115  const AxisConfig<typename Config::Precision_t>& axisC)
116  : _impl(
117  title,
118  ROOT::Experimental::RAxisConfig(
119  axisA.title(),
120  details::safe_cast<std::size_t, int>(axisA.bins()),
121  axisA.min(),
122  axisA.max()),
123  ROOT::Experimental::RAxisConfig(
124  axisB.title(),
125  details::safe_cast<std::size_t, int>(axisB.bins()),
126  axisB.min(),
127  axisB.max()),
128  ROOT::Experimental::RAxisConfig(
129  axisC.title(),
130  details::safe_cast<std::size_t, int>(axisC.bins()),
131  axisC.min(),
132  axisC.max())
133  )
134  {
135  static_assert(std::is_same_v<typename Config::Precision_t, double>);
136  static_assert(Dimension == 3);
137  }
138 
139 
140  template<typename Config>
141  void HistT<Config>::Fill(
142  const typename HistT<Config>::Point_t& p,
143  const typename HistT<Config>::Weight_t& w) {
144  _impl.Fill(p);
145  static_assert(std::is_same_v<typename Config::Precision_t, double>);
146  }
147 
148  template<typename Config>
149  void HistT<Config>::FillN(
150  const typename HistT<Config>::Point_t* pFirst,
151  const typename HistT<Config>::Point_t* pLast,
152  const typename HistT<Config>::Weight_t* wFirst,
153  const typename HistT<Config>::Weight_t* wLast
154  ) {
155  // _impl.FillN({pFirst, pLast}, {wFirst, wLast});
156  auto p = pFirst;
157  auto w = wFirst;
158  for(;p != pLast && w != wLast; ++p,++w) {
159  this->Fill(*p, *w);
160  }
161  static_assert(std::is_same_v<typename Config::Precision_t, double>);
162  }
163 
164  template<typename Config>
165  void HistT<Config>::FillN(
166  const typename HistT<Config>::Point_t* first,
167  const typename HistT<Config>::Point_t* last ) {
168  _impl.FillN({first, last});
169  static_assert(std::is_same_v<typename Config::Precision_t, double>);
170  }
171 
172  template<typename Config>
173  HistT<Config>& add(HistT<Config>& to, const HistT<Config>& from) {
174  ROOT::Experimental::Add(to.impl(), from.impl());
175  return to;
176  }
177 
178 
179  template<typename Config>
180  auto toRoot6(const HistT<Config>& hist, const std::string_view& name) {
181  return into_root6_hist(hist.get(), std::string(name).c_str());
182  }
183 
184  template<typename Config>
185  void add(
186  const std::shared_ptr<HistT<Config>>& to,
187  const std::shared_ptr<HistT<Config>>& from) {
188  ROOT::Experimental::Add(to->impl(), from->impl());
189  }
190 
191  template<typename Config>
192  HistConcurrentFillManager<Config>::HistConcurrentFillManager(
193  HistT<Config>& hist)
194  : _impl(hist.impl()){}
195 
196  template<typename Config>
197  HistConcurrentFiller<Config>::HistConcurrentFiller(
198  HistConcurrentFillManager<Config>& manager
199  ) : _impl(manager.impl()){}
200 
201  template<typename Config>
202  void HistConcurrentFiller<Config>::Fill(
203  const typename HistT<Config>::Point_t& p,
204  const typename HistT<Config>::Weight_t& w) {
205  _impl.Fill(p, w);
206  static_assert(std::is_same_v<typename Config::Precision_t, double>);
207  }
208 
209 
210  template<typename Config>
211  void HistConcurrentFiller<Config>::FillN(
212  const typename HistT<Config>::Point_t* pFirst,
213  const typename HistT<Config>::Point_t* pLast,
214  const typename HistT<Config>::Weight_t* wFirst,
215  const typename HistT<Config>::Weight_t* wLast
216  ) {
217  // _impl.FillN({pFirst, pLast}, {wFirst, wLast});
218  auto p = pFirst;
219  auto w = wFirst;
220  for(;p != pLast && w != wLast; ++p,++w) {
221  this->Fill(*p, *w);
222  }
223  static_assert(std::is_same_v<typename Config::Precision_t, double>);
224  }
225 
226  template<typename Config>
227  void HistConcurrentFiller<Config>::Flush() {
228  _impl.Flush();
229  }
230 
231  } // end namespace types
232  } // end namespace book
233 } // end namespace marlin
234 
HistT(const AxisConfig_t &axis)
non-title 1D-histogram constructor.
Definition: Base.h:196
HistT< HistConfig< double, double, 1 > > H1D
Definition: Dummy.h:77
constexpr std::size_t HistogramFillerBufferSize
Buffer size for Histograms used in Shared mode.
Definition: ROOTv7.h:44
HistT< HistConfig< double, double, 3 > > H3D
Definition: Dummy.h:83
HistConfig_ROOT(H1F, ROOT::Experimental::RH1F, float, 1)
book::types::HistT< HistConfig< P, W, D > > HistT
HistT< HistConfig< double, float, 1 > > H1F
Definition: Dummy.h:76
HistT< HistConfig< double, float, 3 > > H3F
Definition: Dummy.h:82
Definition: EntryData.h:93
auto into_root6_hist(const Root7Hist &src, const char *name)
book::types::AxisConfig< P > AxisConfig
#define MARLIN_HIST_FILLER_BUFFER_SIZE
Definition: ROOTv7.h:34
HistT< HistConfig< double, int, 3 > > H3I
Definition: Dummy.h:84
HistT< HistConfig< double, int, 2 > > H2I
Definition: Dummy.h:81
constexpr O safe_cast(const I &input)
caste integral types with domain check.
Definition: Base.h:339
auto toRoot6(const HistT< Config > &hist, const std::string_view &name)
convert histogram to Root-6 Object for serialization
Definition: Dummy.h:71
HistT< Config > & add(HistT< Config > &to, const HistT< Config > &from)
add weights from one Histogram to an other.
Definition: Dummy.h:14
HistT< HistConfig< double, float, 2 > > H2F
Definition: Dummy.h:79
HistT< HistConfig< double, int, 1 > > H1I
Definition: Dummy.h:78
HistT< HistConfig< double, double, 2 > > H2D
Definition: Dummy.h:80