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  parser.add_argument('--FTs', dest='ft', default=[], nargs="+", type=int, help='list of FT which will be read out (space separated).')
49  parser.add_argument('--posneg', dest='posneg', default=[], nargs="+", help='side to read out (-1 means both), can give multiple arguments (space separated). Default %(default)s.', type=int,choices=range(-1,2))
50  parser.add_argument('--barrel_ec', dest='be', default=[], nargs="+", help='subdet to read out (-1 means both), can give multiple arguments (space separated) Default %(default)s.', type=int,choices=range(-1,2))
51  parser.add_argument('--ETThresh', dest='etthresh', default=-1., help='ET threshold to dump info', type=float)
52  parser.add_argument('--ETThreshMain', dest='etthreshmain', default=-1., help='ET threshold from Main to dump info', type=float)
53  parser.add_argument('--ADCThresh', dest='adcthresh', default=-1, help='ADC threshold to dump info', type=int)
54 
55  args = parser.parse_args()
56  if help in args and args.help is not None and args.help:
57  parser.print_help()
58  sys.exit(0)
59 
60  for _, value in args._get_kwargs():
61  if value is not None:
62  log.debug(value)
63 
64  #Import the flag-container that is the arguemnt to the configuration methods
65  from AthenaConfiguration.AllConfigFlags import initConfigFlags
67  if args.accsamples or args.acccalibsamples:
68  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
69  addLArCalibFlags(flags, True)
70  if len(args.posneg) >= 0:
71  flags.LArCalib.Preselection.Side = args.posneg
72  if len(args.be) >=0:
73  flags.LArCalib.Preselection.BEC = args.be
74  if len(args.ft) > 0:
75  flags.LArCalib.Preselection.FT = args.ft
76  #add SC dumping specific flags
77  from LArCafJobs.LArSCDumperFlags import addSCDumpFlags
78  addSCDumpFlags(flags)
79 
80  # check samples combination:
81  if (args.accsamples or args.acccalibsamples) and (args.samples or args.samplesBas):
82  log.error('Could not dump both samples and accumulated calib samples')
83  sys.exit(1)
84  if args.accsamples and args.acccalibsamples:
85  log.error('Could not dump both accsamples and acc calib samples')
86  sys.exit(1)
87 
88  if len(args.infile) > 0:
89  flags.Input.Files = [args.infile]
90  elif len(args.inppatt) > 0:
91  from LArCalibProcessing.GetInputFiles import GetInputFilesFromPattern
92  flags.Input.Files = GetInputFilesFromPattern(args.indir,args.inppatt)
93  else:
94  from LArCalibProcessing.GetInputFiles import GetInputFilesFromPrefix
95  flags.Input.Files = GetInputFilesFromPrefix(args.indir,args.inpref)
96 
97  if args.run != 0:
98  flags.Input.RunNumbers = [args.run]
99 
100  # geometry
101  from AthenaConfiguration.TestDefaults import defaultGeometryTags
102  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
103 
104  if args.accsamples:
105  flags.LArSCDump.accdigitsKey="accSC"
106  else:
107  flags.LArSCDump.accdigitsKey=""
108  if args.acccalibsamples:
109  flags.LArSCDump.acccalibdigitsKey="acccalibSC"
110  else:
111  flags.LArSCDump.acccalibdigitsKey=""
112 
113  flags.LArSCDump.doBC = args.bc
114  bckey='LArBadChannel'
115 
116  flags.LArSCDump.digitsKey=""
117  CKeys=[]
118  fwversion=5
119 
120  # autoconfig
121  from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
122  try:
123  runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
124  except Exception:
125  log.warning("Could not get DT run info, using defaults !")
126  flags.LArSCDump.doEt=True
127  if args.nsamp > 0:
128  flags.LArSCDump.nSamples=args.nsamp
129  else:
130  flags.LArSCDump.nSamples=5
131  flags.LArSCDump.nEt=1
132  if args.samples:
133  flags.LArSCDump.digitsKey="SC"
134  CKeys=["SC_ET"]
135  log.debug(runinfo.streamTypes(), ' ',runinfo.streamLengths())
136  else:
137  fwversion=runinfo.FWversion()
138  if not (args.accsamples or args.acccalibsamples):
139  flags.LArSCDump.digitsKey=""
140  for i in range(0,len(runinfo.streamTypes())):
141  if args.EtId and runinfo.streamTypes()[i] == "SelectedEnergy":
142  CKeys += ["SC_ET_ID"]
143  flags.LArSCDump.doEt=True
144  flags.LArSCDump.nEt=runinfo.streamLengths()[i]
145  elif args.Et and runinfo.streamTypes()[i] == "Energy":
146  CKeys += ["SC_ET"]
147  flags.LArSCDump.doEt=True
148  flags.LArSCDump.nEt=runinfo.streamLengths()[i]
149  elif args.samples and runinfo.streamTypes()[i] == "RawADC":
150  flags.LArSCDump.digitsKey="SC"
151  if args.nsamp > 0:
152  flags.LArSCDump.nSamples=args.nsamp
153  else:
154  flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
155  elif args.samplesBas and runinfo.streamTypes()[i] == "ADC":
156  CKeys += ["SC_ADC_BAS"]
157  if args.nsamp > 0:
158  flags.LArSCDump.nSamples=args.nsamp
159  else:
160  flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
161  if args.nsamp > 0 and args.nsamp < flags.LArSCDump.nSamples:
162  flags.LArSCDump.nSamples=args.nsamp
163 
164  # calib runs do not have info about accumulation
165  if args.accsamples or args.acccalibsamples:
166  flags.Input.OverrideRunNumber = True
167 
168  # now set flags according parsed options
169  #if args.samples and not ("SC" in CKeys or flags.LArSCDump.digitsKey=="SC"):
170  # log.warning("Samples asked, but they are not in RunLogger, no output !!!!")
171 
172  if args.samples and not ("SC" in flags.LArSCDump.digitsKey):
173  flags.LArSCDump.digitsKey="SC"
174  if args.samplesBas and "SC_ADC_BAS" not in CKeys:
175  CKeys += ["SC_ADC_BAS"]
176  flags.LArSCDump.doSamplesBas=True
177  if args.Et and "SC_ET" not in CKeys:
178  CKeys += ["SC_ET"]
179  if args.EtId and "SC_ET_ID" not in CKeys:
180  CKeys += ["SC_ET_ID"]
181  if args.lheader and "SC_LATOME_HEADER" not in CKeys:
182  CKeys += ["SC_LATOME_HEADER"]
183 
184  if args.rod:
185  flags.LArSCDump.doRawChan=True
186  CKeys += ["LArRawChannels"]
187  log.info("Adding ROD energies")
188 
189  log.info("Autoconfigured: ")
190  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)
191  log.info(CKeys)
192 
193  # now construct the job
194  flags.LAr.doAlign=False
195 
196  if args.evtree: # should include trigger info
197  flags.Trigger.triggerConfig = 'DB'
198  flags.Trigger.L1.doCTP = True
199  flags.Trigger.L1.doMuon = False
200  flags.Trigger.L1.doCalo = False
201  flags.Trigger.L1.doTopo = False
202 
203  flags.Trigger.enableL1CaloLegacy = True
204  flags.Trigger.enableL1CaloPhase1 = False
205 
206  if args.TT:
207  flags.Trigger.L1.doCalo = True
208  flags.Trigger.triggerConfig = 'DB'
209 
210  flags.LArSCDump.fillNoisyRO=args.noisyRO
211  # in case stores needs to be debugged:
212  #from AthenaCommon.Constants import DEBUG
213  flags.Exec.OutputLevel=args.olevel
214  #flags.Debug.DumpCondStore=True
215  #flags.Debug.DumpDetStore=True
216  #flags.Debug.DumpEvtStore=True
217 
218  if args.emf:
219  # additions for EMF
220  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
221  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
222 
223  if args.etthresh > 0.:
224  flags.LArSCDump.ETThresh = args.etthresh
225 
226  if args.etthreshmain > 0.:
227  flags.LArSCDump.ETThreshMain = args.etthreshmain
228 
229  flags.lock()
230  flags.dump('LArSCDump.*')
231 
232 
233 
234  #Import the MainServices (boilerplate)
235  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
236  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
237 
238  acc = MainServicesCfg(flags)
239  acc.merge(LArGMCfg(flags))
240 
241  if args.accsamples:
242  from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg
243  acc.merge(LArCalibBaseCfg(flags))
244  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
245  acc.merge(ByteStreamReadCfg(flags))
246 
247  if args.evtree: # should include trigger info
248  from LArCafJobs.LArSCDumperSkeleton import L1CaloMenuCfg
249  acc.merge(L1CaloMenuCfg(flags))
250  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
251  tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
252  else:
253  tdt = None
254 
255 
256  if args.fw6 or fwversion==6:
257  # addition for new firmware
258  from IOVDbSvc.IOVDbSvcConfig import addOverride
259  if args.emf:
260  acc.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-emf-fw6"))
261  else:
262  acc.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
263  if args.bc:
264  from LArBadChannelTool.LArBadChannelConfig import LArBadFebCfg, LArBadChannelCfg
265  acc.merge(LArBadChannelCfg(flags,None,True))
266  acc.merge(LArBadFebCfg(flags))
267  bckey+='SC'
268 
269  if args.geom:
270  acc.addCondAlgo(CompFactory.CaloAlignCondAlg(LArAlignmentStore="",CaloCellPositionShiftFolder=""))
271  acc.addCondAlgo(CompFactory.CaloSuperCellAlignCondAlg())
272  args.offline=True
273 
274  from LArCalibTools.LArSC2NtupleConfig import LArSC2NtupleCfg
275  acc.merge(LArSC2NtupleCfg(flags, isEmf = args.emf, AddBadChannelInfo=args.bc, AddFEBTempInfo=False, isSC=True, isFlat=False,
276  OffId=args.offline, AddHash=args.ahash, AddCalib=args.calib, RealGeometry=args.geom, ExpandId=args.expid, BadChanKey=bckey, # from LArCond2NtupleBase
277  NSamples=flags.LArSCDump.nSamples, FTlist=[], FillBCID=args.bcid, ContainerKey=flags.LArSCDump.digitsKey, AccContainerKey=flags.LArSCDump.accdigitsKey, AccCalibContainerKey=flags.LArSCDump.acccalibdigitsKey,# from LArDigits2Ntuple
278  SCContainerKeys=CKeys, OverwriteEventNumber = args.overEvN, # from LArSC2Ntuple
279  FillRODEnergy = flags.LArSCDump.doRawChan,
280  FillLB=args.evtree, FillTriggerType = args.evtree,
281  ETThreshold = flags.LArSCDump.ETThresh, ETThresholdMain = flags.LArSCDump.ETThreshMain, ADCThreshold=args.adcthresh,
282  TrigNames=["L1_EM3","L1_EM7","L1_EM15","L1_EM22VHI","L1_eEM5","L1_eEM15","L1_eEM22M"],
283  TrigDecisionTool=tdt, FillTriggerTowers = args.TT,
284  OutputLevel=args.olevel
285  ))
286  # ROOT file writing
287  if os.path.exists(args.outfile):
288  os.remove(args.outfile)
289  acc.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+args.outfile+"' OPT='NEW'" ]))
290  acc.setAppProperty("HistogramPersistency","ROOT")
291 
292  # calib runs do not have proper run number in metadata
293  if args.accsamples or args.acccalibsamples:
294  acc.getService("IOVDbSvc").forceRunNumber=int(args.run)
295 
296  acc.getService("MessageSvc").defaultLimit=999999
297 
298  # some logging
299  acc.getService("MessageSvc").defaultLimit=99999999
300  log.info("Input files to be processed:")
301  for f in flags.Input.Files:
302  log.info(f)
303  log.info("Output file: ")
304  log.info(args.outfile)
305 
306  # and run
307  acc.run(args.maxev)
python.LArBadChannelConfig.LArBadFebCfg
def LArBadFebCfg(configFlags, tag=None, dbname=None)
Definition: LArBadChannelConfig.py:43
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.LArRunFormat.getLArDTInfoForRun
def getLArDTInfoForRun(run, quiet=False, connstring="COOLONL_LAR/CONDBR2")
Definition: LArRunFormat.py:152
LArRunFormat
LArSCDumperFlags.addSCDumpFlags
def addSCDumpFlags(flags)
Definition: LArSCDumperFlags.py:3
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:312
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
LArSC2NtupleDumper.int
int
Definition: LArSC2NtupleDumper.py:48
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.IOVDbSvcConfig.addOverride
def addOverride(flags, folder, tag, tagType="tag", db=None)
Definition: IOVDbSvcConfig.py:238
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