ATLAS Offline Software
LArSC2NtupleDumper.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 from AthenaConfiguration.ComponentFactory import CompFactory
6 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
7 
8 if __name__=='__main__':
9 
10  import os,sys
11  import argparse
12  import subprocess
13  from AthenaCommon import Logging
14  log = Logging.logging.getLogger( 'LArSC2Ntuple' )
15 
16  parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
17 
18  parser.add_argument('-i','--indir', dest='indir', default="/eos/atlas/atlastier0/rucio/data_test/calibration_pulseall/00414414/data_test.00414414.calibration_pulseall.daq.RAW/", help='input files dir', type=str)
19  parser.add_argument('-p','--inprefix', dest='inpref', default="data_test", help='Input filenames prefix', type=str)
20  parser.add_argument('-y','--inppatt', dest='inppatt', default="lb3512", help='Input filenames pattern', type=str)
21  parser.add_argument('-f','--infile', dest='infile', default="", help='Input filename (if given indir and inprefix are ignored', type=str)
22  parser.add_argument('-r','--run', dest='run', default=0, help='Run number (if not given trying to judge from input file name)', type=int)
23  parser.add_argument('-m','--maxev', dest='maxev', default=-1, help='Max number of events to dump', type=int)
24  parser.add_argument('-x','--outlevel', dest='olevel', default=5, help='OuputLevel for dumping algo', type=int)
25  parser.add_argument('-o','--outfile', dest='outfile', default="Digits.root", help='Output root filename', type=str)
26  parser.add_argument('-s','--addSamples', dest='samples', default=False, help='Add Samples to output ntuple', action="store_true")
27  parser.add_argument('-a','--addSampBas', dest='samplesBas', default=False, help='Add ADC_BAS to output ntuple', action="store_true")
28  parser.add_argument('-z','--addEt', dest='Et', default=False, help='Add ET to output ntuple', action="store_true")
29  parser.add_argument('-g','--addEtId', dest='EtId', default=False, help='Add ET_ID to output ntuple', action="store_true")
30  parser.add_argument('-l','--noLatHeader', dest='lheader', default=True, help='Add LATOME Header to output ntuple', action='store_false')
31  parser.add_argument('-b','--noBCID', dest='bcid', default=True, help='Add BCID info to output ntuple', action='store_false')
32  parser.add_argument('-e','--expandId', dest='expid', default=False, help='Expand online Id to fields', action='store_true')
33  parser.add_argument('-n','--nsamp', dest='nsamp', default=0, help='Number of samples to dump', type=int)
34  parser.add_argument('-c','--overEvNumber', dest='overEvN', default=False, help='Overwrite event number', action='store_true')
35  parser.add_argument('-d','--addHash', dest='ahash', default=False, help='Add hash number to output ntuple', action='store_true')
36  parser.add_argument('-j','--addOffline', dest='offline', default=False, help='Add offline Id to output ntuple', action='store_true')
37  parser.add_argument('-k','--addCalib', dest='calib', default=False, help='Add calib. info to output ntuple', action='store_true')
38  parser.add_argument('-t','--addGeom', dest='geom', default=False, help='Add real geom info to output ntuple', action='store_true')
39  parser.add_argument('-u','--noBC', dest='bc', default=False, help='Add Bad. chan info to output ntuple', action='store_true')
40  parser.add_argument('-w','--addROD', dest='rod', default=False, help='Add ROD energies sum to output ntuple', action='store_true')
41  parser.add_argument('-v','--addEvTree', dest='evtree', default=False, help='Add tree with per event info to output ntuple', action='store_true')
42  parser.add_argument('-q','--addNoisyRO', dest='noisyRO', default=False, help='Add reco and info from LArNoisyROSummary to output ntuple', action='store_true')
43  parser.add_argument('--addTT', dest='TT', default=False, help='Add info from LArTriggerTowers to output ntuple', action='store_true')
44  parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
45 
46  args = parser.parse_args()
47  if help in args and args.help is not None and args.help:
48  parser.print_help()
49  sys.exit(0)
50 
51  for _, value in args._get_kwargs():
52  if value is not None:
53  log.debug(value)
54 
55  #Import the flag-container that is the arguemnt to the configuration methods
56  from AthenaConfiguration.AllConfigFlags import initConfigFlags
58  #add SC dumping specific flags
59  from LArCafJobs.LArSCDumperFlags import addSCDumpFlags
60  addSCDumpFlags(flags)
61 
62  if len(args.infile) > 0:
63  flags.Input.Files = [args.infile]
64  elif len(args.inppatt) > 0:
65  from LArCalibProcessing.GetInputFiles import GetInputFilesFromPattern
66  flags.Input.Files = GetInputFilesFromPattern(args.indir,args.inppatt)
67  else:
68  from LArCalibProcessing.GetInputFiles import GetInputFilesFromPrefix
69  flags.Input.Files = GetInputFilesFromPrefix(args.indir,args.inpref)
70 
71  if args.run != 0:
72  flags.Input.RunNumbers = [args.run]
73 
74  # geometry
75  from AthenaConfiguration.TestDefaults import defaultGeometryTags
76  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
77 
78  # first autoconfig
79  from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
80  try:
81  runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
82  except Exception:
83  log.warning("Could not get DT run info, using defaults !")
84  flags.LArSCDump.doEt=True
85  if args.nsamp > 0:
86  flags.LArSCDump.nSamples=args.nsamp
87  else:
88  flags.LArSCDump.nSamples=5
89  flags.LArSCDump.nEt=1
90  flags.LArSCDump.digitsKey="SC"
91  CKeys=["SC_ET"]
92  else:
93  CKeys=[]
94  flags.LArSCDump.digitsKey=""
95  for i in range(0,len(runinfo.streamTypes())):
96  if args.EtId and runinfo.streamTypes()[i] == "SelectedEnergy":
97  CKeys += ["SC_ET_ID"]
98  flags.LArSCDump.doEt=True
99  flags.LArSCDump.nEt=runinfo.streamLengths()[i]
100  elif args.Et and runinfo.streamTypes()[i] == "Energy":
101  CKeys += ["SC_ET"]
102  flags.LArSCDump.doEt=True
103  flags.LArSCDump.nEt=runinfo.streamLengths()[i]
104  elif args.samples and runinfo.streamTypes()[i] == "RawADC":
105  flags.LArSCDump.digitsKey="SC"
106  if args.nsamp > 0:
107  flags.LArSCDump.nSamples=args.nsamp
108  else:
109  flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
110  elif args.samplesBas and runinfo.streamTypes()[i] == "ADC":
111  CKeys += ["SC_ADC_BAS"]
112  if args.nsamp > 0:
113  flags.LArSCDump.nSamples=args.nsamp
114  else:
115  flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
116  if args.nsamp > 0 and args.nsamp < flags.LArSCDump.nSamples:
117  flags.LArSCDump.nSamples=args.nsamp
118 
119  log.info("Autoconfigured: ")
120  log.info("nSamples: %d nEt: %d digitsKey %s",flags.LArSCDump.nSamples, flags.LArSCDump.nEt, flags.LArSCDump.digitsKey)
121  log.info(CKeys)
122 
123  # now set flags according parsed options
124  #if args.samples and not ("SC" in CKeys or flags.LArSCDump.digitsKey=="SC"):
125  # log.warning("Samples asked, but they are not in RunLogger, no output !!!!")
126 
127  if args.samplesBas and "SC_ADC_BAS" not in CKeys:
128  CKeys += ["SC_ADC_BAS"]
129  if args.Et and "SC_ET" not in CKeys:
130  CKeys += ["SC_ET"]
131  if args.EtId and "SC_ET_ID" not in CKeys:
132  CKeys += ["SC_ET_ID"]
133  if args.lheader and "SC_LATOME_HEADER" not in CKeys:
134  CKeys += ["SC_LATOME_HEADER"]
135 
136  if args.rod:
137  flags.LArSCDump.doRawChan=True
138  CKeys += ["LArRawChannels"]
139  log.info("Adding ROD energies")
140 
141  # now construct the job
142  flags.LAr.doAlign=False
143 
144  if args.evtree: # should include trigger info
145  flags.Trigger.triggerConfig = 'DB'
146  flags.Trigger.L1.doCTP = True
147  flags.Trigger.L1.doMuon = False
148  flags.Trigger.L1.doCalo = False
149  flags.Trigger.L1.doTopo = False
150 
151  flags.Trigger.enableL1CaloLegacy = True
152  flags.Trigger.enableL1CaloPhase1 = False
153 
154  if args.TT:
155  flags.Trigger.L1.doCalo = True
156  flags.Trigger.triggerConfig = 'DB'
157 
158  flags.LArSCDump.fillNoisyRO=args.noisyRO
159  # in case stores needs to be debugged:
160  #from AthenaCommon.Constants import DEBUG
161  flags.Exec.OutputLevel=args.olevel
162  #flags.Debug.DumpCondStore=True
163  #flags.Debug.DumpDetStore=True
164  #flags.Debug.DumpEvtStore=True
165 
166  # additions for EMF
167  if args.emf:
168  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
169  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
170 
171  flags.lock()
172  flags.dump('LArSCDump.*')
173 
174 
175  #Import the MainServices (boilerplate)
176  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
177  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
178 
179  acc = MainServicesCfg(flags)
180  acc.merge(LArGMCfg(flags))
181 
182  if args.evtree: # should include trigger info
183  from LArCafJobs.LArSCDumperSkeleton import L1CaloMenuCfg
184  acc.merge(L1CaloMenuCfg(flags))
185  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
186  tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
187  else:
188  tdt = None
189 
190 
191  if args.bc:
192  from LArBadChannelTool.LArBadChannelConfig import LArBadFebCfg, LArBadChannelCfg
193  acc.merge(LArBadChannelCfg(flags,None,True))
194  acc.merge(LArBadFebCfg(flags))
195 
196  if args.geom:
197  acc.addCondAlgo(CompFactory.CaloAlignCondAlg(LArAlignmentStore="",CaloCellPositionShiftFolder=""))
198  acc.addCondAlgo(CompFactory.CaloSuperCellAlignCondAlg())
199 
200  from LArCalibTools.LArSC2NtupleConfig import LArSC2NtupleCfg
201  acc.merge(LArSC2NtupleCfg(flags, isEmf = args.emf, AddBadChannelInfo=args.bc, AddFEBTempInfo=False, isSC=True, isFlat=False,
202  OffId=args.offline, AddHash=args.ahash, AddCalib=args.calib, RealGeometry=args.geom, ExpandId=args.expid, # from LArCond2NtupleBase
203  NSamples=flags.LArSCDump.nSamples, FTlist=[], FillBCID=args.bcid, ContainerKey=flags.LArSCDump.digitsKey, # from LArDigits2Ntuple
204  SCContainerKeys=CKeys, OverwriteEventNumber = args.overEvN, # from LArSC2Ntuple
205  FillRODEnergy = flags.LArSCDump.doRawChan,
206  FillLB=args.evtree, FillTriggerType = args.evtree,
207  TrigNames=["L1_EM3","L1_EM7","L1_EM15","L1_EM22VHI","L1_eEM5","L1_eEM15","L1_eEM22M"],
208  TrigDecisionTool=tdt, FillTriggerTowers = args.TT,
209  OutputLevel=args.olevel
210  ))
211  # ROOT file writing
212  if os.path.exists(args.outfile):
213  os.remove(args.outfile)
214  acc.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+args.outfile+"' OPT='NEW'" ]))
215  acc.setAppProperty("HistogramPersistency","ROOT")
216 
217  # some logging
218  log.info("Input files to be processed:")
219  for f in flags.Input.Files:
220  log.info(f)
221  log.info("Output file: ")
222  log.info(args.outfile)
223 
224  # and run
225  acc.run(args.maxev)
LArSCDumperSkeleton.L1CaloMenuCfg
def L1CaloMenuCfg(flags)
Definition: LArSCDumperSkeleton.py:11
python.LArBadChannelConfig.LArBadChannelCfg
def LArBadChannelCfg(configFlags, tag=None, isSC=False)
Definition: LArBadChannelConfig.py:8
python.LArBadChannelConfig.LArBadFebCfg
def LArBadFebCfg(configFlags, tag=None)
Definition: LArBadChannelConfig.py:45
python.LArRunFormat.getLArDTInfoForRun
def getLArDTInfoForRun(run, quiet=False, connstring="COOLONL_LAR/CONDBR2")
Definition: LArRunFormat.py:114
LArRunFormat
LArSCDumperFlags.addSCDumpFlags
def addSCDumpFlags(flags)
Definition: LArSCDumperFlags.py:3
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:252
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
python.GetInputFiles.GetInputFilesFromPrefix
def GetInputFilesFromPrefix(inputPath, prefix=".*")
Definition: GetInputFiles.py:37
python.TriggerInterface.TrigDecisionToolCfg
def TrigDecisionToolCfg(flags)
Definition: TriggerInterface.py:14
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.GetInputFiles.GetInputFilesFromPattern
def GetInputFilesFromPattern(inputPath, prefix=".*", trigger=".*")
Definition: GetInputFiles.py:32
LArSC2NtupleConfig.LArSC2NtupleCfg
def LArSC2NtupleCfg(flags, isEmf=False, **kwargs)
Definition: LArSC2NtupleConfig.py:6