ATLAS Offline Software
TileCalibBlobPython_writeTimingFromASCII.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 #
5 # TileCalibBlobPython_writeTimingFromASCII.py
6 # Nils Gollub <nils.gollub@cern.ch>, 2007-11-26
7 # change: Yuri Smirnov <iouri.smirnov@cern.ch>, 2014-12-24
8 
9 import cppyy
10 
11 from TileCalibBlobPython import TileCalibTools
12 from TileCalibBlobObjs.Classes import TileCalibUtils
13 import os
14 
15 #=== some preparation
16 from TileCalibBlobPython.TileCalibLogger import getLogger
17 log = getLogger("writeTiming")
18 import logging
19 log.setLevel(logging.DEBUG)
20 
21 #
22 #________________________________________________________________________
23 def fillTimingTc(fileTclas, tag, since,
24  until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)):
25 
26  #=== construct folder path
27  folderTclas = TileCalibTools.getTilePrefix(True,True)+"TIME/CHANNELOFFSET/LAS"
28 
29  #=== create default: one number
30  #--- per ADC for Tclas
31  default = cppyy.gbl.std.vector('float')()
32  default.push_back(0.)
33 
34  #=====================================================
35  #=== fill Tclas
36  #=====================================================
37  tclasWriter = TileCalibTools.TileBlobWriter(db,folderTclas,'Flt')
38  tclasWriter.setComment(os.getlogin(),fileTclas)
39  parserTclas = TileCalibTools.TileASCIIParser(fileTclas,"Tclas")
40  defTclas = cppyy.gbl.std.vector('std::vector<float>')()
41  defTclas.push_back(default) # low gain
42  defTclas.push_back(default) # high gain
43  #=== initialize defaults
44  ros = 0
45  for mod in range(20):
46  flt = tclasWriter.zeroBlob(ros,mod)
47  flt = tclasWriter.getDrawer(0, 0)
48  flt.init(defTclas,1,0)
49  #=== loop over whole detector
50  for ros in range(1,5):
51  for mod in range(64):
52  #=== need to invalidate previous blob in DB when reading from ASCII file
53  tclasWriter.zeroBlob(ros,mod)
54  for chn in range(48):
55  tclas = parserTclas.getData(ros,mod,chn)
56  if not len(tclas):
57  log.warning("%i/%2i/%2i/x: No value found in file", ros,mod,chn)
58  continue
59  #=== init drawer for first entry
60  calibDrawer = tclasWriter.getDrawer(ros,mod)
61  if not calibDrawer.getNObjs():
62  log.info("Initializing drawer %i/%2i\t%i", ros,mod,calibDrawer.getNObjs())
63  calibDrawer.init(defTclas,48,0)
64  #=== loop over gainsa
65  for adc in range(2):
66  val = float(tclas[adc])
67  log.debug("%i/%2i/%2i/%i: tclas = %f", ros,mod,chn,adc, val)
68  calibDrawer.setData(chn,adc,0,val)
69 
70  folderTag = TileCalibUtils.getFullTag(folderTclas, tag)
71  tclasWriter.setComment(os.getlogin(),"Timing update for all partitions")
72  tclasWriter.register(since, until, folderTag)
73 
74 
75 #
76 #________________________________________________________________________
77 def fillTimingTd(fileTdlas, tag, since,
78  until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)):
79 
80  #=== construct folder path
81  folderTdlas = TileCalibTools.getTilePrefix(True,True)+"TIME/DRAWEROFFSET/LAS"
82 
83  #=== create default: one number
84  #--- per drawer for Tdlas
85  default = cppyy.gbl.std.vector('float')()
86  default.push_back(0.)
87 
88  #=====================================================
89  #=== fill Tdlas
90  #=====================================================
91  tdlasWriter = TileCalibTools.TileBlobWriter(db,folderTdlas,'Flt')
92  tdlasWriter.setComment(os.getlogin(),fileTdlas)
93  parserTdlas = TileCalibTools.TileASCIIParser(fileTdlas,"Tdlas")
94  defTdlas = cppyy.gbl.std.vector('std::vector<float>')()
95  defTdlas.push_back(default)
96  #=== initialize defaults
97  ros = 0
98  for mod in range(20):
99  flt = tdlasWriter.zeroBlob(ros,mod)
100  flt = tdlasWriter.getDrawer(0, 0)
101  flt.init(defTdlas,1,0)
102  #=== loop over whole detector
103  for ros in range(1,5):
104  for mod in range(64):
105  #=== need to invalidate previous blob in DB when reading from ASCII file
106  tdlasWriter.zeroBlob(ros,mod)
107  tdlas = parserTdlas.getData(ros,mod,0)
108  if not len(tdlas):
109  log.warning("(ros,mod)=(%i,%2i): No value found in file", ros,mod)
110  continue
111  defTdlas[0][0] = float(tdlas[0])
112  log.debug("(ros,mod)=(%i,%2i): tdlas = %f", ros,mod,defTdlas[0][0])
113  calibDrawer = tdlasWriter.getDrawer(ros,mod)
114  calibDrawer.init(defTdlas,1,0)
115 
116  folderTag = TileCalibUtils.getFullTag(folderTdlas, tag)
117  tdlasWriter.setComment(os.getlogin(),"Timing update for all partitions")
118  tdlasWriter.register(since, until, folderTag)
119 
120 
121 #===================================================================
122 #====================== FILL DB BELOW ==============================
123 #===================================================================
124 
125 timingDict = {
126 # "/afs/cern.ch/user/n/ngollub/public/timing/residuals-2008-05-07" : (68340,0)
127 # "/afs/cern.ch/user/b/bjorn" : (68340,0)
128  "./" : (68340,0)
129  }
130 
131 
132 #=== open the database
133 db = TileCalibTools.openDb('SQLITE', 'CONDBR2', 'UPDATE')
134 
135 tag = "RUN2-HLT-UPD1-00"
136 for directory in sorted(timingDict.keys()):
137  since = timingDict[directory]
138  fileTclas = directory+"/Tile.tclas"
139  fillTimingTc(fileTclas,tag,since)
140  #fileTdlas = directory+"/Tile.tdlas"
141  #fillTimingTd(fileTdlas,tag,since)
142 
143 #=== close the database connection
144 db.closeDatabase()
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TileCalibBlobPython_writeTimingFromASCII.fillTimingTc
def fillTimingTc(fileTclas, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK))
Definition: TileCalibBlobPython_writeTimingFromASCII.py:23
TileCalibBlobPython_writeTimingFromASCII.fillTimingTd
def fillTimingTd(fileTdlas, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK))
Definition: TileCalibBlobPython_writeTimingFromASCII.py:77
readCCLHist.float
float
Definition: readCCLHist.py:83
python.CaloCondLogger.getLogger
def getLogger(name="CaloCond")
Definition: CaloCondLogger.py:16
TileCalibUtils::getFullTag
static std::string getFullTag(const std::string &folder, const std::string &tag)
Returns the full tag string, composed of camelized folder name and tag part.
Definition: TileCalibUtils.cxx:33