ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
python.AthConfigFlags.CfgFlag Class Reference
Inheritance diagram for python.AthConfigFlags.CfgFlag:
Collaboration diagram for python.AthConfigFlags.CfgFlag:

Public Member Functions

def __init__ (self, default, type=None, help=None)
 
def set (self, value)
 
def get (self, flagdict=None)
 
def __repr__ (self)
 

Private Member Functions

def _validateType (self, value)
 

Private Attributes

 _type
 
 _help
 
 _value
 
 _setDef
 

Static Private Attributes

list __slots__ = ['_value', '_setDef', '_type', '_help']
 
dictionary _compatibleTypes
 

Detailed Description

The base flag object.

A flag can be set to either a fixed value or a callable, which computes
the value based on other flags.

Definition at line 19 of file AthConfigFlags.py.

Constructor & Destructor Documentation

◆ __init__()

def python.AthConfigFlags.CfgFlag.__init__ (   self,
  default,
  type = None,
  help = None 
)
Initialise the flag with the default value.

Optionally set the type of the flag value and the help string.

Definition at line 32 of file AthConfigFlags.py.

32  def __init__(self, default, type=None, help=None):
33  """Initialise the flag with the default value.
34 
35  Optionally set the type of the flag value and the help string.
36  """
37  if default is None:
38  raise ValueError("Default value of a flag must not be None")
39  self._type = type
40  self._help = help
41  self.set(default)
42  return
43 

Member Function Documentation

◆ __repr__()

def python.AthConfigFlags.CfgFlag.__repr__ (   self)

Definition at line 89 of file AthConfigFlags.py.

89  def __repr__(self):
90  if self._value is not None:
91  return repr(self._value)
92  else:
93  return "[function]"
94 

◆ _validateType()

def python.AthConfigFlags.CfgFlag._validateType (   self,
  value 
)
private

Definition at line 95 of file AthConfigFlags.py.

95  def _validateType(self, value):
96  if (self._type is None or value is None or
97  isinstance(value, self._type) or
98  (type(value), self._type) in self._compatibleTypes):
99  return
100  # Type mismatch
101  raise TypeError(f"Flag is of type '{self._type.__name__}', "
102  f"but value '{value}' of type '{type(value).__name__}' set.")
103 
104 

◆ get()

def python.AthConfigFlags.CfgFlag.get (   self,
  flagdict = None 
)
Get the value of the flag.

If the currently set value is a callable, a dictionary of all available
flags needs to be provided.

Definition at line 58 of file AthConfigFlags.py.

58  def get(self, flagdict=None):
59  """Get the value of the flag.
60 
61  If the currently set value is a callable, a dictionary of all available
62  flags needs to be provided.
63  """
64 
65  if self._value is not None:
66  return deepcopy(self._value)
67 
68  # For cases where the value is intended to be None
69  # i.e. _setDef applied this value, we should not progress
70  if self._setDef is None:
71  return None
72 
73  if not flagdict:
74  raise RuntimeError("Flag is using a callable but all flags are not available.")
75 
76  # Have to call the method to obtain the default value, and then reuse it in all next accesses
77  if flagdict.locked():
78  # optimise future reads, drop possibility to update this flag ever
79  self._value = self._setDef(flagdict)
80  self._setDef = None
81  value = self._value
82  else:
83  # use function for as long as the flags are not locked
84  value = self._setDef(flagdict)
85 
86  self._validateType(value)
87  return deepcopy(value)
88 

◆ set()

def python.AthConfigFlags.CfgFlag.set (   self,
  value 
)
Set the value of the flag.

Can be a constant value or a callable.

Definition at line 44 of file AthConfigFlags.py.

44  def set(self, value):
45  """Set the value of the flag.
46 
47  Can be a constant value or a callable.
48  """
49  if callable(value):
50  self._value=None
51  self._setDef=value
52  else:
53  self._value=value
54  self._setDef=None
55  self._validateType(self._value)
56  return
57 

Member Data Documentation

◆ __slots__

list python.AthConfigFlags.CfgFlag.__slots__ = ['_value', '_setDef', '_type', '_help']
staticprivate

Definition at line 26 of file AthConfigFlags.py.

◆ _compatibleTypes

dictionary python.AthConfigFlags.CfgFlag._compatibleTypes
staticprivate
Initial value:
= {
(int, float), # int can be assigned to float flag
}

Definition at line 28 of file AthConfigFlags.py.

◆ _help

python.AthConfigFlags.CfgFlag._help
private

Definition at line 40 of file AthConfigFlags.py.

◆ _setDef

python.AthConfigFlags.CfgFlag._setDef
private

Definition at line 51 of file AthConfigFlags.py.

◆ _type

python.AthConfigFlags.CfgFlag._type
private

Definition at line 39 of file AthConfigFlags.py.

◆ _value

python.AthConfigFlags.CfgFlag._value
private

Definition at line 50 of file AthConfigFlags.py.


The documentation for this class was generated from the following file:
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
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:224
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127