3 import FWCore.ParameterSet.Config
as cms
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():
143 if repr(self.
_parameters[key].value)!=repr(self._defaultParameters[key].value):
144 dumpPython+=
", "+
str(key)+
" = "
151 return (dumpPythonImport,dumpPython)
154 """ Write a comment in the configuration file
158 """ Return the comment set for this tool
162 return "The type for parameter "+
'"'+
str(value)+
'"'+
" is not "+
'"'+
str(type)+
'"'
168 elif (isinstance(value,dict))
and (isinstance(self.
_parameters[name].allowedValues,list)):
169 for key
in value.keys():
170 if (key
not in self.
_parameters[name].allowedValues):
171 raise ValueError(
"The input key value "+
'"'+
str(key)+
'"'+
" for parameter "+
'"'+name+
'"'+
" is not supported. Supported ones are: "+
str(self.
_parameters[name].allowedValues)[1:-1])
172 elif (isinstance(value,list))
and (isinstance(self.
_parameters[name].allowedValues,list )):
174 if (val
not in self.
_parameters[name].allowedValues) :
175 raise ValueError(
"The input value "+
'"'+
str(val)+
'"'+
" for parameter "+
'"'+name+
'"'+
" is not supported. Supported ones are: "+
str(self.
_parameters[name].allowedValues)[1:-1])
176 elif (
not isinstance(value,list))
and (isinstance(self.
_parameters[name].allowedValues,list)) :
177 if (value
not in self.
_parameters[name].allowedValues
and value ==
None)
and (
not self.
_parameters[name].acceptNoneValue) :
179 elif not isinstance(self.
_parameters[name].allowedValues,list):
180 if (value!=self.
_parameters[name].allowedValues
and value ==
None)
and (
not self.
_parameters[name].acceptNoneValue) :
183 raise ValueError(
"The input value "+
'"'+
str(value)+
'"'+
" for parameter "+
'"'+name+
'"'+
" is not supported. Supported ones are: "+
str(self.
_parameters[name].allowedValues)[1:-1])
186 if self.
_parameters[name].acceptNoneValue
is False:
193 return self._defaultParameters[name].allowedValues
uint16_t *__restrict__ id