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/Histograms.h"
18#include "Framework/Logger.h"
19#include "Framework/NtupleManager.h"
20#include "Framework/RunHeader.h"
22
23/*~~~~~~~~~~~~~~~~*/
24/* C++ StdLib */
25/*~~~~~~~~~~~~~~~~*/
26#include <any>
27#include <map>
28
29class TDirectory;
30
31namespace framework {
32
33class Process;
34class EventProcessor;
35class EventFile;
36
38typedef EventProcessor *EventProcessorMaker(const std::string &name,
39 Process &process);
40
47 public:
53 AbortEventException() throw() : framework::exception::Exception() {}
54
58 virtual ~AbortEventException() throw() {}
59};
60
66 public:
79 EventProcessor(const std::string &name, Process &process);
80
84 virtual ~EventProcessor() { ; }
85
98 virtual void configure(framework::config::Parameters &parameters) {}
99
105 virtual void onNewRun(const ldmx::RunHeader &runHeader) {}
106
113 virtual void onFileOpen(EventFile &eventFile) {}
114
121 virtual void onFileClose(EventFile &eventFile) {}
122
128 virtual void onProcessStart() {}
129
135 virtual void onProcessEnd() {}
136
140 template <class T>
141 const T &getCondition(const std::string &condition_name) {
142 return getConditions().getCondition<T>(condition_name);
143 }
144
154 TDirectory *getHistoDirectory();
155
163
171 const std::string &purposeString);
172
177 int getLogFrequency() const;
178
183 int getRunNumber() const;
184
188 std::string getName() const { return name_; }
189
196 static void declare(const std::string &classname, int classtype,
198
204 void createHistograms(
205 const std::vector<framework::config::Parameters> &histos);
206
207 protected:
213 void abortEvent() { throw AbortEventException(); }
214
217
220
222 logging::logger theLog_;
223
224 private:
228 Conditions &getConditions() const;
229
233 const ldmx::EventHeader &getEventHeader() const;
234
237
239 std::string name_;
240
242 TDirectory *histoDir_{0};
243};
244
252class Producer : public EventProcessor {
253 public:
255 static const int CLASSTYPE{1};
256
271 Producer(const std::string &name, Process &process);
272
277 virtual void produce(Event &event) = 0;
278
283 virtual void beforeNewRun(ldmx::RunHeader &header) {}
284};
285
293class Analyzer : public EventProcessor {
294 public:
296 static const int CLASSTYPE{2};
297
313 Analyzer(const std::string &name, Process &process);
314
319 virtual void analyze(const Event &event) = 0;
320};
321
322} // namespace framework
323
333#define DECLARE_PRODUCER(CLASS) \
334 framework::EventProcessor *CLASS##_ldmx_make(const std::string &name, \
335 framework::Process &process) { \
336 return new CLASS(name, process); \
337 } \
338 __attribute__((constructor(1000))) static void CLASS##_ldmx_declare() { \
339 framework::EventProcessor::declare( \
340 #CLASS, ::framework::Producer::CLASSTYPE, &CLASS##_ldmx_make); \
341 }
342
352#define DECLARE_ANALYZER(CLASS) \
353 framework::EventProcessor *CLASS##_ldmx_make(const std::string &name, \
354 framework::Process &process) { \
355 return new CLASS(name, process); \
356 } \
357 __attribute__((constructor(1000))) static void CLASS##_ldmx_declare() { \
358 framework::EventProcessor::declare( \
359 #CLASS, ::framework::Analyzer::CLASSTYPE, &CLASS##_ldmx_make); \
360 }
361
371#define DECLARE_PRODUCER_NS(NS, CLASS) \
372 framework::EventProcessor *CLASS##_ldmx_make(const std::string &name, \
373 framework::Process &process) { \
374 return new NS::CLASS(name, process); \
375 } \
376 __attribute__((constructor(1000))) static void CLASS##_ldmx_declare() { \
377 framework::EventProcessor::declare( \
378 std::string(#NS) + "::" + std::string(#CLASS), \
379 ::framework::Producer::CLASSTYPE, &CLASS##_ldmx_make); \
380 }
381
391#define DECLARE_ANALYZER_NS(NS, CLASS) \
392 framework::EventProcessor *CLASS##_ldmx_make(const std::string &name, \
393 framework::Process &process) { \
394 return new NS::CLASS(name, process); \
395 } \
396 __attribute__((constructor(1000))) static void CLASS##_ldmx_declare() { \
397 framework::EventProcessor::declare( \
398 std::string(#NS) + "::" + std::string(#CLASS), \
399 ::framework::Analyzer::CLASSTYPE, &CLASS##_ldmx_make); \
400 }
401
402#endif
Container and caching class for conditions information.
Class implementing an event buffer system for storing event data.
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.
static const int CLASSTYPE
Constant used to track EventProcessor types by the PluginFactory.
virtual void analyze(const Event &event)=0
Process the event and make histograms or summaries.
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.
static void declare(const std::string &classname, int classtype, EventProcessorMaker *)
Internal function which is part of the PluginFactory machinery.
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.
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...
virtual void onFileClose(EventFile &eventFile)
Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
TDirectory * histoDir_
Histogram directory.
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.
virtual void onNewRun(const ldmx::RunHeader &runHeader)
Callback for the EventProcessor to take any necessary action when the run being processed changes.
std::string getName() const
Get the processor name.
virtual ~EventProcessor()
Class destructor.
virtual void onProcessStart()
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
virtual void onFileOpen(EventFile &eventFile)
Callback for the EventProcessor to take any necessary action when a new event input ROOT file is open...
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...
logging::logger theLog_
The logger for this EventProcessor.
HistogramHelper histograms_
Interface class for making and filling histograms.
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.
Implements an event buffer system for storing event data.
Definition Event.h:41
Interface class between an EventProcessor and the HistogramPool.
Definition Histograms.h:72
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.
static const int CLASSTYPE
Constant used to track EventProcessor types by the PluginFactory.
virtual void produce(Event &event)=0
Process the event and put new data products into it.
virtual void beforeNewRun(ldmx::RunHeader &header)
Handle allowing producers to modify run headers before the run begins.
Hint
Hints that can be provided by processors to the storage controller.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
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:54
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45
EventProcessor * EventProcessorMaker(const std::string &name, Process &process)
Typedef for EventProcessorFactory use.