ATLAS Offline Software
LArNewCalib_Delay_OFC_Cali.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='00408918', 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','--outrwaveprefix', dest='outrwaveprefix', default="LArCaliWave", help='Prefix of CaliWave output root filename', type=str)
22  parser.add_argument('-l','--outpprefix', dest='outpprefix', default="LArCaliWave_OFC_Cali", help='Prefix of output pool filename', type=str)
23  parser.add_argument('-j','--outrofcprefix', dest='outrofcprefix', default="LArOFCCali", help='Prefix of output Cali OFC root filename', type=str)
24  parser.add_argument('-e','--outrdir', dest='outrdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/ntuples", help='Output root file directory', type=str)
25  parser.add_argument('-k','--outpdir', dest='outpdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/poolFiles", help='Output pool file directory', type=str)
26  parser.add_argument('-u','--insqlite', dest='insql', default="mysql.db", help='Input sqlite file with pedestals, in pool output dir.', type=str)
27  parser.add_argument('-n','--outsqlite', dest='outsql', default="mysql_delay.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, FCAL or HECFCAL', 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('-x','--ignoreBarrel', dest='ignoreB', default=False, action="store_true", help='ignore Barrel channels ?')
33  parser.add_argument('-v','--ignoreEndcap', dest='ignoreE', default=False, action="store_true", help='ignore Endcap channels ?')
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('--FW6', dest='fw6', default=False, help='Is it for fw v. 6', action='store_true')
36  parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
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  if not args.supercells:
56  partstr = args.partition
57  else:
58  partstr = args.partition+"-DT"
59  if args.rawdata:
60  partstr += "-RawData"
61  # here - add optional nsamples
62  InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Delay-32s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Delay-32s-"+gain+"-"+partstr+".daq.RAW/"
63 
64  #Import the configution-method we want to use (here: Pedestal and AutoCorr)
65  from LArCalibProcessing.LArCalib_Delay_OFCCaliConfig import LArDelay_OFCCaliCfg
66 
67  #Import the MainServices (boilerplate)
68  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
69 
70  #Import the flag-container that is the arguemnt to the configuration methods
71  from AthenaConfiguration.AllConfigFlags import initConfigFlags
72  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
74  addLArCalibFlags(flags, args.supercells)
75 
76  #Now we set the flags as required for this particular job:
77  #The following flags help finding the input bytestream files:
78  flags.LArCalib.Input.Dir = InputDir
79  flags.LArCalib.Input.Type = args.trig
80  flags.LArCalib.Input.RunNumbers = [int(args.run),]
81  flags.LArCalib.Input.Database = args.outpdir + "/" +args.insql
82  flags.LArCalib.Input.isRawData = args.rawdata
83  gainNumMap={"HIGH":0,"MEDIUM":1,"LOW":2}
84  flags.LArCalib.Gain=gainNumMap[args.gain.upper()]
85 
86 
87  # Input files
88  flags.Input.Files=flags.LArCalib.Input.Files
89  #Print the input files we found
90  print ("Input files to be processed:")
91  for f in flags.Input.Files:
92  print (f)
93 
94  if len(flags.Input.Files) == 0 :
95  print("Unable to find any input files. Please check the input directory:",InputDir)
96  sys.exit(0)
97 
98  #Some configs depend on the sub-calo in question
99  #(sets also the preselection of LArRawCalibDataReadingAlg)
100  if not flags.LArCalib.isSC:
101  if args.subdet == 'EMB' or args.subdet == 'EMEC':
102  flags.LArCalib.Input.SubDet="EM"
103  elif args.subdet:
104  flags.LArCalib.Input.SubDet=args.subdet
105 
106  if not args.side:
107  flags.LArCalib.Preselection.Side = [0,1]
108  elif args.side == "C":
109  flags.LArCalib.Preselection.Side = [0]
110  elif args.side == "A":
111  flags.LArCalib.Preselection.Side = [1]
112  else:
113  print("unknown side ",args.side)
114  sys.exit(-1)
115 
116  if args.subdet != "EM":
117  if args.subdet == 'EMB':
118  flags.LArCalib.Preselection.BEC = [0]
119  else:
120  flags.LArCalib.Preselection.BEC = [1]
121 
122  if args.subdet == 'FCAL':
123  flags.LArCalib.Preselection.FT = [6]
124  elif args.subdet == 'HEC':
125  flags.LArCalib.Preselection.FT = [3,10,16,22]
126  elif args.subdet == 'HECFCAL':
127  flags.LArCalib.Preselection.FT = [3,6,10,16,22]
128 
129  #Configure the Bad-Channel database we are reading
130  #(the AP typically uses a snapshot in an sqlite file
131  flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
132 
133  #Output of this job:
134  OutputCaliWaveRootFileName = args.outrwaveprefix + "_" + args.run
135  OutputPoolFileName = args.outpprefix + "_" + args.run
136  OutputOFCCaliRootFileName = args.outrofcprefix + "_" + args.run
137 
138  if args.subdet != "" and not flags.LArCalib.isSC:
139  OutputCaliWaveRootFileName += "_"+args.subdet
140  OutputPoolFileName += "_"+args.subdet
141  OutputOFCCaliRootFileName += "_"+args.subdet
142 
143  if flags.LArCalib.Input.SubDet=="EM":
144  OutputCaliWaveRootFileName += args.side
145  OutputPoolFileName += args.side
146  OutputOFCCaliRootFileName += args.side
147 
148  OutputCaliWaveRootFileName += ".root"
149  OutputPoolFileName += ".pool.root"
150  OutputOFCCaliRootFileName += ".root"
151 
152  flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputCaliWaveRootFileName
153  flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputPoolFileName
154  flags.LArCalib.Output.ROOTFile2 = args.outrdir + "/" + OutputOFCCaliRootFileName
155  if args.outsql.startswith("/"):
156  flags.IOVDb.DBConnection="sqlite://;schema=" + args.outsql +";dbname=CONDBR2"
157  else:
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  #validation not working for SC because no reference in OFL DB
164  if args.supercells:
165  flags.LArCalib.doValidation=False
166 
167  #Other potentially useful flags-settings:
168 
169  # patterns file searching
170  if args.rawdata:
171  if args.emf:
172  pdir='/afs/cern.ch/user/l/lardaq/public/detlar/athena/P1CalibrationProcessing/run/Patterns/EMF/EMF_Oct2024/Delay/emf/'
173  pfile = pdir+args.partition+'/parameters.dat'
174  else:
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_HighDelay/parameters.dat'
180  else:
181  pfile = pdir + 'barrel/Delay_' + 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  flags.LArCalib.Input.paramsFile = pfile
189 
190 
191  #Define the global output Level:
192  from AthenaCommon.Constants import INFO
193  flags.Exec.OutputLevel = INFO
194 
195  from AthenaConfiguration.Enums import LHCPeriod
196  flags.GeoModel.Run = LHCPeriod.Run3
197 
198  from AthenaConfiguration.TestDefaults import defaultGeometryTags
199  flags.GeoModel.AtlasVersion = defaultGeometryTags.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  flags.LArCalib.doValidation=False
206 
207  flags.lock()
208  flags.dump(evaluate=True)
209 
210  cfg=MainServicesCfg(flags)
211 
212  cfg.merge(LArDelay_OFCCaliCfg(flags))
213 
214  # Switch on, in case some calib. board is failing:
215  # adding new patching, again needed in summer 2023
216  #if flags.LArCalib.CorrectBadChannels:
217  # if flags.LArCalib.doValidation:
218  # cfg.getEventAlgo("CaliWaveVal").PatchCBs=[0x3df70000]
219  #
220  # # block standard patching for this CB
221  # cfg.getEventAlgo("LArCaliWavePatch").DoNotPatchCBs=[0x3df70000]
222 
223  if args.fw6:
224  from IOVDbSvc.IOVDbSvcConfig import addOverride
225  cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
226 
227  if args.emf:
228  from IOVDbSvc.IOVDbSvcConfig import addOverride
229  cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-EMF"))
230  fldrs=cfg.getService("IOVDbSvc").Folders
231  for i in range(0, len(fldrs)):
232  if 'Align' in fldrs[i]: fldrs[i] += '<forceRunNumber>9999999</forceRunNumber>'
233 
234  # ignore some channels ?
235  if args.ignoreB:
236  if args.rawdata:
237  cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
238  else:
239  cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreBarrelChannels=args.ignoreB
240  if args.ignoreE:
241  if args.rawdata:
242  cfg.getEventAlgo("LArRawSCDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
243  else:
244  cfg.getEventAlgo("LArRawSCCalibDataReadingAlg").LATOMEDecoder.IgnoreEndcapChannels=args.ignoreE
245 
246  cfg.getService("IOVDbSvc").DBInstance=""
247 
248  cfg.getService("MessageSvc").defaultLimit=20000 #more messages
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 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
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
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Constants
some useful constants -------------------------------------------------—
python.LArCalib_Delay_OFCCaliConfig.LArDelay_OFCCaliCfg
def LArDelay_OFCCaliCfg(flags)
Definition: LArCalib_Delay_OFCCaliConfig.py:6
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