4 from __future__
import print_function
6 from time
import gmtime
8 from CoolRunQuery.AtlRunQueryRun
import Run
9 from CoolRunQuery.utils.AtlRunQueryUtils
import coolDbConn, GetRanges
10 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector, RunLBBasedCondition, TimeBasedCondition, DataKey
19 super(FilenameSelector,self).
__init__(name=name,
20 dbfolderkey=
'COOLONL_TDAQ::/TDAQ/RunCtrl/SOR%s' % (
"_Params" if Selector.condDB() ==
"COMP200" else ""),
21 channelKeys = [(0,
'Project tag',
'FilenameTag' if Selector.condDB() ==
"COMP200" else 'T0ProjectTag')])
24 if self.applySelection:
25 return 'SELOUT Checking if the filename tag matches "%s"' % self.
filenametag
27 return "Retrieving filenametag"
38 super(PartitionSelector,self).
__init__(name=name,
39 dbfolderkey=
'COOLONL_TDAQ::/TDAQ/RunCtrl/EventCounters',
40 channelKeys = [(0,
'Partition',
'PartitionName')])
43 if self.applySelection:
44 return 'SELOUT Checking if partition name matches "%s"' % self.
partition
46 return "Retrieving partition name"
55 def __init__(self, name, readyforphysics=None):
57 super(ReadyForPhysicsSelector,self).
__init__(name=name,
58 dbfolderkey=
'COOLONL_TDAQ::/TDAQ/RunCtrl/DataTakingMode',
59 channelKeys = [(0,
'Ready for physics',
'ReadyForPhysics')])
62 if self.applySelection:
63 return 'SELOUT Checking if ReadyForPhysics flag matches "%s"' % self.
readyforphysics
65 return "Retrieving ReadyForPhysics flag"
76 self.
geReq = (duration[-1]!=
'-')
78 super(DurationSelector,self).
__init__(name)
80 return "SELOUT Checking if duration of run is %s than %i seconds" % (
"more" if self.
geReq else "less",self.
duration)
85 rmlist = [r
for r
in runlist
if (r.eor-r.sor)/1E9<self.
duration]
87 rmlist = [r
for r
in runlist
if (r.eor-r.sor)/1E9>self.
duration]
90 if self.applySelection:
91 print (
" ==> %i runs selected" % len(runlist))
96 def __init__(self, name, dmin=None, dmout=None):
116 if Selector.condDB() ==
"COMP200":
117 dbfolder =
"/TDAQ/RunCtrl/SOR_Params"
118 if Selector.condDB() ==
"CONDBR2":
119 dbfolder =
"/TDAQ/RunCtrl/SOR"
121 super(DetectorSelector,self).
__init__(name=name,
122 dbfolderkey=
'COOLONL_TDAQ::%s' % dbfolder,
123 channelKeys = [(0,
'Detector systems',
'DetectorMask')])
125 self.data_keys[0]._type = DataKey.DETECTOR
130 if self.applySelection:
131 if self.
bm!=0
and self.
bmany!=0:
132 return "SELOUT Checking if [detector mask & %i] matches %i and [detector mask & %i] is greater 0" % (self.
bm,self.
bp,self.
bmany)
134 return "SELOUT Checking if [detector mask & %i] is greater 0" % self.
bmany
136 return "SELOUT Checking if [detector mask & %i] matches %i" % (self.
bm,self.
bp)
138 return "Retrieving detector mask"
148 retval &= ((val & self.
bm) == self.
bp)
150 retval &= ((val & self.
bmany) != 0)
155 run 1: run 211541 has DetectorMask 281474976710647
156 run 2: run 252233 has DetectorMask 0d00069fffffffff0
164 def __init__(self, name, condition=None, channel=0, resDictKey=''):
165 super(BFieldCondition,self).
__init__(name,
166 dbfolderkey=
'COOLOFL_DCS::/EXT/DCS/MAGNETS/SENSORDATA',
167 channelKeys = [(channel,resDictKey,
'value')])
171 if self.applySelection:
173 txt =
'[%.0f,+inf]' % (self.
cutRange[0][0])
176 return "SELOUT Checking if the %s is within %s" % (
', '.
join(self.ResultKey()), txt)
178 return "Retrieving magnet currents %s" % self.ResultKey()
182 val = abs(
float(values))
187 if val>=cr[0]
and val<=cr[1]:
199 super(BFieldSelector,self).
__init__(name)
202 if 'solenoidon' in bf
or 'solenoidoff' in bf:
204 if 'solenoidon' in bf:
206 elif 'solenoidoff' in bf:
209 if 'toroidon' in bf
or 'toroidoff' in bf:
213 elif 'toroidoff' in bf:
221 sel.applySelection =
False
236 if s.name ==
'csolcur':
238 if s.name ==
'ctorcur':
241 sol =
BFieldCondition(
'csolcur', channel = 1, resDictKey =
'SolCurrent')
242 sol.applySelection =
False
245 tor =
BFieldCondition(
'ctorcur', channel = 3, resDictKey =
'TorCurrent')
246 tor.applySelection =
False
253 runlist = sel.select(runlist)
261 super(BPMSelector,self).
__init__(name)
264 return "Retrieving Beam Position Monitor values from PVSS archive"
274 from CoolRunQuery.AtlRunQueryPVSS
import GetPVSS_BPMs
275 pvssdb = coolDbConn.GetPVSSDBConnection()
276 cursor = pvssdb.cursor()
277 cursor.arraysize = 1000
279 t = gmtime(r.sor/1.E9)
280 sor =
"%02i-%02i-%4i %02i:%02i:%02i" % (t[2], t[1], t[0], t[3], t[4], t[5])
281 t = gmtime(r.eor/1.E9)
282 eor =
"%02i-%02i-%4i %02i:%02i:%02i" % (t[2], t[1], t[0], t[3], t[4], t[5])
286 r.addResult(
'BPM', res )
288 Run.AddToShowOrder(DataKey(
'BPM'))
297 super(DatasetsSelector,self).
__init__(name)
300 return "Retrieving datasets from Tier-0 DB"
309 if pattern.lower() ==
'caf':
315 if 'caf' == sp[0].lower():
318 elif 'caf' == sp[1].lower():
323 print (
'ERROR: wrong format in "show dataset". Usage: "show dataset [pattern] [caf]"')
332 from CoolRunQuery.AtlRunQueryTier0
import GetTier0_allDatasets
333 runnrlist = [r.runNr
for r
in runlist]
334 tier0connection = coolDbConn.GetTier0DBConnection()
338 if run.runNr
in tier0retdico:
339 run.addResult(
'Datasets', tier0retdico[run.runNr])
341 run.addResult(
'Datasets', {})
343 Run.AddToShowOrder(DataKey(
'Datasets'))
350 super(LArcondSelector,self).
__init__(name=name,
351 dbfolderkey=
'COOLONL_LAR::/LAR/Configuration/RunLog',
352 channelKeys = [(0,
'lar:runtype',
'runType'),
353 (0,
'lar:nsamples',
'nbOfSamples'),
354 (0,
'lar:format',
'format')])
360 larcondargs = c.split()
361 if len(larcondargs) == 2:
362 key =
'lar:' + larcondargs[0].strip().lower()
364 if key
not in self.ResultKey():
365 print (
'ERROR: unknown larcond variable "%s"' % key)
367 self.
larcond[key] = larcondargs[1].strip()
369 print (
'ERROR: unknown condition format for larcond: "%s" -> need two arguments separated by blank' % larcondargs)
374 if self.applySelection:
375 return "SELOUT Checking if LAr condition matches %s" % self.
larcond
377 return "Retrieving LAr run conditions"
380 if key.lower().strip()
in self.
larcond:
381 if values.strip() == self.
larcond[key.lower().strip()]: