ATLAS Offline Software
TopoAlgorithms.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from collections import OrderedDict as odict
4 from operator import attrgetter
5 from enum import Enum
6 
7 from AthenaCommon.Logging import logging
8 log = logging.getLogger(__name__)
9 
10 from .TopoAlgos import DecisionAlgo, MultiplicityAlgo, SortingAlgo
11 
12 class AlgType(Enum):
13  SORT = ('sortingAlgorithms')
14  DEC = ('decisionAlgorithms')
15  MULT = ('multiplicityAlgorithms')
16 
17  def __init__(self, key):
18  self.key = key
19 
20 class AlgCategory(Enum):
21  TOPO = (1, 'TOPO', 'new topo', 'TopoAlgoDef')
22  MUCTPI = (2, 'MUTOPO', 'muctpi topo', 'TopoAlgoDefMuctpi')
23  LEGACY = (3, 'R2TOPO', 'legacy topo', 'TopoAlgoDefLegacy')
24  MULTI = (4, 'MULTTOPO', 'multiplicity topo', 'TopoAlgoDefMultiplicity')
25 
26  def __init__(self, _, key, desc, defFile ):
27  self.key = key
28  self.prefix = key + '_' if key else ''
29  self.desc = desc
30  self.defFile = defFile
31 
32  def __str__(self):
33  return self.desc
34 
35  @staticmethod
37  return [ AlgCategory.TOPO, AlgCategory.MUCTPI, AlgCategory.MULTI, AlgCategory.LEGACY ]
38 
39  @staticmethod
40  def getCategoryFromBoardName(boardName):
41  if 'muctpi' in boardName.lower():
42  currentTopoCategory = AlgCategory.MUCTPI
43  elif 'topo' in boardName.lower():
44  if 'legacy' in boardName.lower():
45  currentTopoCategory = AlgCategory.LEGACY
46  else:
47  currentTopoCategory = AlgCategory.TOPO
48  else:
49  raise RuntimeError("Board %s is not a topo board" % boardName )
50  return currentTopoCategory
51 
52 
54 
55  def __init__(self):
56  # all algos that are in menu (new and legacy)
57  self.topoAlgos = odict()
58  for cat in AlgCategory:
59  self.topoAlgos[cat] = odict()
60  if cat in [AlgCategory.TOPO, AlgCategory.MUCTPI, AlgCategory.LEGACY]:
61  self.topoAlgos[cat][AlgType.DEC] = odict()
62  self.topoAlgos[cat][AlgType.SORT] = odict()
63  elif cat in [AlgCategory.MULTI]:
64  self.topoAlgos[cat][AlgType.MULT] = odict()
65 
66  def addAlgo(self, algo, category):
67  if type(category) is not AlgCategory:
68  raise RuntimeError( "No category is provided when adding topo algo %s to menu" % algo.name)
69 
70  if isinstance(algo,DecisionAlgo):
71  algType = AlgType.DEC
72  elif isinstance(algo, SortingAlgo):
73  algType = AlgType.SORT
74  elif isinstance(algo, MultiplicityAlgo):
75  algType = AlgType.MULT
76  else:
77  raise RuntimeError("Trying to add topo algorithm %s of unknown type %s to the menu" % (algo.name, type(algo)))
78 
79  if algType not in self.topoAlgos[category]:
80  self.topoAlgos[category][algType] = odict()
81 
82  if algo.name in self.topoAlgos[category][algType]:
83  raise RuntimeError("Trying to add topo algorithm %s a second time" % algo.name)
84 
85  self.topoAlgos[category][algType][algo.name] = algo
86 
87 
88  def json(self):
89 
90  confObj = odict()
91  for cat in self.topoAlgos:
92  confObj[cat.key] = odict()
93  for typ in self.topoAlgos[cat]:
94  confObj[cat.key][typ.key] = odict()
95  for alg in sorted(self.topoAlgos[cat][typ].values(), key=attrgetter('name')):
96  confObj[cat.key][typ.key][alg.name] = alg.json()
97 
98  return confObj
python.L1.Base.TopoAlgorithms.AlgCategory.key
key
Definition: TopoAlgorithms.py:27
python.L1.Base.TopoAlgorithms.MenuTopoAlgorithmsCollection.topoAlgos
topoAlgos
Definition: TopoAlgorithms.py:57
python.L1.Base.TopoAlgorithms.MenuTopoAlgorithmsCollection.json
def json(self)
Definition: TopoAlgorithms.py:88
python.L1.Base.TopoAlgorithms.AlgCategory.getAllCategories
def getAllCategories()
Definition: TopoAlgorithms.py:36
python.L1.Base.TopoAlgorithms.AlgCategory.prefix
prefix
Definition: TopoAlgorithms.py:28
python.L1.Base.TopoAlgorithms.MenuTopoAlgorithmsCollection
Definition: TopoAlgorithms.py:53
python.L1.Base.TopoAlgorithms.AlgCategory.desc
desc
Definition: TopoAlgorithms.py:29
python.L1.Base.TopoAlgorithms.AlgCategory.__init__
def __init__(self, _, key, desc, defFile)
Definition: TopoAlgorithms.py:26
python.L1.Base.TopoAlgorithms.AlgType
Definition: TopoAlgorithms.py:12
python.L1.Base.TopoAlgorithms.AlgType.__init__
def __init__(self, key)
Definition: TopoAlgorithms.py:17
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:797
python.L1.Base.TopoAlgorithms.AlgCategory.__str__
def __str__(self)
Definition: TopoAlgorithms.py:32
python.L1.Base.TopoAlgorithms.AlgCategory
Definition: TopoAlgorithms.py:20
python.L1.Base.TopoAlgorithms.MenuTopoAlgorithmsCollection.__init__
def __init__(self)
Definition: TopoAlgorithms.py:55
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
pickleTool.object
object
Definition: pickleTool.py:30
python.L1.Base.TopoAlgorithms.MenuTopoAlgorithmsCollection.addAlgo
def addAlgo(self, algo, category)
Definition: TopoAlgorithms.py:66
python.L1.Base.TopoAlgorithms.AlgCategory.getCategoryFromBoardName
def getCategoryFromBoardName(boardName)
Definition: TopoAlgorithms.py:40
python.L1.Base.TopoAlgorithms.AlgCategory.defFile
defFile
Definition: TopoAlgorithms.py:30
python.L1.Base.TopoAlgorithms.AlgType.key
key
Definition: TopoAlgorithms.py:18