ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.TriggerAPI.TriggerAPISession.TriggerAPISession Class Reference
Collaboration diagram for python.TriggerAPI.TriggerAPISession.TriggerAPISession:

Public Member Functions

def __init__ (self, input=None, *grl=None, flags=None, json=None, menu=None, file=None, period=None)
 
def save (self, path)
 
def chains (self, *triggerType=TriggerType.ALL)
 
def triggerInfo (self)
 
def runs (self)
 
def setRunRange (self, start=0, end=999999)
 
def getLowestUnprescaled (self, *triggerType=TriggerType.ALL, livefraction=1.0, runStart=0, runEnd=999999)
 
def getLowestUnprescaledByRun (self, *triggerType=TriggerType.ALL, livefraction=1.0, runStart=0, runEnd=999999)
 
def getLowestUnprescaledAnyRun (self, *triggerType=TriggerType.ALL, livefraction=1.0, runStart=0, runEnd=999999)
 
def getLiveFractions (self, *triggerType=TriggerType.ALL, runStart=0, runEnd=999999)
 
def getLowerUnprescaled (self, *chainName, triggerType=TriggerType.ALL, livefraction=1.0, runStart=0, runEnd=999999)
 

Public Attributes

 dbQueries
 
 customGRL
 
 flags
 
 release
 
 cacheread
 

Detailed Description

--------------------------------------------------------------------------------------------------------------------
TriggerAPI helper class. Use the following import in your code:

  from TriggerMenuMT.TriggerAPI import TriggerAPISession,TriggerType,TriggerPeriod

Examples of use:
================

Set of triggers of a given type that are unprescaled for an entire GRL:

  s = TriggerAPISession("path/to/grl.xml") # can be a PathResolver path as well
  triggers = s.getLowestUnprescaled(triggerType=TriggerType.el_single)

Dictionary of sets of triggers of a given type that are unprescaled, for each run in the GRL:

  s = TriggerAPISession("path/to/grl.xml")
  triggersByRun = s.getLowestUnprescaledByRun(triggerType=TriggerType.el_single)

Set of triggers that are unprescaled for all runs between two run numbers (inclusive), in a GRL:

  s = TriggerAPISession("path/to/grl.xml")
  triggers = s.getLowestUnprescaledByRun(triggerType=TriggerType.el_single,runStart=123456,runEnd=234567)

Other helpful methods are:

  - Set of runs present in the session's GRL: s.runs()
  - List of trigger types: [x.name for x in TriggerType]
  - Dictionary of livefractions between given runs, key = trigger chain name:
    liveFractions = s.getLiveFractions(triggerType=TriggerType.el_single,runStart=123456,runEnd=234567)
  - Dictionary of chains (key is chain.name): s.chains()
  - Set of triggers that are deemed to be of same type and lower threshold than a given trigger and unprescaled:
    triggers = s.getLowerPrescaled(chainName="myChain")

Each method accepts an "additionalTriggerType" parameter that is used for multi-leg triggers of different type
(e.g. e-mu triggers).

Instead of passing a GRL you can pass a menu name ("menu_name") in the constructor, and the unprescaled
triggers will be the Primary|TagAndProbe triggers from the menu.


Saving a session
================
Sessions can be saved to json file and reloaded at a later time (to save requerying the database):

    s.save("myDump.json")
    s2 = TriggerAPISession(json="myDump.json") # reloads the session

--------------------------------------------------------------------------------------------------------------------

Definition at line 14 of file TriggerAPISession.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.__init__ (   self,
  input = None,
grl = None,
  flags = None,
  json = None,
  menu = None,
  file = None,
  period = None 
)
--------------------------------------------------------------------------------------------------------------------
TriggerAPI helper class. Use the following import in your code:

  from TriggerMenuMT.TriggerAPI import TriggerAPISession,TriggerType,TriggerPeriod

Examples of use:
================

Set of triggers of a given type that are unprescaled for an entire GRL:

  s = TriggerAPISession("path/to/grl.xml") # can be a PathResolver path as well
  triggers = s.getLowestUnprescaled(triggerType=TriggerType.el_single)

Dictionary of sets of triggers of a given type that are unprescaled, for each run in the GRL:

  s = TriggerAPISession("path/to/grl.xml")
  triggersByRun = s.getLowestUnprescaledByRun(triggerType=TriggerType.el_single)

Set of triggers that are unprescaled for all runs between two run numbers (inclusive), in a GRL:

  s = TriggerAPISession("path/to/grl.xml")
  triggers = s.getLowestUnprescaledByRun(triggerType=TriggerType.el_single,runStart=123456,runEnd=234567)

Other helpful methods are:

  - Set of runs present in the session's GRL: s.runs()
  - List of trigger types: [x.name for x in TriggerType]
  - Dictionary of livefractions between given runs, key = trigger chain name:
liveFractions = s.getLiveFractions(triggerType=TriggerType.el_single,runStart=123456,runEnd=234567)
  - Dictionary of chains (key is chain.name): s.chains()
  - Set of triggers that are deemed to be of same type and lower threshold than a given trigger and unprescaled:
triggers = s.getLowerPrescaled(chainName="myChain")

Each method accepts an "additionalTriggerType" parameter that is used for multi-leg triggers of different type
(e.g. e-mu triggers).

Instead of passing a GRL you can pass a menu name ("menu_name") in the constructor, and the unprescaled
triggers will be the Primary|TagAndProbe triggers from the menu.


Saving a session
================
Sessions can be saved to json file and reloaded at a later time (to save requerying the database):

s.save("myDump.json")
s2 = TriggerAPISession(json="myDump.json") # reloads the session

--------------------------------------------------------------------------------------------------------------------
Specify one and only one of the following parameters to construct your API session:

:param input: If specified, will try to auto-infer which of the things below it is:

:param grl: Path to a GRL file, locatable by PathResolver
:param flags: flag container, used if reading triggers from the trigger menu (in the file or the release) - EXPERT OPTION
:param json: Path to a JSON file, locatable by PathResolver, containing a cache of TriggerAPI session
:param menu: Specify a menu to use, such as "Physics_pp_run3_v1". This is otherwise taken from flags
:param file: Specify a root file (AOD etc) from which the menu will be taken
:param period: Legacy option, can specify a TriggerPeriod and will load through the hardcoded GRLs (TriggerPeriodData)

Definition at line 67 of file TriggerAPISession.py.

67  def __init__(self, input=None, *, grl=None, flags=None, json=None, menu=None, file=None, period=None):
68  """
69  Specify one and only one of the following parameters to construct your API session:
70 
71  :param input: If specified, will try to auto-infer which of the things below it is:
72 
73  :param grl: Path to a GRL file, locatable by PathResolver
74  :param flags: flag container, used if reading triggers from the trigger menu (in the file or the release) - EXPERT OPTION
75  :param json: Path to a JSON file, locatable by PathResolver, containing a cache of TriggerAPI session
76  :param menu: Specify a menu to use, such as "Physics_pp_run3_v1". This is otherwise taken from flags
77  :param file: Specify a root file (AOD etc) from which the menu will be taken
78  :param period: Legacy option, can specify a TriggerPeriod and will load through the hardcoded GRLs (TriggerPeriodData)
79  """
80 
81  import os
82 
83  if input is not None:
84  if type(input)==str:
85  if input.endswith(".xml"):
86  log.info("Loading session for GRL:" + input)
87  grl = input
88  elif input.endswith(".json"):
89  log.info("Loading saved session from:" + input)
90  json = input
91  elif os.path.exists(input):
92  log.info("Loading session with menu from file:" + input)
93  file = input
94  else:
95  log.info("Loading session for menu:" + input)
96  menu = input
97  else:
98  raise RuntimeError("Unsupported input type:" + type(input).__name__)
99 
100 
101  # the following represents the complete "state" of the TriggerAPI
102  self.dbQueries = {}
103  self.customGRL = None
104  self.flags = None
105  self.release = None
106  self.cacheread = True # always prevent auto-loading of cache in singleton
107 
108  if json is not None:
109  self.dbQueries = SerializeAPI.load(json)
110  elif grl is not None:
111  from PathResolver import PathResolver
112  grl = PathResolver.FindCalibFile(grl) if grl[0] != "/" else grl
113  self.customGRL = grl
114  elif flags is not None:
115  self.flags = flags
116  elif menu is not None:
117  from AthenaConfiguration.AllConfigFlags import initConfigFlags
118  self.flags = initConfigFlags()
119  self.flags.Trigger.triggerMenuSetup = menu
120  self.flags.lock()
121  elif file is not None:
122  from AthenaConfiguration.AllConfigFlags import initConfigFlags
123  self.flags = initConfigFlags()
124  self.flags.Input.Files = [file]
125  self.flags.lock()
126  elif period is not None:
127  TriggerAPI.reset()
128  TriggerAPI._loadTriggerPeriod(period,reparse=False)
129  if not TriggerAPI.dbQueries:
130  raise RuntimeError("Failed to load TriggerAPI information for period")
131  import copy
132  self.dbQueries = copy.deepcopy(TriggerAPI.dbQueries)
133  else:
134  raise RuntimeError("Must specify one of: grl, flags, json, menu, period")
135 
136  if self.flags is not None or self.customGRL is not None:
137  TriggerAPI.reset()
138  period = TriggerPeriod.future2e34 # used when loading with a flags container
139  if self.flags is not None:
140  TriggerAPI.setConfigFlags(self.flags)
141  else:
142  TriggerAPI.setCustomGRL(self.customGRL)
143  period = TriggerPeriod.customGRL
144  TriggerAPI._loadTriggerPeriod(period,reparse=False)
145  if not TriggerAPI.dbQueries:
146  raise RuntimeError("Failed to load TriggerAPI information")
147  import copy
148  self.dbQueries = copy.deepcopy(TriggerAPI.dbQueries)
149 
150  # TODO:
151  # for any query loaded with an actual period enum (so through json or period arg)
152  # we should use TriggerPeriodData to assign per run values of activeLB and totalLB
153  # could then merge into a single ti object ... but then need to look at is2015 in isLowerThan
154  # since there is special behaviour for 2015 that will be lost
155 
156  pass
157 

Member Function Documentation

◆ chains()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.chains (   self,
triggerType = TriggerType.ALL 
)
:param triggerType: you can list available types with "[x.name for x in TriggerType]"
:return: dictionary of triggerChain objects of given types, key = chain Name

Definition at line 166 of file TriggerAPISession.py.

166  def chains(self,*,triggerType=TriggerType.ALL):
167  """
168  :param triggerType: you can list available types with "[x.name for x in TriggerType]"
169  :return: dictionary of triggerChain objects of given types, key = chain Name
170  """
171  if len(self.dbQueries)>1:
172  raise RuntimeError("Unsupported in multi-period TriggerAPI sessions (should only happen if using a period enum or an old json cache)")
173 
174  if not isinstance(triggerType,list): triggerType = [triggerType,TriggerType.UNDEFINED]
175  if len(triggerType)==1: triggerType += [TriggerType.UNDEFINED]
176  elif len(triggerType) > 2:
177  raise RuntimeError("More than two trigger types not currently supported")
178 
179  out = {}
180  for tc in self.triggerInfo().triggerChains:
181  if not tc.passType(triggerType[0],triggerType[1]): continue
182  out[tc.name] = tc
183  return out
184 

◆ getLiveFractions()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.getLiveFractions (   self,
triggerType = TriggerType.ALL,
  runStart = 0,
  runEnd = 999999 
)
:param triggerType: can be a single type or a list of types
:param runStart:
:param runEnd:
:return: a dictionary of live fractions for triggers matching given trigger types

Definition at line 262 of file TriggerAPISession.py.

262  def getLiveFractions(self,*,triggerType=TriggerType.ALL,runStart=0,runEnd=999999):
263  """
264  :param triggerType: can be a single type or a list of types
265  :param runStart:
266  :param runEnd:
267  :return: a dictionary of live fractions for triggers matching given trigger types
268  """
269  out = {}
270  self.setRunRange(runStart,runEnd)
271  for x in self.chains(triggerType=triggerType).values():
272  out[x.name] = x.livefraction
273  self.setRunRange()
274  return out
275 

◆ getLowerUnprescaled()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.getLowerUnprescaled (   self,
chainName,
  triggerType = TriggerType.ALL,
  livefraction = 1.0,
  runStart = 0,
  runEnd = 999999 
)
:param chainName:
:param triggerType:
:param livefraction:
:param runStart:
:param runEnd:
:return: set of chains of unprescaled triggers that were lower than the given chain

Definition at line 276 of file TriggerAPISession.py.

276  def getLowerUnprescaled(self,*,chainName,triggerType=TriggerType.ALL,livefraction=1.0,runStart=0,runEnd=999999):
277  """
278  :param chainName:
279  :param triggerType:
280  :param livefraction:
281  :param runStart:
282  :param runEnd:
283  :return: set of chains of unprescaled triggers that were lower than the given chain
284  """
285 
286  chains = self.chains()
287  if chainName not in chains:
288  raise RuntimeError(chainName + " not found")
289  chain = chains[chainName]
290  self.setRunRange(runStart,runEnd)
291  out = set()
292  for x in self.chains(triggerType=triggerType).values():
293  if x.name==chain.name: continue
294  if not x.isUnprescaled(livefraction): continue
295  if x.isLowerThan(chain,period=self.triggerInfo().period)==1: out.add(x)
296  self.setRunRange()
297  return out
298 
299 

◆ getLowestUnprescaled()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.getLowestUnprescaled (   self,
triggerType = TriggerType.ALL,
  livefraction = 1.0,
  runStart = 0,
  runEnd = 999999 
)
:param triggerType: list available types with "[x.name for x in TriggerType] .. provide a list of length 2 for multi-leg types"
:param livefraction: threshold to be considered unprescaled
:param runStart:
:param runEnd:
:return: set of lowest unprescaled (according to livefraction) triggers of given type

Definition at line 203 of file TriggerAPISession.py.

203  def getLowestUnprescaled(self,*, triggerType=TriggerType.ALL,livefraction=1.0,runStart=0,runEnd=999999):
204  """
205  :param triggerType: list available types with "[x.name for x in TriggerType] .. provide a list of length 2 for multi-leg types"
206  :param livefraction: threshold to be considered unprescaled
207  :param runStart:
208  :param runEnd:
209  :return: set of lowest unprescaled (according to livefraction) triggers of given type
210  """
211 
212 
213  if not isinstance(triggerType,list): triggerType = [triggerType,TriggerType.UNDEFINED]
214  if len(triggerType)==1: triggerType += [TriggerType.UNDEFINED]
215  elif len(triggerType) > 2:
216  raise RuntimeError("More than two trigger types not currently supported")
217 
218  self.setRunRange(runStart,runEnd)
219  out = set()
220  for ti in self.dbQueries.values():
221  out.update(ti._getLowestUnprescaled(triggerType[0], triggerType[1], "", livefraction))
222  self.setRunRange() # reset to include all ranges
223 
224  if not out and livefraction==1.0 and list(self.dbQueries.keys())[0][1] and runStart!=runEnd:
225  log.warning("No triggers found that are fully unprescaled in your GRL ... checking for livefractions per run:")
226  # check result by-run to see if there are problems with individual runs (possibly lumiblocks included in each)
227  for run in sorted(list(self.runs())):
228  liveFractions = self.getLiveFractions(triggerType=triggerType,runStart=run,runEnd=run)
229  lf = max(liveFractions.values())
230  if lf < 1 and lf > 0.9:
231  log.warning(f"run {run} has maximum livefraction {lf} - prescaled LBs may have been included in your GRL accidentally. Please report this to Data Preparation")
232  elif lf==1.0:
233  log.info(f"run {run} is unprescaled")
234 
235  return out
236 

◆ getLowestUnprescaledAnyRun()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.getLowestUnprescaledAnyRun (   self,
triggerType = TriggerType.ALL,
  livefraction = 1.0,
  runStart = 0,
  runEnd = 999999 
)

Definition at line 257 of file TriggerAPISession.py.

257  def getLowestUnprescaledAnyRun(self,*,triggerType=TriggerType.ALL,livefraction=1.0,runStart=0,runEnd=999999):
258  out = set()
259  for tc in self.getLowestUnprescaledByRun(triggerType=triggerType,livefraction=livefraction,runStart=runStart,runEnd=runEnd).values():
260  out.update(tc)
261  return out

◆ getLowestUnprescaledByRun()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.getLowestUnprescaledByRun (   self,
triggerType = TriggerType.ALL,
  livefraction = 1.0,
  runStart = 0,
  runEnd = 999999 
)
:param triggerType:
:param livefraction:
:param runStart:
:param runEnd:
:return: lowest unprescaled trigger by run. If this session does not have per-run info, all triggers will be listed under a dummy key of ""

Definition at line 237 of file TriggerAPISession.py.

237  def getLowestUnprescaledByRun(self,*,triggerType=TriggerType.ALL,livefraction=1.0,runStart=0,runEnd=999999):
238  """
239 
240  :param triggerType:
241  :param livefraction:
242  :param runStart:
243  :param runEnd:
244  :return: lowest unprescaled trigger by run. If this session does not have per-run info, all triggers will be listed under a dummy key of ""
245  """
246  if not self.runs(): # case where loaded from trigger menu, for example
247  return {"":self.getLowestUnprescaled(triggerType=triggerType,livefraction=livefraction,runStart=runStart,runEnd=runEnd)}
248  out = {}
249  import tqdm
250  pbar = tqdm.tqdm(self.runs(),unit=" runs",bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}')
251  for run in pbar:
252  pbar.set_description(f"Determining lowest unprescaled for run {run}")
253  if int(run)<runStart or int(run)>runEnd: continue
254  out[run] = self.getLowestUnprescaled(triggerType=triggerType,livefraction=livefraction,runStart=run,runEnd=run)
255  return out
256 

◆ runs()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.runs (   self)
:return: set of runs covered by this session

Definition at line 188 of file TriggerAPISession.py.

188  def runs(self):
189  """
190  :return: set of runs covered by this session
191  """
192  out = set()
193  for ti in self.dbQueries.values():
194  for tc in ti.triggerChains:
195  for run in tc.activeLBByRun.keys():
196  out.add(run)
197  return out
198 

◆ save()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.save (   self,
  path 
)
:param path: Save a cache of the current session to the given json file
:return: result of json dump

Definition at line 158 of file TriggerAPISession.py.

158  def save(self, path):
159  """
160  :param path: Save a cache of the current session to the given json file
161  :return: result of json dump
162  """
163  return SerializeAPI.dump(self.dbQueries,path)
164 
165 

◆ setRunRange()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.setRunRange (   self,
  start = 0,
  end = 999999 
)

Definition at line 199 of file TriggerAPISession.py.

199  def setRunRange(self,start=0,end=999999):
200  for ti in self.dbQueries.values():
201  ti.setRunRange(start,end)
202 

◆ triggerInfo()

def python.TriggerAPI.TriggerAPISession.TriggerAPISession.triggerInfo (   self)

Definition at line 185 of file TriggerAPISession.py.

185  def triggerInfo(self):
186  return self.dbQueries[list(self.dbQueries.keys())[0]]
187 

Member Data Documentation

◆ cacheread

python.TriggerAPI.TriggerAPISession.TriggerAPISession.cacheread

Definition at line 106 of file TriggerAPISession.py.

◆ customGRL

python.TriggerAPI.TriggerAPISession.TriggerAPISession.customGRL

Definition at line 103 of file TriggerAPISession.py.

◆ dbQueries

python.TriggerAPI.TriggerAPISession.TriggerAPISession.dbQueries

Definition at line 102 of file TriggerAPISession.py.

◆ flags

python.TriggerAPI.TriggerAPISession.TriggerAPISession.flags

Definition at line 104 of file TriggerAPISession.py.

◆ release

python.TriggerAPI.TriggerAPISession.TriggerAPISession.release

Definition at line 105 of file TriggerAPISession.py.


The documentation for this class was generated from the following file:
PathResolver::FindCalibFile
static std::string FindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.h:108
python.TriggerAPI.TriggerAPISession.type
type
Definition: TriggerAPISession.py:321
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
find_tgc_unfilled_channelids.runs
int runs
Definition: find_tgc_unfilled_channelids.py:10
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
python.TriggerAPI.TriggerAPISession.int
int
Definition: TriggerAPISession.py:343
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.TriggerAPI.TriggerAPISession.chains
chains
Definition: TriggerAPISession.py:367
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798