CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

Mixins::_Parameterizable Class Reference

Inheritance diagram for Mixins::_Parameterizable:
Mixins::_TypedParameterizable Modules::_Module Modules::ESPrefer Modules::ESProducer Modules::ESSource Modules::Looper Modules::Service Modules::Source Modules::EDAnalyzer Modules::EDFilter Modules::EDProducer Modules::OutputModule

List of all members.

Public Member Functions

def __delattr__
def __init__
def __repr__
def __setattr__
def dumpPython
def getParameter
def hasParameter
def insertContentsInto
def isFrozen
def isModified
def parameterNames_
def parameters_
def setIsFrozen

Private Member Functions

def __addParameter
def __raiseBadSetAttr
def __setParameters

Private Attributes

 _isFrozen
 _isModified

Detailed Description

Base class for classes which allow addition of _ParameterTypeBase data

Definition at line 108 of file Mixins.py.


Constructor & Destructor Documentation

def Mixins::_Parameterizable::__init__ (   self,
  arg,
  kargs 
)

Definition at line 110 of file Mixins.py.

00111                                    :
00112         self.__dict__['_Parameterizable__parameterNames'] = []
00113         self.__dict__["_isFrozen"] = False
00114         """The named arguments are the 'parameters' which are added as 'python attributes' to the object"""
00115         if len(arg) != 0:
00116             #raise ValueError("unnamed arguments are not allowed. Please use the syntax 'name = value' when assigning arguments.")
00117             for block in arg:
00118                 if type(block).__name__ != "PSet":
00119                     raise ValueError("Only PSets can be passed as unnamed argument blocks.  This is a "+type(block).__name__)
00120                 self.__setParameters(block.parameters_())
00121         self.__setParameters(kargs)
00122         self._isModified = False
        

Member Function Documentation

def Mixins::_Parameterizable::__addParameter (   self,
  name,
  value 
) [private]

Definition at line 178 of file Mixins.py.

00179                                          :
00180         if not isinstance(value,_ParameterTypeBase):
00181             self.__raiseBadSetAttr(name)
00182         if name in self.__dict__:
00183             message = "Duplicate insert of member " + name
00184             message += "\nThe original parameters are:\n"
00185             message += self.dumpPython() + '\n'
00186             raise ValueError(message)
00187         self.__dict__[name]=value
00188         self.__parameterNames.append(name)
00189         self._isModified = True

def Mixins::_Parameterizable::__delattr__ (   self,
  name 
)

Definition at line 223 of file Mixins.py.

00224                               :
00225         if self.isFrozen():
00226             raise ValueError("Object already added to a process. It is read only now")
00227         super(_Parameterizable,self).__delattr__(name)
        self.__parameterNames.remove(name)
def Mixins::_Parameterizable::__raiseBadSetAttr (   name) [private]

Definition at line 229 of file Mixins.py.

00230                                :
        raise TypeError(name+" does not already exist, so it can only be set to a CMS python configuration type")
def Mixins::_Parameterizable::__repr__ (   self)

Definition at line 249 of file Mixins.py.

00250                       :
        return self.dumpPython()
def Mixins::_Parameterizable::__setattr__ (   self,
  name,
  value 
)

Definition at line 194 of file Mixins.py.

00195                                     :
00196         #since labels are not supposed to have underscores at the beginning
00197         # I will assume that if we have such then we are setting an internal variable
00198         if self.isFrozen() and not (name in ["_Labelable__label","_isFrozen"] or name.startswith('_')): 
00199             message = "Object already added to a process. It is read only now\n"
00200             message +=  "    %s = %s" %(name, value)
00201             message += "\nThe original parameters are:\n"
00202             message += self.dumpPython() + '\n'           
00203             raise ValueError(message)
00204         # underscored names bypass checking for _ParameterTypeBase
00205         if name[0]=='_':
00206             super(_Parameterizable,self).__setattr__(name,value)
00207         elif not name in self.__dict__:
00208             self.__addParameter(name, value)
00209             self._isModified = True
00210         else:
00211             # handle the case where users just replace with a value, a = 12, rather than a = cms.int32(12)
00212             if isinstance(value,_ParameterTypeBase):
00213                 self.__dict__[name] = value
00214             else:
00215                 self.__dict__[name].setValue(value)
00216             self._isModified = True

def Mixins::_Parameterizable::__setParameters (   self,
  parameters 
) [private]

Definition at line 190 of file Mixins.py.

00191                                         :
00192         for name,value in parameters.iteritems():
00193             self.__addParameter(name, value)

def Mixins::_Parameterizable::dumpPython (   self,
  options = PrintOptions() 
)

Reimplemented in Mixins::_TypedParameterizable.

Definition at line 231 of file Mixins.py.

00232                                                 :
00233         others = []
00234         usings = []
00235         for name in self.parameterNames_():
00236             param = self.__dict__[name]
00237             # we don't want minuses in names
00238             name2 = name.replace('-','_')
00239             options.indent()
00240             #_UsingNodes don't get assigned variables
00241             if name.startswith("using_"):
00242                 usings.append(options.indentation()+param.dumpPython(options))
00243             else:
00244                 others.append(options.indentation()+name2+' = '+param.dumpPython(options))
00245             options.unindent()
00246         # usings need to go first
00247         resultList = usings
00248         resultList.extend(others)
        return ',\n'.join(resultList)+'\n'
def Mixins::_Parameterizable::getParameter (   self,
  params 
)
_getParameter_

Retrieve the specified parameter from the PSet Provided
given the attribute chain

returns None if not found

Definition at line 150 of file Mixins.py.

00151                                   :
00152         """
00153         _getParameter_
00154 
00155         Retrieve the specified parameter from the PSet Provided
00156         given the attribute chain
00157 
00158         returns None if not found
00159         """
00160         lastParam = self
00161         # Don't accidentally iterate over letters in a string
00162         if type(params).__name__ == 'str':
00163             return getattr(self, params, None)
00164         for param in params:
00165             lastParam = getattr(lastParam, param, None)
00166             print str(lastParam)
00167             if lastParam == None:
00168                 return None
00169         return lastParam

def Mixins::_Parameterizable::hasParameter (   self,
  params 
)
_hasParameter_

check that pset provided has the attribute chain
specified.

Eg, if params is [ 'attr1', 'attr2', 'attr3' ]
check for pset.attr1.attr2.attr3

returns True if parameter exists, False if not

Definition at line 136 of file Mixins.py.

00137                                   :
00138         """
00139         _hasParameter_
00140 
00141         check that pset provided has the attribute chain
00142         specified.
00143 
00144         Eg, if params is [ 'attr1', 'attr2', 'attr3' ]
00145         check for pset.attr1.attr2.attr3
00146 
00147         returns True if parameter exists, False if not
00148         """
00149         return (self.getParameter(params) != None)

def Mixins::_Parameterizable::insertContentsInto (   self,
  parameterSet 
)

Definition at line 251 of file Mixins.py.

00252                                               :
00253         for name in self.parameterNames_():
00254             param = getattr(self,name)
00255             param.insertInto(parameterSet, name)
00256 

def Mixins::_Parameterizable::isFrozen (   self)

Definition at line 217 of file Mixins.py.

00218                       :
        return self._isFrozen
def Mixins::_Parameterizable::isModified (   self)

Definition at line 126 of file Mixins.py.

00127                         :
00128         if self._isModified:
00129             return True
00130         for name in self.parameterNames_():
00131             param = self.__dict__[name]
00132             if isinstance(param, _Parameterizable) and param.isModified():
00133                 self._isModified = True
00134                 return True
00135         return False

def Mixins::_Parameterizable::parameterNames_ (   self)
Returns the name of the parameters

Definition at line 123 of file Mixins.py.

00124                              :
00125         """Returns the name of the parameters"""
        return self.__parameterNames[:]
def Mixins::_Parameterizable::parameters_ (   self)
Returns a dictionary of copies of the user-set parameters

Definition at line 170 of file Mixins.py.

00171                          :
00172         """Returns a dictionary of copies of the user-set parameters"""
00173         import copy
00174         result = dict()
00175         for name in self.parameterNames_():
00176                result[name]=copy.deepcopy(self.__dict__[name])
00177         return result

def Mixins::_Parameterizable::setIsFrozen (   self)

Definition at line 219 of file Mixins.py.

00220                          :
00221         self._isFrozen = True
00222         for name in self.parameterNames_():
            self.__dict__[name].setIsFrozen() 

Member Data Documentation

Definition at line 219 of file Mixins.py.

Definition at line 110 of file Mixins.py.