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
28class t_directory;
29
30namespace framework {
31
32class Process;
33class EventProcessor;
34class EventFile;
35
42 public:
48 AbortEventException() throw() : framework::exception::Exception() {}
49
53 virtual ~AbortEventException() throw() {}
54};
55
61 public:
64 Process&);
65
78 EventProcessor(const std::string& name, Process& process);
79
83 virtual ~EventProcessor() = default;
84
97 virtual void configure(framework::config::Parameters& parameters) {}
98
103 virtual void beforeNewRun(ldmx::RunHeader& run_header) {}
104
110 virtual void onNewRun(const ldmx::RunHeader& run_header) {}
111
118 virtual void onFileOpen(EventFile& event_file) {}
119
126 virtual void onFileClose(EventFile& event_file) {}
127
133 virtual void onProcessStart() {}
134
140 virtual void onProcessEnd() {}
141
147 virtual void process(Event& event) = 0;
148
152 template <class T>
153 const T& getCondition(const std::string& condition_name) {
154 return getConditions().getCondition<T>(condition_name);
155 }
156
166 TDirectory* getHistoDirectory();
167
175
183 const std::string& purposeString);
184
189 int getLogFrequency() const;
190
195 int getRunNumber() const;
196
200 std::string getName() const { return name_; }
201
207 void createHistograms(
208 const std::vector<framework::config::Parameters>& histos);
209
210 protected:
216 void abortEvent() { throw AbortEventException(); }
217
220
223
225 logging::logger the_log_;
226
227 private:
231 Conditions& getConditions() const;
232
236 const ldmx::EventHeader& getEventHeader() const;
237
240
242 std::string name_;
243
245 TDirectory* histo_dir_{0};
246};
247
255class Producer : public EventProcessor {
256 public:
271 Producer(const std::string& name, Process& process);
272
276 virtual void process(Event& event) final { produce(event); }
277
282 virtual void produce(Event& event) = 0;
283};
284
292class Analyzer : public EventProcessor {
293 public:
309 Analyzer(const std::string& name, Process& process);
310
314 virtual void process(Event& event) final { analyze(event); }
315
323 virtual void beforeNewRun(ldmx::RunHeader& run_header) final {}
324
329 virtual void analyze(const Event& event) = 0;
330};
331
332} // namespace framework
333
346#define DECLARE_PRODUCER(CLASS) \
347 FACTORY_REGISTRATION(framework::EventProcessor, CLASS)
348
361#define DECLARE_ANALYZER(CLASS) \
362 FACTORY_REGISTRATION(framework::EventProcessor, CLASS)
363
364#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:40
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:82
This class manages all ROOT file input/output operations.
Definition EventFile.h:28
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:40
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:34
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:26
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:68
All classes in the ldmx-sw project use this namespace.