11 from ROOT
import PyConfig
12 PyConfig.IgnoreCommandLineOptions =
True
13 PyConfig.StartGuiThread =
False
15 from argparse
import ArgumentParser
27 """Get the command line options
30 argparse.ArgumentParser for this tool
32 parser = ArgumentParser(
33 description=
"Combines several ``software_trigger_result`` files.")
34 parser.add_argument(
"input", nargs=
'*',
35 help=
"Wildcard to select ``software_trigger_results`` files.")
36 parser.add_argument(
"--output",
37 help=
"The combined output ``software_trigger_result`` file name.",
38 default=
"software_trigger_results_combined.root")
42 def get_prescales(df):
43 """Get prescale values from a data frame
46 a list of the prescale values of each trigger line
49 for col
in df.columns:
50 if col.find(
'software_trigger_cut_') >= 0
and df[col][PRESCALE_ROW] > 0:
51 prescales.append(df[col][PRESCALE_ROW])
55 if __name__ ==
"__main__":
57 args = get_parser().parse_args()
60 if not all([os.path.exists(f)
for f
in args.input]):
61 raise FileNotFoundError(
"Could not find input files: %s" % args.input)
64 sum_out = pd.DataFrame()
69 swtr = uproot.open(fi)[
"software_trigger_results"].pandas.df()
70 if not swtr[
'total_events'][0].any():
77 sum_out = sum_out.add(swtr)
78 prescales.append(get_prescales(swtr))
80 prescales = np.array(prescales)
88 for col
in sum_out.columns:
90 if col.find(
'software_trigger_cut_') >= 0
and sum_out[col][PRESCALE_ROW] > 0:
91 prescale_changed =
False
92 for j
in range(prescales[:, i].size - 1):
94 if not prescales[j, i] == prescales[j+1, i]:
95 prescale_changed =
True
97 if not prescale_changed:
99 sum_out.at[PRESCALE_ROW, col] = prescales[0, i]
101 b2.B2WARNING(
"{}: Different prescale values found for this trigger line! ".format(col) +
102 "Final prescale value is set to NaN.")
103 sum_out.at[PRESCALE_ROW, col] = np.nan
106 root_pandas.to_root(sum_out, key=
'software_trigger_results', path=args.output)
110 print(
"Created file %s" % args.output)