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