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