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 
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  for _, value in args._get_kwargs():
44  if value is not None:
45  print(value)
46 
47  if len(args.run) < 8:
48  args.run = args.run.zfill(8)
49 
50  # now set flags according parsed options
51  if args.indir != "":
52  InputDir = args.indir
53  else:
54  gain=args.gain.lower().capitalize()
55 
56  if not args.supercells:
57  partstr = args.partition
58  else:
59  partstr = args.partition+"-DT"
60  if args.rawdata:
61  partstr += "-RawData"
62  # here - add optional nsamples
63  if args.supercells:
64  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/"
65  else:
66  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/"
67 
68 
69  #Import the configution-method we want to use (here: Pedestal and AutoCorr)
70  from LArCalibProcessing.LArCalib_RampConfig import LArRampCfg
71 
72  #Import the MainServices (boilerplate)
73  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
74 
75  #Import the flag-container that is the arguemnt to the configuration methods
76  from AthenaConfiguration.AllConfigFlags import initConfigFlags
77  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
79  addLArCalibFlags(flags, args.supercells)
80 
81  #Now we set the flags as required for this particular job:
82  #The following flags help finding the input bytestream files:
83  flags.LArCalib.Input.Dir = InputDir
84  flags.LArCalib.Input.Type = args.trig
85  flags.LArCalib.Input.RunNumbers = [int(args.run),]
86  flags.LArCalib.Input.Database = args.outpdir + "/" +args.inpsql
87  if 'db' in args.inofcsql:
88  flags.LArCalib.Input.Database2 = args.outpdir + "/" +args.inofcsql
89  else:
90  flags.LArCalib.Input.Database2 = args.inofcsql
91  gainNumMap={"HIGH":0,"MEDIUM":1,"LOW":2}
92  flags.LArCalib.Gain=gainNumMap[args.gain.upper()]
93 
94  # Input files
95  flags.Input.Files=flags.LArCalib.Input.Files
96  #Print the input files we found
97  print ("Input files to be processed:")
98  for f in flags.Input.Files:
99  print (f)
100 
101  if len(flags.Input.Files) == 0 :
102  print("Unable to find any input files. Please check the input directory:",InputDir)
103  sys.exit(0)
104 
105  #Some configs depend on the sub-calo in question
106  #(sets also the preselection of LArRawCalibDataReadingAlg)
107  if not flags.LArCalib.isSC:
108  if args.subdet == 'EMB' or args.subdet == 'EMEC':
109  flags.LArCalib.Input.SubDet="EM"
110  elif args.subdet:
111  flags.LArCalib.Input.SubDet=args.subdet
112 
113  if not args.side:
114  flags.LArCalib.Preselection.Side = [0,1]
115  elif args.side == "C":
116  flags.LArCalib.Preselection.Side = [0]
117  elif args.side == "A":
118  flags.LArCalib.Preselection.Side = [1]
119  else:
120  print("unknown side ",args.side)
121  sys.exit(-1)
122 
123  if args.subdet != "EM":
124  if args.subdet == 'EMB':
125  flags.LArCalib.Preselection.BEC = [0]
126  else:
127  flags.LArCalib.Preselection.BEC = [1]
128 
129  if args.subdet == 'FCAL':
130  flags.LArCalib.Preselection.FT = [6]
131  elif args.subdet == 'HEC':
132  flags.LArCalib.Preselection.FT = [3,10,16,22]
133  elif args.subdet == 'HECFCAL':
134  flags.LArCalib.Preselection.FT = [3,6,10,16,22]
135 
136  #Configure the Bad-Channel database we are reading
137  #(the AP typically uses a snapshot in an sqlite file
138  flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
139 
140  #Output of this job:
141  OutputRampRootFileName = args.outrprefix + "_" + args.run
142  OutputRampPoolFileName = args.outpprefix + "_" + args.run
143 
144  if args.subdet != "" and not flags.LArCalib.isSC:
145  OutputRampRootFileName += "_"+args.subdet
146  OutputRampPoolFileName += "_"+args.subdet
147  if flags.LArCalib.Input.SubDet=="EM":
148  OutputRampRootFileName += args.side
149  OutputRampPoolFileName += args.side
150 
151  OutputRampRootFileName += ".root"
152  OutputRampPoolFileName += ".pool.root"
153 
154  flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputRampRootFileName
155  flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputRampPoolFileName
156  flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
157 
158  #The global tag we are working with
159  flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
160 
161  from AthenaConfiguration.TestDefaults import defaultGeometryTags
162  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
163 
164  #run validation:
165  if flags.LArCalib.isSC:
166  flags.LArCalib.doValidation= args.doValid
167  else:
168  flags.LArCalib.doValidation=True
169 
170  #Define the global output Level:
171 
172  from AthenaCommon.Constants import INFO
173  flags.Exec.OutputLevel = INFO
174  from AthenaCommon.Constants import DEBUG
175  #flags.Exec.OutputLevel = DEBUG
176 
177  from AthenaConfiguration.Enums import LHCPeriod
178  flags.GeoModel.Run = LHCPeriod.Run3
179 
180  flags.lock()
181 
182  cfg=MainServicesCfg(flags)
183 
184  cfg.merge(LArRampCfg(flags))
185 
186  # all debug messages
187  cfg.getService("MessageSvc").debugLimit = 9999999
188  cfg.printConfig()
189  # in case debug is needed
190  #if flags.LArCalib.doValidation:
191  # from AthenaCommon.Constants import DEBUG
192  # cfg.getEventAlgo("LArRampPatcher").OutputLevel=DEBUG
193  # cfg.getEventAlgo("RampVal").OutputLevel=DEBUG
194 
195  # switch on if some calib. board is failing:
196  # adding new patching, again needed in summer 2023
197  #if flags.LArCalib.CorrectBadChannels:
198  # if flags.LArCalib.doValidation:
199  # cfg.getEventAlgo("RampVal").PatchCBs=[0x3fc70000]
200  #
201  # # block standard patching for this CB
202  # cfg.getEventAlgo("LArRampPatcher").DoNotPatchCBs=[0x3fc70000]
203 
204  # ignore some channels ?
205  if args.ignoreB:
206  cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
207  if args.ignoreE:
208  cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
209 
210  # all messages
211  cfg.getService("MessageSvc").debugLimit = 99999999
212 
213  #run the application
214  cfg.run()
215 
216  #build tag hierarchy in output sqlite file
217  import subprocess
218  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py',args.outpdir + "/" + args.outsql , flags.IOVDb.GlobalTag])
219  print(cmdline)
220  try:
221  subprocess.run(cmdline, check=True)
222  except Exception as e:
223  print('Could not create tag hierarchy in output sqlite file !!!!')
224  sys.exit(-1)
225 
226 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.LArCalib_RampConfig.LArRampCfg
def LArRampCfg(flags)
Definition: LArCalib_RampConfig.py:6
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:252
Constants
some useful constants -------------------------------------------------—
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3