3 from __future__
import print_function
5 from CoolRunQuery.utils.AtlRunQueryTimer
import timer
6 from CoolRunQuery.utils.AtlRunQueryUtils
import GetRanges
8 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector, RunLBBasedCondition, TimeBasedCondition
12 super(LHCSelector,self).
__init__(name)
34 def __init__(self, name, condition=[], channel=0, addArg=''):
35 ck = [(1,
'lhc:fillnumber',
'FillNumber'),
36 (1,
'lhc:stablebeams',
'StableBeams'),
37 (1,
'lhc:beamenergy',
'BeamEnergyGeV')]
39 ck += [(1,
'lhc:beammode',
'BeamMode')]
41 ck = [(1,
'lhc:stablebeams',
'StableBeams')]
42 super(LHCCondition,self).
__init__(name=name,
43 dbfolderkey=
'COOLOFL_DCS::/LHC/DCS/FILLSTATE',
52 key =
'lhc:' + lhcargs[0].strip().lower()
54 if key
not in self.ResultKey():
55 print (
'ERROR: unknown LHC variable "%s"' % key)
58 cond = lhcargs[1].strip()
64 self.
lhc[key] = [[cond]]
67 print (
'ERROR: unknown condition format for LHC: "%s" -> need two arguments separated by blank' % lhcargs)
71 ck = [
'lhc:fillnumber',
'lhc:stablebeams',
'lhc:beamenergy']
73 ck += [
'lhc:beammode']
75 ck = [
'lhc:stablebeams']
79 if self.applySelection:
80 return "SELOUT Checking if LHC fill state information %s" % self.
lhc
82 return "Retrieving LHC fill state information"
96 for cr
in self.
lhc[k]:
97 if v >= cr[0]
and v <= cr[1]:
108 if value == self.
lhc[k][0][0]:
114 super(OLCFillParamsCondition,self).
__init__(name=name,
115 dbfolderkey=
'COOLONL_TDAQ::/TDAQ/OLC/LHC/FILLPARAMS',
116 channelKeys = [(0,
'olc:beam1bunches',
'Beam1Bunches'),
117 (0,
'olc:beam2bunches',
'Beam2Bunches'),
118 (0,
'olc:collbunches',
'LuminousBunches'),
119 (0,
'olc:bcidmask',
'BCIDmasks')])
123 if self.applySelection:
124 return "SELOUT Checking if online lumi is %s" % self.olc
126 return "Retrieving online lumi information /TDAQ/OLC/LHC/FILLPARAMS"
129 if k
not in self.
onl:
133 if values == self.
onl[k]:
139 for k
in self.ResultKey():
140 with timer(
"olc afterquery blocks prepare for: %s" % k):
143 if k
not in run.data:
146 for entry
in run.data[k]:
148 if k!=
'olc:bcidmask':
150 if len(blocks) > 0
and blocks[-1][0]==v
and blocks[-1][2]==entry.startlb:
151 blocks[-1][2] = entry.endlb
153 blocks += [ [v, entry.startlb, entry.endlb] ]
154 run.stats[k] = {
"blocks" : blocks,
"first" : run.data[k][0].value }
160 with timer(
"olc afterquery rest"):
161 from CoolRunQuery.utils.AtlRunQueryUtils
import unpackRun1BCIDMask, unpackRun2BCIDMask
164 if run.runNr < 151260:
168 xb1 = run.stats[
'olc:beam1bunches'][
'blocks']
169 xb2 = run.stats[
'olc:beam2bunches'][
'blocks']
170 xbc = run.stats[
'olc:collbunches'][
'blocks']
173 bcidmask = run.stats[
'olc:bcidmask'][
'blocks']
174 for i
in range(len(bcidmask)):
175 (bcidblob,lbstart,lbend) = bcidmask[i]
178 for nb1, b, e
in xb1:
179 if lbstart>=b
and lbstart<e:
181 for nb2, b, e
in xb2:
182 if lbstart>=b
and lbstart<e:
184 for nbc, b, e
in xbc:
185 if lbstart>=b
and lbstart<e:
189 bcidBlobLength = len(bcidblob)
190 if bcidBlobLength == 3564:
196 if len(bcidblob) == 2 * (nb1 + nb2 + nbc):
200 print (
"WARNING, bcidMask inconsistent",nb1, nb2, nbc,
"should add up to half of",len(bcidblob))
201 beam1, beam2, beam12 = ([],[],[])
204 bcidmask[i] = ((nb1, nb2, nbc), (beam1, beam2, beam12), lbstart, lbend)
208 super(OLCLBDataCondition,self).
__init__(name=name,
209 dbfolderkey=
'COOLONL_TDAQ::/TDAQ/OLC/LHC/LBDATA',
210 channelKeys = [(1,
'olc:beam1intensity',
'Beam1Intensity'),
211 (1,
'olc:beam2intensity',
'Beam2Intensity')])
219 if self.applySelection:
220 return "SELOUT Checking if online lumi is %s" % self.olc
222 return "Retrieving online lumi information /TDAQ/OLC/LHC/LBDATA"
225 if k
not in self.
onl:
229 if values == self.
onl[k]:
234 for k
in self.ResultKey():
238 if len(run.data[k])>0:
239 for entry
in run.data[k]:
241 if len(blocks) > 0
and blocks[-1][0]==v
and blocks[-1][2]==entry.startlb:
242 blocks[-1][2] = entry.endlb
244 blocks += [ [v, entry.startlb, entry.endlb] ]
245 first = run.data[k][0].value
246 run.stats[k] = {
"blocks" : blocks,
"first" : first }
254 name, sep, channel = name.partition(
' ')
256 channel =
int(channel)
264 units = [
'mb',
'ub',
'nb',
'pb',
'fb',
'ab',
'b' ]
265 factoub = [ 1e-3, 1, 1e3, 1e6, 1e9, 1e12, 1e-6 ]
271 for iu,u
in enumerate(units):
278 c = c.replace(
'+',
'').strip()
282 c = c.replace(
'-',
'').strip()
285 print (
"ERROR: in 'olc' condition: %s" % self.
condition)
289 super(OLCLumiCondition,self).
__init__(name=name,
290 dbfolderkey=(
'COOLONL_TRIGGER::/TRIGGER/LUMI/OnlPrefLumi' if self.isRun2()
else 'COOLONL_TRIGGER::/TRIGGER/LUMI/LBLESTONL'),
291 channelKeys = [(channel,
'olc:lumi:%i' % (channel),
'LBAvInstLumi')])
301 if self.applySelection:
302 return "SELOUT Checking if online lumi is %s" % self.
condition
304 return "Retrieving online lumi information /TRIGGER/LUMI/LBLESTONL"
308 if k
not in self.
olc:
313 if values == self.
olc[k]:
320 k = self.ResultKey()[0]
321 kst =
'lhc:stablebeams'
322 for ir,run
in enumerate(runlist):
323 for entry
in run.data[k]:
324 if entry.startlb == 0:
326 if entry.value !=
'n.a.':
327 if run.runNr <= 158632:
337 for ir,run
in enumerate(runlist):
340 for entry
in run.data[k]:
341 assert entry.startlb != 0,
'entry should not start at LB=0'
343 if entry.value !=
'n.a.':
344 val =
max(0,entry.value) * 1.e3
345 lbs =
range(entry.startlb,entry.endlb)
346 yvecInt += len(lbs)*[val]
349 print (run.data[kst].atLB(entry.startlb))
350 stable_beam = run.data[kst].atLB(entry.startlb)[0].value
351 if 'true' in stable_beam.lower():
356 for idx,(lbtime,lbendtime)
in enumerate(run.lbtimes):
360 yvecInt[idx] *= (
float(lbendtime)-
float(lbtime))/1.E9/1000.
361 intlumi += yvecInt[idx]
380 super(OLCLumiSelector,self).
__init__(name)
398 name, tag = (name.split(
None,1) + [
""])[:2]
405 self.
_dbfolderkey=
'COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/LBLESTOFL'
409 self.
_channelKeys = [(channel,
'ofllumi:%i:%s' % (channel,condtag),
'LBAvInstLumi')]
411 super(LuminositySelector,self).
__init__(name=name,
422 self.
_dbfolderkey=
'COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/OflPrefLumi'
424 self.
_dbfolderkey=
'COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/LBLESTOFL'
427 self.
_channelKeys = [(channel,
'ofllumi:%i:%s' % (channel,condtag),
'LBAvInstLumi')]
454 if condtag
is not None:
455 print (
"Using channel %i and conditions tag %s" % (channel, condtag))
456 return channel, condtag
460 from PyCool
import cool
461 sys.path.append(
'/afs/cern.ch/user/a/atlcond/utils/python/')
463 from AtlCoolBKLib
import resolveAlias
465 cur = resolveAlias.getCurrent()
467 dbSvc = cool.DatabaseSvcFactory.databaseService()
469 db = dbSvc.openDatabase(
'oracle://ATLAS_COOLPROD;schema=ATLAS_COOLOFL_TRIGGER;dbname=CONDBR2',
False)
471 fld = db.getFolder(
'/TRIGGER/OFLLUMI/OflPrefLumi')
473 updLumiTag = fld.resolveTag(cur.replace(
'*',
'ST'))
476 except ImportError
as ex:
477 print (
"WARNING: ImportError, can not read conditions tag (likely an afs permission issue): ",ex)
478 condtag =
"OflPrefLumi-RUN2-UPD4-10"
479 except SyntaxError
as ex:
480 print (
"WARNING: SyntaxError, can not read conditions tag (need to understand where the py3 code is located): ",ex)
481 condtag =
"OflPrefLumi-RUN2-UPD4-10"
483 condtag =
"OflLumi-UPD2-006"
485 print (
"Using channel %i and conditions tag %s" % (channel, condtag))
486 return channel, condtag
491 return "SELOUT Checking if number of events matches %r" % self.
cutRange
493 return "Retrieving lumi numbers"
502 if val>=cr[0]
and val<=cr[1]:
512 folder =
'COOLOFL_INDET::/Indet/Beampos'
519 if args[0].lower().startswith(
'onl'):
522 folder =
'COOLONL_INDET::/Indet/Onl/Beampos'
523 self.
condtag =
'IndetBeamposOnl-HLT-UPD1-001-00'
526 self.
condtag =
'IndetBeamposOnl-LiveMon-001-00'
533 super(BeamspotSelector,self).
__init__(name = name,
534 dbfolderkey = folder,
536 (0,
'bs:Status',
'status'),
537 (0,
'bs:Pos-X', (
'posX',
'posXErr')),
538 (0,
'bs:Pos-Y', (
'posY',
'posYErr')),
539 (0,
'bs:Pos-Z', (
'posZ',
'posZErr')),
540 (0,
'bs:Sig-X', (
'sigmaX',
'sigmaXErr')),
541 (0,
'bs:Sig-Y', (
'sigmaY',
'sigmaYErr')),
542 (0,
'bs:Sig-Z', (
'sigmaZ',
'sigmaZErr')),
543 (0,
'bs:Sig-XY',(
'sigmaXY',
'sigmaXYErr')),
544 (0,
'bs:Tilt-X',(
'tiltX',
'tiltXErr')),
545 (0,
'bs:Tilt-Y',(
'tiltY',
'tiltYErr'))
552 if self.applySelection:
553 return "SELOUT Checking if %s beamspot information matches %s" % (
"offline" if self.
isOffline else "online", self.
bs)
555 return "Retrieving %s beamspot information" % (
"offline" if self.
isOffline else "online",)
558 if type(value)==tuple:
559 return tuple(map(float,value))
570 if val>=cr[0]
and val<=cr[1]:
575 whatitis =
'offline' if self.
isOffline else 'online'
576 from CoolRunQuery.AtlRunQueryRun
import Run
577 Run.BeamspotSource =
'%s, COOL tag: %s' % (whatitis, self.
condtag)
579 run.stats[
'Beamspot'] = whatitis
581 if __name__ ==
"__main__":
583 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector
584 from CoolRunQuery.selector.AtlRunQuerySelectorRuntime
import RunTimeSelector
586 runNumbers =
"251103,251106,251363,251367,251371,251663,251666,251667,251669,266904,"
587 runNumbers +=
"266919,267073,251863,251869,251873,251876,251880,252009,252044,252072,"
588 runNumbers +=
"252099,252115,267148,267152,267162,252179,252186,252194,252198,252207,"
589 runNumbers +=
"252220,252222,252223,252226,252233,252376,252380,252390,267167,252402,"
590 runNumbers +=
"252404,252589,252604,252608,252662,252663,252838,252840,252844,252854,"
591 runNumbers +=
"253009,253010,253014,267638,267639"
595 Selector._conddb =
"CONDBR2"
597 print(Selector.condDB())
601 sel.applySelection =
False
604 rtSel = RunTimeSelector(name =
'runtime', runlist = runNumbers.split(
","))
607 runlist = rtSel.select()
609 from CoolRunQuery.AtlRunQuerySelectorWorker
import SelectorWorker
611 SelectorWorker.addSelector(selector=sel, priority=1)
612 sd = SelectorWorker.findSelectorDescriptor(sel.name)
613 sd.doesSelect =
False
617 for sd
in SelectorWorker.getOrderedSelectorList():
619 if hasattr(s,
'initialize'):
620 with timer(
"initializing selector '%s'" % s.name):
625 for s
in SelectorWorker.selectors():
626 with timer(
"run selector '%s'" % s.name):
628 runlist = s.select(runlist)
629 selectionOutput += [
"%s" % s.__str__()]
630 with timer(
"run AfterQuery for selector '%s'" % s.name):
631 s.runAfterQuery(runlist)