11 from ROOT
import PyConfig
12 PyConfig.IgnoreCommandLineOptions =
True
13 PyConfig.StartGuiThread =
False
15 from argparse
import ArgumentParser
26 """Get the command line options
29 argparse.ArgumentParser for this tool
31 parser = ArgumentParser(
32 description=
"Combines several ``software_trigger_result`` files.")
33 parser.add_argument(
"input", nargs=
'*',
34 help=
"Wildcard to select ``software_trigger_results`` files.")
35 parser.add_argument(
"--output",
36 help=
"The combined output ``software_trigger_result`` file name.",
37 default=
"software_trigger_results_combined.root")
41 def get_prescales(df):
42 """Get prescale values from a data frame
45 a list of the prescale values of each trigger line
48 for col
in df.columns:
49 if col.find(
'software_trigger_cut_') >= 0
and df[col][PRESCALE_ROW] > 0:
50 prescales.append(df[col][PRESCALE_ROW])
54 if __name__ ==
"__main__":
56 args = get_parser().parse_args()
59 if not all([os.path.exists(f)
for f
in args.input]):
60 raise FileNotFoundError(
"Could not find input files: %s" % args.input)
63 sum_out = pd.DataFrame()
68 swtr = uproot.open(fi)[
"software_trigger_results"].arrays(library=
'pd')
69 if not swtr[
'total_events'][0].any():
76 sum_out = sum_out.add(swtr)
77 prescales.append(get_prescales(swtr))
79 prescales = np.array(prescales)
87 for col
in sum_out.columns:
89 if col.find(
'software_trigger_cut_') >= 0
and sum_out[col][PRESCALE_ROW] > 0:
90 prescale_changed =
False
91 for j
in range(prescales[:, i].size - 1):
93 if not prescales[j, i] == prescales[j+1, i]:
94 prescale_changed =
True
96 if not prescale_changed:
98 sum_out.at[PRESCALE_ROW, col] = prescales[0, i]
100 b2.B2WARNING(
"{}: Different prescale values found for this trigger line! ".format(col) +
101 "Final prescale value is set to NaN.")
102 sum_out.at[PRESCALE_ROW, col] = np.nan
105 with uproot.recreate(args.output)
as outfile:
106 outfile[
'software_trigger_results'] = sum_out
108 print(
"Created file %s" % args.output)