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  flags.LArCalib.Input.isRawData = args.rawdata
90  if 'db' in args.inofcsql:
91  flags.LArCalib.Input.Database2 = args.outpdir + "/" +args.inofcsql
92  else:
93  flags.LArCalib.Input.Database2 = args.inofcsql
94  gainNumMap={"HIGH":0,"MEDIUM":1,"LOW":2}
95  flags.LArCalib.Gain=gainNumMap[args.gain.upper()]
96 
97  # Input files
98  flags.Input.Files=flags.LArCalib.Input.Files
99  #Print the input files we found
100  print ("Input files to be processed:")
101  for f in flags.Input.Files:
102  print (f)
103 
104  if len(flags.Input.Files) == 0 :
105  print("Unable to find any input files. Please check the input directory:",InputDir)
106  sys.exit(0)
107 
108  #Some configs depend on the sub-calo in question
109  #(sets also the preselection of LArRawCalibDataReadingAlg)
110  if not flags.LArCalib.isSC:
111  if args.subdet == 'EMB' or args.subdet == 'EMEC':
112  flags.LArCalib.Input.SubDet="EM"
113  elif args.subdet:
114  flags.LArCalib.Input.SubDet=args.subdet
115 
116  if not args.side:
117  flags.LArCalib.Preselection.Side = [0,1]
118  elif args.side == "C":
119  flags.LArCalib.Preselection.Side = [0]
120  elif args.side == "A":
121  flags.LArCalib.Preselection.Side = [1]
122  else:
123  print("unknown side ",args.side)
124  sys.exit(-1)
125 
126  if args.subdet != "EM":
127  if args.subdet == 'EMB':
128  flags.LArCalib.Preselection.BEC = [0]
129  else:
130  flags.LArCalib.Preselection.BEC = [1]
131 
132  if args.subdet == 'FCAL':
133  flags.LArCalib.Preselection.FT = [6]
134  elif args.subdet == 'HEC':
135  flags.LArCalib.Preselection.FT = [3,10,16,22]
136  elif args.subdet == 'HECFCAL':
137  flags.LArCalib.Preselection.FT = [3,6,10,16,22]
138 
139  #Configure the Bad-Channel database we are reading
140  #(the AP typically uses a snapshot in an sqlite file
141  flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
142 
143  #Output of this job:
144  OutputRampRootFileName = args.outrprefix + "_" + args.run
145  OutputRampPoolFileName = args.outpprefix + "_" + args.run
146 
147  if args.subdet != "" and not flags.LArCalib.isSC:
148  OutputRampRootFileName += "_"+args.subdet
149  OutputRampPoolFileName += "_"+args.subdet
150  if flags.LArCalib.Input.SubDet=="EM":
151  OutputRampRootFileName += args.side
152  OutputRampPoolFileName += args.side
153 
154  OutputRampRootFileName += ".root"
155  OutputRampPoolFileName += ".pool.root"
156 
157  flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputRampRootFileName
158  flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputRampPoolFileName
159  flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
160 
161  #The global tag we are working with
162  flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
163 
164  from AthenaConfiguration.TestDefaults import defaultGeometryTags
165  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
166 
167  #run validation:
168  if flags.LArCalib.isSC:
169  flags.LArCalib.doValidation= args.doValid
170  else:
171  flags.LArCalib.doValidation=True
172 
173  # patterns file searching
174  if args.rawdata:
175  pdir='/afs/cern.ch/user/l/lardaq/public/detlar/athena/P1CalibrationProcessing/run/Patterns/P1/'
176  if args.supercells:
177  pdir += 'LatomeRuns/'
178  if 'Emec' in args.partition:
179  pfile = pdir + 'emec-std/SC_HighRamp/parameters.dat'
180  else:
181  pfile = pdir + 'barrel/Ramp_' + args.partition[:-4] + '/parameters.dat'
182 
183  flags.LArCalib.Input.paramsFile = pfile
184  else:
185  pdir += 'Delay/'
186  #FIXME create search also for main readout
187  pass
188 
189  #Define the global output Level:
190 
191  from AthenaCommon.Constants import INFO
192  flags.Exec.OutputLevel = INFO
193  from AthenaCommon.Constants import DEBUG
194  #flags.Exec.OutputLevel = DEBUG
195 
196  from AthenaConfiguration.Enums import LHCPeriod
197  flags.GeoModel.Run = LHCPeriod.Run3
198 
199  if args.emf:
200  # additions for EMF
201  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
202  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
203 
204  flags.lock()
205 
206  cfg=MainServicesCfg(flags)
207 
208  cfg.merge(LArRampCfg(flags))
209 
210  # all debug messages
211  cfg.getService("MessageSvc").debugLimit = 9999999
212  cfg.printConfig()
213  # in case debug is needed
214  #if flags.LArCalib.doValidation:
215  # from AthenaCommon.Constants import DEBUG
216  # cfg.getEventAlgo("LArRampPatcher").OutputLevel=DEBUG
217  # cfg.getEventAlgo("RampVal").OutputLevel=DEBUG
218 
219  # switch on if some calib. board is failing:
220  # adding new patching, again needed in summer 2023
221  #if flags.LArCalib.CorrectBadChannels:
222  # if flags.LArCalib.doValidation:
223  # cfg.getEventAlgo("RampVal").PatchCBs=[0x3fc70000]
224  #
225  # # block standard patching for this CB
226  # cfg.getEventAlgo("LArRampPatcher").DoNotPatchCBs=[0x3fc70000]
227 
228  if args.fw6:
229  from IOVDbSvc.IOVDbSvcConfig import addOverride
230  cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
231 
232 
233  # ignore some channels ?
234  if args.ignoreB:
235  if args.rawdata:
236  cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
237  else:
238  cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
239  if args.ignoreE:
240  if args.rawdata:
241  cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
242  else:
243  cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
244 
245  cfg.getService("IOVDbSvc").DBInstance=""
246 
247  # all messages
248  cfg.getService("MessageSvc").debugLimit = 99999999
249 
250  #run the application
251  cfg.run()
252 
253  #build tag hierarchy in output sqlite file
254  import subprocess
255  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py',args.outpdir + "/" + args.outsql , flags.IOVDb.GlobalTag])
256  print(cmdline)
257  try:
258  subprocess.run(cmdline, check=True)
259  except Exception as e:
260  print('Could not create tag hierarchy in output sqlite file !!!!')
261  sys.exit(-1)
262 
263 
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:233
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3