Belle II Software development
independent_merge_path.py
1#!/usr/bin/env python3
2
3
10
11# @cond
12
13import basf2
14from ROOT import Belle2
15
16
17class CreateDataMain(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('EventMetaData')
26 self.array = Belle2.PyStoreArray(Belle2.Particle.Class())
27 self.array.registerInDataStore('Particles')
28 self.arrayRel = Belle2.PyStoreArray(Belle2.MCParticle.Class())
29 self.arrayRel.registerInDataStore('MCParticles')
30
31 self.array.registerRelationTo(self.arrayRel)
32
33 self.objFirst = Belle2.PyStoreObj(Belle2.EventMetaData.Class())
34 self.objFirst.registerInDataStore('EventMetaDataFirst')
35 self.arrayFirst = Belle2.PyStoreArray(Belle2.Particle.Class())
36 self.arrayFirst.registerInDataStore('ParticlesFirst')
37 self.arrayRelFirst = Belle2.PyStoreArray(Belle2.MCParticle.Class())
38 self.arrayRelFirst.registerInDataStore('MCParticlesFirst')
39
40 self.arrayFirst.registerRelationTo(self.arrayRelFirst)
41
42 def event(self):
43 """reimplementation"""
44
45 self.obj.create()
46 self.obj.obj().setExperiment(500)
47
48 for i in range(5):
49 newptr = self.array.appendNew()
50 newptr.setPValue(i)
51
52 for i in range(5):
53 newptr = self.arrayRel.appendNew()
54 newptr.setPDG(i)
55
56 for i in range(5):
57 self.array[i].addRelationTo(self.arrayRel[i])
58
59 self.objFirst.create()
60 self.objFirst.obj().setExperiment(600)
61
62 for i in range(6):
63 newptr = self.arrayFirst.appendNew()
64 newptr.setPValue(i)
65
66 for i in range(6):
67 newptr = self.arrayRelFirst.appendNew()
68 newptr.setPDG(i)
69
70 for i in range(6):
71 self.arrayFirst[i].addRelationTo(self.arrayRelFirst[i])
72
73
74class CreateDataIndep(basf2.Module):
75
76 """create some data"""
77
78 def initialize(self):
79 """reimplementation"""
80
81 self.obj = Belle2.PyStoreObj(Belle2.EventMetaData.Class())
82 self.obj.registerInDataStore('EventMetaData')
83 self.array = Belle2.PyStoreArray(Belle2.Particle.Class())
84 self.array.registerInDataStore('Particles')
85 self.arrayRel = Belle2.PyStoreArray(Belle2.MCParticle.Class())
86 self.arrayRel.registerInDataStore('MCParticles')
87
88 self.array.registerRelationTo(self.arrayRel)
89
90 self.objSecond = Belle2.PyStoreObj(Belle2.EventMetaData.Class())
91 self.objSecond.registerInDataStore('EventMetaDataSecond')
92 self.arraySecond = Belle2.PyStoreArray(Belle2.Particle.Class())
93 self.arraySecond.registerInDataStore('ParticlesSecond')
94 self.arrayRelSecond = Belle2.PyStoreArray(Belle2.MCParticle.Class())
95 self.arrayRelSecond.registerInDataStore('MCParticlesSecond')
96
97 self.arraySecond.registerRelationTo(self.arrayRelSecond)
98
99 def event(self):
100 """reimplementation"""
101
102 self.obj.create()
103 self.obj.obj().setExperiment(700)
104
105 for i in range(7):
106 newptr = self.array.appendNew()
107 newptr.setPValue(i)
108
109 for i in range(7):
110 newptr = self.arrayRel.appendNew()
111 newptr.setPDG(i)
112
113 for i in range(7):
114 self.array[i].addRelationTo(self.arrayRel[i])
115
116 self.objSecond.create()
117 self.objSecond.obj().setExperiment(800)
118
119 for i in range(8):
120 newptr = self.arraySecond.appendNew()
121 newptr.setPValue(i)
122
123 for i in range(8):
124 newptr = self.arrayRelSecond.appendNew()
125 newptr.setPDG(i)
126
127 for i in range(8):
128 self.arraySecond[i].addRelationTo(self.arrayRelSecond[i])
129
130
131class CheckData(basf2.Module):
132
133 """check output of CreateData"""
134
135 def initialize(self):
136 """reimplementation"""
137
138 self.obj = Belle2.PyStoreObj('EventMetaData')
139 self.obj_indepPath = Belle2.PyStoreObj('EventMetaData_indepPath')
140 self.objFirst = Belle2.PyStoreObj('EventMetaDataFirst')
141 self.objSecond = Belle2.PyStoreObj('EventMetaDataSecond')
142 self.array = Belle2.PyStoreArray('Particles')
143 self.arrayRel = Belle2.PyStoreArray('MCParticles')
144 self.arrayFirst = Belle2.PyStoreArray('ParticlesFirst')
145 self.arrayRelFirst = Belle2.PyStoreArray('MCParticlesFirst')
146 self.arraySecond = Belle2.PyStoreArray('ParticlesSecond')
147 self.arrayRelSecond = Belle2.PyStoreArray('MCParticlesSecond')
148
149 def event(self):
150 """reimplementation"""
151
152 print(self.name())
153
154 assert self.obj.obj().getExperiment() == 500
155 assert self.obj_indepPath.obj().getExperiment() == 700
156 assert self.objFirst.obj().getExperiment() == 600
157 assert self.objSecond.obj().getExperiment() == 800
158 assert self.array.getEntries() == 5 + 7
159 assert self.arrayFirst.getEntries() == 6
160 assert self.arraySecond.getEntries() == 8
161
162 for arr in self.array:
163 print(arr.getPValue())
164
165 for arr in self.arrayRel:
166 print(arr.getPDG())
167
168 for arr in self.array:
169 print(arr.getPValue(), '->', arr.getRelated('MCParticles').getPDG())
170
171
172main = basf2.Path()
173main.add_module('EventInfoSetter')
174
175main.add_module(CreateDataMain())
176
177indep = basf2.Path()
178indep.add_module(CreateDataIndep())
179
180main.add_independent_merge_path(
181 indep,
182 merge_back_event=['ALL'])
183
184main.add_module(CheckData())
185
186basf2.print_path(main)
187basf2.process(main)
188
189print(basf2.statistics)
190
191# @endcond
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67