9 import FWCore.ParameterSet.DictTypes
as dicttypes
12 return self.__class__(self)
13 dicttypes.SortedKeysDict.__copy__ = new_SortedKeysDict__copy__
16 from copy
import deepcopy
19 d = memo.get(
id(self),
None)
22 memo[
id(self)] = d = self.__class__()
23 d.__init__(deepcopy(self.items(), memo))
25 dicttypes.SortedKeysDict.__deepcopy__ = new_SortedKeysDict__deepcopy__
35 """ Base class for PAT tools
37 _label=
"ConfigToolBase"
38 _defaultValue=
"No default value. Set parameter value."
46 self.
_path = path.realpath(self._filename)
47 self.
_path = self._path.split(
"/src/")
50 self.
_path = self._path.replace(
"/",
".")
51 self.
_path = self._path.replace(
".py",
"")
57 raise NotImplementedError
61 if hasattr(process,
"addAction"):
62 process.disableRecording()
65 comment=inspect.stack(2)[2][4][0].rstrip(
"\n")
66 if comment.startswith(
"#"):
73 if hasattr(process,
"addAction"):
74 process.enableRecording()
76 process.addAction(action)
79 raise NotImplementedError
89 self.
_parameters=copy.deepcopy(self._defaultParameters)
91 """ Return the value of parameter 'name'
95 """ Return a string with a detailed description of the action.
102 def addParameter(self,dict,parname, parvalue, description,Type=None, allowedValues=None, acceptNoneValue=False):
103 """ Add a parameter with its label, value, description and type to self._parameters
108 par.description=description
110 par.type=type(parvalue)
112 par.allowedValues=allowedValues
113 par.acceptNoneValue=acceptNoneValue
116 """ Return a copy of the dict of the parameters.
120 """ Change parameter 'name' to a new value
126 if self._defaultParameters[name].allowedValues
is not None: self.
isAllowed(name,value )
135 """ Return the python code to perform the action
137 dumpPythonImport =
"\nfrom "+self.
_path+
" import *\n"
141 dumpPython +=
"\n"+self.
_label+
"(process "
142 for key
in self._parameters.keys():
145 string =
"'"+str(self.
getvalue(key))+
"'"
150 return (dumpPythonImport,dumpPython)
153 """ Write a comment in the configuration file
157 """ Return the comment set for this tool
161 return "The type for parameter "+
'"'+str(value)+
'"'+
" is not "+
'"'+str(type)+
'"'
167 elif (isinstance(value,dict))
and (isinstance(self.
_parameters[name].allowedValues,list)):
168 for key
in value.keys():
169 if (key
not in self.
_parameters[name].allowedValues):
170 raise ValueError(
"The input key value "+
'"'+str(key)+
'"'+
" for parameter "+
'"'+name+
'"'+
" is not supported. Supported ones are: "+str(self.
_parameters[name].allowedValues))
171 elif (isinstance(value,list))
and (isinstance(self.
_parameters[name].allowedValues,list )):
173 if (i
not in self.
_parameters[name].allowedValues) :
175 elif (
not isinstance(value,list))
and (isinstance(self.
_parameters[name].allowedValues,list)) :
176 if (value
not in self.
_parameters[name].allowedValues
and value ==
None)
and (
not self.
_parameters[name].acceptNoneValue) :
178 elif not isinstance(self.
_parameters[name].allowedValues,list):
179 if (value!=self.
_parameters[name].allowedValues
and value ==
None)
and (
not self.
_parameters[name].acceptNoneValue) :
182 raise ValueError(
"The input value "+
'"'+str(value)+
'"'+
" for parameter "+
'"'+name+
'"'+
" is not supported. Supported ones are: "+str(self.
_parameters[name].allowedValues)[1:-1])
185 if self.
_parameters[name].acceptNoneValue
is False:
192 return self._defaultParameters[name].allowedValues