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