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