12os.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 (
"-x, --txtfile= specify the text file with the new lumi constants")
26 print (
"-v, --value= specify new lumi value")
27 print (
"-V, --value2= specify new valid flag")
28 print (
"-c, --channel= specify COOL channel, by default COOL channels 0 and 1 are used")
29 print (
"-r, --run= specify run number for start of IOV")
30 print (
"-l, --lumi= specify lumiblock number for start of IOV, default is 0")
31 print (
"-u --update set this flag if output sqlite file should be updated, otherwise it'll be recreated")
33letters =
"hi:o:t:f:d:S:x:v:V:c:r:l:u"
34keywords = [
"help",
"infile=",
"outfile=",
"tag=",
"folder=",
"dbname=",
"server=",
"txtfile=",
"value=",
"value2=",
"channel=",
"run=",
"lumi=",
"update"]
37 opts, extraparams = getopt.getopt(sys.argv[1:],letters,keywords)
38except getopt.GetoptError
as err:
44inFile =
'COOLOFL_CALO/CONDBR2'
45outFile =
'caloSqlite.db'
60 if o
in (
"-i",
"--infile"):
62 elif o
in (
"-o",
"--outfile"):
64 elif o
in (
"-t",
"--tag"):
66 elif o
in (
"-f",
"--folder"):
68 elif o
in (
"-d",
"--dbname"):
70 elif o
in (
"-S",
"--server"):
72 elif o
in (
"-c",
"--channel"):
74 elif o
in (
"-r",
"--run"):
76 elif o
in (
"-l",
"--lumi"):
78 elif o
in (
"-u",
"--update"):
80 elif o
in (
"-x",
"--txtfile"):
82 elif o
in (
"-v",
"--value"):
84 elif o
in (
"-V",
"--value2"):
86 elif o
in (
"-h",
"--help"):
97 raise Exception(
"Please, provide infile (e.g. --infile=COOLOFL_TILE/OFLP200)")
99 raise Exception(
"Please, provide outfile (e.g. --outfile=caloSqlite.db)")
101 raise Exception(
"Please, provide tag (e.g. --tag=RUN2-UPD4-04)")
103 raise Exception(
"Please, provide dbname (e.g. --dbname=OFLP200 or --dbname=CONDBR2)")
104if not txtFile
and value
is None:
105 raise Exception(
"Please, provide input file (e.g. --txtfile=lumi.txt) or value (e.g. --value=12345)")
107 raise Exception(
"Please, provide run number (e.g. --run=123456)")
109from PyCool
import cool
110from CaloCondBlobAlgs
import CaloCondTools, CaloCondLogger
113log = CaloCondLogger.getLogger(
"WriteLumi")
115log.setLevel(logging.DEBUG)
122if os.path.isfile(inFile):
123 ischema =
'sqlite://;schema='+inFile+
';dbname='+dbName
125 log.info(
"File %s was not found, assuming it's full schema string" , inFile)
131oschema =
'sqlite://;schema='+outFile+
';dbname='+dbName
132dbr = CaloCondTools.openDbConn(ischema,server)
133update = update
or (inFile==outFile)
134dbw = CaloCondTools.openDbConn(oschema,(
'UPDATE' if update
else 'RECREATE'))
136if len(folderPath)==0:
138 folderPath =
'/CALO/Noise/PileUpNoiseLumi'
140 folderPath =
'/CALO/Ofl/Noise/PileUpNoiseLumi'
142from TileCalibBlobPython
import TileCalibTools
143folderTag = TileCalibTools.getFolderTag(dbr, folderPath, tag )
146spec = cool.RecordSpecification()
147spec.extend(
'LBAvInstLumi', cool.StorageType.Float )
148spec.extend(
'Valid', cool.StorageType.UInt32 )
150multiVersion=(len(folderTag)>0)
153 folderMode = cool.FolderVersioning.MULTI_VERSION
154 folderSpec = cool.FolderSpecification(folderMode, spec)
156 folderMode = cool.FolderVersioning.SINGLE_VERSION
157 folderSpec = cool.FolderSpecification(folderMode, spec)
159log.info(
"Using folder %s with tag %s", folderPath,folderTag )
160folderDescr = CaloCondTools.getAthenaFolderDescr()
161folderR = dbr.getFolder(folderPath)
164 folderW = dbw.getFolder(folderPath)
166 folderW = dbw.createFolder(folderPath, folderSpec, folderDescr,
True)
168 folderW = dbw.createFolder(folderPath, folderSpec, folderDescr,
True)
170newiov =
"[%d,%d] - infinity" % (run, lumi)
171since = CaloCondTools.iovFromRunLumi( run, lumi )
172until = CaloCondTools.iovFromRunLumi( CaloCondTools.MAXRUN, CaloCondTools.MAXLBK )
176 input[chan] = [
'keep',
'keep']
177 if value
is not None:
178 input[chan][0] = value
179 if value2
is not None:
180 input[chan][1] = value2
184 with open(txtFile,
"r")
as f:
185 allData = f.readlines()
187 print(
"\nCan not read input file %s" % (txtFile))
195 if fields[0].startswith(
"#"):
200 for fld
in fields[1:3]:
201 for chan
in (channels
if ch<0
else [ch]):
202 input[chan][ind] = fld
204 except (TypeError,ValueError):
205 log.error(f
"Can not process line '{line.strip()}' - skipping")
209 obj = folderR.findObject( since, chan, folderTag )
210 (sinceRun,sinceLum) = CaloCondTools.runLumiFromIov(obj.since())
211 (untilRun,untilLum) = CaloCondTools.runLumiFromIov(obj.until())
212 val1 = obj.payload()[0]
213 val2 = obj.payload()[1]
214 oldiov =
"[%d,%d] - (%d,%d)" % (sinceRun,sinceLum,untilRun,untilLum)
218 oldiov =
"[NaN,NaN] - (NaN,NaN)"
222 newval1 = abs(float(input[chan][0]))
223 except (TypeError,ValueError):
224 newval1 = val1
if val1
is not None else 0.0
226 newval2 = abs(int(float(input[chan][1])))
227 except (TypeError,ValueError):
228 newval2 = val2
if val2
is not None else 0
230 print(
"COOL channel",chan,
"old iov",oldiov,
" old values [",val1,
",",val2,
231 "] new values [",newval1,
",",newval2,
"] new iov",newiov)
233 spec = folderW.payloadSpecification()
234 data = cool.Record( spec )
235 data[
'LBAvInstLumi'] = newval1
236 data[
'Valid'] = newval2
237 folderW.storeObject(since, until, data, chan, folderTag, multiVersion)
void print(char *figname, TCanvas *c1)
std::vector< std::string > split(const std::string &s, const std::string &t=":")