Belle II Software  release-05-01-25
packers.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 path_to_output = 'rawdata/tests/digits.root'
5 
6 import basf2 as b2
7 import simulation as sim
8 import rawdata as raw
9 
10 from ROOT import Belle2
11 
12 import sys
13 import os
14 import multiprocessing as mp
15 
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 # This function create a secondary path to create the digits
23 
24 
25 def create_digits():
26  """Create the file 'digits.root' needed for testing the packers if it does not exist"""
27 
28  child_path = b2.create_path()
29  child_path.add_module('EventInfoSetter',
30  evtNumList=[10])
31  child_path.add_module('EvtGenInput')
32  sim.add_simulation(path=child_path)
33  child_path.add_module('RootOutput',
34  outputFileName='${BELLE2_LOCAL_DIR}/' + path_to_output,
35  branchNames=['ARICHDigits',
36  'CDCHits',
37  'ECLDigits',
38  'KLMDigits',
39  'PXDDigits',
40  'SVDEventInfoSim',
41  'SVDShaperDigits',
42  'TOPRawDigits'])
43  child_path.add_module('Progress')
44  b2.process(child_path)
45  print(b2.statistics)
46 
47 if Belle2.FileSystem.findFile(path_to_output, True) == '':
48  # Execute create_digits() in a child process to avoid side effects
49  child = mp.Process(target=create_digits)
50  child.start()
51  # Wait for simulation to finish
52  child.join()
53  # And exit if it had an error
54  if child.exitcode != 0:
55  sys.exit(child.exitcode)
56 
57 # Here starts the main path
58 main_path = b2.create_path()
59 main_path.add_module('RootInput',
60  inputFileNames=Belle2.FileSystem.findFile(path_to_output))
61 raw.add_packers(path=main_path)
62 main_path.add_module('Progress')
63 b2.process(main_path)
64 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