ATLAS Offline Software
LArConditions2Ntuple.py
Go to the documentation of this file.
1 #!/bin/env python
2 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 
6 
7 if __name__=='__main__':
8 
9  import os,sys
10  import argparse
11 
12  # now process the CL options and assign defaults
13  parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
14  parser.add_argument('-r','--run', dest='run', default=0x7fffffff, help='Run number', type=int)
15  parser.add_argument('--sqlite', dest='sqlite', default=None, help='sqlite file to read from (default: oracle)', type=str)
16  parser.add_argument('-t','--tag',dest='dbtag',default=None,help="Global conditions tag", type=str)
17  parser.add_argument('-f','--ftag',dest='ftag',default=None,help="folder tag suffig", type=str)
18  parser.add_argument('-o','--out', dest='out', default="LArConditions.root", help='Output root file', type=str)
19  parser.add_argument('--ofcfolder',dest='ofcfolder',default="", help="OFC flavor",type=str)
20  parser.add_argument('-s','--isSC', dest='isSC', action='store_true', default=False, help='is SC?')
21  parser.add_argument('-m','--isMC', dest='isMC', action='store_true', default=False, help='is MC?')
22 
23  parser.add_argument("--objects",dest="objects",default="PEDESTAL,RAMP",help="List of conditions types to be dumped",type=str)
24  parser.add_argument("--folders",dest="folders",default="/LAR/ElecCalibFlat/Pedestal,/LAR/ElecCalibFlat/Ramp",help="List of folders to be taken from sqlite",type=str)
25  parser.add_argument('--offline',dest="offline", action='store_true', default=False, help='is offline folder?')
26  parser.add_argument('--poolcat',dest="poolcat", default="", type=str, help='is offline folder?')
27  parser.add_argument('-n', '--ntuple', dest='ntname', default='', help='output ntuple name (if different from default)', type=str)
28 
29  args = parser.parse_args()
30  if help in args and args.help is not None and args.help:
31  parser.print_help()
32  sys.exit(0)
33 
34 
35  #Translation table ... with a few potential variant spellings
36  objTable={"RAMP":"Ramp",
37  "DAC2UA":"DAC2uA",
38  "DACUA":"DAC2uA",
39  "PEDESTAL":"Pedestal",
40  "PED":"Pedestal",
41  "UA2MEV":"uA2MeV",
42  "UAMEV":"uA2MeV",
43  "MPHYSOVERMCAL":"MphysOverMcal",
44  "MPHYSMCAL":"MphysOverMcal",
45  "MPMC":"MphysOverMcal",
46  "OFC":"OFC",
47  "SHAPE":"Shape",
48  "HVSCALECORR":"HVScaleCorr",
49  "HVSCALE":"HVScaleCorr",
50  "FSAMPL":"fSampl",
51  "AUTOCORR":"AutoCorr",
52  "AC":"AutoCorr",
53  "CALIWAVE":"CaliWave",
54  "PHYSWAVE":"PhysWave",
55  "OFCCALI":"OFCCali"
56  }
57 
58  objects=set()
59  objectsOnl=set()
60  for obj in args.objects.split(","):
61  objU=obj.upper()
62  if objU not in objTable:
63  print("ERROR: Unknown conditions type",obj)
64  sys.exit(0)
65 
66  objects.add(objTable[objU])
67  if "OFCCALI" not in obj.upper() and 'WAVE' not in obj.upper() and not args.offline:
68  objectsOnl.add(objTable[objU])
69 
70  flds=set()
71  for fld in args.folders.split(","):
72  flds.add(fld)
73 
74  from AthenaConfiguration.AllConfigFlags import initConfigFlags
76  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
77  addLArCalibFlags(flags, args.isSC)
78 
79  flags.Input.RunNumbers=[args.run]
80  from AthenaConfiguration.TestDefaults import defaultGeometryTags
81  flags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
82 
83  flags.Input.Files=[]
84 
85  flags.Input.isMC=args.isMC
86  flags.LArCalib.isSC=args.isSC
87 
88  flags.LAr.doAlign=False
89 
90  flags.LAr.OFCShapeFolder=args.ofcfolder
91 
92  from AthenaConfiguration.Enums import LHCPeriod
93  if flags.Input.RunNumbers[0] < 222222:
94  #Set to run1 for early run-numbers
95  flags.GeoModel.Run=LHCPeriod.Run1
96  flags.IOVDb.DatabaseInstance="OFLP200" if flags.Input.isMC else "COMP200"
97  else:
98  flags.GeoModel.Run=LHCPeriod.Run2
99  flags.IOVDb.DatabaseInstance="OFLP200" if flags.Input.isMC else "CONDBR2"
100 
101  if args.dbtag:
102  flags.IOVDb.GlobalTag=args.dbtag
103  elif flags.Input.isMC:
104  flags.IOVDb.GlobalTag="OFLCOND-MC16-SDR-20"
105  elif flags.IOVDb.DatabaseInstance == "COMP200":
106  flags.IOVDb.GlobalTag="COMCOND-BLKPA-RUN1-09"
107  else:
108  flags.IOVDb.GlobalTag="CONDBR2-ES1PA-2024-01"
109 
110  #flags.Exec.OutputLevel=1
111 
112  if (args.sqlite):
113  flags.IOVDb.SqliteInput=args.sqlite
114  flags.IOVDb.SqliteFolders=tuple(flds)
115  if len(objects)!=len(objectsOnl):
116  flags.IOVDb.DBConnection="COOLOFL_LAR/CONDBR2"
117 
118  flags.lock()
119 
120  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
121  cfg=MainServicesCfg(flags)
122 
123  #MC Event selector since we have no input data file
124  from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
125  cfg.merge(McEventSelectorCfg(flags,
126  EventsPerRun = 1,
127  FirstEvent = 1,
128  InitialTimeStamp = 0,
129  TimeStampInterval = 1))
130 
131 
132 
133  #Get LAr basic services and cond-algos
134  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
135  cfg.merge(LArGMCfg(flags))
136 
137  if flags.LArCalib.isSC:
138  #Setup SuperCell cabling
139  from LArCabling.LArCablingConfig import LArOnOffIdMappingSCCfg, LArCalibIdMappingSCCfg, LArLATOMEMappingCfg
140  cfg.merge(LArOnOffIdMappingSCCfg(flags))
141  cfg.merge(LArCalibIdMappingSCCfg(flags))
142  cfg.merge(LArLATOMEMappingCfg(flags))
143  if not args.offline:
144  from LArConfiguration.LArElecCalibDBConfig import LArElecCalibDBSCCfg
145  cfg.merge(LArElecCalibDBSCCfg(flags,objectsOnl))
146  else:
147  #Setup regular cabling
148  from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg, LArCalibIdMappingCfg
149  cfg.merge(LArOnOffIdMappingCfg(flags))
150  cfg.merge(LArCalibIdMappingCfg(flags))
151  if not args.offline:
152  from LArConfiguration.LArElecCalibDBConfig import LArElecCalibDBCfg
153  cfg.merge(LArElecCalibDBCfg(flags,objectsOnl))
154 
155  from LArBadChannelTool.LArBadChannelConfig import LArBadChannelCfg
156  cfg.merge(LArBadChannelCfg(flags, isSC=flags.LArCalib.isSC))
157 
158  bcKey = "LArBadChannelSC" if flags.LArCalib.isSC else "LArBadChannel"
159 
160  if "Pedestal" in objects:
161  ckey = "LArPedestalSC" if flags.LArCalib.isSC else "LArPedestal"
162  cfg.addEventAlgo(CompFactory.LArPedestals2Ntuple(ContainerKey = ckey,
163  AddFEBTempInfo = False,
164  AddCalib = True,
165  isSC = flags.LArCalib.isSC,
166  BadChanKey = bcKey
167  ))
168 
169  if "AutoCorr" in objects:
170  ckey="LArAutoCorrSC" if flags.LArCalib.isSC else "LArAutoCorr"
171  cfg.addEventAlgo(CompFactory.LArAutoCorr2Ntuple(ContainerKey = "LArAutoCorrSym" if flags.Input.isMC else ckey,
172  AddFEBTempInfo = False,
173  AddCalib = True,
174  isSC = flags.LArCalib.isSC,
175  BadChanKey = bcKey
176  ))
177  if "Ramp" in objects:
178  ckey = "LArRampSC" if flags.LArCalib.isSC else "LArRamp"
179  if args.offline:
180  from IOVDbSvc.IOVDbSvcConfig import addFolders
181  if flags.LArCalib.isSC:
182  cfg.merge(addFolders(flags,'/LAR/ElecCalibOflSC/Ramps/RampLinea',modifiers='<key>LArRampSC</key>',className='LArRampComplete'))
183  else:
184  cfg.merge(addFolders(flags,'/LAR/ElecCalibOfl/Ramps/RampLinea',className='LArRampComplete'))
185  cfg.addEventAlgo(CompFactory.LArRamps2Ntuple(RampKey="LArRampSym" if flags.Input.isMC else ckey,
186  AddFEBTempInfo = False,
187  AddCalib = True,
188  isSC = flags.LArCalib.isSC,
189  BadChanKey = bcKey
190  ))
191 
192  if "OFC" in objects:
193  if args.offline:
194  from IOVDbSvc.IOVDbSvcConfig import addFolders
195  for fld in flds:
196  if 'OFC' in fld:
197  if args.ftag:
198  cfg.merge(addFolders(flags,fld,tag="".join(foldername.split('/')) + args.ftag))
199  else:
200  cfg.merge(addFolders(flags,fld))
201  ckey= 'LArOFC' if '1phase' in fld else 'LArLArOFCPhys4samples'
202  break
203  else:
204  ckey = "LArOFCSC" if flags.LArCalib.isSC else "LArOFC"
205  cfg.addEventAlgo(CompFactory.LArOFC2Ntuple(AddFEBTempInfo = False,
206  ContainerKey=ckey,
207  isSC = flags.LArCalib.isSC,
208  BadChanKey = bcKey
209  ))
210 
211  if "OFCCali" in objects:
212  if args.offline:
213  from IOVDbSvc.IOVDbSvcConfig import addFolders
214  for fld in flds:
215  if 'OFC' in fld:
216  if args.ftag:
217  cfg.merge(addFolders(flags,fld,tag="".join(foldername.split('/')) + args.ftag))
218  else:
219  cfg.merge(addFolders(flags,fld))
220  ckey= 'LArOFC' if '1phase' in fld else 'LArOFC'
221  break
222  else:
223  ckey = "LArOFCSCCali" if flags.LArCalib.isSC else "LArOFCCali"
224  fldr = "/LAR/ElecCalibFlatSC/OFCCali" if flags.LArCalib.isSC else "/LAR/ElecCalibFlat/OFCCali"
225  dbString = "<db>sqlite://;schema="+args.sqlite+";dbname=CONDBR2" if args.sqlite else "<db>COOLONL_LAR/CONDBR2</db>"
226  from IOVDbSvc.IOVDbSvcConfig import addFolders
227  cfg.merge(addFolders(flags,fldr,detDb=dbString,className="CondAttrListCollection"))
228  LArOFCSCCondAlg = CompFactory.getComp("LArFlatConditionsAlg<LArOFCSC>")("LArOFCSCCaliCondAlg")
229  LArOFCSCCondAlg.ReadKey=fldr
230  LArOFCSCCondAlg. WriteKey=ckey
231  cfg.addCondAlgo(LArOFCSCCondAlg)
232 
233  cfg.addEventAlgo(CompFactory.LArOFC2Ntuple("LArOFC2NtupleCali",
234  AddFEBTempInfo = False,
235  ContainerKey=ckey,
236  NtupleName="OFCCali" if args.ntname=='' else args.ntname,
237  isSC = flags.LArCalib.isSC,
238  BadChanKey = bcKey
239  ))
240 
241 
242  if "Shape" in objects:
243  ckey = "LArShapeSC" if flags.LArCalib.isSC else "LArShape"
244  if flags.Input.isMC:
245  ckey="LArShapeSym"
246  cfg.addEventAlgo(CompFactory.LArShape2Ntuple(ContainerKey=ckey,
247  AddFEBTempInfo = False,
248  AddCalib = True,
249  isSC = flags.LArCalib.isSC,
250  BadChanKey = bcKey
251 
252  ))
253  if "MphysOverMcal" in objects:
254  cfg.addEventAlgo(CompFactory.LArMphysOverMcal2Ntuple(ContainerKey = "LArMphysOverMcalSC" if flags.LArCalib.isSC else "LArMphysOverMcal",
255  AddFEBTempInfo = False,
256  AddCalib = True,
257  isSC = flags.LArCalib.isSC,
258  BadChanKey = bcKey
259  ))
260 
261  #ADC2MeV and DACuA are handled by the same ntuple dumper
262  if "DAC2uA" in objects or "uA2MeV" in objects:
263  uackey = "LAruA2MeVSC" if flags.LArCalib.isSC else "LAruA2MeV"
264  dackey = "LArDAC2uASC" if flags.LArCalib.isSC else "LArDAC2uA"
265  ua2MeVKey="LAruA2MeVSym" if flags.Input.isMC else uackey
266  dac2uAKey="LArDAC2uASym" if flags.Input.isMC else dackey
267 
268  cfg.addEventAlgo(CompFactory.LAruA2MeV2Ntuple(uA2MeVKey=ua2MeVKey if "uA2MeV" in objects else "",
269  DAC2uAKey=dac2uAKey if "DAC2uA" in objects else "",
270  isSC = flags.LArCalib.isSC,
271  BadChanKey = bcKey
272  ))
273 
274 
275  if "HVScaleCorr" in objects:
276  cfg.addEventAlgo(CompFactory.LArHVScaleCorr2Ntuple(ContainerKey= "LArHVScaleCorrSC" if flags.LArCalib.isSC else "LArHVScaleCorr",
277  AddFEBTempInfo = False,
278  isSC = flags.LArCalib.isSC,
279  BadChanKey = bcKey
280  ))
281 
282  if "fSampl" in objects:
283  cfg.addEventAlgo(CompFactory.LArfSampl2Ntuple(ContainerKey="LArfSamplSC" if flags.LArCalib.isSC else "LArfSamplSym",
284  isSC=flags.LArCalib.isSC
285  ))
286 
287  if "CaliWave" in objects:
288  if flags.Input.isMC:
289  print('No CaliWave in MC')
290  else:
291  fld = "/LAR/ElecCalibOflSC/CaliWaves/CaliWave" if flags.LArCalib.isSC else "/LAR/ElecCalibOfl/CaliWaves/CaliWave"
292  from IOVDbSvc.IOVDbSvcConfig import addFolders
293  cfg.merge(addFolders(flags,fld,modifiers='<key>LArCaliWave</key><typeName>LArCaliWaveContainer</typeName>'))
294  cfg.addEventAlgo(CompFactory.LArCaliWaves2Ntuple(KeyList = ["LArCaliWave"],
295  NtupleName = "CALIWAVE",
296  AddFEBTempInfo = False,
297  SaveDerivedInfo = True,
298  AddCalib = True,
299  SaveJitter = True,
300  isFlat = False,
301  isSC = flags.LArCalib.isSC,
302  BadChanKey = bcKey
303  ))
304 
305  if "PhysWave" in objects:
306  if flags.Input.isMC:
307  print('No PhysWave in MC yet')
308  else:
309  fld = "/LAR/ElecCalibOflSC/PhysWaves/RTM" if flags.LArCalib.isSC else "/LAR/ElecCalibOfl/PhysWaves/RTM"
310  from IOVDbSvc.IOVDbSvcConfig import addFolders
311  cfg.merge(addFolders(flags,fld))
312  cfg.addEventAlgo(CompFactory.LArPhysWaves2Ntuple(KeyList = ["LArPhysWave"],
313  NtupleName = "PHYSWAVE",
314  AddFEBTempInfo = False,
315  SaveDerivedInfo = True,
316  AddCalib = True,
317  isFlat = False,
318  isSC = flags.LArCalib.isSC,
319  BadChanKey = bcKey
320  ))
321 
322  rootfile=args.out
323  if os.path.exists(rootfile):
324  os.remove(rootfile)
325  cfg.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+rootfile+"' OPT='NEW'" ]))
326  cfg.setAppProperty("HistogramPersistency","ROOT")
327 
328  if args.dbtag and 'CALIB' in args.dbtag:
329  cfg.getService("IOVDbSvc").DBInstance=""
330 
331  if args.poolcat:
332  cfg.getService("PoolSvc").ReadCatalog+=["xmlcatalog_file:%s"%args.poolcat,]
333 
334  cfg.run(1)
335  sys.exit(0)
336 
python.LArElecCalibDBConfig.LArElecCalibDBCfg
def LArElecCalibDBCfg(flags, condObjs)
Definition: LArElecCalibDBConfig.py:47
LArCablingConfig.LArOnOffIdMappingSCCfg
def LArOnOffIdMappingSCCfg(configFlags)
Definition: LArCablingConfig.py:65
python.LArBadChannelConfig.LArBadChannelCfg
def LArBadChannelCfg(configFlags, tag=None, isSC=False)
Definition: LArBadChannelConfig.py:8
LArCablingConfig.LArLATOMEMappingCfg
def LArLATOMEMappingCfg(configFlags)
Definition: LArCablingConfig.py:95
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.McEventSelectorConfig.McEventSelectorCfg
def McEventSelectorCfg(flags, **kwargs)
Definition: McEventSelectorConfig.py:5
python.IOVDbSvcConfig.addFolders
def addFolders(flags, folderStrings, detDb=None, className=None, extensible=False, tag=None, db=None, modifiers='')
Definition: IOVDbSvcConfig.py:72
LArCablingConfig.LArOnOffIdMappingCfg
def LArOnOffIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:62
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
LArCablingConfig.LArCalibIdMappingSCCfg
def LArCalibIdMappingSCCfg(configFlags)
Definition: LArCablingConfig.py:86
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArElecCalibDBConfig.LArElecCalibDBSCCfg
def LArElecCalibDBSCCfg(flags, condObjs, sqlite=None)
Definition: LArElecCalibDBConfig.py:126
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3
LArCablingConfig.LArCalibIdMappingCfg
def LArCalibIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:83