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