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 
101  flags.LArSCDump.digitsKey=""
102  CKeys=[]
103 
104  if not (args.accsamples or args.acccalibsamples):
105  # autoconfig
106  from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
107  try:
108  runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
109  except Exception:
110  log.warning("Could not get DT run info, using defaults !")
111  flags.LArSCDump.doEt=True
112  if args.nsamp > 0:
113  flags.LArSCDump.nSamples=args.nsamp
114  else:
115  flags.LArSCDump.nSamples=5
116  flags.LArSCDump.nEt=1
117  if args.samples:
118  flags.LArSCDump.digitsKey="SC"
119  CKeys=["SC_ET"]
120  else:
121  CKeys=[]
122  flags.LArSCDump.digitsKey=""
123  for i in range(0,len(runinfo.streamTypes())):
124  if args.EtId and runinfo.streamTypes()[i] == "SelectedEnergy":
125  CKeys += ["SC_ET_ID"]
126  flags.LArSCDump.doEt=True
127  flags.LArSCDump.nEt=runinfo.streamLengths()[i]
128  elif args.Et and runinfo.streamTypes()[i] == "Energy":
129  CKeys += ["SC_ET"]
130  flags.LArSCDump.doEt=True
131  flags.LArSCDump.nEt=runinfo.streamLengths()[i]
132  elif args.samples and runinfo.streamTypes()[i] == "RawADC":
133  flags.LArSCDump.digitsKey="SC"
134  if args.nsamp > 0:
135  flags.LArSCDump.nSamples=args.nsamp
136  else:
137  flags.LArSCDump.nSamples=runinfo.streamLengths()[i]
138  elif args.samplesBas and runinfo.streamTypes()[i] == "ADC":
139  CKeys += ["SC_ADC_BAS"]
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 or args.acccalibsamples:
149  flags.Input.OverrideRunNumber = True
150 
151  # now set flags according parsed options
152  #if args.samples and not ("SC" in CKeys or flags.LArSCDump.digitsKey=="SC"):
153  # log.warning("Samples asked, but they are not in RunLogger, no output !!!!")
154 
155  if args.samples and not ("SC" in flags.LArSCDump.digitsKey):
156  flags.LArSCDump.digitsKey="SC"
157  if args.samplesBas and "SC_ADC_BAS" not in CKeys:
158  CKeys += ["SC_ADC_BAS"]
159  flags.LArSCDump.doSamplesBas=True
160  if args.Et and "SC_ET" not in CKeys:
161  CKeys += ["SC_ET"]
162  if args.EtId and "SC_ET_ID" not in CKeys:
163  CKeys += ["SC_ET_ID"]
164  if args.lheader and "SC_LATOME_HEADER" not in CKeys:
165  CKeys += ["SC_LATOME_HEADER"]
166 
167  if args.rod:
168  flags.LArSCDump.doRawChan=True
169  CKeys += ["LArRawChannels"]
170  log.info("Adding ROD energies")
171 
172  log.info("Autoconfigured: ")
173  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)
174  log.info(CKeys)
175 
176  # now construct the job
177  flags.LAr.doAlign=False
178 
179  if args.evtree: # should include trigger info
180  flags.Trigger.triggerConfig = 'DB'
181  flags.Trigger.L1.doCTP = True
182  flags.Trigger.L1.doMuon = False
183  flags.Trigger.L1.doCalo = False
184  flags.Trigger.L1.doTopo = False
185 
186  flags.Trigger.enableL1CaloLegacy = True
187  flags.Trigger.enableL1CaloPhase1 = False
188 
189  if args.TT:
190  flags.Trigger.L1.doCalo = True
191  flags.Trigger.triggerConfig = 'DB'
192 
193  flags.LArSCDump.fillNoisyRO=args.noisyRO
194  # in case stores needs to be debugged:
195  #from AthenaCommon.Constants import DEBUG
196  flags.Exec.OutputLevel=args.olevel
197  #flags.Debug.DumpCondStore=True
198  #flags.Debug.DumpDetStore=True
199  #flags.Debug.DumpEvtStore=True
200 
201  if args.emf:
202  # additions for EMF
203  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
204  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap",)
205 
206  flags.lock()
207  flags.dump('LArSCDump.*')
208 
209 
210 
211  #Import the MainServices (boilerplate)
212  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
213  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
214 
215  acc = MainServicesCfg(flags)
216  acc.merge(LArGMCfg(flags))
217 
218  if args.accsamples:
219  from LArCalibProcessing.LArCalibBaseConfig import LArCalibBaseCfg
220  acc.merge(LArCalibBaseCfg(flags))
221  from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
222  acc.merge(ByteStreamReadCfg(flags))
223 
224  if args.evtree: # should include trigger info
225  from LArCafJobs.LArSCDumperSkeleton import L1CaloMenuCfg
226  acc.merge(L1CaloMenuCfg(flags))
227  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
228  tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
229  else:
230  tdt = None
231 
232 
233  if args.fw6:
234  # addition for new firmware
235  from IOVDbSvc.IOVDbSvcConfig import addOverride
236  acc.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
237  if args.bc:
238  from LArBadChannelTool.LArBadChannelConfig import LArBadFebCfg, LArBadChannelCfg
239  acc.merge(LArBadChannelCfg(flags,None,True))
240  acc.merge(LArBadFebCfg(flags))
241 
242  if args.geom:
243  acc.addCondAlgo(CompFactory.CaloAlignCondAlg(LArAlignmentStore="",CaloCellPositionShiftFolder=""))
244  acc.addCondAlgo(CompFactory.CaloSuperCellAlignCondAlg())
245  args.offline=True
246 
247  from LArCalibTools.LArSC2NtupleConfig import LArSC2NtupleCfg
248  acc.merge(LArSC2NtupleCfg(flags, isEmf = args.emf, AddBadChannelInfo=args.bc, AddFEBTempInfo=False, isSC=True, isFlat=False,
249  OffId=args.offline, AddHash=args.ahash, AddCalib=args.calib, RealGeometry=args.geom, ExpandId=args.expid, # from LArCond2NtupleBase
250  NSamples=flags.LArSCDump.nSamples, FTlist=[], FillBCID=args.bcid, ContainerKey=flags.LArSCDump.digitsKey, AccContainerKey=flags.LArSCDump.accdigitsKey, AccCalibContainerKey=flags.LArSCDump.acccalibdigitsKey,# from LArDigits2Ntuple
251  SCContainerKeys=CKeys, OverwriteEventNumber = args.overEvN, # from LArSC2Ntuple
252  FillRODEnergy = flags.LArSCDump.doRawChan,
253  FillLB=args.evtree, FillTriggerType = args.evtree,
254  TrigNames=["L1_EM3","L1_EM7","L1_EM15","L1_EM22VHI","L1_eEM5","L1_eEM15","L1_eEM22M"],
255  TrigDecisionTool=tdt, FillTriggerTowers = args.TT,
256  OutputLevel=args.olevel
257  ))
258  # ROOT file writing
259  if os.path.exists(args.outfile):
260  os.remove(args.outfile)
261  acc.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+args.outfile+"' OPT='NEW'" ]))
262  acc.setAppProperty("HistogramPersistency","ROOT")
263 
264  # calib runs do not have proper run number in metadata
265  if args.accsamples or args.acccalibsamples:
266  acc.getService("IOVDbSvc").forceRunNumber=int(args.run)
267 
268  acc.getService("MessageSvc").defaultLimit=999999
269 
270  # some logging
271  log.info("Input files to be processed:")
272  for f in flags.Input.Files:
273  log.info(f)
274  log.info("Output file: ")
275  log.info(args.outfile)
276 
277  # and run
278  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