ATLAS Offline Software
TrackCollectionReadConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 # Created: Nov 2019, sss
4 # Purpose: Configure AthReadAlg for reading a TrackCollection.
5 #
6 # The TrackCollection converter has some conditions dependencies,
7 # so to read TrackCollection property in MT, we need to use an algorithm.
8 
9 from __future__ import print_function
10 from AthenaConfiguration.ComponentFactory import CompFactory
11 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
12 
13 
14 def _guessTracksAlias (tcolls):
15  """Given the list of TrackCollection keys from the input file, try to guess
16 which one is aliased to Tracks."""
17 
18  for a in ['CombinedInDetTracks',
19  'MergedTracks',
20  'InDetPseudoTracks',
21  'ConvertedIPatTracks',
22  'ConvertedXKalmanTracks',
23  'RefittedTracks']:
24  if a in tcolls: return a
25  return None
26 
27 
28 def TrackCollectionReadCfg (flags, key):
29  """Configure an algorithm to read a TrackCollection.
30 KEY is the desired TrackCollection key.
31 Will do nothing in serial mode, or if the requested object is not
32 in the input file."""
33 
34  # Don't do anything if we're in serial mode.
35  result = ComponentAccumulator()
36  if flags.Concurrency.NumThreads <= 0:
37  return result
38 
39  # Get the list of TrackCollection keys from the input file,
40  # and try to guess the Tracks alias.
41  from AthenaConfiguration.AutoConfigFlags import GetFileMD
42  tcolls = set ([k for t,k in GetFileMD (flags.Input.Files).get('itemList', [])
43  if t == 'TrackCollection'])
44  tracks_alias = _guessTracksAlias (tcolls)
45 
46  # If Tracks was requested, try to change to the target of the alias.
47  if key == 'Tracks' and tracks_alias is not None and key not in tcolls:
48  key = tracks_alias
49 
50  # Do nothing if the object is not in the input file.
51  if key not in tcolls:
52  return result
53 
54  # Mention Tracks as an alias if appropriate.
55  aliases = []
56  if key == tracks_alias and 'Tracks' not in tcolls:
57  aliases = ['Tracks']
58 
59  extra_inputs = []
60  if flags.Detector.GeometryPixel:
61  extra_inputs.append(('InDetDD::SiDetectorElementCollection', 'ConditionStore+PixelDetectorElementCollection'))
62  if flags.Detector.GeometrySCT:
63  extra_inputs.append(('InDetDD::SiDetectorElementCollection', 'ConditionStore+SCT_DetectorElementCollection'))
64  if flags.Detector.GeometryTRT:
65  extra_inputs.append(( 'InDetDD::TRT_DetElementContainer' , 'ConditionStore+TRT_DetElementContainer' ))
66  if flags.Detector.GeometryITkPixel:
67  extra_inputs.append(( 'InDetDD::SiDetectorElementCollection' , 'ConditionStore+ITkPixelDetectorElementCollection' ))
68  if flags.Detector.GeometryITkStrip:
69  extra_inputs.append(( 'InDetDD::SiDetectorElementCollection' , 'ConditionStore+ITkStripDetectorElementCollection' ))
70  if flags.Detector.GeometryMuon:
71  extra_inputs.append(('MuonGM::MuonDetectorManager', 'ConditionStore+MuonDetectorManager'))
72 
73  # Configure the algorithm.
74  AthReadAlg=CompFactory.AthReadAlg
75  alg = AthReadAlg ('TrackCollectionRead_' + key,
76  Key = 'TrackCollection/' + key,
77  Aliases = aliases,
78  ExtraInputs = extra_inputs)
79  result.addEventAlgo (alg)
80 
81  # We also require AddressRemappingSvc.
82  from SGComps.AddressRemappingConfig import AddressRemappingCfg
83  result.merge (AddressRemappingCfg())
84  return result
85 
86 
87 if __name__ == "__main__":
88  from AthenaConfiguration.AllConfigFlags import initConfigFlags
89  flags = initConfigFlags()
90 
91  from AthenaConfiguration.TestDefaults import defaultTestFiles
92 
93  print ('--- Reference aliased object by base name.')
94  flags1 = flags.clone()
95  flags1.Concurrency.NumThreads = 1
96  flags1.Input.Files = defaultTestFiles.ESD
97  flags1.lock()
98  acc1 = TrackCollectionReadCfg (flags1, 'CombinedInDetTracks')
99  acc1.printConfig (summariseProps=True)
100  acc1.wasMerged()
101 
102  print ('--- Reference aliased object by alias.')
103  flags2 = flags.clone()
104  flags2.Concurrency.NumThreads = 1
105  flags2.Input.Files = defaultTestFiles.ESD
106  flags2.lock()
107  acc2 = TrackCollectionReadCfg (flags2, 'Tracks')
108  acc2.printConfig (summariseProps=True)
109  acc2.wasMerged()
110 
111  print ('--- Non-aliased object.')
112  flags3 = flags.clone()
113  flags3.Concurrency.NumThreads = 1
114  flags3.Input.Files = defaultTestFiles.ESD
115  flags3.lock()
116  acc3 = TrackCollectionReadCfg (flags3, 'ResolvedForwardTracks')
117  acc3.printConfig (summariseProps=True)
118  acc3.wasMerged()
119 
120  print ('--- Non-existent object.')
121  flags4 = flags.clone()
122  flags4.Concurrency.NumThreads = 1
123  flags4.Input.Files = defaultTestFiles.ESD
124  flags4.lock()
125  acc4 = TrackCollectionReadCfg (flags4, 'FooTracks')
126  acc4.printConfig (summariseProps=True)
127  acc4.wasMerged()
128 
129  print ('--- Non-threaded.')
130  flags5 = flags.clone()
131  flags5.Input.Files = defaultTestFiles.ESD
132  flags5.lock()
133  acc5 = TrackCollectionReadCfg (flags5, 'Tracks')
134  acc5.printConfig (summariseProps=True)
135  acc5.wasMerged()
AddressRemappingConfig.AddressRemappingCfg
def AddressRemappingCfg(renameMaps=[], overwriteMaps=[])
Definition: AddressRemappingConfig.py:10
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.TrackCollectionReadConfig._guessTracksAlias
def _guessTracksAlias(tcolls)
Definition: TrackCollectionReadConfig.py:14
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
python.TrackCollectionReadConfig.TrackCollectionReadCfg
def TrackCollectionReadCfg(flags, key)
Definition: TrackCollectionReadConfig.py:28