11 from argparse
import ArgumentParser
14 from CoolLumiUtilities.CoolDataReader
import CoolDataReader
15 from CoolLumiUtilities.LumiDBHandler
import LumiDBHandler
42 print(f
"Finished parsing run list: {', '.join([str(run) for run in self.runList])}")
49 def __exit__(self, exc_type, exc_value, exc_traceback):
60 parser = ArgumentParser()
62 parser.add_argument(
"-v",
"--verbose",
63 action=
"store_true", dest=
"verbose",
64 help=
"turn on verbose output")
66 parser.add_argument(
"-r",
"--run", nargs=
'*', required=
True, type=int,
67 dest=
"runlist", metavar=
"RUN",
68 help=
"show specific run(s)")
70 parser.add_argument(
'-o',
'--output',
71 dest=
'outfile', metavar =
"FILE", default=
None, type=str,
72 help=
"write results to output file (default stdout). If filename ends in csv or json those formats are used.")
74 return parser.parse_args()
87 if self.
outFile.endswith(
".json"):
90 if self.
outFile.endswith(
".csv"):
100 lblb.setIOVRangeFromRun(run)
101 if not lblb.readData():
102 print(f
'RunLumiTime - No LBLB data found for run {run}!')
105 for obj
in lblb.data:
107 run = obj.since() >> 32
108 lb = obj.since() & 0xFFFFFFFF
110 startTime = obj.payload()[
'StartTime']
111 endTime = obj.payload()[
'EndTime']
113 if not run
in output:
117 "begin": startTime/1.e9,
121 entry = (run, lb, startTime/1.e9, endTime/1.e9)
122 separator =
',' if format==
'csv' else ' '
123 print(separator.join([
str(v)
for v
in entry]), file=fp)
127 json.dump(output, fp, indent=4)
132 print(f
"Wrote file {self.outFile}")
135 if __name__ ==
'__main__':