Belle II Software  release-05-02-19
EventLimiterModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: David Dossett *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <framework/modules/core/EventLimiterModule.h>
11 #include <framework/core/Module.h>
12 
13 using namespace Belle2;
14 
15 //-----------------------------------------------------------------
16 // Register the Module
17 //-----------------------------------------------------------------
18 REG_MODULE(EventLimiter)
19 
20 //-----------------------------------------------------------------
21 // Implementation
22 //-----------------------------------------------------------------
23 
25 {
26  // Set module properties
27  setDescription("Allows you to set limits on the number of events per run passing this module. "
28  "It returns True until the limit is reached, after which it returns False. "
29  "basf2 conditional paths can then be used to prevent events continuing onwards from this module.");
30 
31  // Parameter definitions
32  addParam("maxEventsPerRun", m_maxEventsPerRun,
33  "Maximum number of events that will have True returned on them per run. "
34  "This module returns True until the limit in a particular run is reached, it then returns False. "
35  "It will only start returning True again once a new run begins. "
36  "The default value (-1) means that this module always returns True regardless of how many events "
37  "are processed in a run.", int(-1));
38 }
39 
41 {
42  m_eventMetaData.isRequired();
43 }
44 
46 {
47  // Do we care about the number of events and are we past the limit?
48  if (m_maxEventsPerRun > -1 and m_returnValue == true) {
49  // Have we exceeded our maximum events in this run?
51  // If we have, we should skip collection until further notice
52  B2INFO("Reached maximum number of events ("
54  << ") for (Experiment, Run) = ("
55  << m_eventMetaData->getExperiment() << ", "
56  << m_eventMetaData->getRun() << ")");
57  m_returnValue = false;
58  } else {
59  m_runEvents += 1;
60  }
61  }
63 }
64 
66 {
67  // Do we care about the number of events in each run?
68  if (m_maxEventsPerRun > -1) {
69  m_runEvents = 0;
70  m_returnValue = true;
71  }
72 }
Belle2::EventLimiterModule::m_runEvents
int m_runEvents
How many events processed for the current run so far, stops counting up once max is hit Only used/inc...
Definition: EventLimiterModule.h:69
Belle2::EventLimiterModule::event
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...
Definition: EventLimiterModule.cc:45
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::EventLimiterModule::m_returnValue
bool m_returnValue
Flag that will be returned by the module.
Definition: EventLimiterModule.h:65
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::EventLimiterModule::m_maxEventsPerRun
int m_maxEventsPerRun
Maximum number of events to be collected at the start of each run (-1 = no maximum)
Definition: EventLimiterModule.h:61
Belle2::Module::setReturnValue
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:222
Belle2::EventLimiterModule::m_eventMetaData
StoreObjPtr< EventMetaData > m_eventMetaData
Datastore pointers.
Definition: EventLimiterModule.h:58
Belle2::EventLimiterModule
The EventLimiter module.
Definition: EventLimiterModule.h:38
Belle2::EventLimiterModule::beginRun
virtual void beginRun() override
Resets our event counter to zero and return value to True.
Definition: EventLimiterModule.cc:65
Belle2::EventLimiterModule::initialize
virtual void initialize() override
Initialization states required data objects (EventMetaData)
Definition: EventLimiterModule.cc:40