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:
94 elif isinstance(pth, sqt._UnarySequenceOperator):
100 if isinstance(o, sqt._Sequenceable):
104 """ Read connection between objects """
111 compareObjectList+=[(obj,o)
for o
in self.
_allObjects]
112 compareObjectList+=[(o,obj)
for o
in self.
_allObjects]
114 compareObjectList=[(o1,o2)
for o1
in objects
for o2
in objects]
115 for connection
in compareObjectList:
118 if not connection
in self._connections.keys():
119 for key, value
in self.
inputTags(connection[1]):
120 module = str(value).
split(
":")[0]
121 if module == self.
label(connection[0]):
122 product =
".".
join(str(value).
split(
":")[1:])
127 if connection
in self._connections.keys():
129 if not connection[1]
in self._motherRelationsDict.keys():
132 if not connection[0]
in self._daughterRelationsDict.keys():
142 result.sort(
lambda x, y: cmp(self.
label(x).lower(), self.
label(y).lower()))
146 """ Open config file and read it.
148 logging.debug(__name__ +
": open")
151 global imported_configs
156 for i
in imported_configs.iterkeys():
157 if i
in sys.modules.keys():
159 sys.path.insert(0, os.path.dirname(self.
_filename))
160 common_imports = sys.modules.copy()
167 imported_configs = sys.modules.copy()
168 for i
in common_imports.iterkeys():
169 del imported_configs[i]
172 for j
in imported_configs.itervalues():
175 if entry[0] !=
"_" and entry !=
"cms":
177 for k
in imported_configs.itervalues():
178 if hasattr(k, entry):
180 if len(setk) < len(setj)
and setk < setj:
184 if hasattr(j,
"__file__"):
186 file_dict[entry] = filen
198 o=getattr(self.
_file, entry)
199 if entry[0] !=
"_" and entry !=
"cms" and hasattr(o,
"label_"):
200 getattr(self.
_file, entry).setLabel(entry)
201 text = os.path.splitext(os.path.basename(file_dict[o.label_()]))[0]
207 self._file.process=process
209 parameters = {
"name": self.
process().process}
210 process_folder =
ConfigFolder(
"process",
None, parameters)
216 folder_list += [(
"source", [self.
process().source])]
217 if self.
process().schedule !=
None:
218 folder_list += [(
"paths", self.
process().schedule)]
220 folder_list += [(
"paths", self.
process().paths.itervalues())]
221 folder_list += [(
"endpaths", self.
process().endpaths.itervalues())]
225 folder_list += [(
"essources", self.
_sort_list(self.
process().es_sources.values()))]
226 folder_list += [(
"esproducers", self.
_sort_list(self.
process().es_producers.values()))]
227 folder_list += [(
"esprefers", self.
_sort_list(self.
process().es_prefers.values()))]
228 for foldername, entry
in folder_list:
235 if hasattr(self.
_file,
"process"):
236 return self._file.process
241 foundHeaderPart1 =
False
242 foundHeaderPart2 =
False
244 search_paths=[os.path.abspath(os.path.dirname(self.
_filename))]
245 while theFile
and not (foundHeaderPart1
and foundHeaderPart2)
and lines > 0:
246 line = theFile.readline()
248 if "Generated by ConfigEditor" in line:
249 foundHeaderPart1 =
True
250 splitline = line.split(
"'")
251 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":
252 search_paths+=[os.path.abspath(os.path.expandvars(os.path.join(splitline[1],splitline[3])))]
253 splitline = line.split()
254 if foundHeaderPart1
and len(splitline) == 4
and splitline[0] ==
"from" and splitline[2] ==
"import":
255 for search_path
in search_paths:
256 if os.path.exists(os.path.join(search_path,splitline[1]+
".py")):
257 self.
_filename = os.path.join(search_path,splitline[1]+
".py")
260 foundHeaderPart2 =
True
264 """ dump python configuration """
265 logging.debug(__name__ +
": dumpPython")
272 """ configuration history """
273 logging.debug(__name__ +
": history")
280 """ Get label of an object """
282 if hasattr(object,
"label_")
and (
not hasattr(object,
"hasLabel_")
or object.hasLabel_()):
283 text = str(object.label_())
285 if hasattr(object,
"type_"):
286 text = str(object.type_())
292 """ Get children of an object """
293 if hasattr(object,
"_configChildren"):
294 return tuple(object._configChildren)
299 return isinstance(object, (ConfigFolder, list, cms.Path, cms.EndPath, cms.Sequence, cms.SequencePlaceholder))
304 for o
in self.allChildren(object):
314 """ Get motherRelations of an object """
315 if object
in self._motherRelationsDict.keys():
324 """ Get daughterRelations of an object """
325 if object
in self._daughterRelationsDict.keys():
334 """ Get type of an object """
335 return object.__class__.__name__
338 """ Get classname of an object """
340 if hasattr(object,
"type_"):
341 text = object.type_()
345 """ Get full filename """
349 if text ==
"" or text.find(
"FWCore/ParameterSet") >= 0
or text.find(
"/build/") >= 0:
350 if self.
label(object)
in file_dict:
351 text = file_dict[self.
label(object)]
354 root = os.path.splitext(text)[0]
360 """ Get linenumber """
362 if hasattr(object,
"_filename"):
363 if object._filename.find(
"FWCore/ParameterSet") < 0
and object._filename.find(
"ConfigEditor") < 0:
364 if hasattr(object,
"_lineNumber"):
365 text = str(object._lineNumber)
370 text = os.path.splitext(os.path.basename(self.
fullFilename(object)))[0]
374 match_compiled = re.match(
r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/)*\w*)\.py$',self.
fullFilename(object))
376 return match_compiled.group(1).
replace(
'/',
'.')
378 match_norm = re.match(
r'(?:^|.*?/)(\w*)/(\w*)/(?:test|python)/((?:\w*/)*)(\w*)\.py$',self.
fullFilename(object))
380 return '%s.%s.%s%s' % (match_norm.group(1),match_norm.group(2),match_norm.group(3).
replace(
'/',
'.'),match_norm.group(4))
384 match_compiled = re.match(
r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/){2})((?:\w*/)*)(\w*\.py)$',self.
fullFilename(object))
386 return '%spython/%s%s' % (match_compiled.group(1),match_compiled.group(2),match_compiled.group(3))
387 match_norm = re.match(
r'(?:^|.*?/)(\w*/\w*/(?:test|python)/(?:\w*/)*\w*\.py)$',self.
fullFilename(object))
389 return match_norm.group(1)
393 """ Get Package of an object file """
396 if len(shortdirname) > 1:
397 text = shortdirname[1]
401 """ Get parameters of an object """
403 if hasattr(object,
"parameters_"):
404 this_parameters = object.parameters_().items()
405 elif hasattr(object,
"_seq"):
406 if hasattr(object._seq,
"dumpSequencePython"):
407 this_parameters = [(
'sequence', object._seq.dumpSequencePython())]
409 this_parameters = [(
'sequence',
'WARNING: object was removed from a sequence.')]
410 if hasattr(object,
"tarlabel_"):
411 this_parameters += [(
'tarlabel', object.tarlabel_())]
412 return this_parameters
415 """ Add alls inputtags of value to a list """
416 if isinstance(value, cms.VInputTag):
417 for i
in range(len(value)):
418 if type(value[i])==str:
419 self.
_addInputTag(cms.InputTag(value[i]), this_key+
"["+str(i)+
"]", this_inputtags)
421 self.
_addInputTag(value[i], this_key+
"["+str(i)+
"]", this_inputtags)
422 elif isinstance(value, list):
425 if hasattr(value,
"parameters_"):
427 if isinstance(value, cms.InputTag):
428 pythonValue = value.value()
429 this_inputtags += [(str(this_key), value.value())]
432 """ Make list of inputtags from parameter dict """
434 for key, value
in this_parameters:
440 return this_inputtags
443 """ Make list of inputtags from parameter dict """
444 if not object
in self._inputTagsDict.keys():
452 """ Get list of all config objects that are used as input """
453 if not object
in self._usesDict.keys():
455 for key, value
in self.
inputTags(object):
456 module = str(value).
split(
":")[0]
457 product =
".".
join(str(value).
split(
":")[1:])
458 if module
not in uses:
467 """ Make list of all mother sequences """
468 if not object
in self._foundInDict.keys():
471 for daughter
in self.
children(entry):
472 if self.
label(object) == self.
label(daughter)
and len(self.
children(entry)) > 0
and not self.
label(entry)
in foundin:
473 foundin += [self.
label(entry)]
481 """ Find config objects that use this as input """
482 if not object
in self._usedByDict.keys():
485 for uses
in self.
uses(entry):
486 if self.
label(object) == uses
and not self.
label(entry)
in usedby:
487 usedby += [self.
label(entry)]
497 if name !=
"" and not isinstance(object, typ.PSet):
499 partyp=str(type(object)).
split(
"'")[1].
replace(
"FWCore.ParameterSet.Types",
"cms")
500 if isinstance(object, cms.InputTag):
501 inputtagValue=object.pythonValue()
502 for i
in range(3-len(inputtagValue.split(
","))):
503 inputtagValue+=
', ""'
504 properties += [(
"String", name,
"cms.InputTag("+inputtagValue+
")", partyp, readonly)]
505 elif isinstance(object, cms.bool):
506 properties += [(
"Boolean", name, object.value(), partyp, readonly)]
507 elif isinstance(object, (cms.int32, cms.uint32, cms.int64, cms.uint64)):
508 properties += [(
"Integer", name, object.value(), partyp, readonly)]
509 elif isinstance(object, cms.double):
510 properties += [(
"Double", name, object.value(), partyp, readonly)]
511 elif hasattr(object,
"pythonValue"):
512 properties += [(
"String", name, str(object.pythonValue()).
strip(
"\"'"), partyp, readonly)]
513 elif hasattr(object,
"value"):
514 properties += [(
"MultilineString", name, str(object.value()), partyp, readonly)]
516 properties += [(
"MultilineString", name, str(object), partyp, readonly)]
520 if isinstance(object, ConfigFolder):
524 params.sort(
lambda x, y: cmp(x[0].lower(), y[0].lower()))
525 for key, value
in params:
534 """ Make list of all properties """
537 properties += [(
"Category",
"Object info",
"")]
538 if self.
label(object) !=
"":
539 properties += [(
"String",
"label", self.
label(object),
None,
True)]
540 if self.
type(object) !=
"":
541 text = self.
type(object)
543 text +=
" <" + self.
classname(object) +
">"
544 properties += [(
"String",
"type", text,
None,
True)]
549 properties += [(
"String",
"file", text,
None,
True)]
551 properties += [(
"String",
"package", self.
package(object),
None,
True)]
553 properties += [(
"String",
"full filename", self.
fullFilename(object),
None,
True)]
557 for entry
in foundIn:
561 properties += [(
"String",
"in sequence", text,
"This module/sequence is used the listed sequences",
True)]
562 uses=self.
uses(object)
563 usedBy=self.
usedBy(object)
564 if len(uses) + len(usedBy) > 0:
565 properties += [(
"Category",
"Connections",
"")]
572 properties += [(
"MultilineString",
"uses", text,
"This module/sequence depends on the output of the listes modules/seuquences",
True)]
580 properties += [(
"MultilineString",
"used by", text,
"The listed modules/sequences depend on the output of this module/sequence",
True)]
582 properties += [(
"Category",
"Parameters",
"")]
584 return tuple(properties)
587 """ Sets a property with given name to value.
589 if hasattr(object,
"_seq")
and name==
"sequence":
590 return "Modification of sequences not supported yet."
594 if isinstance(value,str)
and\
595 not value[0]==
"[" and\
596 not value[0:4]==
"cms.":
597 exec
"object." + name +
"='''" + value +
"'''"
599 exec
"object." + name +
"=" + str(value)
601 error=
"Cannot set parameter "+name+
" (see logfile for details):\n"+str(e)
602 logging.warning(__name__ +
": setProperty: Cannot set parameter "+name+
": "+
exception_traceback())
611 for key, value
in self.
inputTags(object):
612 elements=str(value).
split(
":")
615 product = elements[1]
619 process = elements[2]
622 if not module
in allLabels:
623 if not (
"*",module,product,process)
in content:
624 content += [(
"*",module,product,process)]
625 if "*_"+module+
"_"+product+
"_"+process
in content_objects.keys():
626 content_objects[
"*_"+module+
"_"+product+
"_"+process]+=
","+self.
label(object)
628 content_objects[
"*_"+module+
"_"+product+
"_"+process]=self.
label(object)
629 return (content,content_objects)
633 if self.
type(object)
in [
"EDProducer",
"EDFilter",
"EDAnalyzer"]]
637 inputModules = [object
for object
in self.
_allObjects\
638 if self.
type(object) ==
"Source"]
639 if len(inputModules) > 0
and hasattr(inputModules[0],
"inputCommands"):
640 return inputModules[0].inputCommands
645 outputModules = [object
for object
in self.
_allObjects\
646 if self.
type(object) ==
"OutputModule"]
647 if len(outputModules) > 0
and hasattr(outputModules[0],
"outputCommands"):
648 return outputModules[0].outputCommands
def recursePSetProperties
def _readInputTagsRecursive
static std::string join(char **cmd)