4 from __future__
import print_function
10 print (
"Syntax for open-end IoV time constant update")
11 print (
" The first parameter is the run number of IoV start, the second parameter is the lumiblock number for IoV start")
12 print (
" The third and fourth parameters are the Run/lb for IoV end (if run is -1, uses open ended IoV)")
13 print (
" the fifth and sixth parameters are the inputfile for allconstants and runconstants")
19 runSince = sys.argv[1]
20 lbkSince = sys.argv[2]
21 runUntil = sys.argv[3]
22 lbkUntil = sys.argv[4]
24 print (
"runSince ", runSince, lbkSince)
25 print (
"runUntil ", runUntil, lbkUntil)
28 from PyCool
import cool
29 from CaloCondBlobAlgs
import CaloCondTools, CaloCondLogger
36 inputFile_con = sys.argv[5]
37 inputFile_run = sys.argv[6]
40 iovSince_con = CaloCondTools.iovFromRunLumi(runSince,lbkSince)
41 iovUntil_con = CaloCondTools.iovFromRunLumi(runUntil,lbkUntil)
43 iovMin = cool.ValidityKeyMin
44 iovMax = cool.ValidityKeyMax
46 print (
" iovSince_con ", iovSince_con)
47 print (
" iovUntil_con ", iovUntil_con)
49 print (
" iovMin ", iovMin)
50 print (
" iovMax ", iovMax)
56 tagCon =
"LARTimeCorrectionOflNonRunCon-00"
57 tagRun =
"LARTimeCorrectionOflRunCon-00"
60 comment =
"Updated time constant values"
69 cppyy.makeClass(
'std::vector<float>')
72 log = CaloCondLogger.getLogger(
"CaloTimeConsWriter")
75 db = CaloCondTools.openDb(
'SQLITE',
'COMP200',
'UPDATE')
79 spec = cool.RecordSpecification()
80 spec.extend(
'CaloCondBlob16M', cool.StorageType.Blob16M )
83 folderPath = CaloCondTools.getCaloPrefix()+
"LAR/TimeCorrectionOfl/NonRunCon"
85 print (
"Filling COOL folder ", folderPath,
" with tag ", folderTag )
86 desc = CaloCondTools.getAthenaFolderDescr()
88 folder = db.getFolder(folderPath)
90 log.warning(
"Folder %s not found, creating it...", folderPath)
91 print (
"Folder ", folderPath,
" not found, creating it... " )
92 folderSpec = cool.FolderSpecification(cool.FolderVersioning.SINGLE_VERSION, spec)
93 folder = db.createFolder(folderPath, folderSpec, desc,
True)
99 gainDefVec_1 = g.std.vector(
'float')()
100 gainDefVec_1.push_back(0.)
101 gainDefVec_1.push_back(0.)
102 gainDefVec_1.push_back(0.)
103 gainDefVec_1.push_back(0.)
104 gainDefVec_1.push_back(0.)
105 gainDefVec_1.push_back(0.)
106 gainDefVec_1.push_back(0.)
107 gainDefVec_1.push_back(0.)
108 gainDefVec_1.push_back(0.)
109 gainDefVec_1.push_back(0.)
110 gainDefVec_1.push_back(0.)
111 gainDefVec_1.push_back(0.)
112 gainDefVec_1.push_back(0.)
113 gainDefVec_1.push_back(0.)
114 gainDefVec_1.push_back(0.)
115 gainDefVec_1.push_back(0.)
116 gainDefVec_1.push_back(0.)
117 gainDefVec_1.push_back(0.)
119 defVecLAr_1 = g.std.vector(
'std::vector<float>')()
120 defVecLAr_1.push_back(gainDefVec_1)
121 defVecLAr_1.push_back(gainDefVec_1)
122 defVecLAr_1.push_back(gainDefVec_1)
126 systemDict = { 0 : (31872, 0, defVecLAr_1 ,
'EMEC, z<0'),
127 1 : (54784, 31872, defVecLAr_1 ,
'EMB , z<0'),
128 2 : (54784, 86656, defVecLAr_1 ,
'EMB , z>0'),
129 3 : (31872, 141440, defVecLAr_1 ,
'EMEC, z>0'),
132 print (
"before fill virtual database")
133 for systemId, info
in six.iteritems (systemDict):
134 print (
"before fill virtual database for sysId=", systemId)
136 print (
"Creating BLOB for Calo sysId=", systemId)
140 log.info(
"Creating BLOB for %s", sysName)
141 data_vir = cool.Record( spec )
142 blob_vir = data_vir[
'CaloCondBlob16M']
143 flt_vir = g.CaloCondBlobFlt.getInstance(blob_vir)
144 flt_vir.init(defVec,nChannel,1,author,comment)
146 log.info(
"Committing BLOB for %s", sysName)
147 channelId = cool.ChannelId(systemId)
148 log.info(
"Cool channel ID %s", channelId)
149 folder.storeObject(iovMin, iovMax, data_vir, channelId, folderTag)
151 print (
"after fill virtual database")
154 print (
"Prepare BLOB for Calo")
155 for systemId, info
in six.iteritems (systemDict):
156 print (
"before check sysId=", systemId )
158 print (
"Creating BLOB for Calo sysId=", systemId )
162 log.info(
"Creating BLOB for %s", sysName)
163 data = cool.Record( spec )
164 blob = data[
'CaloCondBlob16M']
165 flt = g.CaloCondBlobFlt.getInstance(blob)
166 flt.init(defVec,nChannel,1,author,comment)
167 fltDict_1[systemId] = [data,flt]
169 print (
"BLOB size is ", kbSize,
" KB")
171 print (
"BLOB size is ", mbSize,
" MB")
175 print (
"before read time values from file")
176 lines =
open(inputFile_con,
"r").readlines()
177 print (
"before enter file line loop")
179 fields = line.split()
182 hash_offset =
int(systemDict[systemId][1])
184 hash = hash_raw - hash_offset
185 hash_check =
int(fields[7])
186 gain = g.CaloCondUtils.getDbCaloGain(
int(fields[8]))
206 if not hash==hash_check:
207 print (
"hash!=hash_check:", hash , hash_check)
212 print (
"hash>=31872 for hash ", hash ,
", sys ", systemId)
217 print (
"hash>=54784 for hash ", hash ,
", sys ", systemId)
222 print (
"hash>=54784 for hash ", hash ,
", sys ", systemId)
227 print (
"hash>=31872 for hash ", hash ,
", sys ", systemId)
230 print (systemId, hash, hash_check, gain, febchanOffset, errPar1, errPar2, enePar1, enePar2, enePar3, enePar4, enePar5, enePar6, enePar7, enePar8, enePar9, enePar10, enePar11, enePar12, enePar13, enePar14, enePar15)
232 print (
"before get flt")
233 flt = fltDict_1[systemId][1]
234 flt.setData(hash,gain,0,febchanOffset)
235 flt.setData(hash,gain,1,errPar1)
236 flt.setData(hash,gain,2,errPar2)
237 flt.setData(hash,gain,3,enePar1)
238 flt.setData(hash,gain,4,enePar2)
239 flt.setData(hash,gain,5,enePar3)
240 flt.setData(hash,gain,6,enePar4)
241 flt.setData(hash,gain,7,enePar5)
242 flt.setData(hash,gain,8,enePar6)
243 flt.setData(hash,gain,9,enePar7)
244 flt.setData(hash,gain,10,enePar8)
245 flt.setData(hash,gain,11,enePar9)
246 flt.setData(hash,gain,12,enePar10)
247 flt.setData(hash,gain,13,enePar11)
248 flt.setData(hash,gain,14,enePar12)
249 flt.setData(hash,gain,15,enePar13)
250 flt.setData(hash,gain,16,enePar14)
251 flt.setData(hash,gain,17,enePar15)
253 print (
"outside file line loop")
256 print (
"Committing BLOB for Calo")
257 for systemId, dataList
in six.iteritems (fltDict_1):
259 sysName = systemDict[systemId][3]
260 log.info(
"Committing BLOB for %s", sysName)
261 channelId = cool.ChannelId(systemId)
262 log.info(
"Cool channel ID %s", channelId)
264 folder.storeObject(iovSince_con, iovUntil_con, data, channelId, folderTag)
266 except Exception
as e:
267 log.fatal(
"Exception caught: fill LAR/TimeCorrectionOfl/NonRunCon")
268 print (
"Exception caught: fill LAR/TimeCorrectionOfl/NonRunCon")
273 spec = cool.RecordSpecification()
274 spec.extend(
'CaloCondBlob16M', cool.StorageType.Blob16M )
277 folderPath = CaloCondTools.getCaloPrefix()+
"LAR/TimeCorrectionOfl/RunCon"
279 print (
"Filling COOL folder ", folderPath,
"with tag ", folderTag)
280 desc = CaloCondTools.getAthenaFolderDescr()
282 folder = db.getFolder(folderPath)
284 log.warning(
"Folder %s not found, creating it...", folderPath)
285 print (
"Folder ", folderPath,
" not found, creating it... " )
287 folder = db.createFolder(folderPath, spec, desc, cool.FolderVersioning.MULTI_VERSION,
True)
293 gainDefVec_2 = g.std.vector(
'float')()
294 gainDefVec_2.push_back(0.)
295 gainDefVec_2.push_back(0.)
297 defVecLAr_2 = g.std.vector(
'std::vector<float>')()
298 defVecLAr_2.push_back(gainDefVec_2)
299 defVecLAr_2.push_back(gainDefVec_2)
300 defVecLAr_2.push_back(gainDefVec_2)
303 print (
"before fill virtual database")
305 channelId = cool.ChannelId(1)
306 data_vir = cool.Record( spec )
307 blob_vir = data_vir[
'CaloCondBlob16M']
308 flt_vir = g.CaloCondBlobFlt.getInstance(blob_vir)
309 flt_vir.init(defVecLAr_2,nChannel,1,author,comment)
310 folder.storeObject(iovMin, iovMax, data_vir, channelId, folderTag)
311 print (
"after fill virtual database")
314 lines =
open(inputFile_run,
"r").readlines()
316 print (
"before fill run_list")
318 fields = line.split()
320 if run_list.count(run)==0:
323 print (
"after fill run_list")
325 print (
"number of runs: ", len(run_list))
326 print (
"run_list: ", run_list)
329 for runId
in run_list:
330 print (
"Creating BLOB for run ", runId )
332 data = cool.Record( spec )
333 blob = data[
'CaloCondBlob16M']
334 flt = g.CaloCondBlobFlt.getInstance(blob)
335 flt.init(defVecLAr_2,nChannel,1,author,comment)
336 fltDict_2[runId] = [data,flt]
337 kbSize =
float(blob.size()) / 1024.
338 print (
"BLOB size is ", kbSize,
" kB")
339 mbSize =
float(kbSize) / 1024
340 print (
"BLOB size is ", mbSize,
" MB")
343 print (
"before enter file line loop")
345 fields = line.split()
355 gain0 = g.CaloCondUtils.getDbCaloGain(0)
356 gain1 = g.CaloCondUtils.getDbCaloGain(1)
357 gain2 = g.CaloCondUtils.getDbCaloGain(2)
359 flt = fltDict_2[runId][1]
360 flt.setData(ftID,gain0,0,runOffsetHigh)
361 flt.setData(ftID,gain0,1,runEntryHigh)
362 flt.setData(ftID,gain1,0,runOffsetMed)
363 flt.setData(ftID,gain1,1,runEntryMed)
364 flt.setData(ftID,gain2,0,runOffsetLow)
365 flt.setData(ftID,gain2,1,runEntryLow)
367 print (runId, ftID, runOffsetHigh, runEntryHigh, runOffsetMed, runEntryMed, runOffsetLow, runEntryLow)
369 print (
"after enter file line loop")
371 for runId, dataList
in six.iteritems (fltDict_2):
372 print (
"Committing BLOB for run ", runId)
373 iovSince_run = CaloCondTools.iovFromRunLumi(runId,lbkdown)
374 iovUntil_run = CaloCondTools.iovFromRunLumi(runId,lbkup)
375 channelId = cool.ChannelId(1)
376 print (
"Cool channel ID ", channelId )
378 folder.storeObject(iovSince_run, iovUntil_run, data, channelId, folderTag)
380 except Exception
as e:
381 log.fatal(
"Exception caught: LAR/TimeCorrectionOfl/RunCon")
382 print (
"Exception caught: LAR/TimeCorrectionOfl/RunCon")