9 from ROOT
import TFile, Belle2
10 from b2test_utils
import skip_test_if_light
15 """Class to check that we see all events we expect exactly once and nothing else"""
18 """Remember number of events to process"""
26 """Accumulate all event numbers we see"""
31 """Check if event numbers are as they should be"""
34 all_numbers = sorted(set(seen) | set(should))
36 for evtNr
in all_numbers:
38 if not (evtNr
in should
and c == 1):
39 basf2.B2ERROR(
"event number %d seen %d times" % (evtNr, c))
42 basf2.B2FATAL(
"Missing/extra events")
47 main.add_module(
"EventInfoSetter", evtNumList=[5])
48 particlegun = main.add_module(
"ParticleGun", pdgCodes=[211, -211, 321, -321],
49 momentumGeneration=
"fixed", momentumParams=[3])
50 main.add_module(
"Gearbox")
53 main.add_module(
"Geometry", components=[
'MagneticField',
'BeamPipe',
'PXD'], logLevel=basf2.LogLevel.ERROR)
54 simulation = main.add_module(
"FullSim", logLevel=basf2.LogLevel.ERROR)
57 main.add_module(
"RootOutput", outputFileName=
'parallel_processing_test.root')
58 main.add_module(
"Progress")
62 if particlegun.has_properties(basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED):
63 basf2.B2FATAL(
"ParticleGun has pp flag?")
64 if not simulation.has_properties(basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED):
65 basf2.B2FATAL(
"Simulation doesn't have pp flag?")
69 basf2.set_nprocesses(5)
72 print(basf2.statistics)
73 print(basf2.statistics(basf2.statistics.TOTAL))
74 assert basf2.statistics.get(simulation).calls(basf2.statistics.EVENT) == 5
76 assert basf2.statistics.get_global().calls(basf2.statistics.EVENT) == 6
79 file = TFile(
'parallel_processing_test.root')
80 tree = file.Get(
'tree')
81 if tree.GetEntries() != 5:
82 B2FATAL(
'Created output file contains wrong number of events! (' + str(tree.GetEntries()) +
')')
84 nummcparticles = tree.Project(
"",
"MCParticles.m_pdg")
85 if nummcparticles < 5:
86 B2FATAL(
'Output file should contain at least five MCParticles!')
88 numhits = tree.Project(
"",
"PXDSimHits.getArrayIndex()")
90 B2FATAL(
'Output file should contain at least 5 hits!')
93 os.remove(
'parallel_processing_test.root')