ATLAS Offline Software
Loading...
Searching...
No Matches
CaloNoise_fillDB Namespace Reference

Functions

 usage ()
 fillLArNoiseDB (iovSince, iovUntil, tag, inputFile=_default_inputFile, filename=_default_filename, dbname="CONDBR2", folderPath="/LAR/NoiseOfl/CellNoise", mu=-1, dt=-1)

Variables

str _default_inputFile = "calonoise.txt"
str _default_filename = "larnoisesqlite.db"
 runSince = sys.argv[1]
 lbkSince = sys.argv[2]
 runUntil = sys.argv[3]
 lbkUntil = sys.argv[4]
 tag = sys.argv[5]
dict kwargs = {}
int mu = -1
 iovSince = CaloCondTools.iovFromRunLumi(runSince,lbkSince)
 iovUntil = cool.ValidityKeyMax
 sc = fillLArNoiseDB(iovSince, iovUntil, tag, **kwargs)

Function Documentation

◆ fillLArNoiseDB()

fillLArNoiseDB ( iovSince,
iovUntil,
tag,
inputFile = _default_inputFile,
filename = _default_filename,
dbname = "CONDBR2",
folderPath = "/LAR/NoiseOfl/CellNoise",
mu = -1,
dt = -1 )

Definition at line 23 of file CaloNoise_fillDB.py.

24 dbname="CONDBR2", folderPath="/LAR/NoiseOfl/CellNoise", mu=-1, dt=-1):
25 import ROOT
26 from PyCool import cool
27 from AthenaPython.PyAthena import StatusCode
28 from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
29 #=== values for the comment channel
30 author = getpass.getuser()
31 comment = "Updated noise values"
32 #=== get a logger
33 log = CaloCondLogger.getLogger("CaloNoiseWriter")
34
35 #=== (re-)create the database
36 dbSvc = cool.DatabaseSvcFactory.databaseService()
37 try:
38 db=dbSvc.openDatabase("sqlite://;schema="+filename+";dbname="+dbname, False)
39 except Exception:
40 db=dbSvc.createDatabase("sqlite://;schema="+filename+";dbname="+dbname)
41
42 try:
43 #=== creating folder specifications
44 spec = cool.RecordSpecification()
45 spec.extend( 'CaloCondBlob16M', cool.StorageType.Blob16M )
46 fspec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
47
48 #=== create the folder
49 folderTag = tag
50 log.info( "Filling COOL folder %s with tag %s", folderPath, folderTag )
51 desc = CaloCondTools.getAthenaFolderDescr()
52 try:
53 folder = db.getFolder(folderPath)
54 except Exception:
55 log.warning("Folder %s not found, creating it...", folderPath)
56 #folder = db.createFolder(folderPath, spec, desc, cool.FolderVersioning.MULTI_VERSION, True)
57 folder = db.createFolder(folderPath, fspec, desc, True)
58
59 #==================================================
60 #=== Create the CaloCondBlobFlt objects
61 #==================================================
62 #=== default a and b to be used for each gain
63 gainDefVec = ROOT.std.vector('float')()
64 gainDefVec.push_back(0.) # a
65 gainDefVec.push_back(0.) # b
66 #=== three gains per channel for LAr
67 #defVecLAr = g.std.vector('std::vector<float>')()
68 defVecLAr = ROOT.std.vector('std::vector<float>')()
69 defVecLAr.push_back(gainDefVec)
70 defVecLAr.push_back(gainDefVec)
71 defVecLAr.push_back(gainDefVec)
72 #=== four "gains" per channel for Tile
73 #defVecTile = g.std.vector('std::vector<float>')()
74 defVecTile = ROOT.std.vector('std::vector<float>')()
75 defVecTile.push_back(gainDefVec)
76 defVecTile.push_back(gainDefVec)
77 defVecTile.push_back(gainDefVec)
78 defVecTile.push_back(gainDefVec)
79
80 #=== system specific data: sysId -> (nChannel, hash-offset, default-vector, name)
81 systemDict = { 0 : (31872, 0, defVecLAr , 'EMEC, z<0'),
82 1 : (54784, 31872, defVecLAr , 'EMB , z<0'),
83 2 : (54784, 86656, defVecLAr , 'EMB , z>0'),
84 3 : (31872, 141440, defVecLAr , 'EMEC, z>0'),
85 16 : ( 5632, 0, defVecLAr , 'HEC' ),
86 32 : ( 3524, 0, defVecLAr , 'FCAL' ),
87 48 : ( 5184, 0, defVecTile, 'TILE' )
88 }
89 fltDict = {}
90 for systemId, info in systemDict.items():
91 if (systemId<48) :
92 nChannel = info[0]
93 defVec = info[2]
94 sysName = info[3]
95 log.info("Creating BLOB for %s", sysName)
96 data = cool.Record( spec )
97 blob = data['CaloCondBlob16M']
98 flt = ROOT.CaloCondBlobFlt.getInstance(blob)
99 flt.init(defVec,nChannel,1,author,comment)
100 fltDict[systemId] = [data,flt]
101 mbSize = float(blob.size()) / 1024.
102 log.info("---> BLOB size is %4.1f kB", mbSize)
103
104 #=== read noise values from file
105 lines = open(inputFile,"r").readlines()
106 for line in lines:
107 fields = line.split()
108 if len(fields) < 5:
109 log.info("---> wrong line length %d entries ", len(fields))
110 continue
111 pass
112 systemId = int(fields[1])
113 hash = int(fields[2]) - systemDict[systemId][1]
114 gain = ROOT.CaloCondUtils.getDbCaloGain(int(fields[3]))
115 noiseA = float(fields[4])
116 noiseB = float(fields[5])
117 flt = fltDict[systemId][1]
118 if mu > 0 and dt > 0:
119 # new normalization
120 if dt > 25:
121 noiseB /= math.sqrt(mu/53.*10.)
122 else:
123 noiseB /= math.sqrt(mu/29.*10.)
124 pass
125 if mu == 0:
126 noiseB = 0
127 flt.setData(hash,gain,0,noiseA)
128 flt.setData(hash,gain,1,noiseB)
129
130 #=== write to DB
131 for systemId, dataList in fltDict.items():
132 if (systemId<48):
133 sysName = systemDict[systemId][3]
134 log.info("Committing BLOB for %s", sysName)
135 channelId = cool.ChannelId(systemId)
136 log.info("Cool channel ID %s", channelId)
137 data = dataList[0]
138 folder.storeObject(iovSince, iovUntil, data, channelId, folderTag)
139 sc = StatusCode.Success
140 except Exception as e:
141 log.fatal("Exception caught:")
142 print (e)
143 sc = StatusCode.Failure
144 #=== close the database
145 db.closeDatabase()
146 return sc
147
148

◆ usage()

usage ( )

Definition at line 10 of file CaloNoise_fillDB.py.

10def usage():
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)")
21
22
StatusCode usage()

Variable Documentation

◆ _default_filename

str CaloNoise_fillDB._default_filename = "larnoisesqlite.db"
protected

Definition at line 7 of file CaloNoise_fillDB.py.

◆ _default_inputFile

str CaloNoise_fillDB._default_inputFile = "calonoise.txt"
protected

Definition at line 6 of file CaloNoise_fillDB.py.

◆ iovSince

CaloNoise_fillDB.iovSince = CaloCondTools.iovFromRunLumi(runSince,lbkSince)

Definition at line 184 of file CaloNoise_fillDB.py.

◆ iovUntil

CaloNoise_fillDB.iovUntil = cool.ValidityKeyMax

Definition at line 185 of file CaloNoise_fillDB.py.

◆ kwargs

dict CaloNoise_fillDB.kwargs = {}

Definition at line 158 of file CaloNoise_fillDB.py.

◆ lbkSince

CaloNoise_fillDB.lbkSince = sys.argv[2]

Definition at line 154 of file CaloNoise_fillDB.py.

◆ lbkUntil

CaloNoise_fillDB.lbkUntil = sys.argv[4]

Definition at line 156 of file CaloNoise_fillDB.py.

◆ mu

int CaloNoise_fillDB.mu = -1

Definition at line 173 of file CaloNoise_fillDB.py.

◆ runSince

CaloNoise_fillDB.runSince = sys.argv[1]

Definition at line 153 of file CaloNoise_fillDB.py.

◆ runUntil

CaloNoise_fillDB.runUntil = sys.argv[3]

Definition at line 155 of file CaloNoise_fillDB.py.

◆ sc

CaloNoise_fillDB.sc = fillLArNoiseDB(iovSince, iovUntil, tag, **kwargs)

Definition at line 192 of file CaloNoise_fillDB.py.

◆ tag

CaloNoise_fillDB.tag = sys.argv[5]

Definition at line 157 of file CaloNoise_fillDB.py.