11 import getopt,sys,os,re
12 os.environ[
'TERM'] =
'linux'
15 print (
"Usage: ",sys.argv[0],
" [OPTION] ... ")
16 print (
"Prepare sqlite file with Lumi values for CALO database")
18 print (
"-h, --help shows this help")
19 print (
"-i, --infile= specify the input sqlite file for comparison or full schema string")
20 print (
"-o, --outfile= specify the output sqlite file")
21 print (
"-t, --tag= specify the tag")
22 print (
"-f, --folder= specify folder to use e.g. /CALO/Ofl/Noise/PileUpNoiseLumi ")
23 print (
"-d, --dbname= specify the database name e.g. OFLP200")
24 print (
"-S, --server= specify server - ORACLE or FRONTIER, default is FRONTIER")
25 print (
"-v, --value= specify new lumi value")
26 print (
"-V, --value2= specify new valid flag")
27 print (
"-c, --channel= specify COOL channel, by default COOL channels 0 and 1 are used")
28 print (
"-r, --run= specify run number for start of IOV")
29 print (
"-l, --lumi= specify lumiblock number for start of IOV, default is 0")
30 print (
"-u --update set this flag if output sqlite file should be updated, otherwise it'll be recreated")
32 letters =
"hi:o:t:f:d:S:v:V:c:r:l:u"
33 keywords = [
"help",
"infile=",
"outfile=",
"tag=",
"folder=",
"dbname=",
"server=",
"value=",
"value2=",
"channel=",
"run=",
"lumi=",
"update"]
36 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
37 except getopt.GetoptError
as err:
43 inFile =
'COOLOFL_CALO/CONDBR2'
44 outFile =
'caloSqlite.db'
58 if o
in (
"-i",
"--infile"):
60 elif o
in (
"-o",
"--outfile"):
62 elif o
in (
"-t",
"--tag"):
64 elif o
in (
"-f",
"--folder"):
66 elif o
in (
"-d",
"--dbname"):
68 elif o
in (
"-S",
"--server"):
70 elif o
in (
"-c",
"--channel"):
72 elif o
in (
"-r",
"--run"):
74 elif o
in (
"-l",
"--lumi"):
76 elif o
in (
"-u",
"--update"):
78 elif o
in (
"-v",
"--value"):
80 elif o
in (
"-V",
"--value2"):
82 elif o
in (
"-h",
"--help"):
93 raise Exception(
"Please, provide infile (e.g. --infile=COOLOFL_TILE/OFLP200)")
95 raise Exception(
"Please, provide outfile (e.g. --outfile=caloSqlite.db)")
97 raise Exception(
"Please, provide tag (e.g. --tag=RUN2-UPD4-04)")
99 raise Exception(
"Please, provide dbname (e.g. --dbname=OFLP200 or --dbname=CONDBR2)")
101 raise Exception(
"Please, provide value (e.g. --value=12345)")
103 raise Exception(
"Please, provide run number (e.g. --run=123456)")
105 from PyCool
import cool
106 from CaloCondBlobAlgs
import CaloCondTools, CaloCondLogger
109 log = CaloCondLogger.getLogger(
"WriteLumi")
111 log.setLevel(logging.DEBUG)
118 if os.path.isfile(inFile):
119 ischema =
'sqlite://;schema='+inFile+
';dbname='+dbName
121 log.info(
"File %s was not found, assuming it's full schema string" , inFile)
127 oschema =
'sqlite://;schema='+outFile+
';dbname='+dbName
128 dbr = CaloCondTools.openDbConn(ischema,server)
129 update = update
or (inFile==outFile)
130 dbw = CaloCondTools.openDbConn(oschema,(
'UPDATE' if update
else 'RECREATE'))
132 if len(folderPath)==0:
134 folderPath =
'/CALO/Noise/PileUpNoiseLumi'
136 folderPath =
'/CALO/Ofl/Noise/PileUpNoiseLumi'
138 if tag==
'UPD1' or tag==
'UPD4':
139 from TileCalibBlobPython
import TileCalibTools
140 folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag )
141 elif folderPath.startswith(
'/CALO/Ofl/Noise/PileUpNoiseLumi'):
142 folderTag =
'CALOOflNoisePileUpNoiseLumi-'+tag
143 elif folderPath.startswith(
'/CALO/Noise/PileUpNoiseLumi'):
144 folderTag =
'CALONoisePileUpNoiseLumi-'+tag
149 spec = cool.RecordSpecification()
150 spec.extend(
'LBAvInstLumi', cool.StorageType.Float )
151 spec.extend(
'Valid', cool.StorageType.UInt32 )
153 multiVersion=(len(folderTag)>0)
156 folderMode = cool.FolderVersioning.MULTI_VERSION
157 folderSpec = cool.FolderSpecification(folderMode, spec)
159 folderMode = cool.FolderVersioning.SINGLE_VERSION
160 folderSpec = cool.FolderSpecification(folderMode, spec)
162 log.info(
"Using folder %s with tag %s", folderPath,folderTag )
163 folderDescr = CaloCondTools.getAthenaFolderDescr()
164 folderR = dbr.getFolder(folderPath)
167 folderW = dbw.getFolder(folderPath)
169 folderW = dbw.createFolder(folderPath, folderSpec, folderDescr,
True)
171 folderW = dbw.createFolder(folderPath, folderSpec, folderDescr,
True)
175 newiov =
"[%d,%d] - infinity" % (run, lumi)
176 since = CaloCondTools.iovFromRunLumi( run, lumi )
177 until = CaloCondTools.iovFromRunLumi( CaloCondTools.MAXRUN, CaloCondTools.MAXLBK )
179 for chan
in channels:
181 obj = folderR.findObject( since, chan, folderTag )
182 (sinceRun,sinceLum) = CaloCondTools.runLumiFromIov(obj.since())
183 (untilRun,untilLum) = CaloCondTools.runLumiFromIov(obj.until())
184 val1 = obj.payload()[0]
185 val2 = obj.payload()[1]
186 oldiov =
"[%d,%d] - (%d,%d)" % (sinceRun,sinceLum,untilRun,untilLum)
190 oldiov =
"[NaN,NaN] - (NaN,NaN)"
193 print(
"COOL channel",chan,
"old iov",oldiov,
" old values [",val1,
",",val2,
194 "] new values [",newval1,
",",newval2,
"] new iov",newiov)
196 spec = folderW.payloadSpecification()
197 data = cool.Record( spec )
198 data[
'LBAvInstLumi'] = newval1
199 data[
'Valid'] = newval2
200 folderW.storeObject(since, until, data, chan, folderTag, multiVersion)