ATLAS Offline Software
AtlRunQueryLookup.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 #
5 # ----------------------------------------------------------------
6 # Script : AtlRunQueryLookup.py
7 # Project: AtlRunQuery
8 # Purpose: Library with references for DQ flags and detector mask
9 # Authors: Andreas Hoecker (CERN), Joerg Stelzer (DESY)
10 # Created: Nov 13, 2008
11 # ----------------------------------------------------------------
12 #
13 # See: DetectorDescription/DetDescrCond/DetectorStatus/doc/mainpage.h
14 # Decription:
15 # http://alxr.usatlas.bnl.gov/lxr/source/atlas/DetectorDescription/DetDescrCond/DetectorStatus/doc/mainpage.h
16 # Implementation:
17 # http://alxr.usatlas.bnl.gov/lxr/source/atlas/DetectorDescription/DetDescrCond/DetectorStatus/python/DetStatusLib.py
18 
19 import sys
20 
21 DQChannelDict = {'PIXB':101,'PIX0':102,'PIXEA':104,'PIXEC':105,
22  'SCTB':111,'SCTEA':114,'SCTEC':115,
23  'TRTB':121,'TRTEA':124,'TRTEC':125,'TRTTR':126,
24  'IDGL':130, # Obsolete: 'IDGB OBSOLETE':131,'IDGEA OBSOLETE':134,'IDGEC OBSOLETE':135,
25  'IDAL':140, # Obsolete: 'IDAB OBSOLETE':141,'IDAEA OBSOLETE':144,'IDAEC OBSOLETE':145,
26  'IDBS':150,
27  'IDVX':161,
28  'IDBCM':170,
29  'EMBA':202,'EMBC':203,'EMECA':204,'EMECC':205,
30  'HECA':214,'HECC':215,
31  'FCALA':224,'FCALC':225,
32  'TIGB':230,
33  'TILBA':232,'TILBC':233,'TIEBA':234,'TIEBC':235,
34  'MBTSA':244,'MBTSC':245,
35  'CALBA':251,'CALEA':254,'CALEC':255,
36  'MDTBA':302,'MDTBC':303,'MDTEA':304,'MDTEC':305,
37  'RPCBA':312,'RPCBC':313,
38  'TGCEA':324,'TGCEC':325,
39  'CSCEA':334,'CSCEC':335,
40  'LCDA':353,'LCDC':354,
41  'ALFA':360,'ZDC':370,
42  'L1CAL':401,'L1MUB':402,'L1MUE':403,'L1CTP':404,
43  'TRCAL':411,
44  'TRBJT':421,'TRBPH':422,'TRCOS':423,'TRELE':424,
45  'TRGAM':425,'TRJET':426,'TRMET':427,'TRMBI':428,
46  'TRMUO':429,'TRTAU':430,'TRIDT':431,
47  'LUMI':450, 'LUMIONL':451,
48  'RUNCLT':460,
49  'RCOPS':461,
50  'ATLGL':480,'ATLSOL':481,'ATLTOR':482,
51  'EIDB':501,'EIDCR':502,'EIDE':503,
52  'PIDB':505,'PIDCR':506,'PIDE':507,
53  'EIDF':508,'EIDSOFT':509,
54  'MSTACO':510,'MMUIDCB':511,'MMUIDVX':512,
55  'MMUGIRL':513,'MMUBOY':514,'MMUIDSA':515,
56  'MMUTAG':516,'MMTIMO':517,'MCMUTAG':518,
57  'MCALLHR':519,
58  'JETB':521,'JETEA':524,'JETEC':525,
59  'JETFA':526,'JETFC':527,
60  'METCALO':531,'METMUON':532,
61  'BTGLIFE':541,'BTGSOFTE':544,'BTGSOFTM':545,
62  'TAUB':551,'TAUCR':552,'TAUE':553}
63 
64 DQSuperGroupsDict = {1 : ['Inner detector', ['PIXB','PIX0','PIXEA','PIXEC','SCTB','SCTEA','SCTEC','TRTB','TRTEA','TRTEC','TRTTR',
65  'IDGL','IDAL','IDBS','IDVX']],
66  2 : ['Calorimeter', ['EMBA','EMBC','EMECA','EMECC','HECA','HECC','FCALA','FCALC',
67  'TIGB','TILBA','TILBC','TIEBA','TIEBC','CALBA','CALEA','CALEC']],
68  3 : ['Muon systems', ['MDTBA','MDTBC','MDTEA','MDTEC','RPCBA','RPCBC','TGCEA','TGCEC','CSCEA','CSCEC']],
69  4 : ['Forward detectors and luminosity', ['MBTSA','MBTSC','IDBCM','LCDA','LCDC','ALFA','ZDC','LUMI']],
70  5 : ['Global, Magnets, DAQ and Trigger',['ATLGL','ATLSOL','ATLTOR','RUNCLT','RCOPS',
71  'L1CAL','L1MUB','L1MUE','L1CTP',
72  'TRCAL','TRBJT','TRBPH','TRCOS','TRELE','TRGAM','TRJET','TRMET','TRMBI','TRMUO','TRTAU','TRIDT']],
73  6 : ['Combined performance', ['EIDB','EIDCR','EIDE',
74  'PIDB','PIDCR','PIDE',
75  'EIDF','EIDSOFT',
76  'MSTACO','MMUIDCB','MMUIDVX',
77  'MMUGIRL','MMUBOY','MMUIDSA',
78  'MMUTAG','MMTIMO','MCMUTAG',
79  'MCALLHR',
80  'JETB','JETEA','JETEC','JETFA','JETFC',
81  'METCALO','METMUON',
82  'BTGLIFE','BTGSOFTE','BTGSOFTM',
83  'TAUB','TAUCR','TAUE']]}
84 
85 DQGroupDict = { 100:'PIX',
86  110:'SCT',
87  120:'TRT',
88  130:'IDGL',
89  140:'IDAL',
90  150:'IDBS',
91  160:'IDVX',
92  170:'IDBCM',
93  200:'LArEM',
94  210:'HEC',
95  220:'FCAL',
96  230:'TILE',
97  240:'MBTS',
98  250:'CAL',
99  300:'MDT',
100  310:'RPC',
101  320:'TGC',
102  330:'CSC',
103  350:'LCD',
104  360:'ALFA',
105  370:'ZDC',
106  400:'L1',
107  410:'TRIG',
108  420:'TRBJT',
109  450:'LUMI',
110  460:'RUNCLT',
111  500:'EGAMCP',
112  510:'MUONCP',
113  520:'JETCP',
114  530:'METCP',
115  540:'BTAGCP',
116  550:'TAUCP'}
117 
119  # sort disctionary
120  dqitems = DQChannelDict.items()
121  dqitems = [(v, k) for (k, v) in dqitems]
122  dqitems.sort()
123  return dqitems
124 
125 def DQChannel(name):
126  name = name.upper()
127  if ':' in name:
128  name = name[name.index(':')+1:]
129  # OLD: if name.startswith('CP_'): return -1
130  if '_' in name:
131  return -1
132  return DQChannelDict[name]
133 
134 
135 def isDQ(name):
136  name = (name.split(':')[-1].split('#')[0]).upper()
137  if name.startswith("CP_") or name.startswith("PHYS_") or name.startswith("TRIG_") or name.startswith("LUM_") or name.startswith("GLOBAL_"):
138  return True
139  return name in DQChannelDict
140 
141 
142 OLCAlgorithms = {
143  0: 'ATLAS_PREFERRED',
144  1: 'LHC',
145  101: 'LUCID_ZEROS_OR',
146  102: 'LUCID_ZEROS_AND',
147  103: 'LUCID_HITS_OR',
148  104: 'LUCID_HITS_AND',
149  151: 'LUCID_AND',
150  201: 'BCM_H_ZEROS_AND',
151  202: 'BCM_H_EVENTS_AND',
152  203: 'BCM_H_EVENTS_XORA',
153  204: 'BCM_H_EVENTS_XORC',
154  205: 'BCM_V_ZEROS_AND',
155  206: 'BCM_V_EVENTS_AND',
156  207: 'BCM_V_EVENTS_XORA',
157  208: 'BCM_V_EVENTS_XORC',
158  301: 'MBTS_ZEROS_AND',
159  302: 'MBTS_ZEROS_OR',
160  303: 'MBTS_HITS_AND',
161  304: 'MBTS_HITS_OR',
162  401: 'ZDC',
163  501: 'FCAL',
164  601: 'HLT',
165  901: 'OffLumi_LArTime_Events',
166  998: 'OflLumi_Fake0',
167  999: 'OflLumi_Fake1'
168  }
169 
171  if lhcRun==3:
173  elif lhcRun==2:
175  else:
177 
179 
180  # taken from:
181  # https://svnweb.cern.ch/trac/atlastdaq/browser/DAQ/DataFlow/eformat/tags/eformat-04-04-03/src/DetectorMask.cxx
182  #
183  # note that these here are obsolete:
184  # https://svnweb.cern.ch/trac/atlastdaq/browser/DAQ/online/RCUtils/trunk/src/get_detectormask.cc
185  # http://isscvs.cern.ch/cgi-bin/viewcvs-all.cgi/DAQ/online/RunControl/src/get_detectormask.cc?root=atlastdaq&view=markup
186 
187  dName = ['unknown']*54
188  dName[0] = "Pix Barrel"
189  dName[1] = "Pix Disks"
190  dName[2] = "Pix B-Layer"
191  dName[3] = "REMOVED"
192  dName[4] = "SCT BA"
193  dName[5] = "SCT BC"
194  dName[6] = "SCT EA"
195  dName[7] = "SCT EC"
196  dName[8] = "TRT BA"
197  dName[9] = "TRT BC"
198  dName[10] = "TRT EA"
199  dName[11] = "TRT EC"
200  dName[12] = "LAr EMBA"
201  dName[13] = "LAr EMBC"
202  dName[14] = "LAr EMECA"
203  dName[15] = "LAr EMECC"
204  dName[16] = "LAr HECA"
205  dName[17] = "LAr HECC"
206  dName[18] = "LAr FCALA"
207  dName[19] = "LAr FCALC"
208  dName[20] = "Tile BA"
209  dName[21] = "Tile BC"
210  dName[22] = "Tile EA"
211  dName[23] = "Tile EC"
212  dName[24] = "MDT BA"
213  dName[25] = "MDT BC"
214  dName[26] = "MDT EA"
215  dName[27] = "MDT EC"
216  dName[28] = "RPC BA"
217  dName[29] = "RPC BC"
218  dName[30] = "TGC EA"
219  dName[31] = "TGC EC"
220  dName[32] = "CSC EA"
221  dName[33] = "CSC EC"
222  dName[34] = "L1Calo preprocessor"
223  dName[35] = "L1Calo cluster DAQ"
224  dName[36] = "L1Calo cluster RoI"
225  dName[37] = "L1Calo Jet/E DAQ"
226  dName[38] = "L1Calo Jet/E RoI"
227  dName[39] = "MUCTPI"
228  dName[40] = "CTP"
229  dName[41] = "L2SV"
230  dName[42] = "SFI"
231  dName[43] = "SFO"
232  dName[44] = "LVL2"
233  dName[45] = "EF"
234  dName[46] = "BCM"
235  dName[47] = "Lucid"
236  dName[48] = "ZDC"
237  dName[49] = "Alfa"
238  dName[50] = "TRT_ANCILLARY_CRATE"
239  dName[51] = "TILECAL_LASER_CRATE"
240  dName[52] = "MUON_ANCILLARY_CRATE"
241  dName[53] = "TDAQ_BEAM_CRATE"
242 
243  # list of detector NOT part of 'all' tag (means, they can be in, but are not required)
244  notInAll = ['CSC', 'L2SV', 'SFI', 'SFO', 'LVL2', 'EF', 'Lucid', 'ZDC', 'Alfa',
245  'TRT_ANCILLARY_CRATE','TILECAL_LASER_CRATE','MUON_ANCILLARY_CRATE','TDAQ_BEAM_CRATE' ]
246 
247  notPartOfAllRequirement = ['']*54
248  for i in range(0,len(dName)):
249  for n in notInAll:
250  if dName[i] == n:
251  notPartOfAllRequirement[i] = ' NotInAll'
252 
253  vetoedbits = [3, 50, 51, 52, 53] #+ list(range(54,64))
254 
255  return (dName, notPartOfAllRequirement, vetoedbits)
256 
257 
259 
260  # taken from:
261  # http://alxr.usatlas.bnl.gov/lxr/source/tdaq-common/eformat/src/DetectorMask.cxx
262  #
263  # note that these here are obsolete:
264  # https://svnweb.cern.ch/trac/atlastdaq/browser/DAQ/online/RCUtils/trunk/src/get_detectormask.cc
265  # http://isscvs.cern.ch/cgi-bin/viewcvs-all.cgi/DAQ/online/RunControl/src/get_detectormask.cc?root=atlastdaq&view=markup
266 
267  dName = ['unknown']*64
268  dName[0] = "Pix Barrel"
269  dName[1] = "Pix Disks"
270  dName[2] = "Pix B-Layer"
271  dName[3] = "REMOVED"
272  dName[4] = "SCT BA"
273  dName[5] = "SCT BC"
274  dName[6] = "SCT EA"
275  dName[7] = "SCT EC"
276  dName[8] = "TRT BA"
277  dName[9] = "TRT BC"
278  dName[10] = "TRT EA"
279  dName[11] = "TRT EC"
280  dName[12] = "LAr EMBA"
281  dName[13] = "LAr EMBC"
282  dName[14] = "LAr EMECA"
283  dName[15] = "LAr EMECC"
284  dName[16] = "LAr HECA"
285  dName[17] = "LAr HECC"
286  dName[18] = "LAr FCALA"
287  dName[19] = "LAr FCALC"
288  dName[20] = "Tile BA"
289  dName[21] = "Tile BC"
290  dName[22] = "Tile EA"
291  dName[23] = "Tile EC"
292  dName[24] = "MDT BA"
293  dName[25] = "MDT BC"
294  dName[26] = "MDT EA"
295  dName[27] = "MDT EC"
296  dName[28] = "RPC BA"
297  dName[29] = "RPC BC"
298  dName[30] = "TGC EA"
299  dName[31] = "TGC EC"
300  dName[32] = "CSC EA"
301  dName[33] = "CSC EC"
302  dName[34] = "L1Calo preprocessor"
303  dName[35] = "L1Calo cluster DAQ"
304  dName[36] = "L1Calo cluster RoI"
305  dName[37] = "L1Calo Jet/E DAQ"
306  dName[38] = "L1Calo Jet/E RoI"
307  dName[39] = "MUCTPI"
308  dName[40] = "CTP"
309  dName[41] = "L2SV"
310  dName[42] = "SFI"
311  dName[43] = "SFO"
312  dName[44] = "LVL2"
313  dName[45] = "HLT"
314  dName[46] = "BCM"
315  dName[47] = "Lucid"
316  dName[48] = "ZDC"
317  dName[49] = "ALFA"
318  dName[50] = "TRT_ANCILLARY_CRATE"
319  dName[51] = "TILECAL_LASER_CRATE"
320  dName[52] = "MUON_ANCILLARY_CRATE"
321  dName[53] = "TDAQ_BEAM_CRATE"
322  dName[54] = "FTK"
323  dName[55] = "Offline"
324  dName[56] = "L1Topo"
325  dName[57] = "L1Calo DIG"
326  dName[58] = "L1Calo DAQ"
327  dName[59] = "L1Calo ROI"
328  dName[60] = "MMEGA EA"
329  dName[61] = "MMEGA EC"
330  dName[62] = "Pix IBL"
331  dName[63] = "Pix DBM"
332 
333  # list of detector NOT part of 'all' tag (means, they can be in, but are not required)
334  notInAll = ['L2SV', 'SFI', 'SFO', 'LVL2', 'Lucid', 'ZDC', 'Alfa',
335  'TRT_ANCILLARY_CRATE','TILECAL_LASER_CRATE','MUON_ANCILLARY_CRATE','TDAQ_BEAM_CRATE' ]
336 
337  notPartOfAllRequirement = map(lambda x: ' NotInAll' if x in notInAll else '', dName)
338 
339  # these bits are ignored
340  vetoedbits = [3, 41, 42, 44, 50, 51, 52, 53, 55, 57, 58, 59] #+ list(range(64,128))
341 
342  return (dName, notPartOfAllRequirement, vetoedbits)
343 
344 
346  # https://gitlab.cern.ch/atlas-tdaq-software/eformat/-/blob/eformat-05-08-03/src/DetectorMask.cxx
347 
348  (dName, _, vetoedbits) = InitDetectorMaskDecoderRun2()
349 
350  dName += [
351  "AFP", # 65
352  "LAr EMBAECA", # 66
353  "LAr EMBAECC",
354  "LAr EMHAECA",
355  "LAr EMHAECC",
356  "STGC A", # 70
357  "STGC C"
358  ]
359 
360  notInAll = ['L2SV', 'SFI', 'SFO', 'LVL2', 'Lucid', 'ZDC', 'Alfa',
361  'TRT_ANCILLARY_CRATE','TILECAL_LASER_CRATE','MUON_ANCILLARY_CRATE','TDAQ_BEAM_CRATE' ]
362  notInAll += [ "CSC EA", "CSC EC", "FTK", "Pix DBM" ]
363 
364  notPartOfAllRequirement = map(lambda x: ' NotInAll' if x in notInAll else '', dName)
365 
366  # these bits are ignored
367  vetoedbits = [3, 32, 33, 41, 42, 44, 50, 51, 52, 53, 54, 55, 57, 58, 59, 63]
368 
369  return (dName, notPartOfAllRequirement, vetoedbits)
370 
371 
372 
373 def DecodeDetectorMaskToString( detmask, lhcRun, smart ):
374  """
375  takes (int) detmask
376  returns ( (string) listOfDetectors, (bool) inclusion )
377  if smart is set to True, then the listOfDetectors might be inversed and excluded ones are shown
378  """
379 
380  dName, _, vetoedbits = InitDetectorMaskDecoder(lhcRun=lhcRun)
381 
382  ic = 0
383  res = ""
384  inclusion = True
385  for i in range( len(dName) ):
386  if i not in vetoedbits and (detmask & (1 << i)):
387  res += dName[i] + ", "
388  ic += 1
389  if res=="":
390  res = "none"
391  else:
392  res = res[:-2] # chop off last comma-space
393 
394  if smart and ic > 30:
395  # many included prefer to show excluded sub detectors
396  inclusion = False
397  res = ""
398  for i in range( len(dName) ):
399  if i not in vetoedbits and not (detmask & (1 << i)):
400  res += dName[i] + ", "
401  if res=="":
402  res = "all"
403  else:
404  res = res[:-2] # chop off last comma-space
405 
406  return (res, inclusion)
407 
408 
409 def splitAt(line, splitstring=',', splitsize=80):
410  res = [line]
411  while len( res[-1] ):
412  linebreak = res[-1].find( splitstring, splitsize)
413  if linebreak==-1:
414  break
415  res[-1:] = [ res[-1][:linebreak], res[-1][linebreak+len(splitstring):] ]
416  return res
417 
418 
419 def DecodeDetectorMask( mask, lhcRun=3, smart=False ):
420  """
421  takes an decimal or hex string (hex string must start with 0x) and returns an HTML element
422  """
423  if type(mask)!=str:
424  raise RuntimeError("DetectorMask must be a string")
425 
426  if mask.startswith('0x'):
427  mask = int(mask[2:],16)
428  else:
429  mask = int(mask)
430 
431  detectors, inclusion = DecodeDetectorMaskToString(mask, lhcRun=lhcRun, smart=smart)
432 
433  col = '#106734' if smart else '#000000'
434  if inclusion:
435  res = '<b>Detector mask = %s (%s), corresponding to the systems:</b><br><font color="%s">' % (mask,hex(mask).rstrip('L'),col)
436  else:
437  res = '<b>Detector mask = %i (%s).<br> <font color="#aa0000">The following systems are NOT included:</b><br>' % (mask,hex(mask).rstrip('L'))
438  res += detectors
439  res += '</font>'
440 
441  return res
442 
443 
444 def LArConfig(type):
445  # runtype, format
446  if 'runtype' in type.lower():
447  return {0:'RawData', 1:'RawDataResult', 2:'Result'}
448  elif 'format' in type.lower():
449  return {0:'Transparent', 1:'Format 1', 2:'Format 2'}
450  else:
451  print ('ERROR in LArconfig: unknown type %s' % type)
452  sys.exit()
453 
454 
455 
456 if __name__=="__main__":
457 
458  # Run 1
459  mask = "0x1fffffffffff7" # all but ALFA
460  print(DecodeDetectorMask(mask, lhcRun=1, smart=True))
461 
462  # Run 2
463  mask = "0x1e5103697c0ffffff7" # all but RPC BA, RPC BC, TGC EA, TGC EC, CSC EA, CSC EC, MUCTPI, Lucid, FTK, MMEGA EC, Pix DBM
464  print(DecodeDetectorMask(mask, lhcRun=2, smart=True))
465 
466  # Run 3
467  mask = "0x1e5103697c0ffffff7" # all but RPC BA, RPC BC, TGC EA, TGC EC, CSC EA, CSC EC, MUCTPI, Lucid, FTK, MMEGA EC, Pix DBM
468  print(DecodeDetectorMask(mask, lhcRun=3, smart=True))
python.utils.AtlRunQueryLookup.DecodeDetectorMaskToString
def DecodeDetectorMaskToString(detmask, lhcRun, smart)
Definition: AtlRunQueryLookup.py:373
python.utils.AtlRunQueryLookup.InitDetectorMaskDecoderRun2
def InitDetectorMaskDecoderRun2()
Definition: AtlRunQueryLookup.py:258
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.utils.AtlRunQueryLookup.isDQ
def isDQ(name)
Definition: AtlRunQueryLookup.py:135
python.utils.AtlRunQueryLookup.DecodeDetectorMask
def DecodeDetectorMask(mask, lhcRun=3, smart=False)
Definition: AtlRunQueryLookup.py:419
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.utils.AtlRunQueryLookup.DQChannels
def DQChannels()
Definition: AtlRunQueryLookup.py:118
python.utils.AtlRunQueryLookup.InitDetectorMaskDecoderRun3
def InitDetectorMaskDecoderRun3()
Definition: AtlRunQueryLookup.py:345
python.utils.AtlRunQueryLookup.splitAt
def splitAt(line, splitstring=',', splitsize=80)
Definition: AtlRunQueryLookup.py:409
python.utils.AtlRunQueryLookup.InitDetectorMaskDecoderRun1
def InitDetectorMaskDecoderRun1()
Definition: AtlRunQueryLookup.py:178
python.utils.AtlRunQueryLookup.LArConfig
def LArConfig(type)
Definition: AtlRunQueryLookup.py:444
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.utils.AtlRunQueryLookup.InitDetectorMaskDecoder
def InitDetectorMaskDecoder(lhcRun)
Definition: AtlRunQueryLookup.py:170
python.utils.AtlRunQueryLookup.DQChannel
def DQChannel(name)
Definition: AtlRunQueryLookup.py:125
Trk::split
@ split
Definition: LayerMaterialProperties.h:38