Belle II Software development
EventLimiterModule.cc
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#include <framework/modules/core/EventLimiterModule.h>
9#include <framework/core/Module.h>
10
11using namespace Belle2;
12
13//-----------------------------------------------------------------
14// Register the Module
15//-----------------------------------------------------------------
16REG_MODULE(EventLimiter);
17
18//-----------------------------------------------------------------
19// Implementation
20//-----------------------------------------------------------------
21
23{
24 // Set module properties
25 setDescription("Allows you to set limits on the number of events per run passing this module. "
26 "It returns True until the limit is reached, after which it returns False. "
27 "basf2 conditional paths can then be used to prevent events continuing onwards from this module.");
28
29 // Parameter definitions
30 addParam("maxEventsPerRun", m_maxEventsPerRun,
31 "Maximum number of events that will have True returned on them per run. "
32 "This module returns True until the limit in a particular run is reached, it then returns False. "
33 "It will only start returning True again once a new run begins. "
34 "The default value (-1) means that this module always returns True regardless of how many events "
35 "are processed in a run.", int(-1));
36}
37
39{
40 m_eventMetaData.isRequired();
41}
42
44{
45 // Do we care about the number of events and are we past the limit?
46 if (m_maxEventsPerRun > -1 and m_returnValue == true) {
47 // Have we exceeded our maximum events in this run?
49 // If we have, we should skip collection until further notice
50 B2INFO("Reached maximum number of events ("
52 << ") for (Experiment, Run) = ("
53 << m_eventMetaData->getExperiment() << ", "
54 << m_eventMetaData->getRun() << ")");
55 m_returnValue = false;
56 } else {
57 m_runEvents += 1;
58 }
59 }
61}
62
64{
65 // Do we care about the number of events in each run?
66 if (m_maxEventsPerRun > -1) {
67 m_runEvents = 0;
68 m_returnValue = true;
69 }
70}
virtual void initialize() override
Initialization states required data objects (EventMetaData)
bool m_returnValue
Flag that will be returned by the module.
virtual void event() override
Checks if we've reached the maximum number of events yet and sets the return value to False if we hav...
StoreObjPtr< EventMetaData > m_eventMetaData
Datastore pointers.
int m_runEvents
How many events processed for the current run so far, stops counting up once max is hit Only used/inc...
virtual void beginRun() override
Resets our event counter to zero and return value to True.
EventLimiterModule()
Constructor: Sets the description, the properties and the parameters of the module.
int m_maxEventsPerRun
Maximum number of events to be collected at the start of each run (-1 = no maximum)
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.