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