4 from CoolRunQuery.utils.AtlRunQueryTimer
import timer
5 from CoolRunQuery.utils.AtlRunQueryUtils
import GetRanges
7 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector, RunLBBasedCondition, TimeBasedCondition
11 super(LHCSelector,self).
__init__(name)
33 def __init__(self, name, condition=[], channel=0, addArg=''):
34 ck = [(1,
'lhc:fillnumber',
'FillNumber'),
35 (1,
'lhc:stablebeams',
'StableBeams'),
36 (1,
'lhc:beamenergy',
'BeamEnergyGeV')]
38 ck += [(1,
'lhc:beammode',
'BeamMode')]
40 ck = [(1,
'lhc:stablebeams',
'StableBeams')]
41 super(LHCCondition,self).
__init__(name=name,
42 dbfolderkey=
'COOLOFL_DCS::/LHC/DCS/FILLSTATE',
51 key =
'lhc:' + lhcargs[0].strip().lower()
53 if key
not in self.ResultKey():
54 print (
'ERROR: unknown LHC variable "%s"' % key)
57 cond = lhcargs[1].strip()
63 self.
lhc[key] = [[cond]]
66 print (
'ERROR: unknown condition format for LHC: "%s" -> need two arguments separated by blank' % lhcargs)
70 ck = [
'lhc:fillnumber',
'lhc:stablebeams',
'lhc:beamenergy']
72 ck += [
'lhc:beammode']
74 ck = [
'lhc:stablebeams']
78 if self.applySelection:
79 return "SELOUT Checking if LHC fill state information %s" % self.
lhc
81 return "Retrieving LHC fill state information"
95 for cr
in self.
lhc[k]:
96 if v >= cr[0]
and v <= cr[1]:
107 if value == self.
lhc[k][0][0]:
113 super(OLCFillParamsCondition,self).
__init__(name=name,
114 dbfolderkey=
'COOLONL_TDAQ::/TDAQ/OLC/LHC/FILLPARAMS',
115 channelKeys = [(0,
'olc:beam1bunches',
'Beam1Bunches'),
116 (0,
'olc:beam2bunches',
'Beam2Bunches'),
117 (0,
'olc:collbunches',
'LuminousBunches'),
118 (0,
'olc:bcidmask',
'BCIDmasks')])
122 if self.applySelection:
123 return "SELOUT Checking if online lumi is %s" % self.olc
125 return "Retrieving online lumi information /TDAQ/OLC/LHC/FILLPARAMS"
128 if k
not in self.
onl:
132 if values == self.
onl[k]:
138 for k
in self.ResultKey():
139 with timer(
"olc afterquery blocks prepare for: %s" % k):
142 if k
not in run.data:
145 for entry
in run.data[k]:
147 if k!=
'olc:bcidmask':
149 if len(blocks) > 0
and blocks[-1][0]==v
and blocks[-1][2]==entry.startlb:
150 blocks[-1][2] = entry.endlb
152 blocks += [ [v, entry.startlb, entry.endlb] ]
153 run.stats[k] = {
"blocks" : blocks,
"first" : run.data[k][0].value }
159 with timer(
"olc afterquery rest"):
160 from CoolRunQuery.utils.AtlRunQueryUtils
import unpackRun1BCIDMask, unpackRun2BCIDMask
163 if run.runNr < 151260:
167 xb1 = run.stats[
'olc:beam1bunches'][
'blocks']
168 xb2 = run.stats[
'olc:beam2bunches'][
'blocks']
169 xbc = run.stats[
'olc:collbunches'][
'blocks']
172 bcidmask = run.stats[
'olc:bcidmask'][
'blocks']
173 for i
in range(len(bcidmask)):
174 (bcidblob,lbstart,lbend) = bcidmask[i]
177 for nb1, b, e
in xb1:
178 if lbstart>=b
and lbstart<e:
180 for nb2, b, e
in xb2:
181 if lbstart>=b
and lbstart<e:
183 for nbc, b, e
in xbc:
184 if lbstart>=b
and lbstart<e:
188 bcidBlobLength = len(bcidblob)
189 if bcidBlobLength == 3564:
195 if len(bcidblob) == 2 * (nb1 + nb2 + nbc):
199 print (
"WARNING, bcidMask inconsistent",nb1, nb2, nbc,
"should add up to half of",len(bcidblob))
200 beam1, beam2, beam12 = ([],[],[])
203 bcidmask[i] = ((nb1, nb2, nbc), (beam1, beam2, beam12), lbstart, lbend)
207 super(OLCLBDataCondition,self).
__init__(name=name,
208 dbfolderkey=
'COOLONL_TDAQ::/TDAQ/OLC/LHC/LBDATA',
209 channelKeys = [(1,
'olc:beam1intensity',
'Beam1Intensity'),
210 (1,
'olc:beam2intensity',
'Beam2Intensity')])
218 if self.applySelection:
219 return "SELOUT Checking if online lumi is %s" % self.olc
221 return "Retrieving online lumi information /TDAQ/OLC/LHC/LBDATA"
224 if k
not in self.
onl:
228 if values == self.
onl[k]:
233 for k
in self.ResultKey():
237 if len(run.data[k])>0:
238 for entry
in run.data[k]:
240 if len(blocks) > 0
and blocks[-1][0]==v
and blocks[-1][2]==entry.startlb:
241 blocks[-1][2] = entry.endlb
243 blocks += [ [v, entry.startlb, entry.endlb] ]
244 first = run.data[k][0].value
245 run.stats[k] = {
"blocks" : blocks,
"first" : first }
253 name, sep, channel = name.partition(
' ')
255 channel =
int(channel)
263 units = [
'mb',
'ub',
'nb',
'pb',
'fb',
'ab',
'b' ]
264 factoub = [ 1e-3, 1, 1e3, 1e6, 1e9, 1e12, 1e-6 ]
270 for iu,u
in enumerate(units):
277 c = c.replace(
'+',
'').strip()
281 c = c.replace(
'-',
'').strip()
284 print (
"ERROR: in 'olc' condition: %s" % self.
condition)
288 super(OLCLumiCondition,self).
__init__(name=name,
289 dbfolderkey=(
'COOLONL_TRIGGER::/TRIGGER/LUMI/OnlPrefLumi' if self.isRun2()
else 'COOLONL_TRIGGER::/TRIGGER/LUMI/LBLESTONL'),
290 channelKeys = [(channel,
'olc:lumi:%i' % (channel),
'LBAvInstLumi')])
300 if self.applySelection:
301 return "SELOUT Checking if online lumi is %s" % self.
condition
303 return "Retrieving online lumi information /TRIGGER/LUMI/LBLESTONL"
307 if k
not in self.
olc:
312 if values == self.
olc[k]:
319 k = self.ResultKey()[0]
320 kst =
'lhc:stablebeams'
321 for ir,run
in enumerate(runlist):
322 for entry
in run.data[k]:
323 if entry.startlb == 0:
325 if entry.value !=
'n.a.':
326 if run.runNr <= 158632:
336 for ir,run
in enumerate(runlist):
339 for entry
in run.data[k]:
340 assert entry.startlb != 0,
'entry should not start at LB=0'
342 if entry.value !=
'n.a.':
343 val =
max(0,entry.value) * 1.e3
344 lbs =
range(entry.startlb,entry.endlb)
345 yvecInt += len(lbs)*[val]
348 print (run.data[kst].atLB(entry.startlb))
349 stable_beam = run.data[kst].atLB(entry.startlb)[0].value
350 if 'true' in stable_beam.lower():
355 for idx,(lbtime,lbendtime)
in enumerate(run.lbtimes):
359 yvecInt[idx] *= (
float(lbendtime)-
float(lbtime))/1.E9/1000.
360 intlumi += yvecInt[idx]
379 super(OLCLumiSelector,self).
__init__(name)
397 name, tag = (name.split(
None,1) + [
""])[:2]
404 self.
_dbfolderkey=
'COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/LBLESTOFL'
408 self.
_channelKeys = [(channel,
'ofllumi:%i:%s' % (channel,condtag),
'LBAvInstLumi')]
410 super(LuminositySelector,self).
__init__(name=name,
421 self.
_dbfolderkey=
'COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/OflPrefLumi'
423 self.
_dbfolderkey=
'COOLOFL_TRIGGER::/TRIGGER/OFLLUMI/LBLESTOFL'
426 self.
_channelKeys = [(channel,
'ofllumi:%i:%s' % (channel,condtag),
'LBAvInstLumi')]
453 if condtag
is not None:
454 print (
"Using channel %i and conditions tag %s" % (channel, condtag))
455 return channel, condtag
459 from PyCool
import cool
460 sys.path.append(
'/afs/cern.ch/user/a/atlcond/utils/python/')
462 from AtlCoolBKLib
import resolveAlias
464 cur = resolveAlias.getCurrent()
466 dbSvc = cool.DatabaseSvcFactory.databaseService()
468 db = dbSvc.openDatabase(
'oracle://ATLAS_COOLPROD;schema=ATLAS_COOLOFL_TRIGGER;dbname=CONDBR2',
False)
470 fld = db.getFolder(
'/TRIGGER/OFLLUMI/OflPrefLumi')
472 updLumiTag = fld.resolveTag(cur.replace(
'*',
'ST'))
475 except ImportError
as ex:
476 print (
"WARNING: ImportError, can not read conditions tag (likely an afs permission issue): ",ex)
477 condtag =
"OflPrefLumi-RUN2-UPD4-10"
478 except SyntaxError
as ex:
479 print (
"WARNING: SyntaxError, can not read conditions tag (need to understand where the py3 code is located): ",ex)
480 condtag =
"OflPrefLumi-RUN2-UPD4-10"
482 condtag =
"OflLumi-UPD2-006"
484 print (
"Using channel %i and conditions tag %s" % (channel, condtag))
485 return channel, condtag
490 return "SELOUT Checking if number of events matches %r" % self.
cutRange
492 return "Retrieving lumi numbers"
501 if val>=cr[0]
and val<=cr[1]:
511 folder =
'COOLOFL_INDET::/Indet/Beampos'
518 if args[0].lower().startswith(
'onl'):
521 folder =
'COOLONL_INDET::/Indet/Onl/Beampos'
522 self.
condtag =
'IndetBeamposOnl-HLT-UPD1-001-00'
525 self.
condtag =
'IndetBeamposOnl-LiveMon-001-00'
532 super(BeamspotSelector,self).
__init__(name = name,
533 dbfolderkey = folder,
535 (0,
'bs:Status',
'status'),
536 (0,
'bs:Pos-X', (
'posX',
'posXErr')),
537 (0,
'bs:Pos-Y', (
'posY',
'posYErr')),
538 (0,
'bs:Pos-Z', (
'posZ',
'posZErr')),
539 (0,
'bs:Sig-X', (
'sigmaX',
'sigmaXErr')),
540 (0,
'bs:Sig-Y', (
'sigmaY',
'sigmaYErr')),
541 (0,
'bs:Sig-Z', (
'sigmaZ',
'sigmaZErr')),
542 (0,
'bs:Sig-XY',(
'sigmaXY',
'sigmaXYErr')),
543 (0,
'bs:Tilt-X',(
'tiltX',
'tiltXErr')),
544 (0,
'bs:Tilt-Y',(
'tiltY',
'tiltYErr'))
551 if self.applySelection:
552 return "SELOUT Checking if %s beamspot information matches %s" % (
"offline" if self.
isOffline else "online", self.
bs)
554 return "Retrieving %s beamspot information" % (
"offline" if self.
isOffline else "online",)
557 if type(value)==tuple:
558 return tuple(map(float,value))
569 if val>=cr[0]
and val<=cr[1]:
574 whatitis =
'offline' if self.
isOffline else 'online'
575 from CoolRunQuery.AtlRunQueryRun
import Run
576 Run.BeamspotSource =
'%s, COOL tag: %s' % (whatitis, self.
condtag)
578 run.stats[
'Beamspot'] = whatitis
580 if __name__ ==
"__main__":
582 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector
583 from CoolRunQuery.selector.AtlRunQuerySelectorRuntime
import RunTimeSelector
585 runNumbers =
"251103,251106,251363,251367,251371,251663,251666,251667,251669,266904,"
586 runNumbers +=
"266919,267073,251863,251869,251873,251876,251880,252009,252044,252072,"
587 runNumbers +=
"252099,252115,267148,267152,267162,252179,252186,252194,252198,252207,"
588 runNumbers +=
"252220,252222,252223,252226,252233,252376,252380,252390,267167,252402,"
589 runNumbers +=
"252404,252589,252604,252608,252662,252663,252838,252840,252844,252854,"
590 runNumbers +=
"253009,253010,253014,267638,267639"
594 Selector._conddb =
"CONDBR2"
596 print(Selector.condDB())
600 sel.applySelection =
False
603 rtSel = RunTimeSelector(name =
'runtime', runlist = runNumbers.split(
","))
606 runlist = rtSel.select()
608 from CoolRunQuery.AtlRunQuerySelectorWorker
import SelectorWorker
610 SelectorWorker.addSelector(selector=sel, priority=1)
611 sd = SelectorWorker.findSelectorDescriptor(sel.name)
612 sd.doesSelect =
False
616 for sd
in SelectorWorker.getOrderedSelectorList():
618 if hasattr(s,
'initialize'):
619 with timer(
"initializing selector '%s'" % s.name):
624 for s
in SelectorWorker.selectors():
625 with timer(
"run selector '%s'" % s.name):
627 runlist = s.select(runlist)
628 selectionOutput += [
"%s" % s.__str__()]
629 with timer(
"run AfterQuery for selector '%s'" % s.name):
630 s.runAfterQuery(runlist)