ATLAS Offline Software
LArBadChannelDBAlg.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 from AthenaConfiguration.ComponentFactory import CompFactory
3 from AthenaCommon.Logging import logging
4 
5 
6 def LArBadChannelDBAlgCfg(flags,InputFile,dbname="LAR_OFL",folder=None,tag=None,
7  IOVStart=[0,0],IOVEnd=[0x7FFFFFFF,0xFFFFFFFF]):
8 
9  logger = logging.getLogger( "LArBadChannelDBAlgCfg" )
10  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
11  result=LArGMCfg(flags)
12 
13  if flags.LArCalib.isSC:
14  #Setup SuperCell cabling
15  from LArCabling.LArCablingConfig import LArOnOffIdMappingSCCfg
16  result.merge(LArOnOffIdMappingSCCfg(flags))
17  else:
18  #Setup regular cabling
19  from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
20  result.merge(LArOnOffIdMappingCfg(flags))
21 
22 
23  if folder is None:
24  if dbname in ("LAR","LAR_ONL"):
25  folder="/LAR/BadChannels/BadChannels"
26  else:
27  folder="/LAR/BadChannelsOfl/BadChannels"
28 
29  if flags.LArCalib.isSC:
30  folder+="SC"
31 
32  if tag is None:
33  tag="".join(folder.split("/"))+"-RUN2-Bulk-00"
34 
35  if not tag.startswith("LAR"):
36  if not tag.startswith("-"): tag= "-"+tag
37  tag="".join(folder.split("/"))+tag
38 
39  logger.info("Writing to folder %s, tag %s",folder,tag)
40  theLArBadChannelCondAlgo=CompFactory.LArBadChannelCondAlg(ReadKey="",InputFileName=InputFile)
41  if flags.LArCalib.isSC:
42  theLArBadChannelCondAlgo.CablingKey="LArOnOffIdMapSC"
43  theLArBadChannelCondAlgo.isSC=True
44 
45  result.addCondAlgo(theLArBadChannelCondAlgo)
46 
47  #Thats the registration algo
48  theLArDBAlg=CompFactory.LArBadChannelDBAlg()
49  theLArDBAlg.WritingMode = 0
50  theLArDBAlg.DBFolder=folder
51  if flags.LArCalib.isSC:
52  theLArDBAlg.SuperCell=True
53  result.addEventAlgo(theLArDBAlg)
54 
55  from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
56  result.merge(OutputConditionsAlgCfg(flags,"dummy.pool.root",
57  ObjectList=["CondAttrListCollection#"+folder],
58  IOVTagList=[tag],
59  Run1=IOVStart[0],LB1=IOVStart[1],
60  Run2=IOVEnd[0],LB2=IOVEnd[1]))
61 
62  return result
63 
64 
65 if __name__=="__main__":
66  import sys,argparse
67  parser= argparse.ArgumentParser()
68  parser.add_argument("inputfile")
69  parser.add_argument("--loglevel", default=None, help="logging level (ALL, VERBOSE, DEBUG,INFO, WARNING, ERROR, or FATAL")
70  parser.add_argument("-r","--runnumber",default=0, type=int, help="IOV start (runnumber)")
71  parser.add_argument("-l","--lbnumber",default=0, type=int, help="IOV start (LB number)")
72  parser.add_argument("--runnumber2",default=0x7FFFFFFF, type=int, help="IOV start (runnumber)")
73  parser.add_argument("--lbnumber2",default=0xFFFFFFFF, type=int, help="IOV start (LB number)")
74  parser.add_argument("-o","--output",default="BadChannels.db", help="sqlite output file name")
75  parser.add_argument("-f","--folder",default=None, help="database folder to create")
76  parser.add_argument("-t","--tag",default=None, help="folder-level tag (or tag-suffix) to create")
77  parser.add_argument("--SC", action='store_true', help="Work on SuperCells")
78 
79 
80  (args,leftover)=parser.parse_known_args(sys.argv[1:])
81 
82  if len(leftover)>0:
83  print("ERROR, unhandled argument(s):",leftover)
84  sys.exit(-1)
85 
86  from AthenaConfiguration.AllConfigFlags import initConfigFlags
87  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
89  addLArCalibFlags(flags)
90 
91  flags.Input.isMC = False
92  flags.IOVDb.DatabaseInstance="CONDBR2"
93  flags.LAr.doAlign=False
94  flags.Input.RunNumbers=[args.runnumber if args.runnumber>0 else 300000]
95  flags.IOVDb.GlobalTag="CONDBR2-ES1PA-2022-06"
96  from AthenaConfiguration.TestDefaults import defaultGeometryTags
97  flags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
98  flags.LArCalib.isSC=args.SC
99 
100  flags.IOVDb.DBConnection="sqlite://;schema="+args.output+";dbname=CONDBR2"
101 
102  if args.loglevel:
103  from AthenaCommon import Constants
104  if hasattr(Constants,args.loglevel):
105  flags.Exec.OutputLevel=getattr(Constants,args.loglevel)
106  else:
107  raise ValueError("Unknown log-level, allowed values are ALL, VERBOSE, DEBUG,INFO, WARNING, ERROR, FATAL")
108 
109  flags.lock()
110 
111  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
112  cfg=MainServicesCfg(flags)
113  #MC Event selector since we have no input data file
114  from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
115  cfg.merge(McEventSelectorCfg(flags,
116  FirstLB=args.lbnumber,
117  EventsPerRun = 1,
118  FirstEvent = 1,
119  InitialTimeStamp = 0,
120  TimeStampInterval = 1))
121 
122  cfg.merge(LArBadChannelDBAlgCfg(flags,
123  args.inputfile,
124  folder=args.folder,
125  tag=args.tag,
126  IOVStart=[args.runnumber,args.lbnumber],
127  IOVEnd=[args.runnumber2,args.lbnumber2]
128  ))
129 
130 
131 
132  sc=cfg.run(1)
133  if sc.isSuccess():
134  sys.exit(0)
135  else:
136  sys.exit(1)
LArCablingConfig.LArOnOffIdMappingSCCfg
def LArOnOffIdMappingSCCfg(configFlags)
Definition: LArCablingConfig.py:65
OutputConditionsAlgConfig.OutputConditionsAlgCfg
def OutputConditionsAlgCfg(flags, name="OutputConditionsAlg", outputFile='condobjs.root', **kwargs)
Definition: OutputConditionsAlgConfig.py:5
python.LArBadChannelDBAlg.LArBadChannelDBAlgCfg
def LArBadChannelDBAlgCfg(flags, InputFile, dbname="LAR_OFL", folder=None, tag=None, IOVStart=[0, 0], IOVEnd=[0x7FFFFFFF, 0xFFFFFFFF])
Definition: LArBadChannelDBAlg.py:6
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.McEventSelectorConfig.McEventSelectorCfg
def McEventSelectorCfg(flags, **kwargs)
Definition: McEventSelectorConfig.py:5
LArCablingConfig.LArOnOffIdMappingCfg
def LArOnOffIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:62
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
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