ATLAS Offline Software
LArCalib_HVCorrConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 from AthenaConfiguration.MainServicesConfig import MainEvgenServicesCfg
6 
7 def HVCorrConfig(flags,outputName="hvcorr",runOut=0, lbOut=0):
8  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
9  result=LArGMCfg(flags)
10 
11  #Use the standard LArHVScaleCfg and adjust properties afterwards as needed
12  from LArCalibUtils.LArHVScaleConfig import LArHVScaleCfg
13 
14  result.merge(LArHVScaleCfg(flags))
15  result.getCondAlgo("LArHVCondAlg").UndoOnlineHVCorr=False
16  result.getCondAlgo("LArHVCondAlg").keyOutputCorr="NewLArHVScaleCorr"
17 
18 
19  #The LArHVCorrMaker creates a flat blob in a CondAttrListCollection
20  #Input: The HV Scale Correction computed by the LArHVCondAlg based on the DCS HV values
21  result.addEventAlgo(CompFactory.LArHVCorrMaker(LArHVScaleCorr="NewLArHVScaleCorr"))
22 
23  #Ntuple writing ...
24  from LArCalibTools.LArCalib_HVScale2NtupleConfig import LArHVScaleCorr2NtupleCfg
25  result.merge(LArHVScaleCorr2NtupleCfg(flags,rootfile=outputName+'.root'))
26  result.getEventAlgo("LArHVScaleCorr2Ntuple").ContainerKey="NewLArHVScaleCorr"
27 
28  #sqlite writing ...
29  from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
30  result.merge(OutputConditionsAlgCfg(flags,
31  outputFile="dummy.root",
32  ObjectList=["CondAttrListCollection#/LAR/ElecCalibFlat/HVScaleCorr",],
33  Run1=runOut,
34  LB1=lbOut
35  ))
36 
37 
38 
39  #RegistrationSvc
40  result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders = True,
41  SVFolder=True,
42  OverrideNames = ["HVScaleCorr"],
43  OverrideTypes = ["Blob16M"],
44  ))
45 
46  result.getService("IOVDbSvc").DBInstance=""
47  return result
48 
49 
50 if __name__=="__main__":
51  import sys
52  from time import time,strptime
53  from calendar import timegm
54  import argparse
55  parser= argparse.ArgumentParser(description="Recalclulate HV corrections based on DCS values")
56  parser.add_argument('datestamp',help="time specification like 2007-05-25:14:01:00")
57  parser.add_argument('Run',type=int, nargs='?', default=0,help="IOV start (run-number)")
58  parser.add_argument('LB',type=int, nargs='?', default=0,help="IOV start (run-number)")
59  parser.add_argument('-g', '--globaltag', type=str, help="Geometry Tag ")
60  parser.add_argument('-o', '--output',type=str,default="hvcorr",help="name stub for root and sqlite output files")
61 
62  args = parser.parse_args()
63  try:
64  ts=strptime(args.datestamp+'/UTC','%Y-%m-%d:%H:%M:%S/%Z')
65  TimeStamp=int(timegm(ts))
66  TimeStamp_ns=TimeStamp*1000000000
67  except ValueError as e:
68  print("ERROR in time specification, use e.g. 2007-05-25:14:01:00")
69  print(e)
70  sys.exit(-1)
71 
72  from LArCalibProcessing.TimeStampToRunLumi import TimeStampToRunLumi
73 
74  rlb=TimeStampToRunLumi(TimeStamp_ns)
75  if rlb is None:
76  rlb=[0xFFFFFFF-1,0]
77  print("WARNING: Failed to convert time",TimeStamp_ns,"into a run/lumi number. Using 'infinite' run-number",rlb[0])
78 
79 
80  print("---> Working on run",rlb[0],"LB",rlb[1],"Timestamp:",TimeStamp)
81  timediff=int(time()-TimeStamp)
82  if timediff<0:
83  print("ERROR: Timestamp in the future???")
84  else:
85  (days,remainder)=divmod(timediff,24*60*60)
86  (hours,seconds)=divmod(remainder,60*60)
87  print ("---> Timestamp is %i days %i hours and %i minutes ago" % (days,hours,int(seconds/60)))
88  pass
89 
90  print("Output IOV will be from run %i lumiblock %i to INF" % (args.Run,args.LB))
91 
92  outputName=args.output
93 
94  from AthenaConfiguration.TestDefaults import defaultGeometryTags
95  from AthenaConfiguration.AllConfigFlags import initConfigFlags
96  ConfigFlags=initConfigFlags()
97 
98  if args.globaltag:
99  ConfigFlags.IOVDb.GlobalTag=args.globaltag
100 
101  ConfigFlags.Input.RunNumbers=[rlb[0]]
102  ConfigFlags.Input.LumiBlockNumbers=[rlb[1]]
103  ConfigFlags.Input.TimeStamps=[TimeStamp]
104  ConfigFlags.Input.Files=[]
105  ConfigFlags.IOVDb.DatabaseInstance="CONDBR2"
106  ConfigFlags.IOVDb.DBConnection="sqlite://;schema="+outputName+".sqlite;dbname=CONDBR2"
107  ConfigFlags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
108  #ConfigFlags.Exec.OutputLevel=1
109  ConfigFlags.lock()
110  cfg=MainEvgenServicesCfg(ConfigFlags)
111  #First LB not set by McEventSelectorCfg, set it here:
112  cfg.getService("EventSelector").FirstLB=ConfigFlags.Input.LumiBlockNumbers[0]
113  cfg.merge(HVCorrConfig(ConfigFlags,outputName,args.Run,args.LB))
114 
115 
116  print("Start running...")
117  import sys
118  sys.exit(cfg.run(1).isFailure())
python.LArCalib_HVCorrConfig.HVCorrConfig
def HVCorrConfig(flags, outputName="hvcorr", runOut=0, lbOut=0)
Definition: LArCalib_HVCorrConfig.py:7
OutputConditionsAlgConfig.OutputConditionsAlgCfg
def OutputConditionsAlgCfg(flags, name="OutputConditionsAlg", outputFile='condobjs.root', **kwargs)
Definition: OutputConditionsAlgConfig.py:5
python.MainServicesConfig.MainEvgenServicesCfg
def MainEvgenServicesCfg(flags, LoopMgr="AthenaEventLoopMgr", withSequences=True)
Definition: MainServicesConfig.py:353
python.LArCalib_HVCorrConfig.int
int
Definition: LArCalib_HVCorrConfig.py:57
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
LArCalib_HVScale2NtupleConfig.LArHVScaleCorr2NtupleCfg
def LArHVScaleCorr2NtupleCfg(flags, rootfile="hvcorr_read.root")
Definition: LArCalib_HVScale2NtupleConfig.py:6
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArHVScaleConfig.LArHVScaleCfg
def LArHVScaleCfg(configFlags)
Definition: LArHVScaleConfig.py:8
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
python.TimeStampToRunLumi.TimeStampToRunLumi
def TimeStampToRunLumi(tmstmp, guard=1, dbInstance="CONDBR2")
Definition: TimeStampToRunLumi.py:3