11 import getopt,sys,os,json
12 os.environ[
'TERM'] =
'linux'
15 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
16 print (
"Read TileCal blobs from COOL and convert them to JSON format for CREST")
18 print (
"-h, --help shows this help")
19 print (
"-s, --schema= specify schema to use, ONL or OFL for RUN1 or ONL2 or OFL2 for RUN2 or MC")
20 print (
"-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
21 print (
"-d, --dbname= specify the database name e.g. CONDBR2")
22 print (
"-f, --folder= specify folder to use e.g. /TILE/OFL02/STATUS/ADC")
23 print (
"-t, --tag= specify tag to use, f.i. UPD1 or UPD4 or tag suffix like RUN2-UPD4-04")
24 print (
"-r, --run= specify run number, by default uses latest iov")
25 print (
"-l, --lumi= specify lumi block number, default is 0")
26 print (
"-c, --channel= specify COOL channel, by default COOL channels 0-275 and 1000 are used")
27 print (
"-o, --output= specify the prefix for output json file")
29 letters =
"hS:s:d:t:f:r:l:c:o:"
30 keywords = [
"help",
"server=",
"schema=",
"dbname=",
"tag=",
"folder=",
"run=",
"lumi=",
"channel=",
"output="]
33 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
34 except getopt.GetoptError
as err:
43 schema =
'COOLOFL_TILE/CONDBR2'
44 folderPath =
'/TILE/OFL02/CALIB/CIS/LIN'
52 if o
in (
"-s",
"--schema"):
54 elif o
in (
"-S",
"--server"):
56 elif o
in (
"-d",
"--dbname"):
58 elif o
in (
"-f",
"--folder"):
60 elif o
in (
"-t",
"--tag"):
62 elif o
in (
"-r",
"--run"):
64 elif o
in (
"-l",
"--lumi"):
66 elif o
in (
"-c",
"--channel"):
68 elif o
in (
"-o",
"--output"):
70 elif o
in (
"-h",
"--help"):
79 from PyCool
import cool
80 from TileCalibBlobPython
import TileCalibTools
81 from TileCalibBlobPython
import TileBchTools
82 from TileCalibBlobPython.TileCalibTools
import MAXRUN, MAXLBK
83 from TileCalibBlobObjs.Classes
import TileCalibUtils, TileCalibDrawerCmt
85 Blob = cppyy.gbl.coral.Blob
93 from TileCalibBlobPython.TileCalibLogger
import getLogger
96 logLevel=logging.DEBUG
97 log.setLevel(logLevel)
101 if os.path.isfile(schema):
102 schema =
'sqlite://;schema='+schema+
';dbname='+dbName
104 log.info(
"File %s was not found, assuming it's full schema string" , schema)
106 db = TileCalibTools.openDbConn(schema,server)
107 folderTag = TileCalibTools.getFolderTag(db
if 'CONDBR2' in schema
else schema, folderPath, tag)
108 log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
110 folder = db.getFolder(folderPath)
114 payloadSpec = cool.RecordSpecification()
115 payloadSpec.extend(
'TileCalibBlob', cool.StorageType.Blob64k )
116 folderMode = cool.FolderVersioning.MULTI_VERSION
117 folderSpec = cool.FolderSpecification(folderMode, payloadSpec)
122 since = (run<<32)+lumi
125 for chan
in channels:
127 obj = folder.findObject( since, chan, folderTag )
128 objsince = obj.since()
129 objuntil = obj.until()
130 (sinceRun,sinceLum) = (objsince>>32,objsince&0xFFFFFFFF)
131 (untilRun,untilLum) = (objuntil>>32,objuntil&0xFFFFFFFF)
132 if (objsince>maxSince):
134 coralblob = obj.payload()[0]
135 blob = coralblob.read()
136 b64string =
str(base64.b64encode(blob),
'ascii')
137 jdata[chan] = [b64string]
140 fullcmt = cmt.getFullComment()
141 log.info(fullcmt+
"\n")
143 blob1 = base64.decodebytes(bytes(b64string,
'ascii'))
146 fullcmt1 = cmt1.getFullComment()
147 if(fullcmt!=fullcmt1): log.error(fullcmt1+
"\n")
149 log.warning(
"Warning: can not read COOL channel %d from input DB" , chan)
153 if "." not in output:
154 (sinceRun,sinceLumi) = (maxSince>>32,maxSince&0xFFFFFFFF)
155 suff =
"." +
str(sinceRun) +
"." +
str(sinceLumi) +
".json"
156 ofile = output + suff
159 with open(ofile,
'w')
as the_file:
160 json.dump(jdata,the_file)
163 print(
"see file",ofile)