ATLAS Offline Software
ReadBadBitsFromCool.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #
5 # ReadBadBitsFromCool.py --schema='COOLOFL_TILE/CONDBR2' --folder='OFL02' --tag='UPD4'
6 # Sanya Solodkov 2011-07-15
7 
8 import getopt,sys,os
9 os.environ['TERM'] = 'linux'
10 
11 def usage():
12  print ("Usage: ",sys.argv[0]," [OPTION] ... ")
13  print ("Dumps the TileCal status bits from various schemas / folders")
14  print ("")
15  print ("-h, --help shows this help")
16  print ("-f, --folder= specify status folder to use ONL01 or OFL02, don't need to specify full path")
17  print ("-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or full suffix like RUN2-HLT-UPD1-00")
18  print ("-r, --run= specify run number, by default uses latest iov")
19  print ("-l, --lumi= specify lumi block number, default is 0")
20  print ("-s, --schema= specify schema to use, like 'COOLOFL_TILE/CONDBR2' or 'sqlite://;schema=tileSqlite.db;dbname=CONDBR2' or tileSqlite.db")
21  print ("-D, --dbname= specify dbname part of schema if schema only contains file name, default is CONDBR2")
22  print ("-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
23  print ("-w, --warning suppress warning messages about missing drawers in DB")
24 
25 letters = "hr:l:s:t:f:D:S:w"
26 keywords = ["help","run=","lumi=","schema=","tag=","folder=","dbname=","server=","warning"]
27 
28 try:
29  opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
30 except getopt.GetoptError as err:
31  print (str(err))
32  usage()
33  sys.exit(2)
34 
35 # defaults
36 run = 2147483647
37 lumi = 0
38 schema = 'COOLOFL_TILE/CONDBR2'
39 dbname = 'CONDBR2'
40 server = ''
41 folderPath = "/TILE/OFL02/STATUS/ADC"
42 tag = "UPD4"
43 warn = 1
44 
45 for o, a in opts:
46  a = a.strip()
47  if o in ("-f","--folder"):
48  folderPath = "/TILE/%s/STATUS/ADC" % a
49  elif o in ("-t","--tag"):
50  tag = a
51  elif o in ("-s","--schema"):
52  schema = a
53  elif o in ("-D","--dbname"):
54  dbname = a
55  elif o in ("-S","--server"):
56  server = a
57  elif o in ("-r","--run"):
58  run = int(a)
59  elif o in ("-l","--lumi"):
60  lumi = int(a)
61  elif o in ("-w","--warning"):
62  warn = -1
63  elif o in ("-h","--help"):
64  usage()
65  sys.exit(2)
66  else:
67  raise RuntimeError("unhandeled option")
68 
69 
70 from TileCalibBlobPython import TileCalibTools
71 from TileCalibBlobObjs.Classes import TileCalibUtils
72 
73 from TileCalibBlobPython.TileCalibLogger import getLogger
74 log = getLogger("ReadBadBits")
75 import logging
76 logLevel=logging.DEBUG
77 log.setLevel(logLevel)
78 log1 = getLogger("TileCalibTools")
79 log1.setLevel(logLevel)
80 
81 
82 #=== check parameters
83 if len(dbname)<7 and run!=2147483647:
84  dbname = 'COMP200' if run<232000 else 'CONDBR2'
85 
86 if 'COOLO' not in schema and ':' not in schema and ';' not in schema:
87  schema='sqlite://;schema='+schema+';dbname='+(dbname if len(dbname) else 'CONDBR2')
88 
89 if 'sqlite:' not in schema and len(dbname):
90  schema=schema.replace('CONDBR2',dbname)
91  schema=schema.replace('COMP200',dbname)
92 
93 if len(tag)==0:
94  folderPath='/TILE/ONL01/STATUS/ADC'
95  if 'COOLOFL' in schema:
96  if 'COMP200' in schema:
97  schema='COOLONL_TILE/COMP200'
98  if 'CONDBR2' in schema:
99  schema='COOLONL_TILE/CONDBR2'
100  log.warning("tag is empty, using %s folder and schema %s", folderPath,schema)
101 
102 if schema=='COOLONL_TILE/COMP200':
103  if folderPath!="/TILE/ONL01/STATUS/ADC" and folderPath!="/TILE/OFL01/STATUS/ADC":
104  log.warning("Folder %s doesn't exist in schema %s", folderPath,schema)
105  folderPath="/TILE/ONL01/STATUS/ADC"
106  log.warning("Changing folder to %s", folderPath)
107 
108 if schema=='COOLONL_TILE/CONDBR2':
109  if folderPath!="/TILE/ONL01/STATUS/ADC":
110  log.warning("Folder %s doesn't exist in schema %s ", folderPath,schema)
111  folderPath="/TILE/ONL01/STATUS/ADC"
112  log.warning("Changing folder to %s", folderPath)
113 
114 if schema=='COOLOFL_TILE/COMP200' or schema=='COOLOFL_TILE/CONDBR2':
115  if folderPath!="/TILE/OFL02/STATUS/ADC":
116  log.warning("Folder %s doesn't exist in schema %s ", folderPath,schema)
117  folderPath="/TILE/OFL02/STATUS/ADC"
118  log.warning("Changing folder to %s", folderPath)
119 
120 
121 #=== set database
122 db = TileCalibTools.openDbConn(schema,server)
123 folderTag = TileCalibTools.getFolderTag(db, folderPath, tag)
124 log.info("Initializing folder %s with tag %s", folderPath, folderTag)
125 
126 #=== initialize blob reader
127 blobReader = TileCalibTools.TileBlobReader(db,folderPath, folderTag)
128 #blobReader.log().setLevel(logging.DEBUG)
129 
130 #=== get drawer with status at given run
131 log.info("Initializing for run %d, lumiblock %d", run,lumi)
132 log.info("Comment: %s", blobReader.getComment((run,lumi)))
133 log.info( "\n" )
134 
135 #=== loop over all partitions,modules,channels
136 for ros in range(0,5):
137  for mod in range(0, min(64,TileCalibUtils.getMaxDrawer(ros))):
139  flt = blobReader.getDrawer(ros, mod,(run,lumi))
140  for chn in range(TileCalibUtils.max_chan()):
141  adcLG = flt.getData(chn, 0, 0)
142  adcHG = flt.getData(chn, 1, 0)
143  chanS = flt.getData(chn, 2, 0)
144  if adcLG or adcHG or chanS:
145  msg = "%s %2i %5i %5i %5i " % ( modName, chn, adcLG, adcHG, chanS)
146  print (msg)
147 
148 #=== close DB
149 db.closeDatabase()
TileCalibUtils::getMaxDrawer
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
Definition: TileCalibUtils.cxx:136
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ReadBadBitsFromCool.usage
def usage()
Definition: ReadBadBitsFromCool.py:11
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
min
#define min(a, b)
Definition: cfImp.cxx:40
TileCalibUtils::getDrawerString
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
Definition: TileCalibUtils.cxx:145
TileCalibUtils::max_chan
static unsigned int max_chan()
Python compatibility function.
Definition: TileCalibUtils.h:112
str
Definition: BTagTrackIpAccessor.cxx:11
python.CaloCondLogger.getLogger
def getLogger(name="CaloCond")
Definition: CaloCondLogger.py:16