ATLAS Offline Software
AtlRunQuerySelectorEvents.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 
4 from __future__ import print_function
5 from time import time
6 import sys
7 
8 from CoolRunQuery.utils.AtlRunQueryIOV import IOVRange
9 from CoolRunQuery.utils.AtlRunQueryTimer import timer
10 from CoolRunQuery.utils.AtlRunQueryUtils import coolDbConn, GetRanges
11 
12 from .AtlRunQuerySelectorBase import RunLBBasedCondition
13 
15  def __init__(self, name, events=None):
16  self.events = events
17  super(EventSelector,self).__init__(name=name,
18  dbfolderkey='oracle::SFO-based',
19  channelKeys = [(0,'#Events','EFEvents')])
20  if events:
21  self.cutRange = GetRanges(events)
22 
23 
24 
25  def __str__(self):
26  if self.applySelection:
27  return "SELOUT Checking if number of events matches %s" % self.events
28  else:
29  return "Retrieving event numbers"
30 
31  def select(self, runlist):
32 
33  # some preparation: compile the show patterns
34  start = time()
35 
36  print (self, end='')
37  sys.stdout.flush()
38  newrunlist = []
39  connection = coolDbConn.GetSFODBConnection()
40  cursor = connection.cursor()
41  cursor.arraysize = 1000
42 
43  runnrlist = [r.runNr for r in runlist]
44 
45  from CoolRunQuery.AtlRunQuerySFO import GetSFO_NphysicseventsAll
46  with timer("GetSFO_NphysicseventsAll", disabled=True):
47  events = GetSFO_NphysicseventsAll( cursor, runnrlist ) # { runnr: nPhysEvents }
48 
49  for run in runlist:
50 
51  iov = IOVRange(runStart=run.runNr, lbStart=1, runEnd=run.runNr+1, lbEnd=0)
52 
53  for k in self.ResultKey():
54  if run.runNr not in events:
55  # the OVERLAP_EVENTS information is not yet available in the SFO (before Nov 15, 2009)
56  # use the inclusive number instead
57  run.addResult(k, "n.a.", iov, reject=False)
58  run.showDataIncomplete=True
59  continue
60 
61  nev = events[run.runNr]
62 
63  if self.ApplySelection(k) and not self.passes(nev,k):
64  run.addResult(k, self.prettyValue(nev,k), iov, reject=True)
65  continue
66 
67  run.addResult(k, self.prettyValue(nev,k), iov)
68 
69  rej = self.rejectRun(run)
70 
71  if not rej:
72  newrunlist += [run.runNr]
73 
74  runlist = [r for r in runlist if r.runNr in newrunlist]
75 
76  duration = time() - start
77  if self.applySelection:
78  print (" ==> %i runs found (%.2f sec)" % (len(runlist),duration))
79  else:
80  print (" ==> Done (%g sec)" % duration)
81  return runlist
82 
83  def passes(self,values,key):
84  try:
85  val = int(values)
86  except ValueError: # if n.a.
87  self.selDataMissing = True
88  return True
89  for cr in self.cutRange:
90  if val>=cr[0] and val<=cr[1]:
91  return True
92  return False
93 
94 
96  def __init__(self, name, events=None):
97  self.events = events
98  self.showAllevents = False
99  super(AllEventsSelector,self).__init__(name=name,
100  dbfolderkey='COOLONL_TDAQ::/TDAQ/RunCtrl/EventCounters',
101  channelKeys = [(0,'#Events (incl. calib.)','EFEvents'),
102  (0,'#Events (streamed)','RecordedEvents'),
103  (0,'#L2A','L2Events')])
104  if events:
105  self.cutRange = GetRanges(events)
106 
107  def __str__(self):
108  if self.applySelection:
109  return "SELOUT Checking if number of events matches %s" % self.events
110  else:
111  return "Retrieving event numbers"
112 
113  def passes(self,values,key):
114  try:
115  val = int(values)
116  except ValueError: # if n.a.
117  self.selDataMissing = True
118  return True
119  for cr in self.cutRange:
120  if val>=cr[0] and val<=cr[1]:
121  return True
122  return False
123 
125  def __init__(self, name, events=None):
126  self.events = events
127  self.showL1events = False
128  super(L1EventsSelector,self).__init__(name=name,
129  dbfolderkey='COOLONL_TRIGGER::/TRIGGER/LVL1/CTPCORELBDATA',
130  channelKeys = [(0,'#L1A','GlobalL1AcceptCounter')])
131  def setShowL1events(self):
132  self.showL1events = True
133  super(L1EventsSelector,self).setShowOutput()
134 
135  def __str__(self):
136  if self.applySelection:
137  return "SELOUT Checking if number of L1A events matches %s" % self.events
138  else:
139  return "Retrieving L1A numbers"
140 
141  def passes(self,values,key):
142  return True
143 
python.selector.AtlRunQuerySelectorEvents.AllEventsSelector
Definition: AtlRunQuerySelectorEvents.py:95
python.selector.AtlRunQuerySelectorEvents.AllEventsSelector.passes
def passes(self, values, key)
Definition: AtlRunQuerySelectorEvents.py:113
python.selector.AtlRunQuerySelectorEvents.EventSelector.cutRange
cutRange
Definition: AtlRunQuerySelectorEvents.py:21
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.selector.AtlRunQuerySelectorEvents.EventSelector.__init__
def __init__(self, name, events=None)
Definition: AtlRunQuerySelectorEvents.py:15
python.selector.AtlRunQuerySelectorEvents.AllEventsSelector.__str__
def __str__(self)
Definition: AtlRunQuerySelectorEvents.py:107
python.selector.AtlRunQuerySelectorEvents.EventSelector.select
def select(self, runlist)
Definition: AtlRunQuerySelectorEvents.py:31
python.selector.AtlRunQuerySelectorEvents.EventSelector.events
events
Definition: AtlRunQuerySelectorEvents.py:16
python.selector.AtlRunQuerySelectorBase.Selector.applySelection
applySelection
Definition: AtlRunQuerySelectorBase.py:150
python.selector.AtlRunQuerySelectorBase.Condition.setShowOutput
def setShowOutput(self, listofchans=None)
Definition: AtlRunQuerySelectorBase.py:249
python.selector.AtlRunQuerySelectorEvents.AllEventsSelector.cutRange
cutRange
Definition: AtlRunQuerySelectorEvents.py:105
python.selector.AtlRunQuerySelectorBase.Selector.ApplySelection
def ApplySelection(self, key)
Definition: AtlRunQuerySelectorBase.py:156
python.selector.AtlRunQuerySelectorEvents.AllEventsSelector.showAllevents
showAllevents
Definition: AtlRunQuerySelectorEvents.py:98
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
python.selector.AtlRunQuerySelectorEvents.L1EventsSelector.showL1events
showL1events
Definition: AtlRunQuerySelectorEvents.py:127
python.selector.AtlRunQuerySelectorEvents.AllEventsSelector.events
events
Definition: AtlRunQuerySelectorEvents.py:97
python.AtlRunQuerySFO.GetSFO_NphysicseventsAll
def GetSFO_NphysicseventsAll(cursor, runlist)
Definition: AtlRunQuerySFO.py:250
python.selector.AtlRunQuerySelectorEvents.EventSelector.__str__
def __str__(self)
Definition: AtlRunQuerySelectorEvents.py:25
python.selector.AtlRunQuerySelectorEvents.L1EventsSelector
Definition: AtlRunQuerySelectorEvents.py:124
python.selector.AtlRunQuerySelectorEvents.EventSelector
Definition: AtlRunQuerySelectorEvents.py:14
python.selector.AtlRunQuerySelectorEvents.L1EventsSelector.__init__
def __init__(self, name, events=None)
Definition: AtlRunQuerySelectorEvents.py:125
python.selector.AtlRunQuerySelectorBase.RunLBBasedCondition.rejectRun
def rejectRun(self, run)
Definition: AtlRunQuerySelectorBase.py:448
python.selector.AtlRunQuerySelectorEvents.AllEventsSelector.__init__
def __init__(self, name, events=None)
Definition: AtlRunQuerySelectorEvents.py:96
python.utils.AtlRunQueryUtils.GetRanges
def GetRanges(rangestr, intRepFnc=stringToIntOrTime, maxval=1<< 30)
Definition: AtlRunQueryUtils.py:328
python.selector.AtlRunQuerySelectorBase.Condition.ResultKey
def ResultKey(self)
Definition: AtlRunQuerySelectorBase.py:231
python.selector.AtlRunQuerySelectorEvents.L1EventsSelector.passes
def passes(self, values, key)
Definition: AtlRunQuerySelectorEvents.py:141
python.selector.AtlRunQuerySelectorBase.Condition.selDataMissing
selDataMissing
Definition: AtlRunQuerySelectorBase.py:169
python.selector.AtlRunQuerySelectorEvents.EventSelector.passes
def passes(self, values, key)
Definition: AtlRunQuerySelectorEvents.py:83
python.selector.AtlRunQuerySelectorEvents.L1EventsSelector.events
events
Definition: AtlRunQuerySelectorEvents.py:126
python.selector.AtlRunQuerySelectorBase.Selector.prettyValue
def prettyValue(self, value, key)
Definition: AtlRunQuerySelectorBase.py:154
python.selector.AtlRunQuerySelectorEvents.L1EventsSelector.__str__
def __str__(self)
Definition: AtlRunQuerySelectorEvents.py:135
python.selector.AtlRunQuerySelectorBase.RunLBBasedCondition
Definition: AtlRunQuerySelectorBase.py:265
python.selector.AtlRunQuerySelectorEvents.L1EventsSelector.setShowL1events
def setShowL1events(self)
Definition: AtlRunQuerySelectorEvents.py:131