ATLAS Offline Software
LArDigits2NtupleDumper.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 
5 from AthenaConfiguration.ComponentFactory import CompFactory
6 
7 if __name__=='__main__':
8 
9  import os,sys
10  import argparse
11  from AthenaCommon import Logging
12  log = Logging.logging.getLogger( 'LArDigits2Ntuple' )
13 
14  parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
15 
16  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)
17  parser.add_argument('-p','--inprefix', dest='inpref', default="data_test", help='Input filenames prefix', type=str)
18  parser.add_argument('-y','--inppatt', dest='inppatt', default="lb3512", help='Input filenames pattern', type=str)
19  parser.add_argument('-f','--infile', dest='infile', default="", help='Input filename (if given indir and inprefix are ignored', type=str)
20  parser.add_argument('-r','--run', dest='run', default=0, help='Run number (if not given trying to judge from input file name)', type=int)
21  parser.add_argument('-m','--maxev', dest='maxev', default=-1, help='Max number of events to dump', type=int)
22  parser.add_argument('-x','--outlevel', dest='olevel', default=3, help='OuputLevel for dumping algo', type=int)
23  parser.add_argument('-o','--outfile', dest='outfile', default="Digits.root", help='Output root filename', type=str)
24  parser.add_argument('-n','--nsamp', dest='nsamp', default=0, help='Number of samples to dump', type=int)
25  parser.add_argument('-d','--addHash', dest='ahash', default=False, help='Add hash number to output ntuple', type=bool)
26  parser.add_argument('-j','--addOffline', dest='offline', default=False, help='Add offline Id to output ntuple', type=bool)
27  parser.add_argument('-k','--addCalib', dest='calib', default=False, help='Add calib. info to output ntuple', type=bool)
28  parser.add_argument('-t','--addGeom', dest='geom', default=False, help='Add real geom info to output ntuple', type=bool)
29  parser.add_argument('-u','--addBC', dest='bc', default=False, help='Add Bad. chan info to output ntuple', type=bool)
30  parser.add_argument('-v','--addEvTree', dest='evtree', default=False, help='Add tree with per event info to output ntuple', type=bool)
31  parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
32 
33  args = parser.parse_args()
34  if help in args and args.help is not None and args.help:
35  parser.print_help()
36  sys.exit(0)
37 
38  for _, value in args._get_kwargs():
39  if value is not None:
40  log.debug(value)
41 
42  #Import the flag-container that is the arguemnt to the configuration methods
43  from AthenaConfiguration.AllConfigFlags import initConfigFlags
44  flags = initConfigFlags()
45 
46  # add SCDump flags, here re-used for digitsdump
47  from LArCafJobs.LArSCDumperFlags import addSCDumpFlags
48  addSCDumpFlags(flags)
49 
50 
51  if len(args.infile) > 0:
52  flags.Input.Files = [args.infile]
53  elif len(args.inppatt) > 0:
54  from LArCalibProcessing.GetInputFiles import GetInputFilesFromPattern
55  flags.Input.Files = GetInputFilesFromPattern(args.indir,args.inppatt)
56  else:
57  from LArCalibProcessing.GetInputFiles import GetInputFilesFromPrefix
58  flags.Input.Files = GetInputFilesFromPrefix(args.indir,args.inpref)
59 
60  if args.run != 0:
61  flags.Input.RunNumbers = [args.run]
62 
63  # first autoconfig
64  from LArConditionsCommon.LArRunFormat import getLArFormatForRun
65  try:
66  runinfo=getLArFormatForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
67  except Exception:
68  log.warning("Could not get run info, using defaults !")
69  if args.nsamp > 0:
70  flags.LArSCDump.nSamples=args.nsamp
71  else:
72  flags.LArSCDump.nSamples=4
73  else:
74  flags.LArSCDump.nSamples=runinfo.nSamples()
75 
76  flags.LArSCDump.digitsKey="FREE"
77  if args.nsamp > 0 and args.nsamp < flags.LArSCDump.nSamples:
78  flags.LArSCDump.nSamples=args.nsamp
79 
80  log.info("Autoconfigured: ")
81  log.info("nSamples: %d digitsKey %s",flags.LArSCDump.nSamples, flags.LArSCDump.digitsKey)
82 
83  #GEometry
84  from AthenaConfiguration.TestDefaults import defaultGeometryTags
85  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
86 
87  # now construct the job
88  flags.LAr.doAlign=False
89 
90  if args.evtree: # should include trigger info
91  flags.Trigger.triggerConfig = 'DB'
92  flags.Trigger.L1.doCTP = True
93  flags.Trigger.L1.doMuon = False
94  flags.Trigger.L1.doCalo = False
95  flags.Trigger.L1.doTopo = False
96 
97  flags.Trigger.enableL1CaloLegacy = True
98  flags.Trigger.enableL1CaloPhase1 = True
99 
100  # additions for EMF
101  if args.emf:
102  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
103  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannels","/LAR/BadChannelsOfl/KnownBADFEBs","/LAR/BadChannelsOfl/KnownMNBFEBs","/LAR/BadChannelsOfl/MissingFEBs","/LAR/Identifier/OnOffIdMap",)
104 
105  flags.lock()
106 
107  #Import the MainServices (boilerplate)
108  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
109  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
110 
111  acc = MainServicesCfg(flags)
112  acc.merge(LArGMCfg(flags))
113 
114  from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
115  acc.merge(LArOnOffIdMappingCfg(flags))
116 
117  if args.evtree: # should include trigger info
118  from LArCafJobs.LArSCDumperSkeleton import L1CaloMenuCfg
119  acc.merge(L1CaloMenuCfg(flags))
120  from TrigDecisionTool.TrigDecisionToolConfig import TrigDecisionToolCfg
121  tdt = acc.getPrimaryAndMerge(TrigDecisionToolCfg(flags))
122  else:
123  tdt = None
124 
125 
126  if args.bc:
127  from LArBadChannelTool.LArBadChannelConfig import LArBadFebCfg, LArBadChannelCfg
128  acc.merge(LArBadChannelCfg(flags))
129  acc.merge(LArBadFebCfg(flags))
130 
131  if args.geom:
132  log.warning("Adding real geometry is not working yet")
133  args.geom=False
134  # FIXME
135  #acc.addCondAlgo(CompFactory.CaloAlignCondAlg(LArAlignmentStore="",CaloCellPositionShiftFolder=""))
136  #acc.addCondAlgo(CompFactory.CaloSuperCellAlignCondAlg())
137  #AthReadAlg_ExtraInputs.append(('CaloSuperCellDetDescrManager', 'ConditionStore+CaloSuperCellDetDescrManager'))
138 
139  from LArCalibTools.LArDigits2NtupleConfig import LArDigits2NtupleCfg
140  acc.merge(LArDigits2NtupleCfg(flags, AddBadChannelInfo=args.bc, AddFEBTempInfo=False, isSC=False, isFlat=True,
141  OffId=args.offline, AddHash=args.ahash, AddCalib=args.calib, RealGeometry=args.geom, # from LArCond2NtupleBase
142  NSamples=flags.LArSCDump.nSamples, FTlist=[], ContainerKey=flags.LArSCDump.digitsKey, # from LArDigits2Ntuple
143  FillLB=args.evtree,
144  OutputLevel=args.olevel
145  ))
146  # ROOT file writing
147  if os.path.exists(args.outfile):
148  os.remove(args.outfile)
149  acc.addService(CompFactory.NTupleSvc(Output = [ "FILE1 DATAFILE='"+args.outfile+"' OPT='NEW'" ]))
150  acc.setAppProperty("HistogramPersistency","ROOT")
151 
152  # some logging
153  log.info("Input files to be processed:")
154  for f in flags.Input.Files:
155  log.info(f)
156  log.info("Output file: ")
157  log.info(args.outfile)
158 
159 
160  # and run
161  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
LArDigits2NtupleConfig.LArDigits2NtupleCfg
def LArDigits2NtupleCfg(flags, isEMF=False, **kwargs)
Definition: LArDigits2NtupleConfig.py:6
LArRunFormat
LArSCDumperFlags.addSCDumpFlags
def addSCDumpFlags(flags)
Definition: LArSCDumperFlags.py:3
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
LArCablingConfig.LArOnOffIdMappingCfg
def LArOnOffIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:62
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.LArRunFormat.getLArFormatForRun
def getLArFormatForRun(run, quiet=False, connstring="COOLONL_LAR/CONDBR2")
Definition: LArRunFormat.py:58
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.GetInputFiles.GetInputFilesFromPattern
def GetInputFilesFromPattern(inputPath, prefix=".*", trigger=".*")
Definition: GetInputFiles.py:32