4 from __future__
import print_function
11 print (
"Syntax for UPD4 open-end IoV noise update")
12 print (
" The first parameter is the run number of IoV start, the second parameter is the lumiblock number for IoV start")
13 print (
" The third and fourth parameter are the Run/lb for IoV end (if run is -1, uses open ended IoV)")
14 print (
" The fifth parameter is the upd4 tag name")
15 print (
" The sixth parameter is input text file name (default calonoise.txt)")
16 print (
" The seventh parameter is output sqlite file name (default caloSqlite.db)")
17 print (
" The eigth parameter is output DB name (default CONDBR2)")
18 print (
" The nineth parameter is output folder name (default /LAR/NoiseOfl/CellNoise) ")
19 print (
" The tenth parameter is mu (default 30)")
20 print (
" The eleventh parameter is dt (default 25)")
27 runSince = sys.argv[1]
28 lbkSince = sys.argv[2]
29 runUntil = sys.argv[3]
30 lbkUntil = sys.argv[4]
35 inputFile=
"calonoise.txt"
40 filename=
"larnoisesqlite.db"
48 folderPath = sys.argv[9]
50 folderPath =
"/LAR/NoiseOfl/CellNoise"
53 mu =
int(sys.argv[10])
58 dt =
int(sys.argv[11])
63 dt =
int(sys.argv[11])
68 print (
"input: ",inputFile)
69 print (
"runUntil ", runUntil, lbkUntil)
70 print (
"output:",filename)
71 print (
"input: ",inputFile)
75 from PyCool
import cool
76 from CaloCondBlobAlgs
import CaloCondTools, CaloCondLogger
84 iovSince = CaloCondTools.iovFromRunLumi(runSince,lbkSince)
85 iovUntil = cool.ValidityKeyMax
86 print (
" iovUntil max ",iovUntil)
88 print (
" use run number to define iobUntil ", runUntil)
89 iovUntil = CaloCondTools.iovFromRunLumi(runUntil,lbkUntil)
91 print (
" iovSince ", iovSince)
92 print (
" iovUntil ", iovUntil)
96 comment =
"Updated noise values"
105 log = CaloCondLogger.getLogger(
"CaloNoiseWriter")
108 dbSvc = cool.DatabaseSvcFactory.databaseService()
110 db=dbSvc.openDatabase(
"sqlite://;schema="+filename+
";dbname="+dbname,
False)
112 db=dbSvc.createDatabase(
"sqlite://;schema="+filename+
";dbname="+dbname)
116 spec = cool.RecordSpecification()
117 spec.extend(
'CaloCondBlob16M', cool.StorageType.Blob16M )
118 fspec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
122 log.info(
"Filling COOL folder %s with tag %s", folderPath, folderTag )
123 desc = CaloCondTools.getAthenaFolderDescr()
125 folder = db.getFolder(folderPath)
127 log.warning(
"Folder %s not found, creating it...", folderPath)
129 folder = db.createFolder(folderPath, fspec, desc,
True)
135 gainDefVec = ROOT.std.vector(
'float')()
136 gainDefVec.push_back(0.)
137 gainDefVec.push_back(0.)
140 defVecLAr = ROOT.std.vector(
'std::vector<float>')()
141 defVecLAr.push_back(gainDefVec)
142 defVecLAr.push_back(gainDefVec)
143 defVecLAr.push_back(gainDefVec)
146 defVecTile = ROOT.std.vector(
'std::vector<float>')()
147 defVecTile.push_back(gainDefVec)
148 defVecTile.push_back(gainDefVec)
149 defVecTile.push_back(gainDefVec)
150 defVecTile.push_back(gainDefVec)
153 systemDict = { 0 : (31872, 0, defVecLAr ,
'EMEC, z<0'),
154 1 : (54784, 31872, defVecLAr ,
'EMB , z<0'),
155 2 : (54784, 86656, defVecLAr ,
'EMB , z>0'),
156 3 : (31872, 141440, defVecLAr ,
'EMEC, z>0'),
157 16 : ( 5632, 0, defVecLAr ,
'HEC' ),
158 32 : ( 3524, 0, defVecLAr ,
'FCAL' ),
159 48 : ( 5184, 0, defVecTile,
'TILE' )
162 for systemId, info
in six.iteritems (systemDict):
167 log.info(
"Creating BLOB for %s", sysName)
168 data = cool.Record( spec )
169 blob = data[
'CaloCondBlob16M']
170 flt = ROOT.CaloCondBlobFlt.getInstance(blob)
171 flt.init(defVec,nChannel,1,author,comment)
172 fltDict[systemId] = [data,flt]
174 log.info(
"---> BLOB size is %4.1f kB", mbSize)
177 lines =
open(inputFile,
"r").readlines()
179 fields = line.split()
181 log.info(
"---> wrong line length %d entries ", len(fields))
185 hash =
int(fields[1]) - systemDict[systemId][1]
186 gain = ROOT.CaloCondUtils.getDbCaloGain(
int(fields[2]))
189 flt = fltDict[systemId][1]
190 if mu > 0
and dt > 0:
193 noiseB /= math.sqrt(mu/53.*10.)
195 noiseB /= math.sqrt(mu/29.*10.)
197 flt.setData(hash,gain,0,noiseA)
198 flt.setData(hash,gain,1,noiseB)
201 for systemId, dataList
in six.iteritems (fltDict):
203 sysName = systemDict[systemId][3]
204 log.info(
"Committing BLOB for %s", sysName)
205 channelId = cool.ChannelId(systemId)
206 log.info(
"Cool channel ID %s", channelId)
208 folder.storeObject(iovSince, iovUntil, data, channelId, folderTag)
210 except Exception
as e:
211 log.fatal(
"Exception caught:")