5 __doc__ =
"""Prints the list of events passing the specified trigger."""
6 __author__ =
"Gianluca Petrillo (petrillo@slac.stanford.edu)"
7 __date__ = time.strptime(
"July 11, 2021",
"%B %d, %Y")
15 DefaultTriggerModuleLabel =
"trigger"
17 TriggerDataProductClass =
'std::vector<raw::Trigger>'
22 run=
False, subRun=
False, event=
True, sourceFile=
False,
23 human=
False, short=
False,
50 if self.
trigTime: info.append(f
"{trigInfo['trigTime']:.3f}")
51 return self.separator.join(info)
55 if event
is not None: self.
eventObj = event
56 assert self.
eventObj,
"Needs to prepareFor(event) this object first!"
57 eventAux = self.eventObj.eventAuxiliary()
61 if self.
human: eventID.append(f
"run {run}")
62 elif self.
short: eventID.append(f
"R:{run}")
63 else: eventID.append(str(run))
66 subrun = eventAux.subRun()
67 if self.
human: eventID.append(f
"subrun {subrun}")
68 elif self.
short: eventID.append(f
"S:{subrun}")
69 else: eventID.append(str(subrun))
72 evt = eventAux.event()
73 if self.
human: eventID.append(f
"event {evt}")
74 elif self.
short: eventID.append(f
"E:{evt}")
75 else: eventID.append(str(evt))
78 sourceFile = self.eventObj.getTFile()
79 fileName = sourceFile.GetName()
if sourceFile
else "<unknown>"
80 eventInFile = self.eventObj.eventEntry()
81 if self.
human: eventID.append(f
"from file {fileName} entry {eventInFile}")
82 elif self.
short: eventID.append(f
"F:{fileName!r}@{eventInFile}")
84 eventID.append(repr(fileName))
85 eventID.append(str(eventInFile))
87 return self.separator.join(eventID)
94 """Simple numeric range class (usual [ lower, upper [ interval).
96 Boundaries set to `None` are ignored.
103 if self.
lower is not None and value < self.
lower:
return False
104 if self.
upper is not None and value >= self.
upper:
return False
109 if self.
lower is None:
110 if self.
upper is None:
return "(any)"
111 else:
return f
" < {self.upper}"
113 if self.
upper is None:
return f
">= {self.lower}"
114 else:
return f
"{self.lower} -- {self.upper}"
121 if len(triggers) == 0:
return False
125 trigTime = triggers[0].TriggerTime()
126 if trigTime
not in args.timeRange:
return False
128 trigSpec[
'count'] += 1
130 if args.noList:
return True
132 trigInfo = {
'trigTime': trigTime, }
133 print(eventTag(trigInfo=trigInfo), file=trigSpec[
'dest'])
142 trigSpecs = triggers.copy()
143 for trigSpec
in trigSpecs:
144 tag = trigSpec[
'spec']
145 if not isinstance(tag, ROOT.art.InputTag):
146 if ':' not in tag: tag = DefaultTriggerModuleLabel +
':' + tag
147 tag = ROOT.art.InputTag(tag)
151 'dest': (
open(trigSpec[
'destList'],
'w')
152 if trigSpec[
'destList']
else sys.stdout),
166 sourceFile=args.sourcefile,
169 trigTime=args.trigtime,
171 )
if args.doList
else None
175 if args.maxEvents
and iEvent >= args.maxEvents:
176 logging.warning(f
"Limit of {iEvent} events reached: stopping now.")
179 if eventTag: eventTag.prepareFor(event)
181 for trigSpec
in trigSpecs:
182 triggers = getTrigger(trigSpec[
'tag']).product()
190 for trigSpec
in trigSpecs:
191 if trigSpec[
'dest']
is not sys.stdout: trigSpec[
'dest'].
close()
195 for trigSpec
in trigSpecs:
197 f
"{trigSpec['tag'].encode()}:"
198 f
" {trigSpec['count']}/{iEvent} events triggered"
199 f
" ({trigSpec['count']/iEvent*100:g}%)",
202 if (trigSpec[
'dest']
is not sys.stdout):
203 print(f
" (->'{trigSpec['dest'].name}')", end=
"")
214 sampleEvents.getInputTags[TriggerDataProductClass](),
215 key=ROOT.art.InputTag.encode
224 nProducts = len(inputTags)
225 print(f
"{nProducts} '{TriggerDataProductClass}' data products found:")
226 PadLength=len(str(nProducts))
227 for iProduct, inputTag
in enumerate(inputTags):
228 print(f
"[#{iProduct+1:0>{PadLength}}] {inputTag.encode()}")
235 if isinstance(spec, ROOT.art.InputTag): spec = spec.encode()
236 return f
"triggeredEvents_{spec.replace(':', '_')}.log"
244 lower, upper = rangeSpec.split(sep)
246 raise RuntimeError(f
"Invalid format for time range: {rangeSpec}")
249 try: lower = float(lower)
252 "Lower bound of time range '{rangeSpec}' ('f{lower}')"
253 " is not a valid time."
257 try: upper = float(upper)
260 "Upper bound of time range '{rangeSpec}' ('f{upper}')"
261 " is not a valid time."
268 if __name__ ==
"__main__":
273 parser = argparse.ArgumentParser(description=__doc__)
276 parser.add_argument(
"InputFile", help=
"art/ROOT input file or file list")
277 parser.add_argument(
"TriggerSpec", nargs=
"*",
278 help=f
"trigger to check: data product name (`{DefaultTriggerModuleLabel}:inst`)"
279 f
" or just instance name (`M5S10`, becoming `{DefaultTriggerModuleLabel}:M5S10`)"
283 inputGroup = parser.add_argument_group(
"Input options")
284 inputGroup.add_argument(
"--maxEvents",
"-n", type=int,
285 help=
"do not process more that this number of events")
286 inputGroup.add_argument(
"--deflabel", type=str, default=DefaultTriggerModuleLabel,
287 help=
"trigger module label used in TriggerSpec by default [%(default)s]")
288 inputGroup.add_argument(
"--all", action=
"store_true",
289 help=
"processes all available trigger data products")
290 inputGroup.add_argument(
"--all-to-files", dest=
"allToFiles",
292 help=
"like `--all`, redirecting each trigger into its default-named file"
296 filterGroup = parser.add_argument_group(
"Filtering options")
297 filterGroup.add_argument(
"--accept-time",
"-T", dest=
"acceptTime", type=str,
298 help=
"only consider triggers in the specified range of time: `<min>:<max>`;"
299 " time is in electronics time scale, microseconds;"
300 " either `<min>` or `<max>` may be omitted"
304 outputFormatGroup = parser.add_argument_group(
"Output format")
305 outputFormatGroup.add_argument(
"--run",
"-r", action=
"store_true",
306 help=
"print the run number for triggering events [%(default)s]")
307 outputFormatGroup.add_argument(
"--subrun",
"-a", action=
"store_true",
308 help=
"print the subrun number for triggering events [%(default)s]")
309 outputFormatGroup.add_argument(
"--event",
"-e", action=
"store_false",
310 help=
"print the event number for triggering events [%(default)s]")
311 outputFormatGroup.add_argument(
"--trigtime",
"-t", action=
"store_true",
312 help=
"print the relative time of first trigger [%(default)s]")
313 outputFormatGroup.add_argument(
"--sourcefile",
"--file",
"-f",
315 help=
"print the file where triggering events are stored [%(default)s]"
317 outputFormatGroup.add_argument(
"--human",
"--hr",
"-H", action=
"store_true",
318 help=
"print the event ID with extended labels [%(default)s]")
319 outputFormatGroup.add_argument(
"--short",
"-S", action=
"store_true",
320 help=
"print the event ID with short labels [%(default)s]")
321 outputFormatGroup.add_argument(
"--nolist",
"-N", dest=
"noList",
322 action=
"store_true", help=
"do not print any event ID (only summary)")
323 outputFormatGroup.add_argument(
"--separator", dest=
"sep", default=
" ",
324 help=
"use this string as separator [%(default)r]")
327 generalOptGroup = parser.add_argument_group(
"General options")
328 generalOptGroup.add_argument(
"--list",
"-l", dest=
"doList", action=
"store_true",
329 help=
"prints the available trigger data product tags, and exits")
330 generalOptGroup.add_argument(
"--debug", action=
"store_true",
331 help=
"enable additional diagnostic output")
332 generalOptGroup.add_argument(
"--version",
"-V", action=
"version",
333 version=f
"%(prog)s v{__version__} ({time.asctime(__date__)})",
334 help=
"prints the version number"
337 args = parser.parse_args()
339 logging.basicConfig(level=(logging.DEBUG
if args.debug
else logging.INFO))
341 DefaultTriggerModuleLabel = args.deflabel
346 hasTriggerSpecs = args.TriggerSpec
or args.all
or args.allToFiles
348 if not args.doList
and not hasTriggerSpecs:
350 logging.error(
"No trigger tag specified!")
359 if args.all
or args.allToFiles:
361 triggerSpecs.append({
367 for spec
in args.TriggerSpec:
368 spec, sep, destList = spec.partition(
'->')
370 triggerSpecs.append({
'spec': spec,
'destList': destList, })
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def buildDefaultOutputFile
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
tuple make_getValidHandle
def listTriggerDataProducts
print OUTPUT<< EOF;< setup name="Default"version="1.0">< worldref="volWorld"/></setup ></gdml > EOF close(OUTPUT)
open(RACETRACK) or die("Could not open file $RACETRACK for writing")