MarlinMT  0.1.0
ProcessorApi.cc
Go to the documentation of this file.
2 
3 // -- std headers
4 #include <utility>
5 
6 // -- marlinmt headers
7 #include <marlinmt/Exceptions.h>
9 
10 namespace marlinmt {
11 
17  std::filesystem::path constructPath(
18  const Processor *proc,
19  const std::filesystem::path &path ) {
20  return (std::filesystem::path("/")
21  += proc->name()) += path;
22  }
23 
24  //--------------------------------------------------------------------------
25 
26  template<typename HistT>
28  const BookStoreManager &storeManager,
29  const std::filesystem::path &path,
30  const std::string_view &name) {
31 
32  return storeManager.getObject<HistT>(
33  storeManager.getKey(path, name));
34  }
35 
36  //--------------------------------------------------------------------------
37 
39  Processor *proc,
40  const std::filesystem::path &path,
41  const std::string_view &name,
42  const std::string_view &title,
43  const AxisConfigD &axisconfig,
44  const BookFlag_t &flags ) {
45  return proc->application().bookStoreManager().bookHist<Hist1F>(
46  constructPath(proc, path),
47  name,
48  title,
49  {&axisconfig},
50  flags);
51  }
52 
53  //--------------------------------------------------------------------------
54 
56  const Processor *proc,
57  const std::filesystem::path &path,
58  const std::string_view &name ) {
59  return getObject<Hist1F>(
60  proc->application().bookStoreManager(),
61  constructPath(proc, path), name);
62  }
63 
64  //--------------------------------------------------------------------------
65 
67  Processor *proc,
68  const std::filesystem::path &path,
69  const std::string_view &name,
70  const std::string_view &title,
71  const AxisConfigD &axisconfigX,
72  const AxisConfigD &axisconfigY,
73  const BookFlag_t &flags) {
74  return proc->application().bookStoreManager().bookHist<Hist2F>(
75  constructPath(proc, path),
76  name,
77  title,
78  {&axisconfigX, &axisconfigY},
79  flags);
80  }
81 
82  //--------------------------------------------------------------------------
83 
85  const Processor *proc,
86  const std::filesystem::path &path,
87  const std::string_view &name ) {
88  return getObject<Hist2F>(
89  proc->application().bookStoreManager(),
90  constructPath(proc, path), name);
91  }
92 
93  //--------------------------------------------------------------------------
94 
96  Processor *proc,
97  const std::filesystem::path &path,
98  const std::string_view &name,
99  const std::string_view &title,
100  const AxisConfigD &axisconfigX,
101  const AxisConfigD &axisconfigY,
102  const AxisConfigD &axisconfigZ,
103  const BookFlag_t &flags ) {
104  return proc->application().bookStoreManager().bookHist<Hist3F>(
105  constructPath(proc, path),
106  name,
107  title,
108  {&axisconfigX, &axisconfigY, &axisconfigZ},
109  flags);
110  }
111 
112  //--------------------------------------------------------------------------
113 
115  const Processor *proc,
116  const std::filesystem::path &path,
117  const std::string_view &name ) {
118  return getObject<Hist3F>(
119  proc->application().bookStoreManager(),
120  constructPath(proc, path), name);
121  }
122 
123  //--------------------------------------------------------------------------
124 
126  Processor *proc,
127  const std::filesystem::path &path,
128  const std::string_view &name,
129  const std::string_view &title,
130  const AxisConfigD &axisconfig,
131  const BookFlag_t &flags ) {
132  return proc->application().bookStoreManager().bookHist<Hist1D>(
133  constructPath(proc, path),
134  name,
135  title,
136  {&axisconfig},
137  flags);
138  }
139 
140  //--------------------------------------------------------------------------
141 
143  const Processor *proc,
144  const std::filesystem::path &path,
145  const std::string_view &name ) {
146  return getObject<Hist1D>(
147  proc->application().bookStoreManager(),
148  constructPath(proc, path), name);
149  }
150 
151  //--------------------------------------------------------------------------
152 
154  Processor *proc,
155  const std::filesystem::path &path,
156  const std::string_view &name,
157  const std::string_view &title,
158  const AxisConfigD &axisconfigX,
159  const AxisConfigD &axisconfigY,
160  const BookFlag_t &flags) {
161  return proc->application().bookStoreManager().bookHist<Hist2D>(
162  constructPath(proc, path),
163  name,
164  title,
165  {&axisconfigX, &axisconfigY},
166  flags);
167  }
168 
169  //--------------------------------------------------------------------------
170 
172  const Processor *proc,
173  const std::filesystem::path &path,
174  const std::string_view &name ) {
175  return getObject<Hist2D>(
176  proc->application().bookStoreManager(),
177  constructPath(proc, path), name);
178  }
179 
180  //--------------------------------------------------------------------------
181 
183  Processor *proc,
184  const std::filesystem::path &path,
185  const std::string_view &name,
186  const std::string_view &title,
187  const AxisConfigD &axisconfigX,
188  const AxisConfigD &axisconfigY,
189  const AxisConfigD &axisconfigZ,
190  const BookFlag_t &flags ) {
191  return proc->application().bookStoreManager().bookHist<Hist3D>(
192  constructPath(proc, path),
193  name,
194  title,
195  {&axisconfigX, &axisconfigY, &axisconfigZ},
196  flags);
197  }
198 
199  //--------------------------------------------------------------------------
200 
202  const Processor *proc,
203  const std::filesystem::path &path,
204  const std::string_view &name ) {
205  return getObject<Hist3D>(
206  proc->application().bookStoreManager(),
207  constructPath(proc, path), name);
208  }
209 
210  //--------------------------------------------------------------------------
211 
213  Processor *proc,
214  const std::filesystem::path &path,
215  const std::string_view &name,
216  const std::string_view &title,
217  const AxisConfigD &axisconfig,
218  const BookFlag_t &flags ) {
219  return proc->application().bookStoreManager().bookHist<Hist1I>(
220  constructPath(proc, path),
221  name,
222  title,
223  {&axisconfig},
224  flags);
225  }
226 
227  //--------------------------------------------------------------------------
228 
230  const Processor *proc,
231  const std::filesystem::path &path,
232  const std::string_view &name ) {
233  return getObject<Hist1I>(
234  proc->application().bookStoreManager(),
235  constructPath(proc, path), name);
236  }
237 
238  //--------------------------------------------------------------------------
239 
241  Processor *proc,
242  const std::filesystem::path &path,
243  const std::string_view &name,
244  const std::string_view &title,
245  const AxisConfigD &axisconfigX,
246  const AxisConfigD &axisconfigY,
247  const BookFlag_t &flags) {
248  return proc->application().bookStoreManager().bookHist<Hist2I>(
249  constructPath(proc, path),
250  name,
251  title,
252  {&axisconfigX, &axisconfigY},
253  flags);
254  }
255 
256  //--------------------------------------------------------------------------
257 
259  const Processor *proc,
260  const std::filesystem::path &path,
261  const std::string_view &name ) {
262  return getObject<Hist2I>(
263  proc->application().bookStoreManager(),
264  constructPath(proc, path), name);
265  }
266 
267  //--------------------------------------------------------------------------
268 
270  Processor *proc,
271  const std::filesystem::path &path,
272  const std::string_view &name,
273  const std::string_view &title,
274  const AxisConfigD &axisconfigX,
275  const AxisConfigD &axisconfigY,
276  const AxisConfigD &axisconfigZ,
277  const BookFlag_t &flags ) {
278  return proc->application().bookStoreManager().bookHist<Hist3I>(
279  constructPath(proc, path),
280  name,
281  title,
282  {&axisconfigX, &axisconfigY, &axisconfigZ},
283  flags);
284  }
285 
286  //--------------------------------------------------------------------------
287 
289  const Processor *proc,
290  const std::filesystem::path &path,
291  const std::string_view &name ) {
292  return getObject<Hist3I>(
293  proc->application().bookStoreManager(),
294  constructPath(proc, path), name);
295  }
296 
297  //--------------------------------------------------------------------------
298 
300  Processor *proc,
301  const book::EntryKey &key)
302  {
303  proc->application().bookStoreManager().addToWrite(key);
304  }
305 
306  //--------------------------------------------------------------------------
307 
309  Processor *proc,
310  const book::EntryKey &key)
311  {
313  }
314 
315  //--------------------------------------------------------------------------
316 
318  proc->application().randomSeedManager().addEntry( proc ) ;
319  }
320 
321  //--------------------------------------------------------------------------
322 
323  unsigned int ProcessorApi::getRandomSeed( const Processor *const proc, EventStore *event ) {
324  auto randomSeeds = event->extensions().get<extensions::RandomSeed, RandomSeedExtension>();
325  if( nullptr == randomSeeds ) {
326  MARLINMT_THROW( "No random seed extension in event" ) ;
327  }
328  return randomSeeds->randomSeed( proc ) ;
329  }
330 
331  //--------------------------------------------------------------------------
332 
333  void ProcessorApi::setReturnValue( const Processor *const proc, EventStore *event, bool value ) {
334  auto procConds = event->extensions().get<extensions::ProcessorConditions, ProcessorConditionsExtension>() ;
335  if( nullptr == procConds ) {
336  MARLINMT_THROW( "No processor conditions extension in event" ) ;
337  }
338  return procConds->set( proc, value ) ;
339  }
340 
341  //--------------------------------------------------------------------------
342 
343  void ProcessorApi::setReturnValue( const Processor *const proc, EventStore *event, const std::string &name, bool value ) {
344  auto procConds = event->extensions().get<extensions::ProcessorConditions, ProcessorConditionsExtension>() ;
345  if( nullptr == procConds ) {
346  MARLINMT_THROW( "No processor conditions extension in event" ) ;
347  }
348  return procConds->set( proc, name, value ) ;
349  }
350 
351  //--------------------------------------------------------------------------
352 
354  return *event->extensions().get<extensions::IsFirstEvent, bool>() ;
355  }
356 
357  //--------------------------------------------------------------------------
358 
359  void ProcessorApi::skipCurrentEvent( const Processor *const proc ) {
360  proc->log<WARNING>() << "Skipping current event !" << std::endl ;
361  MARLINMT_SKIP_EVENT( proc ) ;
362  }
363 
364  //--------------------------------------------------------------------------
365 
366  void ProcessorApi::abort( const Processor *const proc, const std::string &reason ) {
367  proc->log<WARNING>() << "Stopping application: " << reason << std::endl ;
368  MARLINMT_STOP_PROCESSING( proc ) ;
369  }
370 
371 }
static bool isFirstEvent(EventStore *event)
Whether the event is the first event to be processed.
Data selection to identify and manage an Entry.
Definition: EntryData.h:21
static H3DEntry getHist3D(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 3D, double type.
static H1IEntry getHist1I(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 1D, integer type.
const std::string & name() const
Get the component name.
Definition: Component.cc:23
ProcessorConditionsExtension class Event extension providing access to processor runtime conditions (...
book::Handle< book::Entry< HistT > > bookHist(const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const std::array< const AxisConfig< typename HistT::Precision_t > *, HistT::Dimension > &axesconfig, const BookFlag_t &flags)
Book a histogram 1D, float type.
BookStoreManager class.
static H1DEntry getHist1D(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 1D, double type.
static H3FEntry bookHist3F(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfigX, const AxisConfigD &axisconfigY, const AxisConfigD &axisconfigZ, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 3D, float type.
Definition: ProcessorApi.cc:95
constexpr unsigned long long value(const Flag_t &flag)
Definition: Flags.h:106
static H1IEntry bookHist1I(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfig, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 1D, integer type.
BookStoreManager & bookStoreManager()
Get book store manager.
Definition: Application.cc:266
std::filesystem::path constructPath(const Processor *proc, const std::filesystem::path &path)
construct absolute path from relative path and processor.
Definition: ProcessorApi.cc:17
static H1FEntry bookHist1F(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfig, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 1D, float type.
Definition: ProcessorApi.cc:38
RandomSeedExtension class Event extension providing access to random seeds.
static H2DEntry bookHist2D(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfigX, const AxisConfigD &axisconfigY, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 2D, double type.
const RandomSeedManager & randomSeedManager() const
Get the random seed manager.
Definition: Application.cc:243
Flag type for flags in marlinmt::book.
Definition: Flags.h:15
static H2IEntry getHist2I(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 2D, integer type.
Generalized histogram class.
Definition: Base.h:151
static H2FEntry bookHist2F(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfigX, const AxisConfigD &axisconfigY, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 2D, float type.
Definition: ProcessorApi.cc:66
#define MARLINMT_THROW(message)
Definition: Exceptions.h:8
book::Handle< book::Entry< T > > getObject(const book::EntryKey &key) const
access object managed by this store.
static H3IEntry bookHist3I(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfigX, const AxisConfigD &axisconfigY, const AxisConfigD &axisconfigZ, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 3D, integer type.
static unsigned int getRandomSeed(const Processor *const proc, EventStore *event)
Get a random seed from the event.
void removeFromWrite(const book::EntryKey &key)
remove entry key from write list.
static void write(Processor *proc, const std::filesystem::path &path, const std::string_view &name)
register Object to write it at end of lifetime.
static void abort(const Processor *const proc, const std::string &reason)
Abort program execution properly.
collection for Axis Description
Definition: Base.h:23
static H1DEntry bookHist1D(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfig, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 1D, double type.
#define MARLINMT_SKIP_EVENT(proc)
Definition: Exceptions.h:14
Logging::StreamType log() const
Log a message with specific log level.
Definition: Component.h:93
const Application & application() const
Get the application in which the component is registered.
Definition: Component.cc:83
void addEntry(HashResult entry)
Add an entry to the random seed manager.
static H2IEntry bookHist2I(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfigX, const AxisConfigD &axisconfigY, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 2D, integer type.
static H3IEntry getHist3I(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 3D, integer type.
vanilla Handle.
Definition: Handle.h:54
const book::EntryKey & getKey(const std::filesystem::path &path, const std::string_view &name) const
receive key from Entry with given path and name.
static H2FEntry getHist2F(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 2D, float type.
Definition: ProcessorApi.cc:84
book::Handle< book::Entry< HistT > > getObject(const BookStoreManager &storeManager, const std::filesystem::path &path, const std::string_view &name)
Definition: ProcessorApi.cc:27
static H3DEntry bookHist3D(Processor *proc, const std::filesystem::path &path, const std::string_view &name, const std::string_view &title, const AxisConfigD &axisconfigX, const AxisConfigD &axisconfigY, const AxisConfigD &axisconfigZ, const BookFlag_t &flags=BookFlags::Default)
Book a histogram 3D, double type.
void addToWrite(const book::EntryKey &key)
add entry key to write list.
static void skipCurrentEvent(const Processor *const proc)
Notify the application to skip the current event processing and go directly to the next event by skip...
Processor class.
Definition: Processor.h:43
static H2DEntry getHist2D(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 2D, double type.
static H1FEntry getHist1F(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 1D, float type.
Definition: ProcessorApi.cc:55
static void dontWrite(Processor *proc, const std::filesystem::path &path, const std::string_view &name)
cancels writing of Object at end of lifetime.
static void setReturnValue(const Processor *const proc, EventStore *event, bool value)
Set the processor return value.
static H3FEntry getHist3F(const Processor *proc, const std::filesystem::path &path, const std::string_view &name)
Get handle for booked histogram 3D, float type.
static void registerForRandomSeeds(Processor *const proc)
Register the processor to get random seeds.
#define MARLINMT_STOP_PROCESSING(proc)
Definition: Exceptions.h:15
EventStore class.
Definition: EventStore.h:17