Belle II Software development
EventProcessor.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/Path.h>
12#include <framework/core/Module.h>
13#include <framework/core/PathIterator.h>
14#include <framework/core/ProcessStatistics.h>
15#include <framework/datastore/StoreObjPtr.h>
16#include <framework/dataobjects/EventMetaData.h>
17
18#include <stdexcept>
19
20namespace Belle2 {
30 public:
31
36
40 virtual ~EventProcessor();
41
52 void process(const PathPtr& startPath, long maxEvent = 0);
53
57 void setProfileModuleName(const std::string& name) { m_profileModuleName = name; }
58
60 static void writeToStdErr(const char msg[]);
61
65 static void installSignalHandler(int sig, void (*fn)(int));
66
71 static void installMainSignalHandlers(void (*fn)(int) = nullptr);
72
73 protected:
75 class StoppedBySignalException : public std::runtime_error {
76 public:
78 explicit StoppedBySignalException(int signal);
79 int signal;
80 };
81
82
93 void processInitialize(const ModulePtrList& modulePathList, bool setEventInfo = true);
94
103 void processCore(const PathPtr& startPath, const ModulePtrList& modulePathList, long maxEvent = 0, bool isInputProcess = true);
104
113 bool processEvent(PathIterator moduleIter, bool skipMasterModule);
114
118 void callEvent(Module* module);
119
126 void processTerminate(const ModulePtrList& modulePathList);
127
136 void processBeginRun(bool skipDB = false);
137
146 void processEndRun();
147
151 long getMaximumEventNumber(long maxEvent) const;
152
158
161
164
167
170
173
176
179
182 };
183
185}
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
Exception thrown when execution is stopped by a signal.
provides the core event processing loop.
void processEndRun()
Calls the end run methods of all modules.
void processInitialize(const ModulePtrList &modulePathList, bool setEventInfo=true)
Initializes the modules.
bool m_inRun
Are we currently in a run? If yes, processEndRun() needs to do something.
std::string m_profileModuleName
Name of the module which should be profiled, empty if no profiling is requested.
void processBeginRun(bool skipDB=false)
Calls the begin run methods of all modules.
void processCore(const PathPtr &startPath, const ModulePtrList &modulePathList, long maxEvent=0, bool isInputProcess=true)
Processes the full module chain consisting of an arbitrary number of connected paths,...
void setProfileModuleName(const std::string &name)
Set the name of the module we want to profile.
double m_lastMetadataUpdate
Time in seconds of last call for metadata update in event loop.
static void installSignalHandler(int sig, void(*fn)(int))
Install a signal handler 'fn' for given signal.
StoreObjPtr< ProcessStatistics > m_processStatisticsPtr
Also used in a number of places.
void process(const PathPtr &startPath, long maxEvent=0)
Processes the full module chain, starting with the first module in the given path.
void callEvent(Module *module)
Calls event() on one single module, setting up logging and statistics as needed.
void processTerminate(const ModulePtrList &modulePathList)
Terminates the modules.
Module * m_profileModule
Adress of the module which we want to profile, nullptr if no profiling is requested.
static void writeToStdErr(const char msg[])
async-safe method to write something to STDERR.
bool processEvent(PathIterator moduleIter, bool skipMasterModule)
Calls event() functions on all modules for the current event.
virtual ~EventProcessor()
Destructor.
const Module * m_master
The master module that determines the experiment/run/event number.
EventProcessor()
Constructor.
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
EventMetaData is used by processEvent()/processCore().
ModulePtrList m_moduleList
List of all modules in order initialized.
long getMaximumEventNumber(long maxEvent) const
Calculate the maximum event number out of the argument from command line and the environment.
EventMetaData m_previousEventMetaData
Stores state of EventMetaData before it was last changed.
bool m_steerRootInputModuleOn
True if the SteerRootInputModule is in charge for event processing.
double m_metadataUpdateInterval
Minimal time difference in seconds for metadata updates in event loop.
static void installMainSignalHandlers(void(*fn)(int)=nullptr)
Install signal handler for INT, TERM and QUIT signals.
Base class for Modules.
Definition: Module.h:72
Iterator over a Path (returning Module pointers).
Definition: PathIterator.h:26
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
std::shared_ptr< Path > PathPtr
Defines a pointer to a path object as a boost shared pointer.
Definition: Path.h:35
std::list< ModulePtr > ModulePtrList
Defines a std::list of shared module pointers.
Definition: Module.h:584
Abstract base class for different kinds of events.