6 from Vispa.Share.BasicDataAccessor
import BasicDataAccessor
7 from Vispa.Share.RelativeDataAccessor
import RelativeDataAccessor
8 from Vispa.Main.Exceptions
import PluginIgnoredException,exception_traceback
10 import FWCore.ParameterSet.SequenceTypes
as sqt
12 import FWCore.ParameterSet.Modules
as mod
13 import FWCore.ParameterSet.Types
as typ
19 def __init__(self, label, parent=None, parameters=None):
24 parent._configChildren += [self]
25 if parameters !=
None:
36 logging.debug(__name__ +
": __init__")
69 """ Read cms objects recursively from path """
71 if isinstance(pth, (cms.Path, cms.EndPath, cms.Sequence, cms.SequencePlaceholder, cms.Source, mod._Module, cms.Service, cms.ESSource, cms.ESProducer, cms.ESPrefer, cms.PSet, cms.VPSet)):
73 entry._configChildren=[]
76 if not pth
in mother._configChildren:
77 mother._configChildren += [pth]
83 if isinstance(pth, list):
86 if hasattr(sqt,
"_SequenceCollection"):
88 if isinstance(pth, (sqt._ModuleSequenceType)):
89 if isinstance(pth._seq, (sqt._SequenceCollection)):
90 for o
in pth._seq._collection:
96 if isinstance(o, sqt._Sequenceable):
100 """ Read connection between objects """
107 compareObjectList+=[(obj,o)
for o
in self.
_allObjects]
108 compareObjectList+=[(o,obj)
for o
in self.
_allObjects]
110 compareObjectList=[(o1,o2)
for o1
in objects
for o2
in objects]
111 for connection
in compareObjectList:
114 if not connection
in self._connections.keys():
115 for key, value
in self.
inputTags(connection[1]):
116 module = str(value).
split(
":")[0]
117 if module == self.
label(connection[0]):
118 product =
".".
join(str(value).
split(
":")[1:])
123 if connection
in self._connections.keys():
125 if not connection[1]
in self._motherRelationsDict.keys():
128 if not connection[0]
in self._daughterRelationsDict.keys():
138 result.sort(
lambda x, y: cmp(self.
label(x).lower(), self.
label(y).lower()))
142 """ Open config file and read it.
144 logging.debug(__name__ +
": open")
147 global imported_configs
152 for i
in imported_configs.iterkeys():
153 if i
in sys.modules.keys():
155 sys.path.insert(0, os.path.dirname(self.
_filename))
156 common_imports = sys.modules.copy()
163 imported_configs = sys.modules.copy()
164 for i
in common_imports.iterkeys():
165 del imported_configs[i]
168 for j
in imported_configs.itervalues():
171 if entry[0] !=
"_" and entry !=
"cms":
173 for k
in imported_configs.itervalues():
174 if hasattr(k, entry):
176 if len(setk) < len(setj)
and setk < setj:
180 if hasattr(j,
"__file__"):
182 file_dict[entry] = filen
194 o=getattr(self.
_file, entry)
195 if entry[0] !=
"_" and entry !=
"cms" and hasattr(o,
"label_"):
196 getattr(self.
_file, entry).setLabel(entry)
197 text = os.path.splitext(os.path.basename(file_dict[o.label_()]))[0]
203 self._file.process=process
205 parameters = {
"name": self.
process().process}
206 process_folder =
ConfigFolder(
"process",
None, parameters)
212 folder_list += [(
"source", [self.
process().source])]
213 if self.
process().schedule !=
None:
214 folder_list += [(
"paths", self.
process().schedule)]
216 folder_list += [(
"paths", self.
process().paths.itervalues())]
217 folder_list += [(
"endpaths", self.
process().endpaths.itervalues())]
221 folder_list += [(
"essources", self.
_sort_list(self.
process().es_sources.values()))]
222 folder_list += [(
"esproducers", self.
_sort_list(self.
process().es_producers.values()))]
223 folder_list += [(
"esprefers", self.
_sort_list(self.
process().es_prefers.values()))]
224 for foldername, entry
in folder_list:
231 if hasattr(self.
_file,
"process"):
232 return self._file.process
237 foundHeaderPart1 =
False
238 foundHeaderPart2 =
False
240 search_paths=[os.path.abspath(os.path.dirname(self.
_filename))]
241 while theFile
and not (foundHeaderPart1
and foundHeaderPart2)
and lines > 0:
242 line = theFile.readline()
244 if "Generated by ConfigEditor" in line:
245 foundHeaderPart1 =
True
246 splitline = line.split(
"'")
247 if foundHeaderPart1
and len(splitline) == 5
and splitline[0] ==
"sys.path.append(os.path.abspath(os.path.expandvars(os.path.join(" and splitline[4] ==
"))))\n":
248 search_paths+=[os.path.abspath(os.path.expandvars(os.path.join(splitline[1],splitline[3])))]
249 splitline = line.split()
250 if foundHeaderPart1
and len(splitline) == 4
and splitline[0] ==
"from" and splitline[2] ==
"import":
251 for search_path
in search_paths:
252 if os.path.exists(os.path.join(search_path,splitline[1]+
".py")):
253 self.
_filename = os.path.join(search_path,splitline[1]+
".py")
256 foundHeaderPart2 =
True
260 """ dump python configuration """
261 logging.debug(__name__ +
": dumpPython")
268 """ configuration history """
269 logging.debug(__name__ +
": history")
276 """ Get label of an object """
278 if hasattr(object,
"label_")
and (
not hasattr(object,
"hasLabel_")
or object.hasLabel_()):
279 text = str(object.label_())
281 if hasattr(object,
"type_"):
282 text = str(object.type_())
288 """ Get children of an object """
289 if hasattr(object,
"_configChildren"):
290 return tuple(object._configChildren)
295 return isinstance(object, (ConfigFolder, list, cms.Path, cms.EndPath, cms.Sequence, cms.SequencePlaceholder))
300 for o
in self.allChildren(object):
310 """ Get motherRelations of an object """
311 if object
in self._motherRelationsDict.keys():
320 """ Get daughterRelations of an object """
321 if object
in self._daughterRelationsDict.keys():
330 """ Get type of an object """
331 return object.__class__.__name__
334 """ Get classname of an object """
336 if hasattr(object,
"type_"):
337 text = object.type_()
341 """ Get full filename """
345 if text ==
"" or text.find(
"FWCore/ParameterSet") >= 0
or text.find(
"/build/") >= 0:
346 if self.
label(object)
in file_dict:
347 text = file_dict[self.
label(object)]
350 root = os.path.splitext(text)[0]
356 """ Get linenumber """
358 if hasattr(object,
"_filename"):
359 if object._filename.find(
"FWCore/ParameterSet") < 0
and object._filename.find(
"ConfigEditor") < 0:
360 if hasattr(object,
"_lineNumber"):
361 text = str(object._lineNumber)
366 text = os.path.splitext(os.path.basename(self.
fullFilename(object)))[0]
370 match_compiled = re.match(
r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/)*\w*)\.py$',self.
fullFilename(object))
372 return match_compiled.group(1).
replace(
'/',
'.')
374 match_norm = re.match(
r'(?:^|.*?/)(\w*)/(\w*)/(?:test|python)/((?:\w*/)*)(\w*)\.py$',self.
fullFilename(object))
376 return '%s.%s.%s%s' % (match_norm.group(1),match_norm.group(2),match_norm.group(3).
replace(
'/',
'.'),match_norm.group(4))
380 match_compiled = re.match(
r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/){2})((?:\w*/)*)(\w*\.py)$',self.
fullFilename(object))
382 return '%spython/%s%s' % (match_compiled.group(1),match_compiled.group(2),match_compiled.group(3))
383 match_norm = re.match(
r'(?:^|.*?/)(\w*/\w*/(?:test|python)/(?:\w*/)*\w*\.py)$',self.
fullFilename(object))
385 return match_norm.group(1)
389 """ Get Package of an object file """
392 if len(shortdirname) > 1:
393 text = shortdirname[1]
397 """ Get parameters of an object """
399 if hasattr(object,
"parameters_"):
400 this_parameters = object.parameters_().items()
401 elif hasattr(object,
"_seq"):
402 this_parameters = [(
'sequence', object._seq.dumpSequencePython())]
403 if hasattr(object,
"tarlabel_"):
404 this_parameters += [(
'tarlabel', object.tarlabel_())]
405 return this_parameters
408 """ Add alls inputtags of value to a list """
409 if isinstance(value, list):
412 if hasattr(value,
"parameters_"):
414 if isinstance(value, cms.InputTag):
415 pythonValue = value.value()
416 this_inputtags += [(str(this_key), value.value())]
419 """ Make list of inputtags from parameter dict """
421 for key, value
in this_parameters:
427 return this_inputtags
430 """ Make list of inputtags from parameter dict """
431 if not object
in self._inputTagsDict.keys():
439 """ Get list of all config objects that are used as input """
440 if not object
in self._usesDict.keys():
442 for key, value
in self.
inputTags(object):
443 module = str(value).
split(
":")[0]
444 product =
".".
join(str(value).
split(
":")[1:])
445 if module
not in uses:
454 """ Make list of all mother sequences """
455 if not object
in self._foundInDict.keys():
458 for daughter
in self.
children(entry):
459 if self.
label(object) == self.
label(daughter)
and len(self.
children(entry)) > 0
and not self.
label(entry)
in foundin:
460 foundin += [self.
label(entry)]
468 """ Find config objects that use this as input """
469 if not object
in self._usedByDict.keys():
472 for uses
in self.
uses(entry):
473 if self.
label(object) == uses
and not self.
label(entry)
in usedby:
474 usedby += [self.
label(entry)]
484 if name !=
"" and not isinstance(object, typ.PSet):
486 partyp=str(type(object)).
split(
"'")[1].
replace(
"FWCore.ParameterSet.Types",
"cms")
487 if isinstance(object, cms.InputTag):
488 inputtagValue=object.pythonValue()
489 for i
in range(3-len(inputtagValue.split(
","))):
490 inputtagValue+=
', ""'
491 properties += [(
"String", name,
"cms.InputTag("+inputtagValue+
")", partyp, readonly)]
492 elif isinstance(object, cms.bool):
493 properties += [(
"Boolean", name, object.value(), partyp, readonly)]
494 elif isinstance(object, (cms.int32, cms.uint32, cms.int64, cms.uint64)):
495 properties += [(
"Integer", name, object.value(), partyp, readonly)]
496 elif isinstance(object, cms.double):
497 properties += [(
"Double", name, object.value(), partyp, readonly)]
498 elif hasattr(object,
"pythonValue"):
499 properties += [(
"String", name, str(object.pythonValue()).
strip(
"\"'"), partyp, readonly)]
500 elif hasattr(object,
"value"):
501 properties += [(
"MultilineString", name, str(object.value()), partyp, readonly)]
503 properties += [(
"MultilineString", name, str(object), partyp, readonly)]
507 if isinstance(object, ConfigFolder):
511 params.sort(
lambda x, y: cmp(x[0].lower(), y[0].lower()))
512 for key, value
in params:
521 """ Make list of all properties """
524 properties += [(
"Category",
"Object info",
"")]
525 if self.
label(object) !=
"":
526 properties += [(
"String",
"label", self.
label(object),
None,
True)]
527 if self.
type(object) !=
"":
528 text = self.
type(object)
530 text +=
" <" + self.
classname(object) +
">"
531 properties += [(
"String",
"type", text,
None,
True)]
536 properties += [(
"String",
"file", text,
None,
True)]
538 properties += [(
"String",
"package", self.
package(object),
None,
True)]
540 properties += [(
"String",
"full filename", self.
fullFilename(object),
None,
True)]
544 for entry
in foundIn:
548 properties += [(
"String",
"in sequence", text,
"This module/sequence is used the listed sequences",
True)]
549 uses=self.
uses(object)
550 usedBy=self.
usedBy(object)
551 if len(uses) + len(usedBy) > 0:
552 properties += [(
"Category",
"Connections",
"")]
559 properties += [(
"MultilineString",
"uses", text,
"This module/sequence depends on the output of the listes modules/seuquences",
True)]
567 properties += [(
"MultilineString",
"used by", text,
"The listed modules/sequences depend on the output of this module/sequence",
True)]
569 properties += [(
"Category",
"Parameters",
"")]
571 return tuple(properties)
574 """ Sets a property with given name to value.
576 if hasattr(object,
"_seq")
and name==
"sequence":
577 return "Modification of sequences not supported yet."
581 if isinstance(value,str)
and\
582 not value[0]==
"[" and\
583 not value[0:4]==
"cms.":
584 exec
"object." + name +
"='''" + value +
"'''"
586 exec
"object." + name +
"=" + str(value)
588 error=
"Cannot set parameter "+name+
" (see logfile for details):\n"+str(e)
589 logging.warning(__name__ +
": setProperty: Cannot set parameter "+name+
": "+
exception_traceback())
598 for key, value
in self.
inputTags(object):
599 elements=str(value).
split(
":")
602 product = elements[1]
606 process = elements[2]
609 if not module
in allLabels:
610 if not (
"*",module,product,process)
in content:
611 content += [(
"*",module,product,process)]
612 if "*_"+module+
"_"+product+
"_"+process
in content_objects.keys():
613 content_objects[
"*_"+module+
"_"+product+
"_"+process]+=
","+self.
label(object)
615 content_objects[
"*_"+module+
"_"+product+
"_"+process]=self.
label(object)
616 return (content,content_objects)
620 if self.
type(object)
in [
"EDProducer",
"EDFilter",
"EDAnalyzer"]]
624 inputModules = [object
for object
in self.
_allObjects\
625 if self.
type(object) ==
"Source"]
626 if len(inputModules) > 0
and hasattr(inputModules[0],
"inputCommands"):
627 return inputModules[0].inputCommands
632 outputModules = [object
for object
in self.
_allObjects\
633 if self.
type(object) ==
"OutputModule"]
634 if len(outputModules) > 0
and hasattr(outputModules[0],
"outputCommands"):
635 return outputModules[0].outputCommands
def recursePSetProperties
def _readInputTagsRecursive
static std::string join(char **cmd)