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