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