15from ROOT
import TFile, Belle2
16from b2test_utils
import skip_test_if_light, clean_working_directory
21 """Class to check that we see all events we expect exactly once and nothing else"""
24 """Remember number of events to process"""
32 """Accumulate all event numbers we see"""
37 """Check if event numbers are as they should be"""
40 all_numbers = sorted(set(seen) | set(should))
42 for evtNr
in all_numbers:
44 if not (evtNr
in should
and c == 1):
45 basf2.B2ERROR(f
"event number {evtNr} seen {c} times")
48 basf2.B2FATAL(
"Missing/extra events")
53main.add_module(
"EventInfoSetter", evtNumList=[5])
54particlegun = main.add_module(
"ParticleGun", pdgCodes=[211, -211, 321, -321],
55 momentumGeneration=
"fixed", momentumParams=[3])
58main.add_module(
"Gearbox")
59main.add_module(
"Geometry", components=[
'MagneticField',
'BeamPipe',
'PXD'], logLevel=basf2.LogLevel.ERROR)
60simulation = main.add_module(
"FullSim", logLevel=basf2.LogLevel.ERROR)
63main.add_module(
"RootOutput", outputFileName=
'parallel_processing_test.root')
64main.add_module(
"Progress")
68if particlegun.has_properties(basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED):
69 basf2.B2FATAL(
"ParticleGun has pp flag?")
70if not simulation.has_properties(basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED):
71 basf2.B2FATAL(
"Simulation doesn't have pp flag?")
75basf2.set_nprocesses(5)
76with clean_working_directory():
79 print(basf2.statistics)
80 print(basf2.statistics(basf2.statistics.TOTAL))
81 assert basf2.statistics.get(simulation).calls(basf2.statistics.EVENT) == 5
83 assert basf2.statistics.get_global().calls(basf2.statistics.EVENT) == 6
86 file = TFile(
'parallel_processing_test.root')
87 tree = file.Get(
'tree')
88 if tree.GetEntries() != 5:
89 basf2.B2FATAL(
'Created output file contains wrong number of events! (' + str(tree.GetEntries()) +
')')
91 nummcparticles = tree.Project(
"",
"MCParticles.m_pdg")
92 if nummcparticles < 5:
93 basf2.B2FATAL(
'Output file should contain at least five MCParticles!')
95 numhits = tree.Project(
"",
"PXDSimHits.getArrayIndex()")
97 basf2.B2FATAL(
'Output file should contain at least 5 hits!')
a (simplified) python wrapper for StoreObjPtr.
__evtNumList
the number of events so we expect the event numbers 0..(evtNumList-1)
def __init__(self, evtNumList)
__evtNumbers
event numbers we actually saw