ATLAS Offline Software
Loading...
Searching...
No Matches
L1MenuFlags.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3__doc__="Level 1 specific configuration for L1 Run 3"
4
5from .Limits import Limits
6from collections.abc import Iterable
7
8
10 """
11 this is to support the old functionality of calling and setting statusOn for flags
12 """
13 def __init__(self, name, value, cls):
14 self.name = name
15 self.value = value
16 self.cls = cls
17 def __call__(self):
18 return self.value
19 def statusOn(self):
20 return self.name in self.cls.statusOn
21 def setStatusOn(self, on = True):
22 if on:
23 self.cls.statusOn.add(self.name)
24 else:
25 self.cls.statusOn.remove(self.name)
26
28
29 class FlagArgs:
30 def __init__( self, val_type, val_default = None, val_check = None, action = None ):
31 self.val_type = val_type
32 self.val_default = val_default
33 self.val_check = val_check
34 self.action = action
35
36 statusOn = set()
37
38 __slots__ = {
39 "MenuSetup" : FlagArgs( str ),
40 "CTPVersion" : FlagArgs( int, 4, val_check = lambda x: x in range(5), action = lambda x: Limits.setLimits(x) ),
41 "BunchGroupPartitioning" : FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: y not in range(16), x)))==0 ),
42 "BunchGroupNames" : FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: not isinstance(y, str), x)))==0),
43 "items" : FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: not isinstance(y, str), x)))==0),
44 "boards" : FlagArgs( dict, dict() ),
45 "legacyBoards" : FlagArgs( dict, dict() ),
46 "prescales" : FlagArgs( dict, dict() ),
47 "RemapThresholdsAsListed" : FlagArgs( bool, False ),
48 "CtpIdMap" : FlagArgs( dict, dict() ),
49 "ThresholdMap" : FlagArgs( dict, dict() ),
50 "ItemMap" : FlagArgs( dict, dict() ),
51 }
52
53 def __setattr__(self, attr, value):
54 # set the object
55 object.__setattr__(self, attr, value)
56 d = L1MenuFlagsCont.__slots__[attr]
57 # check the type
58 if not isinstance(value, d.val_type):
59 raise TypeError("L1MenuFlags.%s type check failed for %r. Type needs to be '%s'" % ( attr, value, d.valtype.__name__))
60 # check the values
61 if d.val_check and not d.val_check(value):
62 raise ValueError("L1MenuFlags.%s value check failed for %r" % ( attr, value))
63
64 if d.action:
65 d.action(value)
66 L1MenuFlagsCont.statusOn.add(attr)
67
68 def __getattribute__(self,attr):
69 if attr in L1MenuFlagsCont.__slots__:
70 try:
71 object.__getattribute__(self,attr)
72 except AttributeError:
73 if L1MenuFlagsCont.__slots__[attr].val_default is not None:
74 object.__setattr__(self, attr, L1MenuFlagsCont.__slots__[attr].val_default)
75 return FlagWrapper(attr, object.__getattribute__(self,attr), L1MenuFlagsCont)
76 else:
77 return object.__getattribute__(self,attr)
78
79
80L1MenuFlags = L1MenuFlagsCont()
81
__init__(self, name, value, cls)
__init__(self, val_type, val_default=None, val_check=None, action=None)
STL class.