ATLAS Offline Software
LArElecCalibDBConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentFactory import CompFactory
4 
5 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator,ConfigurationError
6 from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg,addFolderList, getSqliteContent
7 
8 
9 #Import LArSymConditionsAlgs: Templated on the payload-type they handle
10 #These algs are mostly needed for MC processing
11 LArDAC2uASymAlg = CompFactory.getComp("LArSymConditionsAlg<LArDAC2uAMC, LArDAC2uASym>")
12 LArMinBiasAverageSymAlg = CompFactory.getComp("LArSymConditionsAlg<LArMinBiasAverageMC, LArMinBiasAverageSym>")
13 LArMinBiasSymAlg = CompFactory.getComp("LArSymConditionsAlg<LArMinBiasMC, LArMinBiasSym>")
14 LArNoiseSymAlg = CompFactory.getComp("LArSymConditionsAlg<LArNoiseMC, LArNoiseSym>")
15 LArRampSymAlg = CompFactory.getComp("LArSymConditionsAlg<LArRampMC, LArRampSym>")
16 LArfSamplSymAlg = CompFactory.getComp("LArSymConditionsAlg<LArfSamplMC, LArfSamplSym>")
17 LArAutoCorrSymAlg = CompFactory.getComp("LArSymConditionsAlg<LArAutoCorrMC, LArAutoCorrSym>")
18 LAruA2MeVSymAlg = CompFactory.getComp("LArSymConditionsAlg<LAruA2MeVMC, LAruA2MeVSym>")
19 LArShapeSymAlg = CompFactory.getComp("LArSymConditionsAlg<LArShape32MC, LArShape32Sym>")
20 LArMPhysOverMcalSymAlg = CompFactory.getComp("LArSymConditionsAlg<LArMphysOverMcalMC, LArMphysOverMcalSym>")
21 
22 
23 LArHVScaleCorrCondFlatAlg = CompFactory.getComp("LArFlatConditionsAlg<LArHVScaleCorrFlat>")
24 LAruA2MeVCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LAruA2MeVFlat>")
25 LArDAC2uACondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArDAC2uAFlat>")
26 LArPedestalCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArPedestalFlat>")
27 LArRampCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArRampFlat>")
28 LArMphysOverMcalCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArMphysOverMcalFlat>")
29 LArOFCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArOFCFlat>")
30 LArShapeCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArShapeFlat>")
31 
32 LArHVScaleCorrSCCondFlatAlg = CompFactory.getComp("LArFlatConditionsAlg<LArHVScaleCorrSC>")
33 LArDAC2uASCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArDAC2uASC>")
34 LArRampSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArRampSC>")
35 LAruA2MeVSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LAruA2MeVSC>")
36 LArfSamplSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArfSamplSC>")
37 LArShapeSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArShapeSC>")
38 LArPedestalSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArPedestalSC>")
39 LArNoiseSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArNoiseSC>")
40 LArMinBiasSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArMinBiasSC>")
41 LArAutoCorrSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArAutoCorrSC>")
42 LArPileupAverageSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArMinBiasAverageSC>")
43 LArMphysOverMcalSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArMphysOverMcalSC>")
44 LArOFCSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArOFCSC>")
45 
46 
47 def LArElecCalibDBCfg(flags,condObjs):
48 
49  #Check MC case
50  if flags.Input.isMC:
51  return LArElecCalibDBMCCfg(flags,condObjs)
52 
53  from AthenaConfiguration.Enums import LHCPeriod
54 
55  #Check run 1 case:
56  if flags.GeoModel.Run < LHCPeriod.Run2 :
57  return LArElecCalibDBRun1Cfg(flags,condObjs)
58 
59  #Everything else, eg run 2 (and 3?) data
60  return LArElecCalibDBRun2Cfg(flags,condObjs)
61 
62 
63 
64 
65 def LArElecCalibDBRun2Cfg(flags,condObjs):
66 
67  sqliteFolders=getSqliteContent(flags.IOVDb.SqliteInput,flags.IOVDb.SqliteFolders,flags.IOVDb.DatabaseInstance)
68 
69  _larCondDBFoldersDataR2 = {"Ramp":("LArRamp","/LAR/ElecCalibFlat/Ramp", LArRampCondAlg ),
70  "DAC2uA":("LArDAC2uA","/LAR/ElecCalibFlat/DAC2uA",LArDAC2uACondAlg),
71  "Pedestal":("LArPedestal","/LAR/ElecCalibFlat/Pedestal",LArPedestalCondAlg),
72  "uA2MeV":("LAruA2MeV","/LAR/ElecCalibFlat/uA2MeV", LAruA2MeVCondAlg),
73  "MphysOverMcal":("LArMphysOverMcal","/LAR/ElecCalibFlat/MphysOverMcal",LArMphysOverMcalCondAlg),
74  "OFC":("LArOFC","/LAR/ElecCalibFlat/OFC",LArOFCCondAlg),
75  "Shape":("LArShape","/LAR/ElecCalibFlat/Shape",LArShapeCondAlg),
76  "HVScaleCorr":("LArHVScaleCorr","/LAR/ElecCalibFlat/HVScaleCorr",LArHVScaleCorrCondFlatAlg),
77  "fSampl":("LArfSamplSym","/LAR/ElecCalibMC/fSampl",LArfSamplSymAlg),
78  }
79 
80  result=IOVDbSvcCfg(flags)
81  iovDbSvc=result.getService("IOVDbSvc")
82  condLoader=result.getCondAlgo("CondInputLoader")
83 
84  for condData in condObjs:
85  try:
86  outputKey,fldr,calg=_larCondDBFoldersDataR2[condData]
87  except KeyError:
88  raise ConfigurationError("No conditions data %s found for Run-2 data" % condData)
89 
90  if fldr in sqliteFolders:
91  sqlite=sqliteFolders[fldr]
92  else:
93  sqlite=None
94 
95 
96  persClass="CondAttrListCollection"
97  # Potential special treatment for OFC/Shape: Load them from offline DB
98  if flags.LAr.OFCShapeFolder and condData == "OFC":
99  fldr="/LAR/ElecCalibOfl/OFC/PhysWave/RTM/"+flags.LAr.OFCShapeFolder
100  dbString=sqlite or "<db>COOLOFL_LAR/CONDBR2</db>"
101  persClass="LArOFCComplete"
102  calg = None
103  elif flags.LAr.OFCShapeFolder and condData == "Shape":
104  fldr="/LAR/ElecCalibOfl/Shape/RTM/"+flags.LAr.OFCShapeFolder
105  dbString=sqlite or "<db>COOLOFL_LAR/CONDBR2</db>"
106  persClass="LArShapeComplete"
107  calg = None
108  elif condData == "fSampl":
109  if not flags.Overlay.DataOverlay:
110  raise ConfigurationError("fSampl is only supported for data overlay")
111  dbString="<db>COOLOFL_LAR/OFLP200</db>"
112  persClass="LArfSamplMC"
113  result.addCondAlgo(CompFactory.LArMCSymCondAlg(ReadKey="LArOnOffIdMap"))
114  result.addCondAlgo(calg(ReadKey="LArfSampl", WriteKey=outputKey))
115  calg = None
116  else:
117  dbString=sqlite or "<db>COOLONL_LAR/CONDBR2</db>"
118 
119  iovDbSvc.Folders.append(fldr+dbString)# (addFolder(flags,fldr,"LAR_ONL",'CondAttrListCollection'))
120  condLoader.Load.add((persClass,fldr))
121  if calg is not None:
122  result.addCondAlgo(calg (ReadKey=fldr, WriteKey=outputKey))
123 
124  return result
125 
126 def LArElecCalibDBSCCfg(flags,condObjs,sqlite=None):
127 
128  sqliteFolders=getSqliteContent(flags.IOVDb.SqliteInput,tuple(flags.IOVDb.SqliteFolders),flags.IOVDb.DatabaseInstance)
129 
130  _larCondDBFoldersDataSC = {"Ramp":("LArRampSC","/LAR/ElecCalibFlatSC/Ramp", LArRampSCCondAlg ),
131  "DAC2uA":("LArDAC2uASC","/LAR/ElecCalibFlatSC/DAC2uA",LArDAC2uASCCondAlg),
132  "Pedestal":("LArPedestalSC","/LAR/ElecCalibFlatSC/Pedestal",LArPedestalSCCondAlg),
133  "uA2MeV":("LAruA2MeVSC","/LAR/ElecCalibFlatSC/uA2MeV", LAruA2MeVSCCondAlg),
134  "MphysOverMcal":("LArMphysOverMcalSC","/LAR/ElecCalibFlatSC/MphysOverMcal",LArMphysOverMcalSCCondAlg),
135  "OFC":("LArOFCSC","/LAR/ElecCalibFlatSC/OFC",LArOFCSCCondAlg),
136  "Shape":("LArShapeSC","/LAR/ElecCalibFlatSC/Shape",LArShapeSCCondAlg),
137  "HVScaleCorr":("LArHVScaleCorrSC","/LAR/ElecCalibFlatSC/HVScaleCorr",LArHVScaleCorrSCCondFlatAlg),
138  "fSampl":("LArfSamplSC","/LAR/ElecCalibMCSC/fSampl",LArfSamplSCCondAlg),
139  }
140 
141  result=IOVDbSvcCfg(flags)
142  iovDbSvc=result.getService("IOVDbSvc")
143  condLoader=result.getCondAlgo("CondInputLoader")
144 
145  for condData in condObjs:
146  try:
147  outputKey,fldr,calg=_larCondDBFoldersDataSC[condData]
148  except KeyError:
149  raise ConfigurationError("No conditions data %s found for SCdata" % condData)
150 
151  if fldr in sqliteFolders:
152  sqlite=sqliteFolders[fldr]
153  else:
154  sqlite=None
155 
156  persClass="CondAttrListCollection"
157  if condData == "fSampl":
158  #Sampling Fraction is always read from MC-db
159  dbString="<db>COOLOFL_LAR/OFLP200</db>"
160  result.addCondAlgo(calg(ReadKey="LArfSampl", WriteKey=outputKey))
161  calg = None
162  else:
163  dbString=sqlite or "<db>COOLONL_LAR/CONDBR2</db>"
164  iovDbSvc.Folders.append(fldr+dbString)# (addFolder(flags,fldr,"LAR_ONL",'CondAttrListCollection'))
165  condLoader.Load.add((persClass,fldr))
166  if calg is not None:
167  result.addCondAlgo(calg (ReadKey=fldr, WriteKey=outputKey))
168 
169  return result
170 
171 
172 
173 def LArElecCalibDBRun1Cfg(flags,condObjs):
174 
175  _larCondDBFoldersDataR1 = {"Ramp":("/LAR/ElecCalibOnl/Ramp","LAR_ONL","LArRampComplete",None),
176  "DAC2uA":("/LAR/ElecCalibOnl/DAC2uA","LAR_ONL","LArDAC2uAMC",LArDAC2uASymAlg),
177  "Pedestal":("/LAR/ElecCalibOnl/Pedestal<key>LArPedestal</key>","LAR_ONL","LArPedestalComplete",None),
178  "uA2MeV":("/LAR/ElecCalibOfl/uA2MeV/Symmetry","LAR_OFL", "LAruA2MeVMC",LAruA2MeVSymAlg),
179  "MphysOverMcal":("/LAR/ElecCalibOfl/MphysOverMcal/RTM","LAR_OFL","LArMphysOverMcalComplete",None),
180  "HVScaleCorr":("/LAR/ElecCalibOnl/HVScaleCorr","LAR_ONL","LArHVScaleCorrComplete",None),
181  "OFC":("/LAR/ElecCalibOfl/OFC/PhysWave/RTM/"+ flags.LAr.OFCShapeFolder if len(flags.LAr.OFCShapeFolder)>0 else "/LAR/ElecCalibOfl/OFC/PhysWave/RTM/5samples1phase","LAR_OFL","LArOFCComplete",None),
182  "Shape":("/LAR/ElecCalibOfl/Shape/RTM/"+ flags.LAr.OFCShapeFolder if len(flags.LAr.OFCShapeFolder)>0 else "/LAR/ElecCalibOfl/Shape/RTM/5samples1phase","LAR_OFL","LArShapeComplete",None),
183  }
184 
185 
186 
187  result=ComponentAccumulator()
188  folderlist=[]
189  for condData in condObjs:
190  try:
191  folder,db,obj,calg=_larCondDBFoldersDataR1[condData]
192  except KeyError:
193  raise ConfigurationError("No conditions data %s found for Run-1 data" % condData)
194  folderlist.append((folder,db,obj))
195  if (calg):
196  if obj.endswith ('MC'):
197  obj = obj[:-2]
198  result.addCondAlgo(calg(ReadKey=obj,WriteKey=obj+"Sym"))
199  result.merge(addFolderList(flags,folderlist))
200 
201  return result
202 
203 
204 def LArElecCalibDBMCCfg(flags,folders,detdb="LAR_OFL"):
205  _larCondDBFoldersMC = {
206  "Ramp":("LArRampMC","/LAR/ElecCalibMC/Ramp","LArRamp", LArRampSymAlg ),
207  "AutoCorr":("LArAutoCorrMC","/LAR/ElecCalibMC/AutoCorr","LArAutoCorr", LArAutoCorrSymAlg),
208  "DAC2uA":("LArDAC2uAMC","/LAR/ElecCalibMC/DAC2uA","LArDAC2uA",LArDAC2uASymAlg),
209  "Pedestal":("LArPedestalMC","/LAR/ElecCalibMC/Pedestal","LArPedestal",None),
210  "Noise":("LArNoiseMC","/LAR/ElecCalibMC/Noise","LArNoise",LArNoiseSymAlg),
211  "fSampl":("LArfSamplMC","/LAR/ElecCalibMC/fSampl","LArfSampl",LArfSamplSymAlg),
212  "uA2MeV":("LAruA2MeVMC","/LAR/ElecCalibMC/uA2MeV","LAruA2MeV", LAruA2MeVSymAlg),
213  "MinBias":("LArMinBiasMC","/LAR/ElecCalibMC/MinBias","LArMinBias",LArMinBiasSymAlg),
214  "Shape":("LArShape32MC","/LAR/ElecCalibMC/Shape","LArShape",LArShapeSymAlg),
215  "MinBiasAvc":("LArMinBiasAverageMC","/LAR/ElecCalibMC/MinBiasAverage","LArMinBiasAverage",LArMinBiasAverageSymAlg),
216  "MphysOverMcal":("LArMphysOverMcalMC","/LAR/ElecCalibMC/MphysOverMcal","LArMphysOverMcal",LArMPhysOverMcalSymAlg),
217  "HVScaleCorr" : ("LArHVScaleCorrComplete", '/LAR/ElecCalibMC/HVScaleCorr',"LArHVScaleCorr",None)
218  }
219 
220  result=ComponentAccumulator()
221  #Add cabling
222  from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
223  result.merge(LArOnOffIdMappingCfg(flags))
224  LArMCSymCondAlg=CompFactory.LArMCSymCondAlg
225  result.addCondAlgo(LArMCSymCondAlg(ReadKey="LArOnOffIdMap"))
226  folderlist=[]
227  for folder in folders:
228  try:
229  classname,fldr,key,calg=_larCondDBFoldersMC[folder]
230  except KeyError:
231  raise ConfigurationError("No conditions data %s found for Monte Carlo" % folder)
232 
233  folderlist+=[(fldr,detdb,classname),]
234  if calg is not None:
235  result.addCondAlgo(calg(ReadKey=key,WriteKey=key+"Sym"))
236 
237  result.merge(addFolderList(flags,folderlist,db="OFLP200"))
238  return result
239 
240 
241 def LArElecCalibDBMCSCCfg(flags,folders,detdb="LAR_OFL"):
242  _larCondDBFoldersMC = {
243  "RampSC":('CondAttrListCollection',"/LAR/ElecCalibMCSC/Ramp","LArRampSC", LArRampSCCondAlg ),
244  "DAC2uASC":('CondAttrListCollection',"/LAR/ElecCalibMCSC/DAC2uA","LArDAC2uASC",LArDAC2uASCCondAlg),
245  "uA2MeVSC":('CondAttrListCollection',"/LAR/ElecCalibMCSC/uA2MeV","LAruA2MeVSC",LAruA2MeVSCCondAlg),
246  "fSamplSC":('CondAttrListCollection','/LAR/ElecCalibMCSC/fSampl',"LArfSamplSC",LArfSamplSCCondAlg),
247  "ShapeSC":('CondAttrListCollection','/LAR/ElecCalibMCSC/Shape',"LArShapeSC",LArShapeSCCondAlg),
248  "PileupAverageSC":('CondAttrListCollection','/LAR/ElecCalibMCSC/LArPileupAverage',"LArPileupAverageSC",LArPileupAverageSCCondAlg),
249  "PedestalSC":('CondAttrListCollection','/LAR/ElecCalibMCSC/Pedestal',"LArPedestalSC",LArPedestalSCCondAlg),
250  "NoiseSC":('CondAttrListCollection','/LAR/ElecCalibMCSC/Noise',"LArNoiseSC",LArNoiseSCCondAlg),
251  "MinBiasSC":('CondAttrListCollection','/LAR/ElecCalibMCSC/MinBias',"LArMinBiasSC",LArMinBiasSCCondAlg),
252  "AutoCorrSC":('CondAttrListCollection','/LAR/ElecCalibMCSC/AutoCorr',"LArAutoCorrSC",LArAutoCorrSCCondAlg)
253  }
254 
255  result=ComponentAccumulator()
256  folderlist=[]
257  for folder in folders:
258  try:
259  classname,fldr,key,calg=_larCondDBFoldersMC[folder]
260  except KeyError:
261  raise ConfigurationError("No conditions data %s found for Monte Carlo" % folder)
262 
263  folderlist+=[(fldr,detdb,classname),]
264  if calg is not None:
265  result.addCondAlgo(calg(ReadKey=fldr,WriteKey=key))
266 
267  result.merge(addFolderList(flags,folderlist,db="OFLP200"))
268  return result
269 
270 
271 if __name__ == "__main__":
272  from AthenaConfiguration.AllConfigFlags import initConfigFlags
273  from AthenaConfiguration.TestDefaults import defaultTestFiles
274 
275  print ('--- run2')
276  flags1 = initConfigFlags()
277  flags1.Input.Files = defaultTestFiles.RAW_RUN2
278  flags1.lock()
279  acc1 = LArElecCalibDBCfg (flags1, ['Ramp', 'Pedestal'])
280  acc1.printCondAlgs(summariseProps=True)
281  print ('IOVDbSvc:', acc1.getService('IOVDbSvc').Folders)
282  acc1.wasMerged()
283 
284  print ('--- run1')
285  flags2 = initConfigFlags()
286  flags2.Input.Files = defaultTestFiles.RAW_RUN2
287  from AthenaConfiguration.Enums import LHCPeriod
288  flags2.GeoModel.Run=LHCPeriod.Run1
289  flags2.lock()
290  acc2 = LArElecCalibDBCfg (flags2, ['Ramp', 'Pedestal'])
291  acc2.printCondAlgs(summariseProps=True)
292  print ('IOVDbSvc:', acc2.getService('IOVDbSvc').Folders)
293  acc2.wasMerged()
294 
295  print ('--- mc')
296  flags3 = initConfigFlags()
297  flags3.Input.Files = defaultTestFiles.ESD
298  flags3.lock()
299  acc3 = LArElecCalibDBCfg (flags3, ['Ramp', 'Pedestal'])
300  acc3.printCondAlgs(summariseProps=True)
301  print ('IOVDbSvc:', acc3.getService('IOVDbSvc').Folders)
302  acc3.wasMerged()
303 
python.LArElecCalibDBConfig.LArElecCalibDBCfg
def LArElecCalibDBCfg(flags, condObjs)
Definition: LArElecCalibDBConfig.py:47
python.LArElecCalibDBConfig.LArElecCalibDBMCSCCfg
def LArElecCalibDBMCSCCfg(flags, folders, detdb="LAR_OFL")
Definition: LArElecCalibDBConfig.py:241
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.LArElecCalibDBConfig.LArElecCalibDBRun1Cfg
def LArElecCalibDBRun1Cfg(flags, condObjs)
Definition: LArElecCalibDBConfig.py:173
python.IOVDbSvcConfig.addFolderList
def addFolderList(flags, listOfFolderInfoTuple, extensible=False, db=None, modifiers='')
Definition: IOVDbSvcConfig.py:90
LArMCSymCondAlg
Definition: LArMCSymCondAlg.h:17
python.LArElecCalibDBConfig.LArElecCalibDBMCCfg
def LArElecCalibDBMCCfg(flags, folders, detdb="LAR_OFL")
Definition: LArElecCalibDBConfig.py:204
python.IOVDbSvcConfig.IOVDbSvcCfg
def IOVDbSvcCfg(flags, **kwargs)
Definition: IOVDbSvcConfig.py:19
LArCablingConfig.LArOnOffIdMappingCfg
def LArOnOffIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:62
python.LArElecCalibDBConfig.LArElecCalibDBRun2Cfg
def LArElecCalibDBRun2Cfg(flags, condObjs)
Definition: LArElecCalibDBConfig.py:65
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArElecCalibDBConfig.LArElecCalibDBSCCfg
def LArElecCalibDBSCCfg(flags, condObjs, sqlite=None)
Definition: LArElecCalibDBConfig.py:126
python.IOVDbSvcConfig.getSqliteContent
def getSqliteContent(sqliteInput, takeFolders, databaseInstance)
Definition: IOVDbSvcConfig.py:259