ATLAS Offline Software
Loading...
Searching...
No Matches
CaloPedestal_fillDB.py
Go to the documentation of this file.
1#!/bin/env python
2# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
4
5import sys
6
7def usage():
8 print ("Syntax for UPD4 open-end IoV noise update")
9 print (" The first parameter is the run number of IoV start, the second parameter is the lumiblock number for IoV start")
10 print (" The third and fourth parameter are the Run/lb for IoV end (if run is -1, uses open ended IoV)")
11
12if len(sys.argv)<6:
13 usage()
14 sys.exit(-1)
15
16runSince = sys.argv[1]
17lbkSince = sys.argv[2]
18runUntil = sys.argv[3]
19lbkUntil = sys.argv[4]
20runTag = sys.argv[5]
21
22print ("runUntil ", runUntil, lbkUntil)
23print ("tag ", runTag)
24
25import cppyy
26from PyCool import cool
27from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
28
29#==================================================
30#===
31#=== Configuration section
32#===
33#==================================================
34inputFile = "calopedestal.txt"
35#=== IOV range
36iovSince = CaloCondTools.iovFromRunLumi(runSince,lbkSince)
37iovUntil = cool.ValidityKeyMax
38print (" iovUntil max ",iovUntil)
39if int(runUntil) > 0:
40 print (" use run number to define iobUntil ", runUntil)
41 iovUntil = CaloCondTools.iovFromRunLumi(runUntil,lbkUntil)
42
43print (" iovSince ", iovSince)
44print (" iovUntil ", iovUntil)
45
46#=== folder tag suffix
47tag = ""
48if runTag == "UPD4":
49 tag = "CALOOflPedestalCellPedestal-UPD4-00"
50elif runTag == "UPD1":
51 tag = "CALOOflPedestalCellPedestal-UPD1-00"
52else:
53 print("expected 'UPD4' or 'BOTH'")
54#=== values for the comment channel
55author = "gunal"
56comment = "Updated pedestal shift values"
57
58#==================================================
59#===
60#=== Code starts below here
61#===
62#==================================================
63#=== set shortcut
64g = cppyy.gbl
65#cppyy.makeClass('std::vector<float>') # This doesn't work in ROOT 6.22 anymore
66getattr(cppyy.gbl,'std::vector<float>')
67
68
69#=== get a logger
70log = CaloCondLogger.getLogger("CaloNoiseWriter")
71
72#=== (re-)create the database
73db = CaloCondTools.openDb('SQLITE', 'CONDBR2', 'UPDATE')
74
75try:
76 #=== creating folder specifications
77 spec = cool.RecordSpecification()
78 spec.extend( 'CaloCondBlob16M', cool.StorageType.Blob16M )
79 fspec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
80
81 #=== create the folder
82 folderPath = CaloCondTools.getCaloPrefix()+"Ofl/Pedestal/CellPedestal"
83 folderTag = tag
84 log.info( "Filling COOL folder %s with tag %s", folderPath, folderTag )
85 desc = CaloCondTools.getAthenaFolderDescr()
86 try:
87 folder = db.getFolder(folderPath)
88 except Exception:
89 log.warning("Folder %s not found, creating it...", folderPath)
90 folder = db.createFolder(folderPath, fspec, desc, True)
91
92 #==================================================
93 #=== Create the CaloCondBlobFlt objects
94 #==================================================
95 #=== default a and b to be used for each gain
96 gainDefVec = g.std.vector('float')()
97 gainDefVec.push_back(0.) # a
98 gainDefVec.push_back(0.) # b
99 #=== three gains per channel for LAr
100 defVecLAr = g.std.vector('std::vector<float>')()
101 defVecLAr.push_back(gainDefVec)
102 defVecLAr.push_back(gainDefVec)
103 defVecLAr.push_back(gainDefVec)
104 #=== four "gains" per channel for Tile
105 defVecTile = g.std.vector('std::vector<float>')()
106 defVecTile.push_back(gainDefVec)
107 defVecTile.push_back(gainDefVec)
108 defVecTile.push_back(gainDefVec)
109 defVecTile.push_back(gainDefVec)
110
111 #=== system specific data: sysId -> (nChannel, hash-offset, default-vector, name)
112 systemDict = { 0 : (31872, 0, defVecLAr , 'EMEC, z<0'),
113 1 : (54784, 31872, defVecLAr , 'EMB , z<0'),
114 2 : (54784, 86656, defVecLAr , 'EMB , z>0'),
115 3 : (31872, 141440, defVecLAr , 'EMEC, z>0'),
116 16 : ( 5632, 0, defVecLAr , 'HEC' ),
117 32 : ( 3524, 0, defVecLAr , 'FCAL' ),
118 48 : ( 5184, 0, defVecTile, 'TILE' )
119 }
120 fltDict = {}
121 for systemId, info in systemDict.items():
122 if (systemId<48) :
123 nChannel = info[0]
124 defVec = info[2]
125 sysName = info[3]
126 log.info("Creating BLOB for %s", sysName)
127 data = cool.Record( spec )
128 blob = data['CaloCondBlob16M']
129 flt = g.CaloCondBlobFlt.getInstance(blob)
130 flt.init(defVec,nChannel,2,author,comment)
131 fltDict[systemId] = [data,flt]
132 mbSize = float(blob.size()) / 1024.
133 log.info("---> BLOB size is %4.1f kB", mbSize)
134
135 #=== read noise values from file
136 lines = open(inputFile,"r").readlines()
137 for line in lines:
138 fields = line.split()
139
140 systemId = int(fields[0])
141 hash = int(fields[1]) - systemDict[systemId][1]
142 gain = g.CaloCondUtils.getDbCaloGain(int(fields[2]))
143 noiseA = float(fields[3])
144 noiseB = float(fields[4])
145 flt = fltDict[systemId][1]
146
147 flt.setData(hash,gain,0,noiseA)
148 flt.setData(hash,gain,1,noiseB)
149
150 #=== write to DB
151 for systemId, dataList in fltDict.items():
152 if (systemId<48):
153 sysName = systemDict[systemId][3]
154 log.info("Committing BLOB for %s", sysName)
155 channelId = cool.ChannelId(systemId)
156 log.info("Cool channel ID %s", channelId)
157 data = dataList[0]
158 folder.storeObject(iovSince, iovUntil, data, channelId, folderTag)
159
160except Exception as e:
161 log.fatal("Exception caught:")
162 print (e)
163
164#=== close the database
165db.closeDatabase()
166
void print(char *figname, TCanvas *c1)