All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Functions | Variables
triggeredEventList Namespace Reference

Classes

class  EventTagCache
 
class  IntervalClass
 

Functions

def analyzeTrigger
 
def findTriggeredEvents
 
def getAllTriggerTags
 
def listTriggerDataProducts
 
def buildDefaultOutputFile
 
def parseTimeRange
 

Variables

string __doc__ = """Prints the list of events passing the specified trigger."""
 
string __author__ = "Gianluca Petrillo (petrillo@slac.stanford.edu)"
 
tuple __date__ = time.strptime("July 11, 2021", "%B %d, %Y")
 
string __version__ = "1.1"
 
string DefaultTriggerModuleLabel = "trigger"
 
string TriggerDataProductClass = 'std::vector<raw::Trigger>'
 
tuple parser = argparse.ArgumentParser(description=__doc__)
 
string help = f"trigger to check: data product name (`{DefaultTriggerModuleLabel}:inst`)"
 
tuple inputGroup = parser.add_argument_group("Input options")
 
string action = "store_true"
 
tuple filterGroup = parser.add_argument_group("Filtering options")
 
tuple outputFormatGroup = parser.add_argument_group("Output format")
 
tuple generalOptGroup = parser.add_argument_group("General options")
 
string version = f"%(prog)s v{__version__} ({time.asctime(__date__)})"
 
tuple args = parser.parse_args()
 
tuple sampleEvents = galleryUtils.makeEvent(args.InputFile)
 
 hasTriggerSpecs = args.TriggerSpecorargs.allorargs.allToFiles
 
list triggerSpecs = []
 

Function Documentation

def triggeredEventList.analyzeTrigger (   eventTag,
  triggers,
  trigSpec,
  args 
)

Definition at line 120 of file triggeredEventList.py.

121 def analyzeTrigger(eventTag, triggers, trigSpec, args):
122  if len(triggers) == 0: return False
123 
124  # if this is expensive (which should not be since the trigger data product
125  # has already been read) it can be made conditional based on `args.timeRange`.
126  trigTime = triggers[0].TriggerTime()
127  if trigTime not in args.timeRange: return False
128 
129  trigSpec['count'] += 1
130 
131  if args.noList: return True # if no printing is requested, skip the rest
132 
133  trigInfo = { 'trigTime': trigTime, }
134  print(eventTag(trigInfo=trigInfo), file=trigSpec['dest'])
135 
136  return True
137 # analyzeTrigger()
138 
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def triggeredEventList.buildDefaultOutputFile (   spec)

Definition at line 234 of file triggeredEventList.py.

235 def buildDefaultOutputFile(spec):
236  if isinstance(spec, ROOT.art.InputTag): spec = spec.encode()
237  return f"triggeredEvents_{spec.replace(':', '_')}.log"
238 # buildDefaultOutputFile()
239 
def triggeredEventList.findTriggeredEvents (   sampleEvents,
  triggers,
  args 
)

Definition at line 139 of file triggeredEventList.py.

140 def findTriggeredEvents(sampleEvents, triggers, args):
141 
142  # digest the trigger info options
143  trigSpecs = triggers.copy()
144  for trigSpec in trigSpecs:
145  tag = trigSpec['spec']
146  if not isinstance(tag, ROOT.art.InputTag):
147  if ':' not in tag: tag = DefaultTriggerModuleLabel + ':' + tag
148  tag = ROOT.art.InputTag(tag)
149  # if
150  trigSpec.update({
151  'tag': tag,
152  'dest': (open(trigSpec['destList'], 'w')
153  if trigSpec['destList'] else sys.stdout),
154  'count': 0,
155  })
156  # for
157 
158  try: # using a context manager here is more complicate...
159 
160  getTrigger \
161  = galleryUtils.make_getValidHandle(TriggerDataProductClass, sampleEvents)
162 
163  eventTag = EventTagCache(
164  run=args.run,
165  subRun=args.subrun,
166  event=args.event,
167  sourceFile=args.sourcefile,
168  human=args.human,
169  short=args.short,
170  trigTime=args.trigtime,
171  separator=args.sep,
172  ) if args.doList else None
173 
174  for iEvent, event in enumerate(galleryUtils.forEach(sampleEvents)):
175 
176  if args.maxEvents and iEvent >= args.maxEvents:
177  logging.warning(f"Limit of {iEvent} events reached: stopping now.")
178  break
179 
180  if eventTag: eventTag.prepareFor(event)
181 
182  for trigSpec in trigSpecs:
183  triggers = getTrigger(trigSpec['tag']).product()
184  analyzeTrigger(eventTag, triggers, trigSpec, args)
185  # for
186 
187  # for all events
188  else: iEvent += 1
189 
190  finally:
191  for trigSpec in trigSpecs:
192  if trigSpec['dest'] is not sys.stdout: trigSpec['dest'].close()
193  # for
194  # try ... finally
195 
196  for trigSpec in trigSpecs:
197  print(
198  f"{trigSpec['tag'].encode()}:"
199  f" {trigSpec['count']}/{iEvent} events triggered"
200  f" ({trigSpec['count']/iEvent*100:g}%)",
201  end="",
202  )
203  if (trigSpec['dest'] is not sys.stdout):
204  print(f" (->'{trigSpec['dest'].name}')", end="")
205  print()
206  # for
207 
208  return 0
209 # findTriggeredEvents()
210 
do one_file $F done echo for F in find $TOP name CMakeLists txt print
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
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")
def triggeredEventList.getAllTriggerTags (   sampleEvents)

Definition at line 211 of file triggeredEventList.py.

212 def getAllTriggerTags(sampleEvents):
213 
214  return sorted(
215  sampleEvents.getInputTags[TriggerDataProductClass](),
216  key=ROOT.art.InputTag.encode
217  )
218 
219 # getAllTriggerTags()
220 
def triggeredEventList.listTriggerDataProducts (   sampleEvents)

Definition at line 221 of file triggeredEventList.py.

222 def listTriggerDataProducts(sampleEvents):
223  # sorted() also converts a returned `std::vector` into a Python list
224  inputTags = getAllTriggerTags(sampleEvents)
225  nProducts = len(inputTags)
226  print(f"{nProducts} '{TriggerDataProductClass}' data products found:")
227  PadLength=len(str(nProducts))
228  for iProduct, inputTag in enumerate(inputTags):
229  print(f"[#{iProduct+1:0>{PadLength}}] {inputTag.encode()}")
230  # for
231  return 0
232 # listTriggerDataProducts()
233 
do one_file $F done echo for F in find $TOP name CMakeLists txt print
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
def triggeredEventList.parseTimeRange (   rangeSpec,
  sep = "/" 
)

Definition at line 240 of file triggeredEventList.py.

241 def parseTimeRange(rangeSpec, sep = "/"):
242 
243  if not rangeSpec: return IntervalClass(None, None)
244  try:
245  lower, upper = rangeSpec.split(sep)
246  except ValueError:
247  raise RuntimeError(f"Invalid format for time range: {rangeSpec}")
248 
249  if lower:
250  try: lower = float(lower)
251  except ValueError:
252  RuntimeError(
253  "Lower bound of time range '{rangeSpec}' ('f{lower}')"
254  " is not a valid time."
255  )
256  else: lower = None
257  if upper:
258  try: upper = float(upper)
259  except ValueError:
260  RuntimeError(
261  "Upper bound of time range '{rangeSpec}' ('f{upper}')"
262  " is not a valid time."
263  )
264  else: upper = None
265  return IntervalClass(lower, upper)
266 # parseTimeRange()
267 

Variable Documentation

string triggeredEventList.__author__ = "Gianluca Petrillo (petrillo@slac.stanford.edu)"

Definition at line 6 of file triggeredEventList.py.

tuple triggeredEventList.__date__ = time.strptime("July 11, 2021", "%B %d, %Y")

Definition at line 7 of file triggeredEventList.py.

string triggeredEventList.__doc__ = """Prints the list of events passing the specified trigger."""

Definition at line 5 of file triggeredEventList.py.

string triggeredEventList.__version__ = "1.1"

Definition at line 8 of file triggeredEventList.py.

string triggeredEventList.action = "store_true"

Definition at line 291 of file triggeredEventList.py.

tuple triggeredEventList.args = parser.parse_args()

Definition at line 337 of file triggeredEventList.py.

triggeredEventList.DefaultTriggerModuleLabel = "trigger"

Definition at line 15 of file triggeredEventList.py.

tuple triggeredEventList.filterGroup = parser.add_argument_group("Filtering options")

Definition at line 296 of file triggeredEventList.py.

tuple triggeredEventList.generalOptGroup = parser.add_argument_group("General options")

Definition at line 327 of file triggeredEventList.py.

triggeredEventList.hasTriggerSpecs = args.TriggerSpecorargs.allorargs.allToFiles

Definition at line 346 of file triggeredEventList.py.

string triggeredEventList.help = f"trigger to check: data product name (`{DefaultTriggerModuleLabel}:inst`)"

Definition at line 278 of file triggeredEventList.py.

tuple triggeredEventList.inputGroup = parser.add_argument_group("Input options")

Definition at line 283 of file triggeredEventList.py.

tuple triggeredEventList.outputFormatGroup = parser.add_argument_group("Output format")

Definition at line 304 of file triggeredEventList.py.

tuple triggeredEventList.parser = argparse.ArgumentParser(description=__doc__)

Definition at line 273 of file triggeredEventList.py.

tuple triggeredEventList.sampleEvents = galleryUtils.makeEvent(args.InputFile)

Definition at line 344 of file triggeredEventList.py.

string triggeredEventList.TriggerDataProductClass = 'std::vector<raw::Trigger>'

Definition at line 17 of file triggeredEventList.py.

list triggeredEventList.triggerSpecs = []

Definition at line 358 of file triggeredEventList.py.

string triggeredEventList.version = f"%(prog)s v{__version__} ({time.asctime(__date__)})"

Definition at line 333 of file triggeredEventList.py.