9 print (
"Syntax for UPD4 open-end IoV noise update")
10 print (
" The first parameter is the run number of IoV start, the second parameter is the lumiblock number for IoV start")
11 print (
" The third and fourth parameter are the Run/lb for IoV end (if run is -1, uses open ended IoV)")
12 print (
" The fifth parameter is the upd4 tag name")
13 print (
" The sixth parameter is input text file name (default calonoise.txt)")
14 print (
" The seventh parameter is output sqlite file name (default caloSqlite.db)")
15 print (
" The eigth parameter is output DB name (default CONDBR2)")
16 print (
" The nineth parameter is output folder name (default /LAR/NoiseOfl/CellNoise) ")
17 print (
" The tenth parameter is mu (default 30)")
18 print (
" The eleventh parameter is dt (default 25)")
25 runSince = sys.argv[1]
26 lbkSince = sys.argv[2]
27 runUntil = sys.argv[3]
28 lbkUntil = sys.argv[4]
33 inputFile=
"calonoise.txt"
38 filename=
"larnoisesqlite.db"
46 folderPath = sys.argv[9]
48 folderPath =
"/LAR/NoiseOfl/CellNoise"
51 mu =
int(sys.argv[10])
56 dt =
int(sys.argv[11])
61 dt =
int(sys.argv[11])
66 print (
"input: ",inputFile)
67 print (
"runUntil ", runUntil, lbkUntil)
68 print (
"output:",filename)
69 print (
"input: ",inputFile)
73 from PyCool
import cool
74 from CaloCondBlobAlgs
import CaloCondTools, CaloCondLogger
82 iovSince = CaloCondTools.iovFromRunLumi(runSince,lbkSince)
83 iovUntil = cool.ValidityKeyMax
84 print (
" iovUntil max ",iovUntil)
86 print (
" use run number to define iobUntil ", runUntil)
87 iovUntil = CaloCondTools.iovFromRunLumi(runUntil,lbkUntil)
89 print (
" iovSince ", iovSince)
90 print (
" iovUntil ", iovUntil)
94 comment =
"Updated noise values"
103 log = CaloCondLogger.getLogger(
"CaloNoiseWriter")
106 dbSvc = cool.DatabaseSvcFactory.databaseService()
108 db=dbSvc.openDatabase(
"sqlite://;schema="+filename+
";dbname="+dbname,
False)
110 db=dbSvc.createDatabase(
"sqlite://;schema="+filename+
";dbname="+dbname)
114 spec = cool.RecordSpecification()
115 spec.extend(
'CaloCondBlob16M', cool.StorageType.Blob16M )
116 fspec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
120 log.info(
"Filling COOL folder %s with tag %s", folderPath, folderTag )
121 desc = CaloCondTools.getAthenaFolderDescr()
123 folder = db.getFolder(folderPath)
125 log.warning(
"Folder %s not found, creating it...", folderPath)
127 folder = db.createFolder(folderPath, fspec, desc,
True)
133 gainDefVec = ROOT.std.vector(
'float')()
134 gainDefVec.push_back(0.)
135 gainDefVec.push_back(0.)
138 defVecLAr = ROOT.std.vector(
'std::vector<float>')()
139 defVecLAr.push_back(gainDefVec)
140 defVecLAr.push_back(gainDefVec)
141 defVecLAr.push_back(gainDefVec)
144 defVecTile = ROOT.std.vector(
'std::vector<float>')()
145 defVecTile.push_back(gainDefVec)
146 defVecTile.push_back(gainDefVec)
147 defVecTile.push_back(gainDefVec)
148 defVecTile.push_back(gainDefVec)
151 systemDict = { 0 : (31872, 0, defVecLAr ,
'EMEC, z<0'),
152 1 : (54784, 31872, defVecLAr ,
'EMB , z<0'),
153 2 : (54784, 86656, defVecLAr ,
'EMB , z>0'),
154 3 : (31872, 141440, defVecLAr ,
'EMEC, z>0'),
155 16 : ( 5632, 0, defVecLAr ,
'HEC' ),
156 32 : ( 3524, 0, defVecLAr ,
'FCAL' ),
157 48 : ( 5184, 0, defVecTile,
'TILE' )
160 for systemId, info
in systemDict.items():
165 log.info(
"Creating BLOB for %s", sysName)
166 data = cool.Record( spec )
167 blob = data[
'CaloCondBlob16M']
168 flt = ROOT.CaloCondBlobFlt.getInstance(blob)
169 flt.init(defVec,nChannel,1,author,comment)
170 fltDict[systemId] = [data,flt]
172 log.info(
"---> BLOB size is %4.1f kB", mbSize)
175 lines =
open(inputFile,
"r").readlines()
177 fields = line.split()
179 log.info(
"---> wrong line length %d entries ", len(fields))
183 hash =
int(fields[1]) - systemDict[systemId][1]
184 gain = ROOT.CaloCondUtils.getDbCaloGain(
int(fields[2]))
187 flt = fltDict[systemId][1]
188 if mu > 0
and dt > 0:
191 noiseB /= math.sqrt(mu/53.*10.)
193 noiseB /= math.sqrt(mu/29.*10.)
195 flt.setData(hash,gain,0,noiseA)
196 flt.setData(hash,gain,1,noiseB)
199 for systemId, dataList
in fltDict.items():
201 sysName = systemDict[systemId][3]
202 log.info(
"Committing BLOB for %s", sysName)
203 channelId = cool.ChannelId(systemId)
204 log.info(
"Cool channel ID %s", channelId)
206 folder.storeObject(iovSince, iovUntil, data, channelId, folderTag)
208 except Exception
as e:
209 log.fatal(
"Exception caught:")