CMS 3D CMS Logo

Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes

python::ConfigToolBase::ConfigToolBase Class Reference

List of all members.

Public Member Functions

def __call__
def __copy__
 __copy__(self) returns a copy of the tool
def __init__
def addParameter
 use addParameter method in the redefinition of tool constructor in order to add parameters to the tools each tool is defined by its label, default value, description, type and allowedValues (the last two attribute can be ignored if the user gives a valid default values and if there is not a list of allowed values)
def apply
def comment
def description
def dumpPython
def errorMessage
def getAllowedValues
def getParameters
def getvalue
def isAllowed
 method isAllowed is called by setParameter to check input values for a specific parameter
def reset
def setComment
def setParameter
def setParameters
def toolCode
def typeError
 check about input value type

Public Attributes

 parAccepted

Private Attributes

 _comment
 _description
 _parameters
 _path

Static Private Attributes

string _defaultValue = "No default value. Set parameter value."
string _label = "ConfigToolBase"
string _path = ""

Detailed Description

Base class for PAT tools

Definition at line 33 of file ConfigToolBase.py.


Constructor & Destructor Documentation

def python::ConfigToolBase::ConfigToolBase::__init__ (   self)

Definition at line 40 of file ConfigToolBase.py.

00041                       :
00042         self._parameters=dicttypes.SortedKeysDict()
00043         self._description=self.__doc__
00044         self._comment = ''
00045         self.parAccepted=True
00046         saveOrigin(self,1)
00047         self._path = path.realpath(self._filename)        
00048         self._path = self._path.split("/src/")
00049         self._path = self._path[1].replace("/python","")
00050         #self._path = "".join(self._path)
00051         self._path = self._path.replace("/",".")
00052         self._path = self._path.replace(".py","")
00053 


Member Function Documentation

def python::ConfigToolBase::ConfigToolBase::__call__ (   self,
  process 
)
Call the instance 

Definition at line 54 of file ConfigToolBase.py.

00055                               :
00056         """ Call the instance 
00057         """
00058         raise NotImplementedError
    
def python::ConfigToolBase::ConfigToolBase::__copy__ (   self)

__copy__(self) returns a copy of the tool

Definition at line 83 of file ConfigToolBase.py.

00084                       :
00085         c=type(self)()
00086         c.setParameters(copy.deepcopy(self._parameters))
00087         c.setComment(self._comment)
        return c
def python::ConfigToolBase::ConfigToolBase::addParameter (   self,
  dict,
  parname,
  parvalue,
  description,
  Type = None,
  allowedValues = None,
  acceptNoneValue = False 
)

use addParameter method in the redefinition of tool constructor in order to add parameters to the tools each tool is defined by its label, default value, description, type and allowedValues (the last two attribute can be ignored if the user gives a valid default values and if there is not a list of allowed values)

Add a parameter with its label, value, description and type to self._parameters

Definition at line 102 of file ConfigToolBase.py.

00103                                                                                                                    :
00104         """ Add a parameter with its label, value, description and type to self._parameters
00105         """
00106         par=parameter()
00107         par.name=parname
00108         par.value=parvalue
00109         par.description=description
00110         if Type==None:
00111             par.type=type(parvalue)
00112         else: par.type=Type
00113         par.allowedValues=allowedValues
00114         par.acceptNoneValue=acceptNoneValue
        dict[par.name]=par        
def python::ConfigToolBase::ConfigToolBase::apply (   self,
  process 
)

Definition at line 59 of file ConfigToolBase.py.

00060                            :
00061         
00062         if hasattr(process, "addAction"):
00063             process.disableRecording()
00064             
00065         try:
00066             comment=inspect.stack(2)[2][4][0].rstrip("\n")
00067             if comment.startswith("#"):
00068                 self.setComment(comment.lstrip("#"))
00069         except:
00070             pass
00071             
00072         self.toolCode(process)
00073         
00074         if hasattr(process, "addAction"):
00075             process.enableRecording()
00076             action=self.__copy__()
00077             process.addAction(action)
            
def python::ConfigToolBase::ConfigToolBase::comment (   self)
Return the comment set for this tool

Definition at line 156 of file ConfigToolBase.py.

00157                      :
00158         """ Return the comment set for this tool
00159         """
        return self._comment
def python::ConfigToolBase::ConfigToolBase::description (   self)
Return a string with a detailed description of the action.

Definition at line 94 of file ConfigToolBase.py.

00095                          :
00096         """ Return a string with a detailed description of the action.
00097         """
00098         return self._description
    
def python::ConfigToolBase::ConfigToolBase::dumpPython (   self)
Return the python code to perform the action

Definition at line 134 of file ConfigToolBase.py.

00135                         :
00136         """ Return the python code to perform the action
00137         """ 
00138         dumpPythonImport = "\nfrom "+self._path+" import *\n"
00139         dumpPython=''
00140         if self._comment!="":
00141             dumpPython = '#'+self._comment
00142         dumpPython += "\n"+self._label+"(process "
00143         for key in self._parameters.keys():
00144             dumpPython+= ", "
00145             if self._parameters[key].type is str:
00146                 string = "'"+str(self.getvalue(key))+"'"
00147             else:
00148                 string = str(self.getvalue(key))
00149             dumpPython+= string
00150         dumpPython+=")"+'\n'
00151         return (dumpPythonImport,dumpPython)
    
def python::ConfigToolBase::ConfigToolBase::errorMessage (   self,
  value,
  type 
)

Definition at line 160 of file ConfigToolBase.py.

00161                                      :
        return "The type for parameter "+'"'+str(value)+'"'+" is not "+'"'+str(type)+'"'
def python::ConfigToolBase::ConfigToolBase::getAllowedValues (   self,
  name 
)

Definition at line 191 of file ConfigToolBase.py.

00192                                    :
00193         return self._defaultParameters[name].allowedValues
def python::ConfigToolBase::ConfigToolBase::getParameters (   self)
Return a copy of the dict of the parameters.

Definition at line 115 of file ConfigToolBase.py.

00116                            :
00117         """ Return a copy of the dict of the parameters.
00118         """
        return copy.deepcopy(self._parameters)
def python::ConfigToolBase::ConfigToolBase::getvalue (   self,
  name 
)
Return the value of parameter 'name'

Definition at line 90 of file ConfigToolBase.py.

00091                            :
00092         """ Return the value of parameter 'name'
00093         """
        return self._parameters[name].value
def python::ConfigToolBase::ConfigToolBase::isAllowed (   self,
  name,
  value 
)

method isAllowed is called by setParameter to check input values for a specific parameter

Definition at line 163 of file ConfigToolBase.py.

00164                                   :
00165         self.parAccepted=True
00166         if value==[]:
00167             self.parAccepted=False
00168         elif (isinstance(value,dict)) and (isinstance(self._parameters[name].allowedValues,list)):
00169             for key in value.keys():
00170                 if (key not in self._parameters[name].allowedValues):
00171                     raise ValueError("The input key value "+'"'+str(key)+'"'+" for parameter "+'"'+name+'"'+" is not supported. Supported ones are: "+str(self._parameters[name].allowedValues))
00172         elif (isinstance(value,list)) and (isinstance(self._parameters[name].allowedValues,list )):
00173             for i in value:
00174                 if (i not in self._parameters[name].allowedValues) :
00175                     self.parAccepted=False
00176         elif (not isinstance(value,list))and (isinstance(self._parameters[name].allowedValues,list)) :
00177             if (value not in self._parameters[name].allowedValues and value == None) and (not self._parameters[name].acceptNoneValue) :
00178                 self.parAccepted=False
00179         elif not isinstance(self._parameters[name].allowedValues,list):
00180             if (value!=self._parameters[name].allowedValues and value == None) and (not self._parameters[name].acceptNoneValue) :
00181                 self.parAccepted=False  
00182         if self.parAccepted==False:
            raise ValueError("The input value "+'"'+str(value)+'"'+" for parameter "+'"'+name+'"'+" is not supported. Supported ones are: "+str(self._parameters[name].allowedValues)[1:-1])
def python::ConfigToolBase::ConfigToolBase::reset (   self)

Definition at line 88 of file ConfigToolBase.py.

00089                    :
        self._parameters=copy.deepcopy(self._defaultParameters)
def python::ConfigToolBase::ConfigToolBase::setComment (   self,
  comment 
)
Write a comment in the configuration file

Definition at line 152 of file ConfigToolBase.py.

00153                                  :
00154         """ Write a comment in the configuration file
00155         """
        self._comment = str(comment)
def python::ConfigToolBase::ConfigToolBase::setParameter (   self,
  name,
  value,
  typeNone = False 
)
Change parameter 'name' to a new value

Definition at line 119 of file ConfigToolBase.py.

00120                                                        :
00121         """ Change parameter 'name' to a new value
00122         """
00123         self._parameters[name].value=value
00124         ### check about input value type 
00125         self.typeError(name)
00126         ### check about input value (it works if allowedValues for the specific parameter is set)
        if self._defaultParameters[name].allowedValues is not None: self.isAllowed(name,value )
def python::ConfigToolBase::ConfigToolBase::setParameters (   self,
  parameters 
)

Definition at line 127 of file ConfigToolBase.py.

00128                                        :
        self._parameters=copy.deepcopy(parameters)
def python::ConfigToolBase::ConfigToolBase::toolCode (   self,
  process 
)

Definition at line 78 of file ConfigToolBase.py.

00079                                :
00080         raise NotImplementedError
00081 
            
def python::ConfigToolBase::ConfigToolBase::typeError (   self,
  name 
)

check about input value type

Definition at line 184 of file ConfigToolBase.py.

00185                             :
00186         if self._parameters[name].acceptNoneValue is False:
00187             if not isinstance(self._parameters[name].value,self._parameters[name].type):
00188                 raise TypeError(self.errorMessage(self._parameters[name].value,self._parameters[name].type))
00189         else:
00190             if not (isinstance(self._parameters[name].value,self._parameters[name].type) or self._parameters[name].value is  None):
                raise TypeError(self.errorMessage(self._parameters[name].value,self._parameters[name].type))

Member Data Documentation

Definition at line 40 of file ConfigToolBase.py.

string python::ConfigToolBase::ConfigToolBase::_defaultValue = "No default value. Set parameter value." [static, private]

Definition at line 38 of file ConfigToolBase.py.

Definition at line 40 of file ConfigToolBase.py.

string python::ConfigToolBase::ConfigToolBase::_label = "ConfigToolBase" [static, private]

Definition at line 37 of file ConfigToolBase.py.

Definition at line 40 of file ConfigToolBase.py.

string python::ConfigToolBase::ConfigToolBase::_path = "" [static, private]

Definition at line 39 of file ConfigToolBase.py.

Definition at line 40 of file ConfigToolBase.py.

Definition at line 40 of file ConfigToolBase.py.