ATLAS Offline Software
xAODEventSelectorConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 # @file xAODHybridSelectorConfig
4 # @purpose make the Athena framework read a set of xAOD files to emulate the
5 # usual TEvent event loop ... BUT READ METADATA WITH POOL!
6 # Converted from ReadAthenaxAODHybrid.py
7 # @author Teng Jian Khoo
8 #
9 
10 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
11 from AthenaConfiguration.ComponentFactory import CompFactory
12 from AthenaCommon import Logging
13 from AthenaCommon import Constants
14 from AthenaServices.MetaDataSvcConfig import MetaDataSvcCfg
15 from enum import IntEnum
16 
17 # Duplicate here because it's probably more efficient than importing from ROOT
18 class xAODAccessMode(IntEnum):
19  BRANCH_ACCESS = 0
20  CLASS_ACCESS = 1
21  ATHENA_ACCESS = 2
22 
23 # Default to the most efficient access method
24 def xAODReadCfg(flags, AccessMode=xAODAccessMode.CLASS_ACCESS):
25  """
26  Creates a ComponentAccumulator instance containing the
27  athena services required for xAOD file reading
28  """
29 
30  msg = Logging.logging.getLogger( 'ReadAthenaxAODHybrid' )
31  msg.debug("Configuring Athena for reading xAOD files (via TEvent, with POOL for Metadata)...")
32 
33 
34  result=ComponentAccumulator()
35 
36  result.addService(CompFactory.EvtPersistencySvc("EventPersistencySvc",)) #No service handle yet???
37  result.merge(MetaDataSvcCfg(flags))
38 
39  result.addService(CompFactory.StoreGateSvc("MetaDataStore"))
40  # Suppress some uninformative messages
41  result.addService(CompFactory.PoolSvc("PoolSvc",OutputLevel=Constants.WARNING))
42 
43  # result.addService(CompFactory.THistSvc())
44  result.addService(CompFactory.Athena.xAODCnvSvc())
45 
46  result.addService(CompFactory.ProxyProviderSvc("ProxyProviderSvc",ProviderNames=[ "MetaDataSvc"]))
47  result.addService(
48  CompFactory.Athena.xAODEventSelector(
49  name='EventSelector',
50  InputCollections=flags.Input.Files,
51  SkipEvents=flags.Exec.SkipEvents,
52  AccessMode=AccessMode,
53  ReadMetaDataWithPool=True,
54  printEventProxyWarnings=False,
55  ))
56  evSel = result.getService("EventSelector")
57 
58  result.setAppProperty("EvtSel",evSel.getFullJobOptName())
59 
60  msg.debug("Configuring Athena for reading ROOT files (via TEvent, with POOL for Metadata)... [OK]")
61 
62  return result
63 
64 
65 
66 if __name__=="__main__":
67  from AthenaConfiguration.AllConfigFlags import initConfigFlags
68  import os
69  asg_test_file_mc = os.environ['ASG_TEST_FILE_MC']
70  flags = initConfigFlags()
71  flags.Input.Files=[asg_test_file_mc]
72 
73  import sys
74  if len(sys.argv)>1:
75  flags.Input.Files=[sys.argv[1]]
76  flags.lock()
77 
78  AccessMode = xAODAccessMode.CLASS_ACCESS
79  if len(sys.argv)>2:
80  AccessMode = xAODAccessMode(int(sys.argv[2]))
81 
82  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
83  cfg = MainServicesCfg(flags)
84  cfg.merge(xAODReadCfg(flags,AccessMode))
85 
86  cfg.run(10)
xAODEventSelectorConfig.xAODReadCfg
def xAODReadCfg(flags, AccessMode=xAODAccessMode.CLASS_ACCESS)
Definition: xAODEventSelectorConfig.py:24
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
xAODEventSelectorConfig.xAODAccessMode
Definition: xAODEventSelectorConfig.py:18
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
python.MetaDataSvcConfig.MetaDataSvcCfg
def MetaDataSvcCfg(flags, toolNames=[], tools=[])
Definition: MetaDataSvcConfig.py:6
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19