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