Belle II Software light-2406-ragdoll
PartialSelectModule.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
9#include <framework/modules/core/PartialSelectModule.h>
10#include <framework/core/Environment.h>
11
12using namespace Belle2;
13
14//-----------------------------------------------------------------
15// Register the Module
16//-----------------------------------------------------------------
17REG_MODULE(PartialSelect);
18
19//-----------------------------------------------------------------
20// Implementation
21//-----------------------------------------------------------------
22
24{
25 // Set module properties
26 setDescription(R"DOC(
27 This module helps you set the interval of events to process. It
28 returns True inside the set window and False outside.
29
30 The input parameters are fractions which can be interpretted as the
31 fraction of leading and (1-)fraction of trailing events that will be
32 skipped. Internally, the total number of events of the input file is
33 used to determine the event selection window boundaries.
34
35 basf2 conditional paths can then be used to select events that pass
36 this module for further processing.
37
38 This module can be used with GRID jobs when dataset collections are
39 passed as input. It helps you control the range of events per file so
40 that you can avoid processing all of the events but still cover all
41 the files in the collection.
42
43 NOTE: This module has to be added directly after the input module so
44 as to filter out events before any other processing. It also only
45 works with one input file for now.
46 )DOC");
47
48 // Parameter definitions
50 "entryStart",
52 "The product of entryStart fraction and total number of events in each "
53 "file will determine the first event to begin processing with. Module will"
54 " return False for all leading events before this. By default(0.0) module "
55 "will start with the first event.",
56 0.);
58 "entryStop",
60 "The product of entryStop fraction and total number of events in each file"
61 " will determine the last event to end processing with. Module will return"
62 " False for all trailing events after this. By default(1.0) module will "
63 "end wtih the last event.",
64 1.);
65}
66
68{
69 // Have we received meaningful values?
70 const bool isOutOfBounds =
71 m_entryStart < 0 || m_entryStop < 0 ||
72 m_entryStart > 1 || m_entryStop > 1 ||
74
75 if (isOutOfBounds)
76 B2FATAL("Either the entryStart and entryStop passed are beyond the accepted"
77 " range or they have been swapped: please refer to the 'entryStart'"
78 " and 'entryStop' descriptions of the PartialSelect module.");
80 B2INFO("Total number of events :"
81 << m_nTotal << ".");
82}
83
85{
86 m_events += 1;
87 // Are we inside the passed interval?
89 m_returnValue = true;
90 }
91 // If not, we skip the events.
92 else {
93 m_returnValue = false;
94 }
95 // Mark the boundary events in log.
97 B2INFO("First event passing the PartialSelect range: "
98 << m_events << ".");
99 }
100 if (m_events <= m_entryStop * m_nTotal and m_events > m_entryStop * m_nTotal - 1) {
101 B2INFO("Last event passing the PartialSelect range: "
102 << m_events << ".");
103 }
105}
unsigned int getNumberOfEvents() const
Return the number of events, from either input or EventInfoSetter, or -n command line override (if le...
Definition: Environment.cc:39
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
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
int m_nTotal
Total number of events in the input file.
double m_entryStart
Input parameter [0.0 -> 1.0) used to determine event start id: (m_entryStart*m_nTotal).
void initialize() override
Initialization fetches the event count in the input file (m_nEvents).
bool m_returnValue
Flag that will be returned by the module.
void event() override
Checks if we are within the passed window to set return value to True, and False if not.
PartialSelectModule()
Constructor: Sets the description, the properties and the parameters of the module.
int m_events
Keeps track of how many events have been processed for so far.
double m_entryStop
Input parameter (0.0 -> 1.0] used to determine event stop id: (m_entryStop*m_nTotal).
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.
Definition: ClusterUtils.h:24