 |
Belle II Software
release-05-02-19
|
12 #include <framework/core/Module.h>
14 #include <framework/core/EventProcessor.h>
16 #include <framework/core/PathIterator.h>
17 #include <framework/datastore/DataStore.h>
18 #include <framework/database/DBStore.h>
19 #include <framework/database/Database.h>
20 #include <framework/logging/Logger.h>
21 #include <framework/core/Environment.h>
22 #include <framework/core/DataFlowVisualization.h>
23 #include <framework/core/RandomNumbers.h>
24 #include <framework/core/MetadataService.h>
25 #include <framework/gearbox/Unit.h>
26 #include <framework/utilities/Utils.h>
29 #include <valgrind/callgrind.h>
36 #define CALL_MODULE(module,x) \
37 if(m_profileModule && m_profileModule==module && RUNNING_ON_VALGRIND){\
38 CALLGRIND_START_INSTRUMENTATION;\
40 CALLGRIND_STOP_INSTRUMENTATION;\
45 #define CALL_MODULE(module, x) module->x()
58 static int gSignalReceived = 0;
59 static void signalHandler(
int signal)
61 gSignalReceived = signal;
63 if (signal == SIGINT) {
64 EventProcessor::writeToStdErr(
"Received Ctrl+C, basf2 will exit safely. (Press Ctrl+\\ (SIGQUIT) to abort immediately - this will break output files.)\n");
68 EventProcessor::StoppedBySignalException::StoppedBySignalException(
int signal_):
69 runtime_error(
"Execution stopped by signal " + to_string(signal_) +
"!"),
80 const int len = strlen(msg);
82 int rc = write(STDERR_FILENO, msg, len);
98 struct NumberEventsOverrideGuard {
100 explicit NumberEventsOverrideGuard(
unsigned int newValue)
106 ~NumberEventsOverrideGuard()
111 unsigned int m_maxEvent;
119 if ((numEventsArgument > 0) && ((maxEvent == 0) || (maxEvent > numEventsArgument))) {
120 return numEventsArgument;
131 NumberEventsOverrideGuard numberOfEventsOverrideGuard(maxEvent);
138 for (
const auto& module : moduleList) {
145 B2FATAL(
"Module profiling was requested via --profile, but no module '" <<
m_profileModuleName <<
"' was found!");
154 v.visualizePath(
"dataflow.dot", *startPath);
159 B2ERROR(
"There is no module that provides event and run numbers (EventMetaData). You must add either the EventInfoSetter or an input module (e.g. RootInput) to the beginning of your path.");
164 if ((numLogError == 0) &&
m_master) {
169 if (e.signal != SIGINT) {
171 gROOT->GetListOfFiles()->Delete();
178 B2ERROR(
"Exception occured in exp/run/evt: "
186 B2FATAL(numLogError <<
" ERROR(S) occurred! The processing of events will not be started.");
194 if (gSignalReceived == SIGINT) {
195 const auto msg = R
"(Processing aborted via SIGINT, terminating.
196 Output files have been closed safely and should be readable. However
197 processing was NOT COMPLETE. The output files do contain only events
198 processed until this point.)";
221 logSystem.
updateModule(&(module->getLogConfig()), module->getName());
225 CALL_MODULE(module, event);
247 for (
const ModulePtr& modPtr : modulePathList) {
248 Module* module = modPtr.get();
250 if (module->hasUnsetForcedParams()) {
256 logSystem.
updateModule(&(module->getLogConfig()), module->getName());
262 CALL_MODULE(module, initialize);
270 B2DEBUG(100,
"Found module providing EventMetaData: " << module->getName());
280 if (gSignalReceived != 0) {
290 memset(&s,
'\0',
sizeof(s));
293 sigemptyset(&s.sa_mask);
295 s.sa_flags |= SA_NOCLDSTOP;
297 if (sigaction(sig, &s,
nullptr) != 0) {
298 B2FATAL(
"Cannot setup signal handler for signal " << sig);
321 while (!moduleIter.
isDone()) {
325 if (!(skipMasterModule && module ==
m_master)) {
333 B2WARNING(
"Event processing stopped by module '" << module->getName() <<
334 "', which is not in control of event processing (does not provide EventMetaData)");
372 B2FATAL(
"Two modules setting EventMetaData were discovered: " <<
m_master->
getName() <<
" and " << module->getName());
376 if (gSignalReceived != 0) {
381 if (module->evalCondition()) {
382 PathPtr condPath = module->getConditionPath();
407 bool endProcess =
false;
408 while (!endProcess) {
413 endProcess =
processEvent(moduleIter, isInputProcess && currEvent == 0);
419 if ((maxEvent > 0) && (currEvent >= maxEvent)) endProcess =
true;
435 ModulePtrList::const_reverse_iterator listIter;
438 for (listIter = modulePathList.rbegin(); listIter != modulePathList.rend(); ++listIter) {
439 Module* module = listIter->get();
442 logSystem.
updateModule(&(module->getLogConfig()), module->getName());
446 CALL_MODULE(module, terminate);
473 Module* module = modPtr.get();
476 logSystem.
updateModule(&(module->getLogConfig()), module->getName());
480 CALL_MODULE(module, beginRun);
509 Module* module = modPtr.get();
512 logSystem.
updateModule(&(module->getLogConfig()), module->getName());
516 CALL_MODULE(module, endRun);
void callEvent(Module *module)
Calls event() on one single module, setting up logging and statistics as needed.
static const double s
[second]
void process(const PathPtr &startPath, long maxEvent=0)
Processes the full module chain, starting with the first module in the given path.
void setNumberEventsOverride(unsigned int nevents)
Override the number of events in run 1 for EventInfoSetter module.
void processTerminate(const ModulePtrList &modulePathList)
Terminates the modules.
DependencyMap & getDependencyMap()
Return map of depedencies between modules.
@ c_Event
Counting time/calls in event()
static DataStore & Instance()
Instance of singleton Store.
@ c_EndRun
Counting time/calls in endRun()
ScopeGuard createScopedUpdateSession()
Make sure we have efficient http pipelinging during initialize/beginRun but don't keep session alive ...
void setInitializeActive(bool active)
Setter for m_initializeActive.
static void useEventDependent()
Set Event dependent Random Generator as current one.
@ c_Term
Counting time/calls in terminate()
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
EventMetaData is used by processEvent()/processCore().
EventProcessor()
Constructor.
double m_lastMetadataUpdate
Time in seconds of last call for metadata update in event loop.
bool processEvent(PathIterator moduleIter, bool skipMasterModule)
Calls event() functions on all modules for the current event.
Exception thrown when execution is stopped by a signal.
static void writeToStdErr(const char msg[])
async-safe method to write something to STDERR.
Module * m_profileModule
Adress of the module which we want to profile, nullptr if no profiling is requested.
void setModule(const Module &mod)
Set the current module (for getCurrentModuleInfo())
void processBeginRun(bool skipDB=false)
Calls the begin run methods of all modules.
bool m_inRun
Are we currently in a run? If yes, processEndRun() needs to do something.
static void initializeEndRun()
Initialize run independent random generator for end run.
@ c_Continue
After the conditional path, resume execution after this module.
virtual ~EventProcessor()
Destructor.
Abstract base class for different kinds of events.
Class for logging debug, info and error messages.
std::list< ModulePtr > ModulePtrList
Defines a std::list of shared module pointers.
std::string m_profileModuleName
Name of the module which should be profiled, empty if no profiling is requested.
std::shared_ptr< Path > PathPtr
Defines a pointer to a path object as a boost shared pointer.
Class to store variables with their name which were sent to the logging service.
long getMaximumEventNumber(long maxEvent) const
Calculate the maximum event number out of the argument from command line and the environment.
std::shared_ptr< Module > ModulePtr
Defines a pointer to a module object as a boost shared pointer.
@ c_Error
Error: for things that went wrong and have to be fixed.
static DBStore & Instance()
Instance of a singleton DBStore.
ModulePtrList m_moduleList
List of all modules in order initialized.
static void initializeEvent(bool force=false)
Initialize event information.
double m_metadataUpdateInterval
Minimal time difference in seconds for metadata updates in event loop.
Module * get() const
dereference.
void updateModule(const LogConfig *moduleLogConfig=nullptr, const std::string &moduleName="")
Sets the log configuration to the given module log configuration and sets the module name This method...
bool getNoStats() const
Disable collection of statistics during event processing.
void processEndRun()
Calls the end run methods of all modules.
void processInitialize(const ModulePtrList &modulePathList, bool setEventInfo=true)
Initializes the modules.
@ c_BeginRun
Counting time/calls in beginRun()
void updateEvent()
Updates all intra-run dependent objects.
StoreObjPtr< ProcessStatistics > m_processStatisticsPtr
Also used in a number of places.
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
double getClock()
Return current value of the real-time clock.
static Database & Instance()
Instance of a singleton Database.
unsigned int getNumberEventsOverride() const
Returns number of events in run 1 for EventInfoSetter module, or 0 for no override.
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,...
class to visualize data flow between modules.
static Environment & Instance()
Static method to get a reference to the Environment instance.
static void initializeBeginRun()
Initialize run independent random generator for begin run.
Iterator over a Path (returning Module pointers).
const Module * m_master
The master module that determines the experiment/run/event number.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
EventMetaData m_previousEventMetaData
Stores state of EventMetaData before it was last changed.
void printErrorSummary()
Print error/warning summary at end of execution.
const std::string & getName() const
Returns the name of the module.
bool isDone() const
Are we finished iterating?
void invalidateData(EDurability durability)
Clears all registered StoreEntry objects of a specified durability, invalidating all objects.
In the store you can park objects that have to be accessed by various modules.
static void installSignalHandler(int sig, void(*fn)(int))
Install a signal handler 'fn' for given signal.
int getMessageCounter(LogConfig::ELogLevel logLevel) const
Returns the number of logging calls per log level.
void update()
Updates all objects that are outside their interval of validity.
static void installMainSignalHandlers(void(*fn)(int)=nullptr)
Install signal handler for INT, TERM and QUIT signals.
@ c_Init
Counting time/calls in initialize()