Belle II Software development
partialselect.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from ROOT import Belle2
13
14
15class CountEvents(basf2.Module):
16 """Count the number of events passing this module"""
17
18 def initialize(self):
19 """Start number of events at zero"""
20
21 self.num_events = 0
22
23 self.events = []
24
25 def event(self):
26 """Increment number of events each event"""
27 evtmetadata = Belle2.PyStoreObj('EventMetaData')
28 self.events.append(evtmetadata.obj().getEvent())
29 self.num_events += 1
30
31
32input_events = 1000
33expected_success_events = 200
34# range input for partialselect module
35entry_start = 0.3
36entry_stop = 0.5
37# subsequent event range boundaries for the above inputs
38expected_event_start = 301
39expected_event_stop = 500
40
41main = basf2.Path()
42main.add_module("EventInfoSetter", evtNumList=[input_events], expList=[0], runList=[0])
43partial_select_mod = main.add_module('PartialSelect', entryStart=entry_start, entryStop=entry_stop)
44
45success_path = basf2.Path()
46success_count = success_path.add_module(CountEvents())
47partial_select_mod.if_true(success_path)
48
49basf2.process(main)
50
51print(basf2.statistics)
52
53assert success_count.num_events == expected_success_events
54assert success_count.events[0] == expected_event_start
55assert success_count.events[-1] == expected_event_stop
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
events
Stores the list of events passing this module.
num_events
Stores the total number of events passing this module.