LDMX Software
EventProcessor.h
Go to the documentation of this file.
1
7#ifndef FRAMEWORK_EVENTPROCESSOR_H_
8#define FRAMEWORK_EVENTPROCESSOR_H_
9
10/*~~~~~~~~~~~~~~~*/
11/* Framework */
12/*~~~~~~~~~~~~~~~*/
14#include "Framework/Configure/Parameters.h"
15#include "Framework/Event.h"
16#include "Framework/Exception/Exception.h"
17#include "Framework/Factory.h"
18#include "Framework/HistogramPool.h"
19#include "Framework/Logger.h"
20#include "Framework/NtupleManager.h"
21#include "Framework/RunHeader.h"
23
24/*~~~~~~~~~~~~~~~~*/
25/* C++ StdLib */
26/*~~~~~~~~~~~~~~~~*/
27#include <any>
28#include <map>
29
30class t_directory;
31
32namespace framework {
33
34class Process;
35class EventProcessor;
36class EventFile;
37
44 public:
50 AbortEventException() throw() : framework::exception::Exception() {}
51
55 virtual ~AbortEventException() throw() {}
56};
57
63 public:
66 Process &);
67
80 EventProcessor(const std::string &name, Process &process);
81
85 virtual ~EventProcessor() = default;
86
99 virtual void configure(framework::config::Parameters &parameters) {}
100
105 virtual void beforeNewRun(ldmx::RunHeader &run_header) {}
106
112 virtual void onNewRun(const ldmx::RunHeader &run_header) {}
113
120 virtual void onFileOpen(EventFile &event_file) {}
121
128 virtual void onFileClose(EventFile &event_file) {}
129
135 virtual void onProcessStart() {}
136
142 virtual void onProcessEnd() {}
143
149 virtual void process(Event &event) = 0;
150
154 template <class T>
155 const T &getCondition(const std::string &condition_name) {
156 return getConditions().getCondition<T>(condition_name);
157 }
158
168 TDirectory *getHistoDirectory();
169
177
185 const std::string &purposeString);
186
191 int getLogFrequency() const;
192
197 int getRunNumber() const;
198
202 std::string getName() const { return name_; }
203
209 void createHistograms(
210 const std::vector<framework::config::Parameters> &histos);
211
212 protected:
218 void abortEvent() { throw AbortEventException(); }
219
222
225
227 logging::logger the_log_;
228
229 private:
233 Conditions &getConditions() const;
234
238 const ldmx::EventHeader &getEventHeader() const;
239
242
244 std::string name_;
245
247 TDirectory *histo_dir_{0};
248};
249
257class Producer : public EventProcessor {
258 public:
273 Producer(const std::string &name, Process &process);
274
278 virtual void process(Event &event) final { produce(event); }
279
284 virtual void produce(Event &event) = 0;
285};
286
294class Analyzer : public EventProcessor {
295 public:
311 Analyzer(const std::string &name, Process &process);
312
316 virtual void process(Event &event) final { analyze(event); }
317
325 virtual void beforeNewRun(ldmx::RunHeader &run_header) final {}
326
331 virtual void analyze(const Event &event) = 0;
332};
333
334} // namespace framework
335
348#define DECLARE_PRODUCER(CLASS) \
349 FACTORY_REGISTRATION(framework::EventProcessor, CLASS)
350
363#define DECLARE_ANALYZER(CLASS) \
364 FACTORY_REGISTRATION(framework::EventProcessor, CLASS)
365
366#endif
Container and caching class for conditions information.
Class implementing an event buffer system for storing event data.
Header holding Factory class and supporting macros.
Definitions related to event storage control from an EventProcessor.
Specific exception used to abort an event.
virtual ~AbortEventException()
Destructor.
Base class for a module which does not produce a data product.
virtual void process(Event &event) final
Processing an event for an Analyzer is calling analyze.
virtual void beforeNewRun(ldmx::RunHeader &run_header) final
Don't allow Analyzers to add parameters to the run header.
virtual void analyze(const Event &event)=0
Process the event and make histograms or summaries.
Analyzer(const std::string &name, Process &process)
Class constructor.
Container and cache for conditions and conditions providers.
Definition Conditions.h:43
const T & getCondition(const std::string &condition_name)
Primary request action for a conditions object If the object is in the cache and still valid (IOV),...
Definition Conditions.h:83
This class manages all ROOT file input/output operations.
Definition EventFile.h:26
Base class for all event processing components.
DECLARE_FACTORY(EventProcessor, EventProcessor *, const std::string &, Process &)
declare that we have a factory for this class
Process & process_
Handle to the Process.
virtual void configure(framework::config::Parameters &parameters)
Callback for the EventProcessor to configure itself from the given set of parameters.
std::string name_
The name of the EventProcessor.
NtupleManager & ntuple_
Manager for any ntuples.
logging::logger the_log_
The logger for this EventProcessor.
virtual ~EventProcessor()=default
Class destructor.
virtual void onProcessEnd()
Callback for the EventProcessor to take any necessary action when the processing of events finishes,...
void createHistograms(const std::vector< framework::config::Parameters > &histos)
Internal function which is used to create histograms passed from the python configuration @parma hist...
EventProcessor(const std::string &name, Process &process)
Class constructor.
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
Conditions & getConditions() const
Internal getter for conditions without exposing all of Process.
void abortEvent()
Abort the event immediately.
const ldmx::EventHeader & getEventHeader() const
Internal getter for EventHeader without exposing all of Process.
std::string getName() const
Get the processor name.
virtual void beforeNewRun(ldmx::RunHeader &run_header)
Callback for Producers to add parameters to the run header before conditions are initialized.
virtual void onFileClose(EventFile &event_file)
Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
virtual void onProcessStart()
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
HistogramPool histograms_
helper object for making and filling histograms
virtual void process(Event &event)=0
How an EventProcessor processes an event.
int getRunNumber() const
Get the run number from the process.
TDirectory * getHistoDirectory()
Access/create a directory in the histogram file for this event processor to create histograms and ana...
TDirectory * histo_dir_
Histogram directory.
int getLogFrequency() const
Get the current logging frequency from the process.
void setStorageHint(framework::StorageControl::Hint hint)
Mark the current event as having the given storage control hint from this module_.
virtual void onFileOpen(EventFile &event_file)
Callback for the EventProcessor to take any necessary action when a new event input ROOT file is open...
virtual void onNewRun(const ldmx::RunHeader &run_header)
Callback for the EventProcessor to take any necessary action when the run being processed changes.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class for holding an EventProcessor's histogram pointers and making sure that they all end up in the ...
Singleton class used to manage the creation and pooling of ntuples.
static NtupleManager & getInstance()
Class which represents the process under execution.
Definition Process.h:36
Base class for a module which produces a data product.
Producer(const std::string &name, Process &process)
Class constructor.
virtual void produce(Event &event)=0
Process the event and put new data products into it.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.
Hint
Hints that can be provided by processors to the storage controller.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Standard base exception class with some useful output information.
Definition Exception.h:20
Exception()
Empty constructor.
Definition Exception.h:27
Provides header information an event such as event number and timestamp.
Definition EventHeader.h:44
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:57
All classes in the ldmx-sw project use this namespace.