ATLAS Offline Software
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 
5 from .Limits import Limits
6 from collections.abc import Iterable
7 
8 
9 class FlagWrapper:
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 
80 L1MenuFlags = L1MenuFlagsCont()
81 
python.L1.Base.L1MenuFlags.FlagWrapper.name
name
Definition: L1MenuFlags.py:14
python.L1.Base.L1MenuFlags.L1MenuFlagsCont.__setattr__
def __setattr__(self, attr, value)
Definition: L1MenuFlags.py:53
python.L1.Base.L1MenuFlags.L1MenuFlagsCont.__getattribute__
def __getattribute__(self, attr)
Definition: L1MenuFlags.py:68
python.L1.Base.L1MenuFlags.FlagWrapper.setStatusOn
def setStatusOn(self, on=True)
Definition: L1MenuFlags.py:21
python.L1.Base.L1MenuFlags.FlagWrapper
Definition: L1MenuFlags.py:9
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.L1.Base.L1MenuFlags.FlagWrapper.value
value
Definition: L1MenuFlags.py:15
python.L1.Base.L1MenuFlags.L1MenuFlagsCont
Definition: L1MenuFlags.py:27
python.L1.Base.L1MenuFlags.L1MenuFlagsCont.FlagArgs.val_type
val_type
Definition: L1MenuFlags.py:31
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
python.L1.Base.L1MenuFlags.FlagWrapper.statusOn
def statusOn(self)
Definition: L1MenuFlags.py:19
python.L1.Base.L1MenuFlags.L1MenuFlagsCont.FlagArgs.val_default
val_default
Definition: L1MenuFlags.py:32
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.L1.Base.L1MenuFlags.L1MenuFlagsCont.FlagArgs.action
action
Definition: L1MenuFlags.py:34
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.L1.Base.L1MenuFlags.FlagWrapper.__init__
def __init__(self, name, value, cls)
Definition: L1MenuFlags.py:13
python.L1.Base.L1MenuFlags.FlagWrapper.cls
cls
Definition: L1MenuFlags.py:16
python.L1.Base.L1MenuFlags.L1MenuFlagsCont.FlagArgs.val_check
val_check
Definition: L1MenuFlags.py:33
python.L1.Base.L1MenuFlags.FlagWrapper.__call__
def __call__(self)
Definition: L1MenuFlags.py:17
pickleTool.object
object
Definition: pickleTool.py:29
python.L1.Base.L1MenuFlags.L1MenuFlagsCont.FlagArgs
Definition: L1MenuFlags.py:29
python.L1.Base.L1MenuFlags.L1MenuFlagsCont.FlagArgs.__init__
def __init__(self, val_type, val_default=None, val_check=None, action=None)
Definition: L1MenuFlags.py:30