MarlinMT  0.1.0
HistEntry.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 // -- std includes
5 #include <functional>
6 #include <mutex>
7 #include <type_traits>
8 #include <vector>
9 
10 // -- MarlinBook includes
11 #include "marlinmt/book/Entry.h"
12 #include "marlinmt/book/Flags.h"
13 #include "marlinmt/book/Types.h"
14 
15 
16 namespace marlinmt {
17  namespace book {
18 
20  template < typename Config>
21  class Handle< types::HistT< Config > >
22  : private BaseHandle< types::HistT<Config> > {
23  friend BookStore ;
24  static constexpr int D = types::HistT<Config>::Dimension;
25 
26  public:
30  using Point_t = typename Type::Point_t ;
32  using Weight_t = typename Type::Weight_t ;
34  using FinalizeFn_t = std::function< void() > ;
35 
36  public:
38  Handle( const std::shared_ptr< MemLayout > &mem,
39  const std::shared_ptr< Type > & obj,
40  std::shared_ptr<void> data,
41  Flag_t type,
42  FinalizeFn_t finalFn ) ;
43 
44 
50  void fill( const Point_t &x, const Weight_t &w ) ;
51 
52 
61  template<typename PointContainer, typename WeightContainer>
62  void fillN(
63  const PointContainer& points,
64  const WeightContainer& weights);
65 
66 
73  const Type &merged() ;
74 
75  private:
81  template<std::size_t I = 0>
82  void fillImp(const Point_t& x, const Weight_t& w);
83 
84 
85 
94  template<std::size_t I = 0>
95  void fillNImp(
96  const Point_t* pFirst, const Point_t* pLast,
97  const Weight_t* wFirst, const Weight_t* wLast);
98 
99 
100 
104  std::shared_ptr<void> _data;
106  const Flag_t _type;
107 
108  } ;
109 
111  template < typename Config>
112  class EntrySingle< types::HistT<Config> > : public EntryBase {
113 
114  friend BookStore ;
116 
117  public:
121  using Point_t = typename Type::Point_t ;
123  using Weight_t = typename Type::Weight_t ;
124 
126  static constexpr Flag_t Flag = EntrySingle<void>::Flag ;
127 
128  private:
129  static void fill(const std::shared_ptr<void>& data,
130  Point_t const& x, Weight_t const& w);
131 
132  static void fillN(const std::shared_ptr<void>& data,
133  Point_t const* pFirst, Point_t const* pLast,
134  Weight_t const* wFirst, Weight_t const* wLast) ;
135 
136  public:
138  explicit EntrySingle( Context context ) ;
139 
141  EntrySingle() = default ;
142 
147  Handle< Type > handle() ;
148 
149  private:
152  } ;
153 
155  template < typename Config>
156  class EntryMultiCopy< types::HistT<Config>> : public EntryBase {
157 
158  friend BookStore ;
160 
161  public:
165  using Point_t = typename Type::Point_t ;
167  using Weight_t = typename Type::Weight_t ;
168 
170  static constexpr Flag_t Flag = EntryMultiCopy<void>::Flag;
171 
172  private:
173  // TODO: Fix Doxygen links
175  static void fill(const std::shared_ptr<void>& data,
176  Point_t const& x,
177  Weight_t const& w);
178 
180  static void fillN(const std::shared_ptr<void>& data,
181  Point_t const* pFirst, Point_t const* pLast,
182  Weight_t const* wFirst, Weight_t const* wLast);
183 
184  public:
186  explicit EntryMultiCopy( Context context ) ;
187 
189  EntryMultiCopy() = default ;
190 
197  Handle< Type > handle( std::size_t idx ) ;
198 
199  private:
202  } ;
204  template < typename Config>
205  class EntryMultiShared< types::HistT<Config>> : public EntryBase {
206 
207  friend BookStore ;
209 
210  public:
214  using Point_t = typename Type::Point_t ;
216  using Weight_t = typename Type::Weight_t ;
217 
219  static constexpr Flag_t Flag = EntryMultiShared<void>::Flag;
220 
221  private:
223  static void fill(const std::shared_ptr<void>& data,
224  Point_t const& x,
225  Weight_t const& w);
226 
228  static void fillN(const std::shared_ptr<void>& data,
229  Point_t const* pFirst, Point_t const* pLast,
230  Weight_t const* wFirst, Weight_t const* wLast);
231 
232  public:
234  explicit EntryMultiShared( Context context ) ;
235 
236  // EntryMultiShared() = default ;
238  ~EntryMultiShared() ;
239 
240  EntryMultiShared(const EntryMultiShared&) = default;
241  EntryMultiShared& operator=(const EntryMultiShared&) = default ;
242  EntryMultiShared(EntryMultiShared&&) = default;
243  EntryMultiShared& operator=(EntryMultiShared && ) = default;
244 
250  Handle< Type > handle() ;
251 
255  Handle< Type > handle( std::size_t idx ) ;
256 
258  void flush() ;
259 
260  private:
264  std::shared_ptr< types::HistConcurrentFillManager< Config > > _fillMgr ;
266  std::vector< std::weak_ptr< types::HistConcurrentFiller< Config > > >
269  std::vector<
270  std::shared_ptr<types::HistConcurrentFiller< Config > > > _staticFiller {};
272  std::mutex _fillersExtend {};
273  } ;
274  } // end namespace book
275 } // end namespace marlinmt
typename Type::Weight_t Weight_t
Weigh_t from managed Histogram.
Definition: HistEntry.h:32
typename Type::Weight_t Weight_t
Weight type for Hist.
Definition: HistEntry.h:216
entry for object to be used Multithreaded.
Definition: Entry.h:87
typename Type::Point_t Point_t
Point type for Hist.
Definition: HistEntry.h:121
std::function< void() > FinalizeFn_t
Function signature called when close Handle.
Definition: HistEntry.h:34
Flag type for flags in marlinmt::book.
Definition: Flags.h:15
Generalized histogram class.
Definition: Base.h:151
typename Type::Point_t Point_t
CoordArray_t from managed Histogram.
Definition: HistEntry.h:30
Base type for Entries. To avoid void pointer.
Definition: EntryData.h:88
std::shared_ptr< types::HistConcurrentFillManager< Config > > _fillMgr
Manager to construct Filler.
Definition: HistEntry.h:264
typename Type::Point_t Point_t
Point type for Hist.
Definition: HistEntry.h:214
entry for object to be used Multithreaded.
Definition: Entry.h:55
const Flag_t _type
entry type decoded as flag.
Definition: HistEntry.h:106
minimal entry for Object.
Definition: Entry.h:27
std::vector< std::weak_ptr< types::HistConcurrentFiller< Config > > > _fillers
list of produced Filler to flush them when needed.
Definition: HistEntry.h:267
Handle(const std::shared_ptr< T > &obj, const std::shared_ptr< MemLayout > &mem)
constructor
Definition: Handle.h:57
FinalizeFn_t _finalFn
functor called when merging.
Definition: HistEntry.h:102
typename Type::Point_t Point_t
Point type for Hist.
Definition: HistEntry.h:165
typename Type::Weight_t Weight_t
Weight type for Hist.
Definition: HistEntry.h:167
class which basic functionality for every handle.
Definition: Handle.h:24
vanilla Handle.
Definition: Handle.h:54
std::shared_ptr< void > _data
pointer to data defined from entry.
Definition: HistEntry.h:104
const T & merged()
get final object.
Definition: Handle.h:40
std::array< Precision_t, Dimension > Point_t
type used for Entry Points
Definition: Base.h:189
Data selection for the Entry to work properly.
Definition: EntryData.h:71
typename Type::Weight_t Weight_t
Weight type for Hist.
Definition: HistEntry.h:123
typename Config::Weight_t Weight_t
type used for bin weight
Definition: Base.h:183