ATLAS Offline Software
LArNewCalib_PedestalAutoCorr.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  import subprocess
11  from AthenaCommon import Logging
12  log = Logging.logging.getLogger( 'LArPedestalAutoCorr' )
13 
14  MinSample = -1
15  MaxSample = -1
16 
17  # now process the CL options and assign defaults
18  parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
19  #parser.add_argument('-r','--runlist', dest='runlist', default=RunNumberList, nargs='+', help='Run numbers string list', type=str)
20  parser.add_argument('-r','--run', dest='run', default='00408913', help='Run number string as in input filename', type=str)
21  parser.add_argument('-g','--gain', dest='gain', default="MEDIUM", help='Gain string', type=str)
22  parser.add_argument('-p','--partition', dest='partition', default="All", help='Partition string', type=str)
23  parser.add_argument('-f','--fileprefix', dest='fprefix', default="data24_calib", help='File prefix string', type=str)
24  parser.add_argument('-i','--indirprefix', dest='dprefix', default="/eos/atlas/atlastier0/rucio/", help='Input directory prefix string', type=str)
25  parser.add_argument('-d','--indir', dest='indir', default="", help='Full input dir string', type=str)
26  parser.add_argument('-t','--trigger', dest='trig', default='calibration_', help='Trigger string in filename', type=str)
27  parser.add_argument('-o','--outrprefix', dest='outrprefix', default="LArPedAutoCorr", help='Prefix of output root filename', type=str)
28  parser.add_argument('-l','--outpprefix', dest='outpprefix', default="LArPedAutoCorr", help='Prefix of output pool filename', type=str)
29  parser.add_argument('-e','--outrdir', dest='outrdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/ntuples", help='Output root file directory', type=str)
30  parser.add_argument('-k','--outpdir', dest='outpdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/poolFiles", help='Output pool file directory', type=str)
31  parser.add_argument('-n','--outsqlite', dest='outsql', default="mysql.db", help='Output sqlite file, in pool output dir.', type=str)
32  parser.add_argument('-m','--subdet', dest='subdet', default="EMB", help='Subdetector, EMB, EMEC, HEC or FCAL', type=str)
33  parser.add_argument('-s','--side', dest='side', default="C", help='Detector side empty (means both), C or A', type=str)
34  parser.add_argument('-c','--isSC', dest='supercells', default=False, action="store_true", help='is SC data ?')
35  parser.add_argument('-a','--isRawdata', dest='rawdata', default=False, action="store_true", help='is raw data ?')
36  parser.add_argument('-b','--badchansqlite', dest='badsql', default="SnapshotBadChannel.db", help='Input sqlite file with bad chans.', type=str)
37  parser.add_argument('--FW6', dest='fw6', default=False, help='Is it for fw v. 6', action='store_true')
38  parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
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  log.debug(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 
59  if not args.supercells:
60  partstr = args.partition
61  else:
62  partstr = args.partition+"-DT"
63  if args.rawdata:
64  partstr += "-RawData"
65  # here - add optional nsamples
66  InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Pedestal-32s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Pedestal-32s-"+gain+"-"+partstr+".daq.RAW/"
67 
68  #Import the configution-method we want to use (here: Pedestal and AutoCorr)
69  from LArCalibProcessing.LArCalib_PedestalAutoCorrConfig import LArPedestalAutoCorrCfg
70 
71  #Import the MainServices (boilerplate)
72  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
73 
74  #Import the flag-container that is the arguemnt to the configuration methods
75  from AthenaConfiguration.AllConfigFlags import initConfigFlags
76  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
77  flags=initConfigFlags()
78  #first needs to define, if we are with SC or not
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.isRawData = args.rawdata
87 
88  from AthenaConfiguration.TestDefaults import defaultGeometryTags
89  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
90 
91  # Input files
92  flags.Input.Files=flags.LArCalib.Input.Files
93  #Print the input files we found
94  log.info("Input files to be processed:")
95  for f in flags.Input.Files:
96  log.info(f)
97 
98  if len(flags.Input.Files) == 0 :
99  print("Unable to find any input files. Please check the input directory:",InputDir)
100  sys.exit(0)
101 
102 
103  #Some configs depend on the sub-calo in question
104  #(sets also the preselection of LArRawCalibDataReadingAlg)
105  if not flags.LArCalib.isSC:
106  if args.subdet == 'EMB' or args.subdet == 'EMEC':
107  flags.LArCalib.Input.SubDet="EM"
108  else:
109  flags.LArCalib.Input.SubDet=args.subdet
110 
111  if args.side !="":
112  if args.side == "C":
113  flags.LArCalib.Preselection.Side = [0]
114  elif args.side == "A":
115  flags.LArCalib.Preselection.Side = [1]
116  else:
117  log.warning("Bad side argument: ",args.side," using both!!")
118 
119  if args.subdet == 'EMB':
120  flags.LArCalib.Preselection.BEC = [0]
121  else:
122  flags.LArCalib.Preselection.BEC = [1]
123 
124  if args.subdet == 'FCAL':
125  flags.LArCalib.Preselection.FT = [6]
126  elif args.subdet == 'HEC':
127  flags.LArCalib.Preselection.FT = [3,10,16,22]
128 
129  #Output of this job:
130  OutputPedAutoCorrRootFileName = args.outrprefix + "_" + args.run
131  OutputPedAutoCorrPoolFileName = args.outpprefix + "_" + args.run
132 
133  if args.subdet != "" and not flags.LArCalib.isSC:
134  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + "_"+args.subdet
135  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + "_"+args.subdet
136  if flags.LArCalib.Input.SubDet=="EM":
137  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + args.side
138  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + args.side
139  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + ".root"
140  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + ".pool.root"
141 
142  flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputPedAutoCorrRootFileName
143  flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputPedAutoCorrPoolFileName
144  if args.outsql.startswith("/"):
145  flags.IOVDb.DBConnection="sqlite://;schema=" + args.outsql +";dbname=CONDBR2"
146  else:
147  flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
148 
149  #The global tag we are working with
150  flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
151 
152  #BadChannels sqlite file to be created
153  if not args.emf:
154  if args.badsql.startswith("/"):
155  flags.LArCalib.BadChannelDB = args.badsql
156  else:
157  flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
158 
159  #Other potentially useful flags-settings:
160 
161  #Define the global output Level:
162  from AthenaCommon.Constants import INFO
163  flags.Exec.OutputLevel = INFO
164 
165  from AthenaConfiguration.Enums import LHCPeriod
166  flags.GeoModel.Run = LHCPeriod.Run3
167 
168  if args.emf:
169  # additions for EMF
170  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
171  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap","/LAR/BadChannelsOfl/MissingFEBs","/LAR/BadChannelsOfl/KnownMNBFEBs", "/LAR/BadChannelsOfl/KnownBADFEBs")
172  flags.LArCalib.doValidation=False
173 
174  flags.lock()
175  flags.dump(evaluate=True)
176 
177  # create bad chan sqlite file
178  cmdlinerm = (['/bin/rm', '-f', flags.LArCalib.BadChannelDB])
179  if not flags.LArCalib.isSC:
180  cmdline = (['AtlCoolCopy', 'COOLOFL_LAR/CONDBR2', 'sqlite://;schema='+flags.LArCalib.BadChannelDB+';dbname=CONDBR2', '-f', '/LAR/BadChannelsOfl/BadChannels', '-f', '/LAR/BadChannelsOfl/MissingFEBs', '-t', flags.IOVDb.GlobalTag, '-c', '-a', '-hitag'])
181  else:
182  cmdline = (['AtlCoolCopy', 'COOLOFL_LAR/CONDBR2', 'sqlite://;schema='+flags.LArCalib.BadChannelDB+';dbname=CONDBR2', '-f', '/LAR/BadChannelsOfl/BadChannelsSC', '-t', 'LARBadChannelsOflBadChannelsSC'+flags.LArCalib.BadChannelTagSC, '-c', '-a', '-hitag', '-ch', '0'])
183 
184  try:
185  cp = subprocess.run(cmdlinerm, check=True, capture_output=True )
186  except Exception as e:
187  print((" ").join(cmdlinerm))
188  log.info('not existing BadChan sqlite file, fine')
189  sys.exit(-1)
190  print((" ").join(cmdlinerm))
191  print(cp.stdout)
192  try:
193  cp = subprocess.run(cmdline, check=True, capture_output=True )
194  except Exception as e:
195  print(e)
196  print((" ").join(cmdline))
197  log.error('Could not create BadChan sqlite file !!!!')
198  sys.exit(-1)
199  print((" ").join(cmdline))
200  print(cp.stdout)
201 
202  cfg=MainServicesCfg(flags)
203 
204  cfg.merge(LArPedestalAutoCorrCfg(flags))
205 
206  if args.fw6:
207  from IOVDbSvc.IOVDbSvcConfig import addOverride
208  cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
209 
210  cfg.getService("IOVDbSvc").DBInstance=""
211 
212  if args.emf:
213  fldrs=cfg.getService("IOVDbSvc").Folders
214  for i in range(0, len(fldrs)):
215  if 'Align' in fldrs[i]: fldrs[i] += '<forceRunNumber>9999999</forceRunNumber>'
216  if 'LatomeMapping' in fldrs[i]: fldrs[i] +='<tag>LARIdentifierLatomeMapping-EMF</tag>'
217 
218  #run the application
219  cfg.run()
220 
221  #build tag hierarchy in output sqlite file
222  if args.outsql.startswith("/"):
223  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py', args.outsql , flags.IOVDb.GlobalTag])
224  else:
225  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py',args.outpdir + "/" + args.outsql , flags.IOVDb.GlobalTag])
226  log.debug(cmdline)
227  try:
228  subprocess.run(cmdline, check=True)
229  except Exception as e:
230  log.error('Could not create tag hierarchy in output sqlite file !!!!')
231  sys.exit(-1)
232 
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_PedestalAutoCorrConfig.LArPedestalAutoCorrCfg
def LArPedestalAutoCorrCfg(flags)
Definition: LArCalib_PedestalAutoCorrConfig.py:32
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
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