ATLAS Offline Software
ActsCollectionsConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 
7  # Allowed types
8  types = ('xAOD::TrackSummaryContainer',
9  'xAOD::TrackStateContainer',
10  'xAOD::TrackParametersContainer',
11  'xAOD::TrackJacobianContainer',
12  'xAOD::TrackMeasurementContainer',
13  'xAOD::TrackSurfaceContainer')
14  # Allowed post-fixes
15  postFixes = ('TrackSummary',
16  'TrackStates',
17  'TrackParameters',
18  'TrackJacobians',
19  'TrackMeasurements',
20  'TrackStateSurfaces',
21  'TrackSurfaces')
22 
23  def __init__(self) -> None:
24  self.collections = dict()
25  for el in TrackBackends.postFixes:
26  self.collections[el] = None
27 
28  def __str__(self) -> str:
29  message = "[ "
30  for el in TrackBackends.postFixes:
31  message += f"{el}={self.collections[el]} "
32  message += "]"
33  return message
34 
35  @staticmethod
36  def extractPrefix(*, collection: str) -> str:
37  assert isinstance(collection, str)
38  for el in TrackBackends.postFixes:
39  if collection.endswith(el):
40  return collection.replace(el, "")
41  # If not in allowed post fixes we raise Exception
42  raise Exception(f"Collection {collection} is a NOT KNOWN ACTS track backend, prefix could not be deduced")
43 
44  def isValid(self) -> bool:
45  for (key, value) in self.collections.items():
46  if value is None:
47  return False
48  return True
49 
50  def addCollection(self,
51  *,
52  collection: str) -> None:
53  assert isinstance(collection, str)
54  for el in TrackBackends.postFixes:
55  if collection.endswith(el):
56  if self.collections[el] is not None:
57  raise Exception(f"Trying to add collection '{collection}', but this backend is already recorded")
58  self.collections[el] = collection
59  return
60  # If not in allowed post fixes we raise Exception
61  raise Exception(f"Collection {collection} is a NOT KNOWN ACTS track backend")
62 
64  prefix: str) -> ComponentAccumulator:
65  assert isinstance(prefix, str)
66  """
67  Setup algorithm that reads xAOD track backends and produced TrackContainer
68  name - the collections prefix, for consistency it also is the prefix of the output container name
69  """
70  acc = ComponentAccumulator()
71  from ActsConfig.ActsGeometryConfig import ActsTrackingGeometryToolCfg
72  acc.addEventAlgo(CompFactory.ActsTrk.TrackContainerReader(f"{prefix}TrackContainerReaderAlg",
73  TrackContainer=prefix+"Tracks",
74  TrackingGeometryTool=acc.popToolsAndMerge(ActsTrackingGeometryToolCfg(flags))
75  ))
76  return acc
77 
78 def ActsPoolReadCfg(flags) -> ComponentAccumulator:
79  acc = ComponentAccumulator()
80 
81  # Reader for InDet objects (i.e. xAOD SpacePoints and Measurements)
82  from InDetConfig.InDetPoolReadConfig import InDetPoolReadCfg
83  acc.merge(InDetPoolReadCfg(flags))
84 
85  StoredTracks = dict()
86  typedCollections = flags.Input.TypedCollections
87 
88  for typedCollection in typedCollections:
89  [colType, colName] = typedCollection.split('#')
90 
91  # Track Backend Collections
92  if colType in TrackBackends.types:
93  prefix = TrackBackends.extractPrefix(collection=colName)
94  StoredTracks[prefix] = StoredTracks.get(prefix, TrackBackends())
95  StoredTracks[prefix].addCollection(collection=colName)
96  continue
97 
98  for (key, backends) in StoredTracks.items():
99  if not backends.isValid():
100  raise Exception(f'Track backends with prefix {key} are not consistent. Be sure all the backends have been properly persistified in the file: {backends}')
101 
102  acc.merge(ActsTrackReaderAlgCfg(flags, key))
103 
104  return acc
105 
106 if __name__ == "__main__":
107  # test reading
108  from AthenaConfiguration.AllConfigFlags import initConfigFlags
109  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
110  flags = initConfigFlags()
111  flags.fillFromArgs()
112  flags.lock()
113 
114  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
115  cfg = MainServicesCfg(flags)
116  cfg.merge(PoolReadCfg(flags))
117  cfg.merge(ActsPoolReadCfg(flags))
118 
119  status = cfg.run()
120  if status.isFailure():
121  import sys
122  sys.exit("Execution failed")
ActsCollectionsConfig.TrackBackends.collections
collections
Definition: ActsCollectionsConfig.py:24
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
ActsCollectionsConfig.TrackBackends.isValid
bool isValid(self)
Definition: ActsCollectionsConfig.py:44
ActsCollectionsConfig.TrackBackends.addCollection
None addCollection(self, *str collection)
Definition: ActsCollectionsConfig.py:50
ActsCollectionsConfig.TrackBackends
Definition: ActsCollectionsConfig.py:6
ActsCollectionsConfig.ActsPoolReadCfg
ComponentAccumulator ActsPoolReadCfg(flags)
Definition: ActsCollectionsConfig.py:78
ActsCollectionsConfig.TrackBackends.__init__
None __init__(self)
Definition: ActsCollectionsConfig.py:23
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
ActsGeometryConfig.ActsTrackingGeometryToolCfg
ComponentAccumulator ActsTrackingGeometryToolCfg(flags, str name="ActsTrackingGeometryTool")
Definition: ActsGeometryConfig.py:100
python.InDetPoolReadConfig.InDetPoolReadCfg
ComponentAccumulator InDetPoolReadCfg(flags)
Definition: InDetPoolReadConfig.py:5
Muon::IDC_Helper::addCollection
IDC::IDENTIFIABLE * addCollection(const Identifier collId, IDC *idc, const IDHELPER &idHelper, MsgStream &log)
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
ActsCollectionsConfig.ActsTrackReaderAlgCfg
ComponentAccumulator ActsTrackReaderAlgCfg(flags, str prefix)
Definition: ActsCollectionsConfig.py:63
ActsCollectionsConfig.TrackBackends.__str__
str __str__(self)
Definition: ActsCollectionsConfig.py:28
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
ActsCollectionsConfig.TrackBackends.extractPrefix
str extractPrefix(*str collection)
Definition: ActsCollectionsConfig.py:36
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69