Belle II Software  release-05-02-19
packers.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 import basf2 as b2
5 import simulation as sim
6 import reconstruction as rec
7 import rawdata as raw
8 
9 from ROOT import Belle2
10 
11 import sys
12 import os
13 import multiprocessing as mp
14 
15 path_to_output = 'rawdata/tests/digits.root'
16 b2.set_random_seed("L1V0RN0")
17 b2.set_log_level(b2.LogLevel.WARNING)
18 # Disable tag replay, we want to test current packers
19 # independent of when the digits were created
20 b2.conditions.disable_globaltag_replay()
21 
22 
23 def create_digits():
24  """Create the file 'digits.root' needed for testing the packers if it does not exist"""
25  child_path = b2.create_path()
26  child_path.add_module('EventInfoSetter',
27  evtNumList=[10])
28  child_path.add_module('EvtGenInput')
29  sim.add_simulation(path=child_path)
30  child_path.add_module(
31  'RootOutput',
32  outputFileName='${BELLE2_LOCAL_DIR}/' +
33  path_to_output,
34  branchNames=list(rec.DIGITS_OBJECTS))
35  child_path.add_module('Progress')
36  b2.process(child_path)
37  print(b2.statistics)
38 
39 
40 if Belle2.FileSystem.findFile(path_to_output, True) == '':
41  # Execute create_digits() in a child process to avoid side effects
42  child = mp.Process(target=create_digits)
43  child.start()
44  # Wait for simulation to finish
45  child.join()
46  # And exit if it had an error
47  if child.exitcode != 0:
48  sys.exit(child.exitcode)
49 
50 # Here starts the main path
51 main_path = b2.create_path()
52 main_path.add_module('RootInput',
53  inputFileNames=Belle2.FileSystem.findFile(path_to_output))
54 raw.add_packers(path=main_path)
55 main_path.add_module('Progress')
56 b2.process(main_path)
57 print(b2.statistics)
Belle2::FileSystem::findFile
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:147