Belle II Software  release-05-02-19
EventProcessor.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2015 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll, Christian Pulvermacher, Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/Path.h>
14 #include <framework/core/Module.h>
15 #include <framework/core/PathIterator.h>
16 #include <framework/core/ProcessStatistics.h>
17 #include <framework/datastore/StoreObjPtr.h>
18 #include <framework/dataobjects/EventMetaData.h>
19 
20 #include <stdexcept>
21 
22 namespace Belle2 {
31  class EventProcessor {
32  public:
33 
38 
42  virtual ~EventProcessor();
43 
54  void process(const PathPtr& startPath, long maxEvent = 0);
55 
59  void setProfileModuleName(const std::string& name) { m_profileModuleName = name; }
60 
62  static void writeToStdErr(const char msg[]);
63 
67  static void installSignalHandler(int sig, void (*fn)(int));
68 
73  static void installMainSignalHandlers(void (*fn)(int) = nullptr);
74 
75  protected:
77  class StoppedBySignalException : public std::runtime_error {
78  public:
80  explicit StoppedBySignalException(int signal);
81  int signal;
82  };
83 
84 
95  void processInitialize(const ModulePtrList& modulePathList, bool setEventInfo = true);
96 
105  void processCore(const PathPtr& startPath, const ModulePtrList& modulePathList, long maxEvent = 0, bool isInputProcess = true);
106 
115  bool processEvent(PathIterator moduleIter, bool skipMasterModule);
116 
120  void callEvent(Module* module);
121 
128  void processTerminate(const ModulePtrList& modulePathList);
129 
138  void processBeginRun(bool skipDB = false);
139 
148  void processEndRun();
149 
153  long getMaximumEventNumber(long maxEvent) const;
154 
155  const Module* m_master;
159  std::string m_profileModuleName;
160 
162  Module* m_profileModule = nullptr;
163 
166 
169 
172 
174  bool m_inRun;
175 
177  double m_lastMetadataUpdate;
178 
181  };
182 
184 }
Belle2::EventProcessor::callEvent
void callEvent(Module *module)
Calls event() on one single module, setting up logging and statistics as needed.
Definition: EventProcessor.cc:216
Belle2::EventProcessor::process
void process(const PathPtr &startPath, long maxEvent=0)
Processes the full module chain, starting with the first module in the given path.
Definition: EventProcessor.cc:125
Belle2::EventProcessor::processTerminate
void processTerminate(const ModulePtrList &modulePathList)
Terminates the modules.
Definition: EventProcessor.cc:430
Belle2::EventProcessor::StoppedBySignalException::signal
int signal
see 'man 7 signal'.
Definition: EventProcessor.h:89
Belle2::EventProcessor::m_eventMetaDataPtr
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
EventMetaData is used by processEvent()/processCore().
Definition: EventProcessor.h:173
Belle2::EventProcessor::EventProcessor
EventProcessor()
Constructor.
Definition: EventProcessor.cc:87
Belle2::EventProcessor::m_lastMetadataUpdate
double m_lastMetadataUpdate
Time in seconds of last call for metadata update in event loop.
Definition: EventProcessor.h:185
Belle2::EventProcessor::processEvent
bool processEvent(PathIterator moduleIter, bool skipMasterModule)
Calls event() functions on all modules for the current event.
Definition: EventProcessor.cc:311
Belle2::EventProcessor::StoppedBySignalException
Exception thrown when execution is stopped by a signal.
Definition: EventProcessor.h:85
Belle2::EventProcessor::writeToStdErr
static void writeToStdErr(const char msg[])
async-safe method to write something to STDERR.
Definition: EventProcessor.cc:74
Belle2::EventProcessor::m_profileModule
Module * m_profileModule
Adress of the module which we want to profile, nullptr if no profiling is requested.
Definition: EventProcessor.h:170
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::EventProcessor::processBeginRun
void processBeginRun(bool skipDB=false)
Calls the begin run methods of all modules.
Definition: EventProcessor.cc:457
Belle2::EventProcessor::m_inRun
bool m_inRun
Are we currently in a run? If yes, processEndRun() needs to do something.
Definition: EventProcessor.h:182
Belle2::EventProcessor::~EventProcessor
virtual ~EventProcessor()
Destructor.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::ModulePtrList
std::list< ModulePtr > ModulePtrList
Defines a std::list of shared module pointers.
Definition: Module.h:586
Belle2::EventProcessor::m_profileModuleName
std::string m_profileModuleName
Name of the module which should be profiled, empty if no profiling is requested.
Definition: EventProcessor.h:167
Belle2::PathPtr
std::shared_ptr< Path > PathPtr
Defines a pointer to a path object as a boost shared pointer.
Definition: Path.h:30
Belle2::EventProcessor::getMaximumEventNumber
long getMaximumEventNumber(long maxEvent) const
Calculate the maximum event number out of the argument from command line and the environment.
Definition: EventProcessor.cc:115
Belle2::EventProcessor::m_moduleList
ModulePtrList m_moduleList
List of all modules in order initialized.
Definition: EventProcessor.h:164
Belle2::EventProcessor::m_metadataUpdateInterval
double m_metadataUpdateInterval
Minimal time difference in seconds for metadata updates in event loop.
Definition: EventProcessor.h:188
Belle2::EventProcessor::processEndRun
void processEndRun()
Calls the end run methods of all modules.
Definition: EventProcessor.cc:491
Belle2::EventProcessor::StoppedBySignalException::StoppedBySignalException
StoppedBySignalException(int signal)
Constructor.
Definition: EventProcessor.cc:68
Belle2::EventProcessor::processInitialize
void processInitialize(const ModulePtrList &modulePathList, bool setEventInfo=true)
Initializes the modules.
Definition: EventProcessor.cc:232
Belle2::EventProcessor::m_processStatisticsPtr
StoreObjPtr< ProcessStatistics > m_processStatisticsPtr
Also used in a number of places.
Definition: EventProcessor.h:179
Belle2::EventMetaData
Store event, run, and experiment numbers.
Definition: EventMetaData.h:43
Belle2::EventProcessor::processCore
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,...
Definition: EventProcessor.cc:396
Belle2::EventProcessor::setProfileModuleName
void setProfileModuleName(const std::string &name)
Set the name of the module we want to profile.
Definition: EventProcessor.h:67
Belle2::PathIterator
Iterator over a Path (returning Module pointers).
Definition: PathIterator.h:36
Belle2::EventProcessor::m_master
const Module * m_master
The master module that determines the experiment/run/event number.
Definition: EventProcessor.h:163
Belle2::EventProcessor::m_previousEventMetaData
EventMetaData m_previousEventMetaData
Stores state of EventMetaData before it was last changed.
Definition: EventProcessor.h:176
Belle2::EventProcessor::installSignalHandler
static void installSignalHandler(int sig, void(*fn)(int))
Install a signal handler 'fn' for given signal.
Definition: EventProcessor.cc:287
Belle2::EventProcessor::installMainSignalHandlers
static void installMainSignalHandlers(void(*fn)(int)=nullptr)
Install signal handler for INT, TERM and QUIT signals.
Definition: EventProcessor.cc:302