ATLAS Offline Software
Loading...
Searching...
No Matches
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
8import getopt,sys,os
9os.environ['TERM'] = 'linux'
10
11def 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
25letters = "hr:l:s:t:f:D:S:w"
26keywords = ["help","run=","lumi=","schema=","tag=","folder=","dbname=","server=","warning"]
27
28try:
29 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
30except getopt.GetoptError as err:
31 print (str(err))
32 usage()
33 sys.exit(2)
34
35# defaults
36run = 2147483647
37lumi = 0
38schema = 'COOLOFL_TILE/CONDBR2'
39dbname = 'CONDBR2'
40server = ''
41folderPath = "/TILE/OFL02/STATUS/ADC"
42tag = "UPD4"
43warn = 1
44
45for 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
70from TileCalibBlobPython import TileCalibTools
71from TileCalibBlobObjs.Classes import TileCalibUtils
72
73from TileCalibBlobPython.TileCalibLogger import getLogger
74log = getLogger("ReadBadBits")
75import logging
76logLevel=logging.DEBUG
77log.setLevel(logLevel)
78log1 = getLogger("TileCalibTools")
79log1.setLevel(logLevel)
80
81
82#=== check parameters
83if len(dbname)<7 and run!=2147483647:
84 dbname = 'COMP200' if run<232000 else 'CONDBR2'
85
86if '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
89if 'sqlite:' not in schema and len(dbname):
90 schema=schema.replace('CONDBR2',dbname)
91 schema=schema.replace('COMP200',dbname)
92
93if 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
102if 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
108if 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
114if 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
122db = TileCalibTools.openDbConn(schema,server)
123folderTag = TileCalibTools.getFolderTag(db, folderPath, tag)
124log.info("Initializing folder %s with tag %s", folderPath, folderTag)
125
126#=== initialize blob reader
127blobReader = TileCalibTools.TileBlobReader(db,folderPath, folderTag)
128#blobReader.log().setLevel(logging.DEBUG)
129
130#=== get drawer with status at given run
131log.info("Initializing for run %d, lumiblock %d", run,lumi)
132log.info("Comment: %s", blobReader.getComment((run,lumi)))
133log.info( "\n" )
134
135#=== loop over all partitions,modules,channels
136for 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
149db.closeDatabase()
#define min(a, b)
Definition cfImp.cxx:40
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static unsigned int max_chan()
Python compatibility function.
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.