Belle II Software  release-08-01-10
independent_path.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # @cond
12 
13 import basf2
14 from ROOT import Belle2
15 
16 
17 class CreateData(basf2.Module):
18 
19  """create some data"""
20 
21  def initialize(self):
22  """reimplementation"""
23 
24  self.obj = Belle2.PyStoreObj(Belle2.EventMetaData.Class())
25  self.obj.registerInDataStore('obj')
26  self.array = Belle2.PyStoreArray(Belle2.EventMetaData.Class())
27  self.array.registerInDataStore('array')
28 
29  def event(self):
30  """reimplementation"""
31 
32  self.obj.create()
33  self.obj.obj().setExperiment(19)
34 
35  for i in range(13):
36  self.array.appendNew()
37 
38 
39 class CheckData(basf2.Module):
40 
41  """check output of CreateData"""
42 
43  def initialize(self):
44  """reimplementation"""
45 
46  self.obj = Belle2.PyStoreObj('obj')
47  self.array = Belle2.PyStoreArray('array')
48 
49  def event(self):
50  """reimplementation"""
51 
52  assert self.obj.obj().getExperiment() == 19
53  assert self.array.getEntries() == 13
54 
55 
56 class CheckAbsence(basf2.Module):
57 
58  """check output of CreateData"""
59 
60  def initialize(self):
61  """reimplementation"""
62 
63  assert not Belle2.PyStoreObj('obj').isOptional()
64  assert not Belle2.PyStoreArray('array').isOptional()
65 
66  def event(self):
67  """reimplementation"""
68 
69  assert not Belle2.PyStoreObj('obj').obj()
70 
71 
72 main = basf2.Path()
73 main.add_module('EventInfoSetter')
74 main.add_module(CheckAbsence())
75 
76 indep = basf2.Path()
77 indep.add_module(CreateData())
78 indep.add_module(CheckData()).set_name("checkdata 1")
79 main.add_independent_path(indep)
80 main.add_module(CheckAbsence())
81 
82 indep2 = basf2.Path()
83 indep2.add_module(CheckAbsence())
84 indep2.add_module(CreateData())
85 indep2.add_module(CheckData()).set_name("checkdata 2")
86 main.add_independent_path(indep2, merge_back_event=['obj', 'array'])
87 main.add_module(CheckData()).set_name("checkdata 3")
88 
89 basf2.print_path(main)
90 basf2.process(main)
91 
92 print(basf2.statistics)
93 # @endcond
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67