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 21 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 34 of file AthConfigFlags.py.

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

Member Function Documentation

◆ __repr__()

def python.AthConfigFlags.CfgFlag.__repr__ (   self)

Definition at line 91 of file AthConfigFlags.py.

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

◆ _validateType()

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

Definition at line 97 of file AthConfigFlags.py.

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

◆ 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 60 of file AthConfigFlags.py.

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

◆ 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 46 of file AthConfigFlags.py.

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

Member Data Documentation

◆ __slots__

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

Definition at line 28 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 30 of file AthConfigFlags.py.

◆ _help

python.AthConfigFlags.CfgFlag._help
private

Definition at line 42 of file AthConfigFlags.py.

◆ _setDef

python.AthConfigFlags.CfgFlag._setDef
private

Definition at line 53 of file AthConfigFlags.py.

◆ _type

python.AthConfigFlags.CfgFlag._type
private

Definition at line 41 of file AthConfigFlags.py.

◆ _value

python.AthConfigFlags.CfgFlag._value
private

Definition at line 52 of file AthConfigFlags.py.


The documentation for this class was generated from the following file:
python.processes.powheg.ZZj_MiNNLO.ZZj_MiNNLO.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZj_MiNNLO.py:18
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
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:232
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127