ATLAS Offline Software
Merge_LAr_blobs.py
Go to the documentation of this file.
1 #!/bin/env python
2 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 
4 
12 
13 
14 import os,sys,getopt
15 from AthenaConfiguration.TestDefaults import defaultGeometryTags
16 import argparse
17 
18 parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
19 parser.add_argument('-r', "--run", dest='run', default=0x7fffffff, help="Run number. Default %(default)s.")
20 parser.add_argument('-i', "--indb", dest='indb', default="COOLONL_LAR/CONDBR2",help="Input DB for base constants. Default %(default)s.")
21 parser.add_argument('-p', "--patchdb", dest='patchdb', default="freshConstantsOnl.db", help="Patching DB, from which constants are taken only for the specified region(s). Default %(default)s.")
22 parser.add_argument('-o', "--outdb", dest='outdb', default="new.db", help="Output DB. Default %(default)s.")
23 parser.add_argument('-f', "--folder", dest='folder', default="/LAR/ElecCalibFlat/OFC", help="COOL folder. Default %(default)s.")
24 parser.add_argument('-s', "--issc", dest='issc', default=False, action="store_true", help="Is this SuperCell Data? Default %(default)s.")
25 parser.add_argument('-d', "--det", dest='patchdet', default=[], nargs='+', type=int, help="Detector to patch. Default %(default)s. EMB = 0, EMEC OW = 1, EMEC IW = 2, HEC = 3, FCAL = 4")
26 parser.add_argument('-ft', "-FT", dest='patchFT', default=[], nargs='+', type=str, help="Feedthrough to patch. Default %(default)s")
27 parser.add_argument('-ch', dest='patchChan', default=[], nargs='+', type=str, help="Channel(s) to patch. Default %(default)s")
28 
30  try:
31  int(s, 16)
32  return True
33  except ValueError:
34  return False
35 
36 # std::string LArOnlineID_Base::feedthrough_name( const HWIdentifier id )const{
37 
38 args = parser.parse_args()
39 if help in args and args.help is not None and args.help:
40  parser.print_help()
41  sys.exit(0)
42 
43 filled = [ len(x) > 0 for x in [args.patchdet, args.patchFT, args.patchChan] ]
44 
45 if filled.count(True) == 0:
46  print("No list of HW to patch was provided! Please provide desired detectors/FTs/channels to patch")
47  sys.exit(1)
48 elif filled.count(True) > 1:
49  print("Ambiguous options given. Please only provide one unit of HW to patch (detectors/FTs/channels)")
50  sys.exit(1)
51 
52 if os.path.isfile(args.outdb):
53  print(f"OUTPUT FILE {args.outdb} ALREADY EXISTS! Please check, and delete it / supply a different output name")
54  sys.exit(1)
55 
56 else:
57  # Convert channel list to int (including hex conversion, where needed)
58  args.patchChan = [int(ch,16) if is_hexadecimal(ch) else int(ch) for ch in args.patchChan]
59 
60 if ".db" in args.indb:
61  indb="sqlite://;schema="+args.indb+";dbname=CONDBR2"
62 else:
63  indb=args.indb
64 if ".db" in args.patchdb:
65  patchdb="sqlite://;schema="+args.patchdb+";dbname=CONDBR2"
66 else:
67  patchdb=args.patchdb
68 if ".db" in args.outdb:
69  outdb="sqlite://;schema="+args.outdb+";dbname=CONDBR2"
70 else:
71  outdb=args.outdb
72 
73 #Don't let PyRoot open X-connections
74 sys.argv = sys.argv[:1] + ['-b']
75 
76 detdescrtag=defaultGeometryTags.RUN3
77 defTag="CONDBR2-BLKPA-2024-01"
78 
79 from AthenaConfiguration.AllConfigFlags import initConfigFlags
81 from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
82 addLArCalibFlags(flags,isSC=args.issc)
83 flags.Input.Files = []
84 flags.Input.TimeStamps = [1000]
85 flags.Input.isMC=False
86 flags.Input.RunNumbers=[int(args.run)]
87 flags.IOVDb.DatabaseInstance="CONDBR2" if int(args.run)>222222 else "COMP200"
88 flags.IOVDb.GlobalTag=defTag
89 flags.GeoModel.AtlasVersion = detdescrtag
90 flags.LAr.doAlign=False
91 from AthenaCommon.Constants import INFO
92 flags.Exec.OutputLevel=INFO
93 flags.lock()
94 
95 from RootUtils import PyROOTFixes # noqa F401
96 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
97 cfg=MainServicesCfg(flags)
98 
99 from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
100 cfg.merge (McEventSelectorCfg (flags))
101 
102 #if geo:
103 # from LArGeoAlgsNV.LArGMConfig import LArGMCfg
104 # cfg.merge(LArGMCfg(flags))
105 #else:
106 from DetDescrCnvSvc.DetDescrCnvSvcConfig import DetDescrCnvSvcCfg
107 cfg.merge(DetDescrCnvSvcCfg(flags))
108 
109 if flags.LArCalib.isSC:
110  #Setup SuperCell cabling
111  from LArCabling.LArCablingConfig import LArOnOffIdMappingSCCfg
112  cfg.merge(LArOnOffIdMappingSCCfg(flags))
113 else:
114  #Setup regular cabling
115  from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
116  cfg.merge(LArOnOffIdMappingCfg(flags))
117 
118 from LArConditionsCommon.LArBlobMergeAlg import LArBlobMergeAlg
119 theLArMergeAlg=LArBlobMergeAlg("LArBlobMergeAlg", fld=args.folder,
120  inputdb=indb,
121  patchingdb=patchdb,
122  outputdb=outdb,
123  runnum=int(args.run),
124  patchdet=args.patchdet,
125  patchFT=args.patchFT,
126  patchChan=args.patchChan,
127  isSC=flags.LArCalib.isSC)
128 cfg.addEventAlgo(theLArMergeAlg)
129 
130 cfg.run(2) # to make sure all conditions are red-out,
131  # actual code is in algo stop
LArCablingConfig.LArOnOffIdMappingSCCfg
def LArOnOffIdMappingSCCfg(configFlags)
Definition: LArCablingConfig.py:65
Merge_LAr_blobs.is_hexadecimal
def is_hexadecimal(s)
Definition: Merge_LAr_blobs.py:29
python.DetDescrCnvSvcConfig.DetDescrCnvSvcCfg
def DetDescrCnvSvcCfg(flags, **kwargs)
Definition: DetDescrCnvSvcConfig.py:6
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
LArCablingConfig.LArOnOffIdMappingCfg
def LArOnOffIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:62
Merge_LAr_blobs.int
int
Definition: Merge_LAr_blobs.py:25
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
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