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__")
70 """ Read cms objects recursively from path """
72 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)):
74 entry._configChildren=[]
77 if not pth
in mother._configChildren:
78 mother._configChildren += [pth]
84 if isinstance(pth, list):
87 if hasattr(sqt,
"_SequenceCollection"):
89 if isinstance(pth, (sqt._ModuleSequenceType)):
90 if isinstance(pth._seq, (sqt._SequenceCollection)):
91 for o
in pth._seq._collection:
95 elif isinstance(pth, sqt._UnarySequenceOperator):
101 if isinstance(o, sqt._Sequenceable):
105 """ Read connection between objects """
112 compareObjectList+=[(obj,o)
for o
in self.
_allObjects]
113 compareObjectList+=[(o,obj)
for o
in self.
_allObjects]
115 compareObjectList=[(o1,o2)
for o1
in objects
for o2
in objects]
116 for connection
in compareObjectList:
119 if not connection
in self._connections.keys():
120 for key, value
in self.
inputTags(connection[1]):
121 module = str(value).
split(
":")[0]
122 if module == self.
label(connection[0]):
123 product =
".".
join(str(value).
split(
":")[1:])
128 if connection
in self._connections.keys():
130 if not connection[1]
in self._motherRelationsDict.keys():
133 if not connection[0]
in self._daughterRelationsDict.keys():
143 result.sort(
lambda x, y: cmp(self.
label(x).lower(), self.
label(y).lower()))
147 """ Open config file and read it.
149 logging.debug(__name__ +
": open")
152 global imported_configs
157 for i
in imported_configs.iterkeys():
158 if i
in sys.modules.keys():
160 sys.path.insert(0, os.path.dirname(self.
_filename))
161 common_imports = sys.modules.copy()
168 imported_configs = sys.modules.copy()
169 for i
in common_imports.iterkeys():
170 del imported_configs[i]
173 for j
in imported_configs.itervalues():
176 if entry[0] !=
"_" and entry !=
"cms":
178 for k
in imported_configs.itervalues():
179 if hasattr(k, entry):
181 if len(setk) < len(setj)
and setk < setj:
185 if hasattr(j,
"__file__"):
187 file_dict[entry] = filen
199 o=getattr(self.
_file, entry)
200 if entry[0] !=
"_" and entry !=
"cms" and hasattr(o,
"label_"):
201 getattr(self.
_file, entry).setLabel(entry)
202 text = os.path.splitext(os.path.basename(file_dict[o.label_()]))[0]
211 for obj
in reversed(self.
children(object)):
219 self._file.process=process
221 parameters = {
"name": self.
process().process}
222 process_folder =
ConfigFolder(
"process",
None, parameters)
228 folder_list += [(
"source", [self.
process().source])]
229 if self.
process().schedule !=
None:
230 folder_list += [(
"paths", self.
process().schedule)]
232 folder_list += [(
"paths", self.
process().paths.itervalues())]
233 folder_list += [(
"endpaths", self.
process().endpaths.itervalues())]
234 if hasattr(self.
process(),
"options")
and hasattr(self.
process().options,
"allowUnscheduled")
and self.
process().options.allowUnscheduled:
235 print "Running in Unscheduled mode"
240 folder_list += [(
"essources", self.
_sort_list(self.
process().es_sources.values()))]
241 folder_list += [(
"esproducers", self.
_sort_list(self.
process().es_producers.values()))]
242 folder_list += [(
"esprefers", self.
_sort_list(self.
process().es_prefers.values()))]
244 for foldername, entry
in folder_list:
247 folders[foldername]=folder
250 if hasattr(self.
process(),
"options")
and hasattr(self.
process().options,
"allowUnscheduled")
and self.
process().options.allowUnscheduled:
251 print "Creating schedule...",
254 self._scheduledObjects.reverse()
257 folders[
"paths"]._configChildren.remove(scheduled_folder)
258 folders[
"paths"]._configChildren.insert(0,scheduled_folder)
265 if hasattr(self.
_file,
"process"):
266 return self._file.process
271 foundHeaderPart1 =
False
272 foundHeaderPart2 =
False
274 search_paths=[os.path.abspath(os.path.dirname(self.
_filename))]
275 while theFile
and not (foundHeaderPart1
and foundHeaderPart2)
and lines > 0:
276 line = theFile.readline()
278 if "Generated by ConfigEditor" in line:
279 foundHeaderPart1 =
True
280 splitline = line.split(
"'")
281 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":
282 search_paths+=[os.path.abspath(os.path.expandvars(os.path.join(splitline[1],splitline[3])))]
283 splitline = line.split()
284 if foundHeaderPart1
and len(splitline) == 4
and splitline[0] ==
"from" and splitline[2] ==
"import":
285 for search_path
in search_paths:
286 if os.path.exists(os.path.join(search_path,splitline[1]+
".py")):
287 self.
_filename = os.path.join(search_path,splitline[1]+
".py")
290 foundHeaderPart2 =
True
294 """ dump python configuration """
295 logging.debug(__name__ +
": dumpPython")
302 """ configuration history """
303 logging.debug(__name__ +
": history")
310 """ Get label of an object """
312 if hasattr(object,
"label_")
and (
not hasattr(object,
"hasLabel_")
or object.hasLabel_()):
313 text = str(object.label_())
315 if hasattr(object,
"_name"):
316 text = str(object._name)
318 if hasattr(object,
"type_"):
319 text = str(object.type_())
325 """ Get children of an object """
326 if hasattr(object,
"_configChildren"):
327 return tuple(object._configChildren)
332 return isinstance(object, (ConfigFolder, list, cms.Path, cms.EndPath, cms.Sequence))
347 """ Get motherRelations of an object """
348 if object
in self._motherRelationsDict.keys():
357 """ Get daughterRelations of an object """
358 if object
in self._daughterRelationsDict.keys():
367 """ Get type of an object """
368 return object.__class__.__name__
371 """ Get classname of an object """
373 if hasattr(object,
"type_"):
374 text = object.type_()
378 """ Get full filename """
382 if text ==
"" or text.find(
"FWCore/ParameterSet") >= 0
or text.find(
"/build/") >= 0:
383 if self.
label(object)
in file_dict:
384 text = file_dict[self.
label(object)]
387 root = os.path.splitext(text)[0]
393 """ Get linenumber """
395 if hasattr(object,
"_filename"):
396 if object._filename.find(
"FWCore/ParameterSet") < 0
and object._filename.find(
"ConfigEditor") < 0:
397 if hasattr(object,
"_lineNumber"):
398 text = str(object._lineNumber)
403 text = os.path.splitext(os.path.basename(self.
fullFilename(object)))[0]
407 match_compiled = re.match(
r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/)*\w*)\.py$',self.
fullFilename(object))
409 return match_compiled.group(1).
replace(
'/',
'.')
411 match_norm = re.match(
r'(?:^|.*?/)(\w*)/(\w*)/(?:test|python)/((?:\w*/)*)(\w*)\.py$',self.
fullFilename(object))
413 return '%s.%s.%s%s' % (match_norm.group(1),match_norm.group(2),match_norm.group(3).
replace(
'/',
'.'),match_norm.group(4))
417 match_compiled = re.match(
r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/){2})((?:\w*/)*)(\w*\.py)$',self.
fullFilename(object))
419 return '%spython/%s%s' % (match_compiled.group(1),match_compiled.group(2),match_compiled.group(3))
420 match_norm = re.match(
r'(?:^|.*?/)(\w*/\w*/(?:test|python)/(?:\w*/)*\w*\.py)$',self.
fullFilename(object))
422 return match_norm.group(1)
426 """ Get Package of an object file """
429 if len(shortdirname) > 1:
430 text = shortdirname[1]
434 """ Get parameters of an object """
436 if hasattr(object,
"parameters_"):
437 this_parameters = object.parameters_().items()
438 elif hasattr(object,
"_seq"):
439 if hasattr(object._seq,
"dumpSequencePython"):
440 this_parameters = [(
'sequence', object._seq.dumpSequencePython())]
442 this_parameters = [(
'sequence',
'WARNING: object was removed from a sequence.')]
443 if hasattr(object,
"tarlabel_"):
444 this_parameters += [(
'tarlabel', object.tarlabel_())]
445 return this_parameters
448 """ Add alls inputtags of value to a list """
449 if isinstance(value, cms.VInputTag):
450 for i
in range(len(value)):
451 if type(value[i])==str:
452 self.
_addInputTag(cms.InputTag(value[i]), this_key+
"["+str(i)+
"]", this_inputtags)
454 self.
_addInputTag(value[i], this_key+
"["+str(i)+
"]", this_inputtags)
455 elif isinstance(value, list):
458 if hasattr(value,
"parameters_"):
460 if isinstance(value, cms.InputTag):
461 pythonValue = value.value()
462 this_inputtags += [(str(this_key), value.value())]
465 """ Make list of inputtags from parameter dict """
467 for key, value
in this_parameters:
473 return this_inputtags
476 """ Make list of inputtags from parameter dict """
477 if not object
in self._inputTagsDict.keys():
485 """ Get list of all config objects that are used as input """
486 if not object
in self._usesDict.keys():
488 for key, value
in self.
inputTags(object):
489 module = str(value).
split(
":")[0]
490 product =
".".
join(str(value).
split(
":")[1:])
491 if module
not in uses:
500 """ Make list of all mother sequences """
501 if not object
in self._foundInDict.keys():
504 for daughter
in self.
children(entry):
505 if self.
label(object) == self.
label(daughter)
and len(self.
children(entry)) > 0
and not self.
label(entry)
in foundin:
506 foundin += [self.
label(entry)]
514 """ Find config objects that use this as input """
515 if not object
in self._usedByDict.keys():
518 for uses
in self.
uses(entry):
519 if self.
label(object) == uses
and not self.
label(entry)
in usedby:
520 usedby += [self.
label(entry)]
530 if name !=
"" and not isinstance(object, typ.PSet):
532 partyp=str(type(object)).
split(
"'")[1].
replace(
"FWCore.ParameterSet.Types",
"cms")
533 if isinstance(object, cms.InputTag):
534 inputtagValue=object.pythonValue()
535 for i
in range(3-len(inputtagValue.split(
","))):
536 inputtagValue+=
', ""'
537 properties += [(
"String", name,
"cms.InputTag("+inputtagValue+
")", partyp, readonly)]
538 elif isinstance(object, cms.bool):
539 properties += [(
"Boolean", name, object.value(), partyp, readonly)]
540 elif isinstance(object, (cms.int32, cms.uint32, cms.int64, cms.uint64)):
541 properties += [(
"Integer", name, object.value(), partyp, readonly)]
542 elif isinstance(object, cms.double):
543 properties += [(
"Double", name, object.value(), partyp, readonly)]
544 elif hasattr(object,
"pythonValue"):
545 properties += [(
"String", name, str(object.pythonValue()).strip(
"\"'"), partyp, readonly)]
546 elif hasattr(object,
"value"):
547 properties += [(
"MultilineString", name, str(object.value()), partyp, readonly)]
549 properties += [(
"MultilineString", name, str(object), partyp, readonly)]
553 if isinstance(object, ConfigFolder):
557 params.sort(
lambda x, y: cmp(x[0].lower(), y[0].lower()))
558 for key, value
in params:
567 """ Make list of all properties """
570 properties += [(
"Category",
"Object info",
"")]
571 if self.
label(object) !=
"":
572 properties += [(
"String",
"label", self.
label(object),
None,
True)]
573 if self.
type(object) !=
"":
574 text = self.
type(object)
576 text +=
" <" + self.
classname(object) +
">"
577 properties += [(
"String",
"type", text,
None,
True)]
582 properties += [(
"String",
"file", text,
None,
True)]
584 properties += [(
"String",
"package", self.
package(object),
None,
True)]
586 properties += [(
"String",
"full filename", self.
fullFilename(object),
None,
True)]
590 for entry
in foundIn:
594 properties += [(
"String",
"in sequence", text,
"This module/sequence is used the listed sequences",
True)]
595 uses=self.
uses(object)
596 usedBy=self.
usedBy(object)
597 if len(uses) + len(usedBy) > 0:
598 properties += [(
"Category",
"Connections",
"")]
605 properties += [(
"MultilineString",
"uses", text,
"This module/sequence depends on the output of the listes modules/seuquences",
True)]
613 properties += [(
"MultilineString",
"used by", text,
"The listed modules/sequences depend on the output of this module/sequence",
True)]
615 properties += [(
"Category",
"Parameters",
"")]
617 return tuple(properties)
620 """ Sets a property with given name to value.
622 if hasattr(object,
"_seq")
and name==
"sequence":
623 return "Modification of sequences not supported yet."
627 if isinstance(value,str)
and\
628 not value[0]==
"[" and\
629 not value[0:4]==
"cms.":
630 exec
"object." + name +
"='''" + value +
"'''"
632 exec
"object." + name +
"=" + str(value)
634 error=
"Cannot set parameter "+name+
" (see logfile for details):\n"+str(e)
635 logging.warning(__name__ +
": setProperty: Cannot set parameter "+name+
": "+
exception_traceback())
644 for key, value
in self.
inputTags(object):
645 elements=str(value).
split(
":")
648 product = elements[1]
652 process = elements[2]
655 if not module
in allLabels:
656 if not (
"*",module,product,process)
in content:
657 content += [(
"*",module,product,process)]
658 if "*_"+module+
"_"+product+
"_"+process
in content_objects.keys():
659 content_objects[
"*_"+module+
"_"+product+
"_"+process]+=
","+self.
label(object)
661 content_objects[
"*_"+module+
"_"+product+
"_"+process]=self.
label(object)
662 return (content,content_objects)
666 if self.
type(object)
in [
"EDProducer",
"EDFilter",
"EDAnalyzer"]]
670 inputModules = [object
for object
in self.
_allObjects\
671 if self.
type(object) ==
"Source"]
672 if len(inputModules) > 0
and hasattr(inputModules[0],
"inputCommands"):
673 return inputModules[0].inputCommands
678 outputModules = [object
for object
in self.
_allObjects\
679 if self.
type(object) ==
"OutputModule"]
680 if len(outputModules) > 0
and hasattr(outputModules[0],
"outputCommands"):
681 return outputModules[0].outputCommands
def recursePSetProperties
static std::string join(char **cmd)
def _readInputTagsRecursive