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
27class L1MenuFlagsCont(object):
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 "Run" : FlagArgs( int, 3, val_check = lambda x: x in [2,3,4] ),
40 "MenuSetup" : FlagArgs( str ),
41 "CTPVersion" : FlagArgs( int, 4, val_check = lambda x: x in range(5), action = lambda x: Limits.setLimits(x) ),
42 "BunchGroupPartitioning" : FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: y not in range(16), x)))==0 ),
43 "BunchGroupNames" : FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: not isinstance(y, str), x)))==0),
44 "items" : FlagArgs( Iterable, val_check = lambda x: len(list(filter(lambda y: not isinstance(y, str), x)))==0),
45 "boards" : FlagArgs( dict, dict() ),
46 "legacyBoards" : FlagArgs( dict, dict() ),
47 "prescales" : FlagArgs( dict, dict() ),
48 "RemapThresholdsAsListed" : FlagArgs( bool, False ),
49 "CtpIdMap" : FlagArgs( dict, dict() ),
50 "ThresholdMap" : FlagArgs( dict, dict() ),
51 "ItemMap" : FlagArgs( dict, dict() ),
52 }
53
54 def __setattr__(self, attr, value):
55 # set the object
56 object.__setattr__(self, attr, value)
57 d = L1MenuFlagsCont.__slots__[attr]
58 # check the type
59 if not isinstance(value, d.val_type):
60 raise TypeError("L1MenuFlags.%s type check failed for %r. Type needs to be '%s'" % ( attr, value, d.val_type.__name__))
61 # check the values
62 if d.val_check and not d.val_check(value):
63 raise ValueError("L1MenuFlags.%s value check failed for %r" % ( attr, value))
64
65 if d.action:
66 d.action(value)
67 L1MenuFlagsCont.statusOn.add(attr)
68
69 def __getattribute__(self,attr):
70 if attr in L1MenuFlagsCont.__slots__:
71 try:
72 object.__getattribute__(self,attr)
73 except AttributeError:
74 if L1MenuFlagsCont.__slots__[attr].val_default is not None:
75 object.__setattr__(self, attr, L1MenuFlagsCont.__slots__[attr].val_default)
76 return FlagWrapper(attr, object.__getattribute__(self,attr), L1MenuFlagsCont)
77 else:
78 return object.__getattribute__(self,attr)
79
80
81L1MenuFlags = L1MenuFlagsCont()
82
__init__(self, name, value, cls)
__init__(self, val_type, val_default=None, val_check=None, action=None)
STL class.