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( '--addAccSamples', dest='accsamples', default=False, help='work on accumulated samples', action="store_true")
29  parser.add_argument( '--addAccCalibSamples', dest='acccalibsamples', default=False, help='work on accumulated samples', action="store_true")
30  parser.add_argument('-z','--addEt', dest='Et', default=False, help='Add ET to output ntuple', action="store_true")
31  parser.add_argument('-g','--addEtId', dest='EtId', default=False, help='Add ET_ID to output ntuple', action="store_true")
32  parser.add_argument('-l','--noLatHeader', dest='lheader', default=True, help='Add LATOME Header to output ntuple', action='store_false')
33  parser.add_argument('-b','--noBCID', dest='bcid', default=True, help='Add BCID info to output ntuple', action='store_false')
34  parser.add_argument('-e','--expandId', dest='expid', default=False, help='Expand online Id to fields', action='store_true')
35  parser.add_argument('-n','--nsamp', dest='nsamp', default=0, help='Number of samples to dump', type=int)
36  parser.add_argument('-c','--overEvNumber', dest='overEvN', default=False, help='Overwrite event number', action='store_true')
37  parser.add_argument('-d','--addHash', dest='ahash', default=False, help='Add hash number to output ntuple', action='store_true')
38  parser.add_argument('-j','--addOffline', dest='offline', default=False, help='Add offline Id to output ntuple', action='store_true')
39  parser.add_argument('-k','--addCalib', dest='calib', default=False, help='Add calib. info to output ntuple', action='store_true')
40  parser.add_argument('-t','--addGeom', dest='geom', default=False, help='Add real geom info to output ntuple', action='store_true')
41  parser.add_argument('-u','--noBC', dest='bc', default=False, help='Add Bad. chan info to output ntuple', action='store_true')
42  parser.add_argument('-w','--addROD', dest='rod', default=False, help='Add ROD energies sum to output ntuple', action='store_true')
43  parser.add_argument('-v','--addEvTree', dest='evtree', default=False, help='Add tree with per event info to output ntuple', action='store_true')
44  parser.add_argument('-q','--addNoisyRO', dest='noisyRO', default=False, help='Add reco and info from LArNoisyROSummary to output ntuple', action='store_true')
45  parser.add_argument('--addTT', dest='TT', default=False, help='Add info from LArTriggerTowers to output ntuple', action='store_true')
46  parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
47  parser.add_argument('--FW6', dest='fw6', default=False, help='Is it for fw v. 6', action='store_true')
48 
49  args = parser.parse_args()
50  if help in args and args.help is not None and args.help:
51  parser.print_help()
52  sys.exit(0)
53 
54  for _, value in args._get_kwargs():
55  if value is not None:
56  log.debug(value)
57 
58  #Import the flag-container that is the arguemnt to the configuration methods
59  from AthenaConfiguration.AllConfigFlags import initConfigFlags
61  if args.accsamples or args.acccalibsamples:
62  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
63  addLArCalibFlags(flags, True)
64  #add SC dumping specific flags
65  from LArCafJobs.LArSCDumperFlags import addSCDumpFlags
66  addSCDumpFlags(flags)
67 
68  # check samples combination:
69  if (args.accsamples or args.acccalibsamples) and (args.samples or args.samplesBas):
70  log.error('Could not dump both samples and accumulated calib samples')
71  sys.exit(1)
72  if args.accsamples and args.acccalibsamples:
73  log.error('Could not dump both accsamples and acc calib samples')
74  sys.exit(1)
75 
76  if len(args.infile) > 0:
77  flags.Input.Files = [args.infile]
78  elif len(args.inppatt) > 0:
79  from LArCalibProcessing.GetInputFiles import GetInputFilesFromPattern
80  flags.Input.Files = GetInputFilesFromPattern(args.indir,args.inppatt)
81  else:
82  from LArCalibProcessing.GetInputFiles import GetInputFilesFromPrefix
83  flags.Input.Files = GetInputFilesFromPrefix(args.indir,args.inpref)
84 
85  if args.run != 0:
86  flags.Input.RunNumbers = [args.run]
87 
88  # geometry
89  from AthenaConfiguration.TestDefaults import defaultGeometryTags
90  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
91 
92  if args.accsamples:
93  flags.LArSCDump.accdigitsKey="accSC"
94  else:
95  flags.LArSCDump.accdigitsKey=""
96  if args.acccalibsamples:
97  flags.LArSCDump.acccalibdigitsKey="acccalibSC"
98  else:
99  flags.LArSCDump.acccalibdigitsKey=""
100  CKeys=[]
101  flags.LArSCDump.digitsKey=""
102  if not (args.accsamples or args.acccalibsamples):
103  # autoconfig
104  from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
105  try:
106  runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
107  log.info("Got DT run info !")
108  except Exception:
109  log.warning("Could not get DT run info, using defaults !")
110  flags.LArSCDump.doEt=True
111  if args.nsamp > 0:
112  flags.LArSCDump.nSamples=args.nsamp
113  else:
114  flags.LArSCDump.nSamples=5
115  flags.LArSCDump.nEt=1
116  if args.samples:
117  flags.LArSCDump.digitsKey="SC"
118  CKeys=["SC_ET"]
119  else:
120  CKeys=[]
121  flags.LArSCDump.digitsKey=""
122  for i in range(0,len(runinfo.streamTypes())):
123  if args.EtId and runinfo.streamTypes()[i] == "SelectedEnergy":
124  CKeys += ["SC_ET_ID"]
125  flags.LArSCDump.doEt=True
126  flags.LArSCDump.nEt=runinfo.streamLengths()[i]
127  elif args.Et and runinfo.streamTypes()[i] == "Energy":
128  CKeys += ["SC_ET"]
129  flags.LArSCDump.doEt=True
130  flags.LArSCDump.nEt=runinfo.streamLengths()[i]
131  elif args.samples and runinfo.streamTypes()[i] == "RawADC":
132  flags.LArSCDump.digitsKey="SC"
133  if args.nsamp > 0:
134  flags.LArSCDump.nSamples=args.nsamp
135  else:
136  flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
137  elif args.samplesBas and runinfo.streamTypes()[i] == "ADC":
138  CKeys += ["SC_ADC_BAS"]
139  flags.LArSCDump.doSamplesBas=True
140  if args.nsamp > 0:
141  flags.LArSCDump.nSamples=args.nsamp
142  else:
143  flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
144  if args.nsamp > 0 and args.nsamp < flags.LArSCDump.nSamples:
145  flags.LArSCDump.nSamples=args.nsamp
146 
147  # calib runs do not have info about accumulation
148  if args.accsamples:
149  flags.LArSCDump.accdigitsKey = "accSC"
150  flags.Input.OverrideRunNumber = True
151 
152  # now set flags according parsed options
153  #if args.samples and not ("SC" in CKeys or flags.LArSCDump.digitsKey=="SC"):
154  # log.warning("Samples asked, but they are not in RunLogger, no output !!!!")
155 
156  if args.samples and not ("SC" in flags.LArSCDump.digitsKey):
157  flags.LArSCDump.digitsKey="SC"
158  if args.samplesBas and "SC_ADC_BAS" not in CKeys:
159  CKeys += ["SC_ADC_BAS"]
160  flags.LArSCDump.doSamplesBas=True
161  if args.Et and "SC_ET" not in CKeys:
162  CKeys += ["SC_ET"]
163  if args.EtId and "SC_ET_ID" not in CKeys:
164  CKeys += ["SC_ET_ID"]
165  if args.lheader and "SC_LATOME_HEADER" not in CKeys:
166  CKeys += ["SC_LATOME_HEADER"]
167 
168  if args.rod:
169  flags.LArSCDump.doRawChan=True
170  CKeys += ["LArRawChannels"]
171  log.info("Adding ROD energies")
172 
173  log.info("Autoconfigured: ")
174  log.info("nSamples: %d nEt: %d digitsKey %s accdigitsKey %s acccalibdigitsKey %s",flags.LArSCDump.nSamples, flags.LArSCDump.nEt, flags.LArSCDump.digitsKey, flags.LArSCDump.accdigitsKey, flags.LArSCDump.acccalibdigitsKey)
175  log.info(CKeys)
176 
177  # now construct the job
178  flags.LAr.doAlign=False
179 
180  if args.evtree: # should include trigger info
181  flags.Trigger.triggerConfig = 'DB'
182  flags.Trigger.L1.doCTP = True
183  flags.Trigger.L1.doMuon = False
184  flags.Trigger.L1.doCalo = False
185  flags.Trigger.L1.doTopo = False
186 
187  flags.Trigger.enableL1CaloLegacy = True
188  flags.Trigger.enableL1CaloPhase1 = False
189 
190  if args.TT:
191  flags.Trigger.L1.doCalo = True
192  flags.Trigger.triggerConfig = 'DB'
193 
194  flags.LArSCDump.fillNoisyRO=args.noisyRO
195  # in case stores needs to be debugged:
196  #from AthenaCommon.Constants import DEBUG
197  flags.Exec.OutputLevel=args.olevel
198  #flags.Debug.DumpCondStore=True
199  #flags.Debug.DumpDetStore=True
200  #flags.Debug.DumpEvtStore=True
201 
202  if args.emf:
203  # additions for EMF
204  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
205  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
206 
207  flags.lock()
208  flags.dump('LArSCDump.*')
209 
210 
211 
212  #Import the MainServices (boilerplate)
213  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
214  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
215 
216  acc = MainServicesCfg(flags)
217  acc.merge(LArGMCfg(flags))
218 
219  if args.accsamples:
220  from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg
221  acc.merge(LArCalibBaseCfg(flags))
222  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
223  acc.merge(ByteStreamReadCfg(flags))
224 
225  if args.evtree: # should include trigger info
226  from LArCafJobs.LArSCDumperSkeleton import L1CaloMenuCfg
227  acc.merge(L1CaloMenuCfg(flags))
228  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
229  tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
230  else:
231  tdt = None
232 
233 
234  if args.fw6:
235  # addition for new firmware
236  from IOVDbSvc.IOVDbSvcConfig import addOverride
237  acc.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
238  if args.bc:
239  from LArBadChannelTool.LArBadChannelConfig import LArBadFebCfg, LArBadChannelCfg
240  acc.merge(LArBadChannelCfg(flags,None,True))
241  acc.merge(LArBadFebCfg(flags))
242 
243  if args.geom:
244  acc.addCondAlgo(CompFactory.CaloAlignCondAlg(LArAlignmentStore="",CaloCellPositionShiftFolder=""))
245  acc.addCondAlgo(CompFactory.CaloSuperCellAlignCondAlg())
246  args.offline=True
247 
248  from LArCalibTools.LArSC2NtupleConfig import LArSC2NtupleCfg
249  acc.merge(LArSC2NtupleCfg(flags, isEmf = args.emf, AddBadChannelInfo=args.bc, AddFEBTempInfo=False, isSC=True, isFlat=False,
250  OffId=args.offline, AddHash=args.ahash, AddCalib=args.calib, RealGeometry=args.geom, ExpandId=args.expid, # from LArCond2NtupleBase
251  NSamples=flags.LArSCDump.nSamples, FTlist=[], FillBCID=args.bcid, ContainerKey=flags.LArSCDump.digitsKey, AccContainerKey=flags.LArSCDump.accdigitsKey, AccCalibContainerKey=flags.LArSCDump.acccalibdigitsKey,# from LArDigits2Ntuple
252  SCContainerKeys=CKeys, OverwriteEventNumber = args.overEvN, # from LArSC2Ntuple
253  FillRODEnergy = flags.LArSCDump.doRawChan,
254  FillLB=args.evtree, FillTriggerType = args.evtree,
255  TrigNames=["L1_EM3","L1_EM7","L1_EM15","L1_EM22VHI","L1_eEM5","L1_eEM15","L1_eEM22M"],
256  TrigDecisionTool=tdt, FillTriggerTowers = args.TT,
257  OutputLevel=args.olevel
258  ))
259  # ROOT file writing
260  if os.path.exists(args.outfile):
261  os.remove(args.outfile)
262  acc.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+args.outfile+"' OPT='NEW'" ]))
263  acc.setAppProperty("HistogramPersistency","ROOT")
264 
265  # calib runs do not have proper run number in metadata
266  if args.accsamples or args.acccalibsamples:
267  acc.getService("IOVDbSvc").forceRunNumber=int(args.run)
268 
269  acc.getService("MessageSvc").defaultLimit=999999
270 
271  # some logging
272  log.info("Input files to be processed:")
273  for f in flags.Input.Files:
274  log.info(f)
275  log.info("Output file: ")
276  log.info(args.outfile)
277 
278  # and run
279  acc.run(args.maxev)
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArSCDumperSkeleton.L1CaloMenuCfg
def L1CaloMenuCfg(flags)
Definition: LArSCDumperSkeleton.py:11
python.LArBadChannelConfig.LArBadChannelCfg
def LArBadChannelCfg(configFlags, tag=None, isSC=False)
Definition: LArBadChannelConfig.py:8
python.ByteStreamConfig.ByteStreamReadCfg
def ByteStreamReadCfg(flags, type_names=None)
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:25
python.LArBadChannelConfig.LArBadFebCfg
def LArBadFebCfg(configFlags, tag=None)
Definition: LArBadChannelConfig.py:45
python.IOVDbSvcConfig.addOverride
def addOverride(flags, folder, tag, db=None)
Definition: IOVDbSvcConfig.py:224
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:260
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.LArCalibBaseConfig.LArCalibBaseCfg
def LArCalibBaseCfg(flags)
Definition: LArCalibBaseConfig.py:5
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
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3
LArSC2NtupleConfig.LArSC2NtupleCfg
def LArSC2NtupleCfg(flags, isEmf=False, **kwargs)
Definition: LArSC2NtupleConfig.py:5