13 import FWCore.ParameterSet.Config
as cms
14 import FWCore.GuiBrowsers.EnablePSetHistory
15 FWCore.GuiBrowsers.EnablePSetHistory.ACTIVATE_INSPECTION=
False
17 from FWCore.GuiBrowsers.editorTools
import UserCodeTool
19 import PhysicsTools.PatAlgos.tools
as tools
20 standardToolsDir=os.path.abspath(os.path.join(os.path.dirname(tools.__file__)))
22 cmsswDir=
"$CMSSW_BASE"
23 cmsswReleaseDir=
"$CMSSW_RELEASE_BASE"
24 standardConfigDir=os.path.abspath(os.path.expandvars(os.path.join(cmsswDir,
"src/PhysicsTools/PatAlgos/test")))
25 if not os.path.exists(standardConfigDir):
26 standardConfigDir=os.path.abspath(os.path.expandvars(os.path.join(cmsswReleaseDir,
"src/PhysicsTools/PatAlgos/test")))
29 """ Import configuration tool """
33 ConfigToolBase.__init__(self)
34 self.addParameter(self.
_defaultParameters,
'filename',
'/',
'The name of the configuration file')
39 dump +=
"### Generated by ConfigEditor ###\n"
40 find1=os.path.abspath(os.path.dirname(self.
_parameters[
'filename'].value)).
find(os.path.abspath(os.path.expandvars(cmsswDir)))
41 find2=os.path.abspath(os.path.dirname(self.
_parameters[
'filename'].value)).
find(os.path.abspath(os.path.expandvars(cmsswReleaseDir)))
42 if find1>=0
or find2>=0:
43 dump +=
"import sys\n"
44 dump +=
"import os.path\n"
46 dir=os.path.abspath(os.path.dirname(self.
_parameters[
'filename'].value))[find1+len(os.path.abspath(os.path.expandvars(cmsswDir)))+1:]
48 dir=os.path.abspath(os.path.dirname(self.
_parameters[
'filename'].value))[find2+len(os.path.abspath(os.path.expandvars(cmsswReleaseDir)))+1:]
49 dump +=
"sys.path.append(os.path.abspath(os.path.expandvars(os.path.join('"+cmsswDir+
"','"+dir+
"'))))\n"
50 dump +=
"sys.path.append(os.path.abspath(os.path.expandvars(os.path.join('"+cmsswReleaseDir+
"','"+dir+
"'))))\n"
51 dump +=
"### ------------------------- ###\n"
54 dump +=
"from "+os.path.splitext(os.path.basename(self.
_parameters[
'filename'].value))[0]+
" import *\n"
56 dump +=
"### Generated by ConfigEditor ###\n"
57 dump +=
"if hasattr(process,'resetHistory'): process.resetHistory()\n"
58 dump +=
"### ------------------------- ###\n"
60 dump += command +
"\n"
65 self._importCommands=commands
75 class ToolDataAccessor(BasicDataAccessor):
77 logging.debug(__name__ +
": __init__")
87 """ Return the children of a container object.
95 """ Return a string that is used as caption of an object.
97 if isinstance(object,type):
98 directory=os.path.splitext(os.path.basename(inspect.getfile(object)))[0]
100 directory=os.path.splitext(os.path.basename(inspect.getfile(type(object))))[0]
101 if directory==
"ToolDataAccessor":
104 return directory+
"."+object._label
106 def _property(self,name,value,description,typ,allowedValues):
107 if typ
in [bool]
and type(value)!=typ:
109 if typ
in [int, long, float]
and type(value)!=typ:
111 if not allowedValues
is None and typ
in [int,long,float,str]:
112 return (
"DropDown", name, value,description,
False,
False, allowedValues)
114 return (
"Boolean", name, value,description)
115 elif typ
in [int, long]:
116 return (
"Integer", name, value,description)
118 return (
"Double", name, value,description)
119 elif name==
"filename":
120 return (
"File", name, str(value),description)
122 return (
"MultilineString", name, str(value).strip(
"\n"),description)
124 return (
"String", name, str(value),description)
127 """ Return the list of the properties of an object.
129 Each property is represented by a tuple containing its
130 type, name, value, description and readonly(True/False).
131 Possible types are: 'Category','String','MultilineString','File','FileVector','Boolean','Integer','Double'.
134 if not isinstance(object,(ImportTool,UserCodeTool,ApplyTool)):
135 properties+=[(
"String",
"Tool",self.
label(object),
None,
True)]
136 if not isinstance(object,(ImportTool,UserCodeTool)):
137 properties+=[(
"String",
"Description",object.description(),
None,
True)]
138 if not isinstance(object,(UserCodeTool,ApplyTool)):
139 code=object.dumpPython()
140 if isinstance(code,tuple):
142 properties+=[(
"MultilineString",
"code",code.strip(
"\n"),
None,
True)]
143 if not isinstance(object,(ImportTool,UserCodeTool,ApplyTool)):
144 properties+=[(
"String",
"comment",object._comment,
None,
False)]
145 if len(object.getParameters().
items())>0:
146 properties += [(
"Category",
"Parameters",
"")]
147 properties+=[self.
_property(value.name,value.value,value.description,value.type,object.getAllowedValues(value.name))
for key,value
in object.getParameters().
items()]
151 """ Change the property 'name' of an object to a new value.
157 process.disableRecording()
159 process.enableRecording()
160 process.resetModified()
161 process.resetModifiedObjects()
162 except Exception
as e:
163 error=
"Error in python code (see logfile for details):\n"+str(e)
167 elif isinstance(value,str):
175 object.setParameter(name,value)
176 except Exception
as e:
177 error=
"Cannot set parameter "+name+
" (see logfile for details):\n"+str(e)
178 logging.warning(__name__ +
": setProperty: Cannot set parameter "+name+
": "+
exception_traceback())
181 elif name==
"comment":
183 object.setComment(value)
184 except Exception
as e:
185 error=
"Cannot set comment (see logfile for details):\n"+str(e)
189 if str(id(object))+
"."+name
in self._parameterErrors.keys():
195 self._importTool.setParameter(
"filename",accessor.configFile())
196 if accessor.process():
198 self._processCopy.resetHistory()
205 self._toolList.remove(tool)
214 logging.debug(__name__ +
": updateProcess")
222 if not process.checkRecording():
223 logging.error(__name__ +
": Could not apply tool: "+self.
label(tool)+
" (problem with enable recording flag)")
224 QCoreApplication.instance().errorMessage(
"Could not apply tool: "+self.
label(tool)+
" (problem with enable recording flag)")
226 except Exception
as e:
228 QCoreApplication.instance().errorMessage(
"Could not apply tool (see log file for details):\n"+str(e))
235 logging.debug(__name__ +
": updateToolList")
242 for tool,objects
in history:
243 if isinstance(tool,str):
244 userTool=UserCodeTool()
245 userTool.setParameter(
"code",tool)
247 elif isinstance(tool,ConfigToolBase):
249 command=tool.dumpPython()[0]
250 if command!=
"" and not command
in importCommands:
251 importCommands+=[command]
253 self._importTool.setImportCommands(importCommands)
265 return [self.
_parameterErrors[key]
for key
in self._parameterErrors.keys()
if str(id(object))==key.split(
".")[0]]
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)