11import getopt,sys,os,json
12os.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 (
"-f, --full if sqlite file doesn't contain everything, try to find missing COOL channels in Oracle DB")
28 print (
"-o, --output= specify the prefix for output json file")
30letters =
"hS:s:d:t:f:r:l:c:o:f"
31keywords = [
"help",
"server=",
"schema=",
"dbname=",
"tag=",
"folder=",
"run=",
"lumi=",
"channel=",
"output=",
"full"]
34 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
35except getopt.GetoptError
as err:
44schema =
'COOLOFL_TILE/CONDBR2'
45folderPath =
'/TILE/OFL02/CALIB/CIS/LIN'
48channels = list(range(276)) + [1000]
54 if o
in (
"-s",
"--schema"):
56 elif o
in (
"-S",
"--server"):
58 elif o
in (
"-d",
"--dbname"):
60 elif o
in (
"-f",
"--folder"):
62 elif o
in (
"-t",
"--tag"):
64 elif o
in (
"-r",
"--run"):
66 elif o
in (
"-l",
"--lumi"):
68 elif o
in (
"-c",
"--channel"):
70 elif o
in (
"-o",
"--output"):
72 elif o
in (
"-f",
"--full"):
74 elif o
in (
"-h",
"--help"):
83from PyCool
import cool
84from TileCalibBlobPython
import TileCalibTools
85from TileCalibBlobObjs.Classes
import TileCalibDrawerCmt
87Blob = cppyy.gbl.coral.Blob
95from TileCalibBlobPython.TileCalibLogger
import getLogger
96log = getLogger(
"CopyBlob")
103if os.path.isfile(schema):
104 schema =
'sqlite://;schema='+schema+
';dbname='+dbName
106 log.info(
"File %s was not found, assuming it's full schema string" , schema)
108db = TileCalibTools.openDbConn(schema,server)
109folderTag = TileCalibTools.getFolderTag(db
if 'CONDBR2' in schema
else schema, folderPath, tag)
110log.info(
"Initializing folder %s with tag %s", folderPath, folderTag)
112folder = db.getFolder(folderPath)
116payloadSpec = cool.RecordSpecification()
117payloadSpec.extend(
'TileCalibBlob', cool.StorageType.Blob64k )
118folderMode = cool.FolderVersioning.MULTI_VERSION
119folderSpec = cool.FolderSpecification(folderMode, payloadSpec)
124since = (run<<32)+lumi
128if full
and 'sqlite' in schema:
132for iter
in range(maxIter):
134 dbOra = TileCalibTools.openDbOracle(server, schema, folderPath)
135 folder = dbOra.getFolder(folderPath)
136 channels = missingChannels
138 for chan
in channels:
140 obj = folder.findObject( since, chan, folderTag )
141 objsince = obj.since()
142 objuntil = obj.until()
143 (sinceRun,sinceLum) = (objsince>>32,objsince&0xFFFFFFFF)
144 (untilRun,untilLum) = (objuntil>>32,objuntil&0xFFFFFFFF)
145 if (objsince>maxSince):
147 coralblob = obj.payload()[0]
148 blob = coralblob.read()
149 b64string = str(base64.b64encode(blob),
'ascii')
150 jdata[chan] = [b64string]
153 fullcmt = cmt.getFullComment()
154 log.info(fullcmt+
"\n")
156 blob1 = base64.decodebytes(bytes(b64string,
'ascii'))
159 fullcmt1 = cmt1.getFullComment()
160 if(fullcmt!=fullcmt1): log.error(fullcmt1+
"\n")
163 log.warning(
"Warning: can not read COOL channel %d from Oracle" , chan)
166 log.info(
"Info: COOL channel %d is missing in input DB, it will be taken from Oracle" , chan)
168 log.warning(
"Warning: can not read COOL channel %d from input DB" , chan)
169 missingChannels.append(chan)
170 if len(missingChannels)==0:
173 jdata = dict(sorted(jdata.items(), key=
lambda item: int(item[0])))
178 (sinceRun,sinceLumi) = (maxSince>>32,maxSince&0xFFFFFFFF)
179 suff =
"." + str(sinceRun) +
"." + str(sinceLumi) +
".json"
180 ofile = output + suff
183with open(ofile,
'w')
as the_file:
184 json.dump(jdata,the_file)
187print(
"see file",ofile)
void print(char *figname, TCanvas *c1)
static const TileCalibDrawerCmt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerCmt.