LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | List of all members
lsst.pex.config.configField.ConfigField Class Reference
Inheritance diagram for lsst.pex.config.configField.ConfigField:

Public Member Functions

def __init__
 
def __get__
 
def __set__
 
def rename
 
def save
 
def freeze
 
def toDict
 
def validate
 

Private Member Functions

def _compare
 

Detailed Description

Defines a field which is itself a Config.

The behavior of this type of field is much like that of the base Field type.

Note that dtype must be a subclass of Config.

If default=None, the field will default to a default-constructed 
instance of dtype.

Additionally, to allow for fewer deep-copies, assigning an instance of 
ConfigField to dtype itself, is considered equivalent to assigning a 
default-constructed sub-config. This means that the argument default can be 
dtype, as well as an instance of dtype.

Assigning to ConfigField will update all of the fields in the config.

Definition at line 29 of file configField.py.

Constructor & Destructor Documentation

def lsst.pex.config.configField.ConfigField.__init__ (   self,
  doc,
  dtype,
  default = None,
  check = None 
)

Definition at line 48 of file configField.py.

48 
49  def __init__(self, doc, dtype, default=None, check=None):
50  if not issubclass(dtype, Config):
51  raise ValueError("dtype=%s is not a subclass of Config" % \
52  _typeStr(dtype))
53  if default is None:
54  default = dtype
55  source = traceback.extract_stack(limit=2)[0]
56  self._setup( doc=doc, dtype=dtype, default=default, check=check,
57  optional=False, source=source)

Member Function Documentation

def lsst.pex.config.configField.ConfigField.__get__ (   self,
  instance,
  owner = None 
)

Definition at line 58 of file configField.py.

58 
59  def __get__(self, instance, owner=None):
60  if instance is None or not isinstance(instance, Config):
61  return self
62  else:
63  value = instance._storage.get(self.name, None)
64  if value is None:
65  at = traceback.extract_stack()[:-1]+[self.source]
66  self.__set__(instance, self.default, at=at, label="default")
67  return value
def lsst.pex.config.configField.ConfigField.__set__ (   self,
  instance,
  value,
  at = None,
  label = "assignment" 
)

Definition at line 68 of file configField.py.

68 
69  def __set__(self, instance, value, at=None, label="assignment"):
70  if instance._frozen:
71  raise FieldValidationError(self, instance, \
72  "Cannot modify a frozen Config")
73  name = _joinNamePath(prefix=instance._name, name=self.name)
74 
75  if value != self.dtype and type(value) != self.dtype:
76  msg = "Value %s is of incorrect type %s. Expected %s" %\
77  (value, _typeStr(value), _typeStr(self.dtype))
78  raise FieldValidationError(self, instance, msg)
79 
80  if at is None:
81  at = traceback.extract_stack()[:-1]
82 
83  oldValue = instance._storage.get(self.name, None)
84  if oldValue is None:
85  if value == self.dtype:
86  instance._storage[self.name] = self.dtype(
87  __name=name, __at=at, __label=label)
88  else:
89  instance._storage[self.name] = self.dtype(
90  __name=name, __at=at, __label=label, **value._storage)
91  else:
92  if value == self.dtype:
93  value = value()
94  oldValue.update(__at=at, __label=label, **value._storage)
95  history = instance._history.setdefault(self.name, [])
96  history.append(("config value set", at, label))
def lsst.pex.config.configField.ConfigField._compare (   self,
  instance1,
  instance2,
  shortcut,
  rtol,
  atol,
  output 
)
private
Helper function for Config.compare; used to compare two fields for equality.

@param[in] instance1  LHS Config instance to compare.
@param[in] instance2  RHS Config instance to compare.
@param[in] shortcut   If True, return as soon as an inequality is found.
@param[in] rtol       Relative tolerance for floating point comparisons.
@param[in] atol       Absolute tolerance for floating point comparisons.
@param[in] output     If not None, a callable that takes a string, used (possibly repeatedly)
              to report inequalities.

Floating point comparisons are performed by numpy.allclose; refer to that for details.

Definition at line 121 of file configField.py.

122  def _compare(self, instance1, instance2, shortcut, rtol, atol, output):
123  """Helper function for Config.compare; used to compare two fields for equality.
124 
125  @param[in] instance1 LHS Config instance to compare.
126  @param[in] instance2 RHS Config instance to compare.
127  @param[in] shortcut If True, return as soon as an inequality is found.
128  @param[in] rtol Relative tolerance for floating point comparisons.
129  @param[in] atol Absolute tolerance for floating point comparisons.
130  @param[in] output If not None, a callable that takes a string, used (possibly repeatedly)
131  to report inequalities.
132 
133  Floating point comparisons are performed by numpy.allclose; refer to that for details.
134  """
135  c1 = getattr(instance1, self.name)
136  c2 = getattr(instance2, self.name)
137  name = getComparisonName(
138  _joinNamePath(instance1._name, self.name),
139  _joinNamePath(instance2._name, self.name)
140  )
141  return compareConfigs(name, c1, c2, shortcut=shortcut, rtol=rtol, atol=atol, output=output)
def lsst.pex.config.configField.ConfigField.freeze (   self,
  instance 
)

Definition at line 105 of file configField.py.

106  def freeze(self, instance):
107  value = self.__get__(instance)
108  value.freeze()
def lsst.pex.config.configField.ConfigField.rename (   self,
  instance 
)

Definition at line 97 of file configField.py.

97 
98  def rename(self, instance):
99  value = self.__get__(instance)
100  value._rename(_joinNamePath(instance._name, self.name))
def lsst.pex.config.configField.ConfigField.save (   self,
  outfile,
  instance 
)

Definition at line 101 of file configField.py.

102  def save(self, outfile, instance):
103  value = self.__get__(instance)
104  value._save(outfile)
def lsst.pex.config.configField.ConfigField.toDict (   self,
  instance 
)

Definition at line 109 of file configField.py.

110  def toDict(self, instance):
111  value = self.__get__(instance)
112  return value.toDict()
def lsst.pex.config.configField.ConfigField.validate (   self,
  instance 
)

Definition at line 113 of file configField.py.

114  def validate(self, instance):
115  value = self.__get__(instance)
116  value.validate()
117 
118  if self.check is not None and not self.check(value):
119  msg = "%s is not a valid value"%str(value)
120  raise FieldValidationError(self, instance, msg)

The documentation for this class was generated from the following file: