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