ATLAS Offline Software
CaloCondBlobAlgs_fillNoiseFromASCII.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 # CaloCondBlobAlgs_fillNoiseFromASCII
4 # Nils Gollub <nils.gollub@cern.ch>, 2008-01-11
5 
6 import cppyy
7 from PyCool import cool
8 from CaloCondBlobAlgs import CaloCondTools, CaloCondLogger
9 import six
10 
11 #==================================================
12 #===
13 #=== Configuration section
14 #===
15 #==================================================
16 #=== Input files with OFCs
17 inputFile = "/afs/cern.ch/user/g/gunal/scratch0/AtlasOffline-12.0.6/calonoise.txt"
18 #=== IOV range
19 runSince = 0
20 lbkSince = 0
21 iovSince = CaloCondTools.iovFromRunLumi(runSince,lbkSince)
22 iovUntil = cool.ValidityKeyMax
23 #=== folder tag suffix
24 tag = "000-00"
25 #=== values for the comment channel
26 author = "ngollub"
27 comment = "Default cell noise values from Guillaume"
28 
29 
30 #==================================================
31 #===
32 #=== Code starts below here
33 #===
34 #==================================================
35 #=== set shortcut
36 g = cppyy.gbl
37 cppyy.makeClass('std::vector<float>')
38 
39 #=== get a logger
40 log = CaloCondLogger.getLogger("CaloNoiseWriter")
41 
42 #=== (re-)create the database
43 db = CaloCondTools.openDb('SQLITE', 'COMP200', 'UPDATE')
44 
45 try:
46  #=== creating folder specifications
47  spec = cool.RecordSpecification()
48  spec.extend( 'CaloCondBlob16M', cool.StorageType.Blob16M )
49 
50  #=== create the folder
51  folderPath = CaloCondTools.getCaloPrefix()+"Noise/CellNoise"
52  folderTag = g.CaloCondUtils.getFullTag(folderPath,tag)
53  log.info( "Filling COOL folder %s with tag %s", folderPath, folderTag )
54  desc = CaloCondTools.getAthenaFolderDescr()
55  try:
56  folder = db.getFolder(folderPath)
57  except Exception:
58  log.warning("Folder %s not found, creating it...", folderPath)
59  folder = db.createFolder(folderPath, spec, desc, cool.FolderVersioning.MULTI_VERSION, True)
60 
61  #==================================================
62  #=== Create the CaloCondBlobFlt objects
63  #==================================================
64  #=== default a and b to be used for each gain
65  gainDefVec = g.std.vector('float')()
66  gainDefVec.push_back(0.) # a
67  gainDefVec.push_back(0.) # b
68  #=== three gains per channel for LAr
69  defVecLAr = g.std.vector('std::vector<float>')()
70  defVecLAr.push_back(gainDefVec)
71  defVecLAr.push_back(gainDefVec)
72  defVecLAr.push_back(gainDefVec)
73  #=== four "gains" per channel for Tile
74  defVecTile = g.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 six.iteritems (systemDict):
91  nChannel = info[0]
92  defVec = info[2]
93  sysName = info[3]
94  log.info("Creating BLOB for %s", sysName)
95  data = cool.Record( spec )
96  blob = data['CaloCondBlob16M']
97  flt = g.CaloCondBlobFlt.getInstance(blob)
98  flt.init(defVec,nChannel,1,author,comment)
99  fltDict[systemId] = [data,flt]
100  mbSize = float(blob.size()) / 1024.
101  log.info("---> BLOB size is %4.1f kB", mbSize)
102 
103  #=== read noise values from file
104  lines = open(inputFile,"r").readlines()
105  for line in lines:
106  fields = line.split()
107 
108  systemId = int(fields[0])
109  hash = int(fields[1]) - systemDict[systemId][1]
110  gain = g.CaloCondUtils.getDbCaloGain(int(fields[2]))
111  noiseA = float(fields[3])
112  noiseB = float(fields[4])
113  flt = fltDict[systemId][1]
114 
115  flt.setData(hash,gain,0,noiseA)
116  flt.setData(hash,gain,1,noiseB)
117 
118  #=== write to DB
119  for systemId, dataList in six.iteritems (fltDict):
120  sysName = systemDict[systemId][3]
121  log.info("Committing BLOB for %s", sysName)
122  channelId = cool.ChannelId(systemId)
123  data = dataList[0]
124  folder.storeObject(iovSince, iovUntil, data, channelId, folderTag)
125 
126 except Exception:
127  import traceback
128  log.fatal("Exception caught:")
129  log.fatal (traceback.format_exc())
130 
131 #=== close the database
132 db.closeDatabase()
133 
Trk::open
@ open
Definition: BinningType.h:40
readCCLHist.int
int
Definition: readCCLHist.py:84
readCCLHist.float
float
Definition: readCCLHist.py:83