ATLAS Offline Software
LArNewCalib_Ramp.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 #
5 
6 if __name__=='__main__':
7 
8  import os,sys
9  import argparse
10 
11  # now process the CL options and assign defaults
12  parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
13  #parser.add_argument('-r','--runlist', dest='runlist', default=RunNumberList, nargs='+', help='Run numbers string list', type=str)
14  parser.add_argument('-r','--run', dest='run', default='00408920', help='Run number string as in input filename', type=str)
15  parser.add_argument('-g','--gain', dest='gain', default="MEDIUM", help='Gain string', type=str)
16  parser.add_argument('-p','--partition', dest='partition', default="Em", help='Data taking partition string', type=str)
17  parser.add_argument('-f','--fileprefix', dest='fprefix', default="data24_calib", help='File prefix string', type=str)
18  parser.add_argument('-i','--indirprefix', dest='dprefix', default="/eos/atlas/atlastier0/rucio/", help='Input directory prefix string', type=str)
19  parser.add_argument('-d','--indir', dest='indir', default="", help='Full input dir string', type=str)
20  parser.add_argument('-t','--trigger', dest='trig', default='calibration_', help='Trigger string in filename', type=str)
21  parser.add_argument('-o','--outrprefix', dest='outrprefix', default="LArRamp", help='Prefix of output ramp root filename', type=str)
22  parser.add_argument('-j','--outpprefix', dest='outpprefix', default="LArRamp", help='Prefix of output ramp pool filename', type=str)
23  parser.add_argument('-e','--outrdir', dest='outrdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/ntuples", help='Output root file directory', type=str)
24  parser.add_argument('-k','--outpdir', dest='outpdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/poolFiles", help='Output pool file directory', type=str)
25  parser.add_argument('-u','--inpsqlite', dest='inpsql', default="mysql.db", help='Input sqlite file with pedestals, in pool output dir.', type=str)
26  parser.add_argument('-l','--inofcsqlite', dest='inofcsql', default="mysql_delay.db", help='Input sqlite file with ofcs, in pool output dir', type=str)
27  parser.add_argument('-n','--outsqlite', dest='outsql', default="mysql_ramp.db", help='Output sqlite file, in pool output dir.', type=str)
28  parser.add_argument('-m','--subdet', dest='subdet', default="EMB", help='Subdetector, EMB, EMEC, HEC or FCAL', type=str)
29  parser.add_argument('-s','--side', dest='side', default="C", help='Detector side empty (means both), C or A', type=str)
30  parser.add_argument('-c','--isSC', dest='supercells', default=False, action="store_true", help='is SC data ?')
31  parser.add_argument('-a','--isRawdata', dest='rawdata', default=False, action="store_true", help='is raw data ?')
32  parser.add_argument('-b','--badchansqlite', dest='badsql', default="SnapshotBadChannel.db", help='Output sqlite file, in pool output dir.', type=str)
33  parser.add_argument('-x','--ignoreBarrel', dest='ignoreB', default=False, action="store_true", help='ignore Barrel channels ?')
34  parser.add_argument('-v','--ignoreEndcap', dest='ignoreE', default=False, action="store_true", help='ignore Endcap channels ?')
35  parser.add_argument('-w','--doValid', dest='doValid', default=False, action="store_true", help='run vcalidation ?')
36  parser.add_argument('--FW6', dest='fw6', default=False, help='Is it for fw v. 6', action='store_true')
37  parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
38 
39 
40  args = parser.parse_args()
41  if help in args and args.help is not None and args.help:
42  parser.print_help()
43  sys.exit(0)
44 
45  for _, value in args._get_kwargs():
46  if value is not None:
47  print(value)
48 
49  if len(args.run) < 8:
50  args.run = args.run.zfill(8)
51 
52  # now set flags according parsed options
53  if args.indir != "":
54  InputDir = args.indir
55  else:
56  gain=args.gain.lower().capitalize()
57 
58  if not args.supercells:
59  partstr = args.partition
60  else:
61  partstr = args.partition+"-DT"
62  if args.rawdata:
63  partstr += "-RawData"
64  # here - add optional nsamples
65  if args.supercells:
66  InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Ramp-32s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Ramp-32s-"+gain+"-"+partstr+".daq.RAW/"
67  else:
68  InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Ramp-7s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Ramp-7s-"+gain+"-"+partstr+".daq.RAW/"
69 
70 
71  #Import the configution-method we want to use (here: Pedestal and AutoCorr)
72  from LArCalibProcessing.LArCalib_RampConfig import LArRampCfg
73 
74  #Import the MainServices (boilerplate)
75  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
76 
77  #Import the flag-container that is the arguemnt to the configuration methods
78  from AthenaConfiguration.AllConfigFlags import initConfigFlags
79  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
81  addLArCalibFlags(flags, args.supercells)
82 
83  #Now we set the flags as required for this particular job:
84  #The following flags help finding the input bytestream files:
85  flags.LArCalib.Input.Dir = InputDir
86  flags.LArCalib.Input.Type = args.trig
87  flags.LArCalib.Input.RunNumbers = [int(args.run),]
88  flags.LArCalib.Input.Database = args.outpdir + "/" +args.inpsql
89  if 'db' in args.inofcsql:
90  flags.LArCalib.Input.Database2 = args.outpdir + "/" +args.inofcsql
91  else:
92  flags.LArCalib.Input.Database2 = args.inofcsql
93  gainNumMap={"HIGH":0,"MEDIUM":1,"LOW":2}
94  flags.LArCalib.Gain=gainNumMap[args.gain.upper()]
95 
96  # Input files
97  flags.Input.Files=flags.LArCalib.Input.Files
98  #Print the input files we found
99  print ("Input files to be processed:")
100  for f in flags.Input.Files:
101  print (f)
102 
103  if len(flags.Input.Files) == 0 :
104  print("Unable to find any input files. Please check the input directory:",InputDir)
105  sys.exit(0)
106 
107  #Some configs depend on the sub-calo in question
108  #(sets also the preselection of LArRawCalibDataReadingAlg)
109  if not flags.LArCalib.isSC:
110  if args.subdet == 'EMB' or args.subdet == 'EMEC':
111  flags.LArCalib.Input.SubDet="EM"
112  elif args.subdet:
113  flags.LArCalib.Input.SubDet=args.subdet
114 
115  if not args.side:
116  flags.LArCalib.Preselection.Side = [0,1]
117  elif args.side == "C":
118  flags.LArCalib.Preselection.Side = [0]
119  elif args.side == "A":
120  flags.LArCalib.Preselection.Side = [1]
121  else:
122  print("unknown side ",args.side)
123  sys.exit(-1)
124 
125  if args.subdet != "EM":
126  if args.subdet == 'EMB':
127  flags.LArCalib.Preselection.BEC = [0]
128  else:
129  flags.LArCalib.Preselection.BEC = [1]
130 
131  if args.subdet == 'FCAL':
132  flags.LArCalib.Preselection.FT = [6]
133  elif args.subdet == 'HEC':
134  flags.LArCalib.Preselection.FT = [3,10,16,22]
135  elif args.subdet == 'HECFCAL':
136  flags.LArCalib.Preselection.FT = [3,6,10,16,22]
137 
138  #Configure the Bad-Channel database we are reading
139  #(the AP typically uses a snapshot in an sqlite file
140  flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
141 
142  #Output of this job:
143  OutputRampRootFileName = args.outrprefix + "_" + args.run
144  OutputRampPoolFileName = args.outpprefix + "_" + args.run
145 
146  if args.subdet != "" and not flags.LArCalib.isSC:
147  OutputRampRootFileName += "_"+args.subdet
148  OutputRampPoolFileName += "_"+args.subdet
149  if flags.LArCalib.Input.SubDet=="EM":
150  OutputRampRootFileName += args.side
151  OutputRampPoolFileName += args.side
152 
153  OutputRampRootFileName += ".root"
154  OutputRampPoolFileName += ".pool.root"
155 
156  flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputRampRootFileName
157  flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputRampPoolFileName
158  flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
159 
160  #The global tag we are working with
161  flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
162 
163  from AthenaConfiguration.TestDefaults import defaultGeometryTags
164  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
165 
166  #run validation:
167  if flags.LArCalib.isSC:
168  flags.LArCalib.doValidation= args.doValid
169  else:
170  flags.LArCalib.doValidation=True
171 
172  #Define the global output Level:
173 
174  from AthenaCommon.Constants import INFO
175  flags.Exec.OutputLevel = INFO
176  from AthenaCommon.Constants import DEBUG
177  #flags.Exec.OutputLevel = DEBUG
178 
179  from AthenaConfiguration.Enums import LHCPeriod
180  flags.GeoModel.Run = LHCPeriod.Run3
181 
182  if args.emf:
183  # additions for EMF
184  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
185  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
186 
187  flags.lock()
188 
189  cfg=MainServicesCfg(flags)
190 
191  cfg.merge(LArRampCfg(flags))
192 
193  # all debug messages
194  cfg.getService("MessageSvc").debugLimit = 9999999
195  cfg.printConfig()
196  # in case debug is needed
197  #if flags.LArCalib.doValidation:
198  # from AthenaCommon.Constants import DEBUG
199  # cfg.getEventAlgo("LArRampPatcher").OutputLevel=DEBUG
200  # cfg.getEventAlgo("RampVal").OutputLevel=DEBUG
201 
202  # switch on if some calib. board is failing:
203  # adding new patching, again needed in summer 2023
204  #if flags.LArCalib.CorrectBadChannels:
205  # if flags.LArCalib.doValidation:
206  # cfg.getEventAlgo("RampVal").PatchCBs=[0x3fc70000]
207  #
208  # # block standard patching for this CB
209  # cfg.getEventAlgo("LArRampPatcher").DoNotPatchCBs=[0x3fc70000]
210 
211  if args.fw6:
212  from IOVDbSvc.IOVDbSvcConfig import addOverride
213  cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
214 
215 
216  # ignore some channels ?
217  if args.ignoreB:
218  cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
219  if args.ignoreE:
220  cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
221 
222  cfg.getService("IOVDbSvc").DBInstance=""
223 
224  # all messages
225  cfg.getService("MessageSvc").debugLimit = 99999999
226 
227  #run the application
228  cfg.run()
229 
230  #build tag hierarchy in output sqlite file
231  import subprocess
232  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py',args.outpdir + "/" + args.outsql , flags.IOVDb.GlobalTag])
233  print(cmdline)
234  try:
235  subprocess.run(cmdline, check=True)
236  except Exception as e:
237  print('Could not create tag hierarchy in output sqlite file !!!!')
238  sys.exit(-1)
239 
240 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.LArCalib_RampConfig.LArRampCfg
def LArRampCfg(flags)
Definition: LArCalib_RampConfig.py:6
python.IOVDbSvcConfig.addOverride
def addOverride(flags, folder, tag, db=None)
Definition: IOVDbSvcConfig.py:224
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
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