Belle II Software  release-08-01-10
emptyrelations.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 from basf2 import set_random_seed, create_path, Module
13 from ROOT import Belle2
14 from b2test_utils import safe_process, clean_working_directory
15 
16 set_random_seed("something important")
17 
18 
19 class MakeRelations(Module):
20  '''Simple module that creates some relations.'''
21 
22  def initialize(self):
23  '''Initialize.'''
24 
25  self.trackstracks = Belle2.PyStoreArray('Tracks')
26 
27  self.clustersclusters = Belle2.PyStoreArray('KLMClusters')
28  self.trackstracks.registerInDataStore()
29  self.clustersclusters.registerInDataStore()
30  self.trackstracks.registerRelationTo(self.clustersclusters)
31 
32  self.firstfirst = True
33 
34  def event(self):
35  '''Event.'''
36  if not self.firstfirst:
37  track = self.trackstracks.appendNew()
38  cluster = self.clustersclusters.appendNew()
39  track.addRelationTo(cluster)
40  self.firstfirst = False
41 
42 
43 def create_file():
44  """Create file with empty first event"""
45  path = create_path()
46  path.add_module('EventInfoSetter')
47  path.add_module(MakeRelations())
48  path.add_module('RootOutput', outputFileName='test.root')
49  safe_process(path, 2)
50 
51 
52 def read_file():
53  """Read file with empty first event"""
54  path = create_path()
55  path.add_module('RootInput', inputFileName='test.root')
56  path.add_module('PrintCollections', printForEvent=0)
57  safe_process(path)
58 
59 
60 if __name__ == "__main__":
61  with clean_working_directory():
62  create_file()
63  read_file()
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
first
Bool for flagging the first event processed.