18 from generators
import add_kkmc_generator
19 from simulation
import add_simulation
20 from validation_gt
import get_validation_globaltags
21 from rawdata
import add_unpackers
22 from reconstruction
import add_reconstruction
23 from argparse
import ArgumentParser
29 parser = ArgumentParser(description=
'Measure the execution time.')
30 parser.add_argument(
'-m',
'--multiplicity', default=
'high', choices=[
'high',
'low',
'data'], help=
'Multiplicity or type of events')
31 parser.add_argument(
'-l',
'--limits', help=
'Name of file containing limits')
32 parser.add_argument(
'-f',
'--file', help=
'Name of benchmark output file')
33 args = parser.parse_args()
36 main = b2.create_path()
37 b2.set_log_level(b2.LogLevel.ERROR)
39 if args.multiplicity ==
'data':
41 b2.conditions.override_globaltags(get_validation_globaltags())
43 input_files = glob.glob(os.environ.get(
'BELLE2_VALIDATION_DATA_DIR',
'') +
'/rawdata/physics.0010.05095*.root')
44 main.add_module(
"RootInput", inputFileNames=input_files)
46 main.add_module(
'EventInfoPrinter').set_log_level(b2.LogLevel.INFO)
49 main.add_module(
'Gearbox')
50 main.add_module(
'Geometry', useDB=
True)
57 main.add_module(
'EventInfoSetter', evtNumList=[1000])
58 main.add_module(
'EventInfoPrinter').set_log_level(b2.LogLevel.INFO)
60 if args.multiplicity ==
'high':
62 main.add_module(
'EvtGenInput')
64 elif args.multiplicity ==
'low':
66 add_kkmc_generator(main,
'mu+mu-')
69 add_simulation(main, bkgfiles=glob.glob(os.environ.get(
'BELLE2_BACKGROUND_DIR',
'/sw/belle2/bkg') +
'/*.root'))
72 add_reconstruction(main)
80 limits_file = args.limits
81 default_limits_file = args.multiplicity +
'.limits'
82 if limits_file
is None and os.path.isfile(default_limits_file):
83 limits_file = default_limits_file
84 if limits_file
is not None:
85 for line
in open(limits_file).readlines():
86 entries = line.split()
87 limits[entries[0]] = float(entries[1])
89 limits[entries[0]] /= float(entries[2])
97 'Posttracking_Reconstruction',
98 'Postfilter_Reconstruction']
100 for module
in b2.statistics.modules:
101 if module.name
not in [
'Sum_' + category
for category
in categories]:
103 category = module.name[4:]
104 if category
not in times.keys():
106 times[category] += module.time_mean(b2.statistics.EVENT) * 1e-6
110 if args.file
is not None:
111 output = open(args.file,
'wt')
114 b2.set_log_level(b2.LogLevel.INFO)
116 for category
in categories:
117 if category
not in times.keys():
119 time = times[category]
120 message =
'Execution time per event for %s is %.f ms' % (category, time)
122 if category
in limits.keys():
123 fraction = time / limits[category]
124 if fraction > max_fraction:
125 max_fraction = fraction
126 message +=
' = %.f%% of the limit.' % (100 * fraction)
130 b2.B2WARNING(message)
136 if output
is not None:
137 output.write(
'%s %.2f' % (category, time))
139 output.write(
' %.4f' % fraction)
143 sys.exit(0
if max_fraction <= 1
else 1)