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