Belle II Software  release-08-01-10
chain_input.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2
12 from b2test_utils import configure_logging_for_tests, skip_test_if_light
13 from ROOT import Belle2
14 
15 skip_test_if_light() # light builds don't know about PXD hits
16 configure_logging_for_tests()
17 basf2.set_random_seed("something important")
18 
19 
20 class NoopModule(basf2.Module):
21  """Doesn't do anything."""
22 
23 
24 class TestModule(basf2.Module):
25  """Test to read relations in the input files."""
26 
27 
28  iEvent = 0
29 
30  def event(self):
31  """reimplementation of Module::event().
32 
33  prints PXD true and simhit indices, using relations
34  """
35  filemetadata = Belle2.PyStoreObj('FileMetaData', 1)
36  nevents = filemetadata.obj().getNEvents()
37  if self.iEventiEvent < 12 and not nevents == 12:
38  basf2.B2FATAL("FileMetaData from file 1 not loaded!")
39  elif self.iEventiEvent >= 12 and not nevents == 15:
40  basf2.B2FATAL("FileMetaData from file 2 not loaded!")
41 
42  simhits = Belle2.PyStoreArray('PXDSimHits')
43  for hit in simhits:
44  relations = hit.getRelationsFrom("PXDTrueHits")
45  for truehit in relations:
46  print('truehit %d => hit %d' % (truehit.getArrayIndex(), hit.getArrayIndex()))
47 
48  self.iEventiEvent += 1
49 
50 
51 inputfiles = [
52  basf2.find_file('framework/tests/chaintest_1.root'),
53  basf2.find_file('framework/tests/chaintest_2.root')
54 ]
55 
56 basf2.conditions.disable_globaltag_replay()
57 main = basf2.Path()
58 
59 # not used for anything, just checking wether the master module
60 # can be found if it's not the first module in the path.
61 main.add_module(NoopModule())
62 
63 main.add_module('RootInput', logLevel=basf2.LogLevel.WARNING, inputFileNames=inputfiles)
64 main.add_module('EventInfoPrinter')
65 main.add_module('PrintCollections', printForEvent=0)
66 
67 main.add_module(TestModule())
68 
69 # Process events
70 basf2.process(main)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
int iEvent
event counter
Definition: chain_input.py:28