Belle II Software  release-08-01-10
split_file.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
16 
17 import basf2 as b2
18 from ROOT import Belle2
19 import sys
20 argvs = sys.argv
21 run = argvs[1]
22 nevent = int(argvs[2])
23 nfile = int(argvs[3])
24 
25 Dir = 'GCR2017_unpacked/'
26 
27 
28 class Split(b2.Module):
29  """
30  Class to split one file to multi files with small data size.
31  """
32 
33  def event(self):
34  """reimplementation of Module::event()."""
35  evtmetadata = Belle2.PyStoreObj('EventMetaData')
36  if not evtmetadata:
37  b2.B2ERROR('No EventMetaData found')
38  else:
39  event = evtmetadata.obj().getEvent()
40  self.return_value(event // nevent)
41 
42 
43 out = []
44 main = b2.create_path()
45 main.add_module('RootInput', inputFileName=Dir + run + '.root')
46 main.add_module('ProgressBar')
47 split = Split()
48 main.add_module(split)
49 for i in range(0, int(nfile)):
50  out.append(b2.create_path())
51  out[i].add_module('RootOutput', outputFileName=Dir + run + '_' + str(i) + '.root')
52  if i == nfile - 1:
53  split.if_value('>={}'.format(i), out[i])
54  else:
55  split.if_value('={}'.format(i), out[i])
56 
57 b2.process(main)
58 
59 print(b2.statistics)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
def event(self)
Definition: split_file.py:33