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 if str(obj)
in names:
261 folders[
"paths"]._configChildren.remove(scheduled_folder)
262 folders[
"paths"]._configChildren.insert(0,scheduled_folder)
269 if hasattr(self.
_file,
"process"):
270 return self._file.process
275 foundHeaderPart1 =
False
276 foundHeaderPart2 =
False
278 search_paths=[os.path.abspath(os.path.dirname(self.
_filename))]
279 while theFile
and not (foundHeaderPart1
and foundHeaderPart2)
and lines > 0:
280 line = theFile.readline()
282 if "Generated by ConfigEditor" in line:
283 foundHeaderPart1 =
True
284 splitline = line.split(
"'")
285 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":
286 search_paths+=[os.path.abspath(os.path.expandvars(os.path.join(splitline[1],splitline[3])))]
287 splitline = line.split()
288 if foundHeaderPart1
and len(splitline) == 4
and splitline[0] ==
"from" and splitline[2] ==
"import":
289 for search_path
in search_paths:
290 if os.path.exists(os.path.join(search_path,splitline[1]+
".py")):
291 self.
_filename = os.path.join(search_path,splitline[1]+
".py")
294 foundHeaderPart2 =
True
298 """ dump python configuration """
299 logging.debug(__name__ +
": dumpPython")
306 """ configuration history """
307 logging.debug(__name__ +
": history")
314 """ Get label of an object """
316 if hasattr(object,
"label_")
and (
not hasattr(object,
"hasLabel_")
or object.hasLabel_()):
317 text = str(object.label_())
319 if hasattr(object,
"_name"):
320 text = str(object._name)
322 if hasattr(object,
"type_"):
323 text = str(object.type_())
329 """ Get children of an object """
330 if hasattr(object,
"_configChildren"):
331 return tuple(object._configChildren)
336 return isinstance(object, (ConfigFolder, list, cms.Path, cms.EndPath, cms.Sequence))
351 """ Get motherRelations of an object """
352 if object
in self._motherRelationsDict.keys():
361 """ Get daughterRelations of an object """
362 if object
in self._daughterRelationsDict.keys():
371 """ Get type of an object """
372 return object.__class__.__name__
375 """ Get classname of an object """
377 if hasattr(object,
"type_"):
378 text = object.type_()
382 """ Get full filename """
386 if text ==
"" or text.find(
"FWCore/ParameterSet") >= 0
or text.find(
"/build/") >= 0:
387 if self.
label(object)
in file_dict:
388 text = file_dict[self.
label(object)]
391 root = os.path.splitext(text)[0]
397 """ Get linenumber """
399 if hasattr(object,
"_filename"):
400 if object._filename.find(
"FWCore/ParameterSet") < 0
and object._filename.find(
"ConfigEditor") < 0:
401 if hasattr(object,
"_lineNumber"):
402 text = str(object._lineNumber)
407 text = os.path.splitext(os.path.basename(self.
fullFilename(object)))[0]
411 match_compiled = re.match(
r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/)*\w*)\.py$',self.
fullFilename(object))
413 return match_compiled.group(1).
replace(
'/',
'.')
415 match_norm = re.match(
r'(?:^|.*?/)(\w*)/(\w*)/(?:test|python)/((?:\w*/)*)(\w*)\.py$',self.
fullFilename(object))
417 return '%s.%s.%s%s' % (match_norm.group(1),match_norm.group(2),match_norm.group(3).
replace(
'/',
'.'),match_norm.group(4))
421 match_compiled = re.match(
r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/){2})((?:\w*/)*)(\w*\.py)$',self.
fullFilename(object))
423 return '%spython/%s%s' % (match_compiled.group(1),match_compiled.group(2),match_compiled.group(3))
424 match_norm = re.match(
r'(?:^|.*?/)(\w*/\w*/(?:test|python)/(?:\w*/)*\w*\.py)$',self.
fullFilename(object))
426 return match_norm.group(1)
430 """ Get Package of an object file """
433 if len(shortdirname) > 1:
434 text = shortdirname[1]
438 """ Get parameters of an object """
440 if hasattr(object,
"parameters_"):
441 this_parameters = object.parameters_().items()
442 elif hasattr(object,
"_seq"):
443 if hasattr(object._seq,
"dumpSequencePython"):
444 this_parameters = [(
'sequence', object._seq.dumpSequencePython())]
446 this_parameters = [(
'sequence',
'WARNING: object was removed from a sequence.')]
447 if hasattr(object,
"tarlabel_"):
448 this_parameters += [(
'tarlabel', object.tarlabel_())]
449 return this_parameters
452 """ Add alls inputtags of value to a list """
453 if isinstance(value, cms.VInputTag):
454 for i
in range(len(value)):
455 if type(value[i])==str:
456 self.
_addInputTag(cms.InputTag(value[i]), this_key+
"["+str(i)+
"]", this_inputtags)
458 self.
_addInputTag(value[i], this_key+
"["+str(i)+
"]", this_inputtags)
459 elif isinstance(value, list):
462 if hasattr(value,
"parameters_"):
464 if isinstance(value, cms.InputTag):
465 pythonValue = value.value()
466 this_inputtags += [(str(this_key), value.value())]
469 """ Make list of inputtags from parameter dict """
471 for key, value
in this_parameters:
477 return this_inputtags
480 """ Make list of inputtags from parameter dict """
481 if not object
in self._inputTagsDict.keys():
489 """ Get list of all config objects that are used as input """
490 if not object
in self._usesDict.keys():
492 for key, value
in self.
inputTags(object):
493 module = str(value).
split(
":")[0]
494 product =
".".
join(str(value).
split(
":")[1:])
495 if module
not in uses:
504 """ Make list of all mother sequences """
505 if not object
in self._foundInDict.keys():
508 for daughter
in self.
children(entry):
509 if self.
label(object) == self.
label(daughter)
and len(self.
children(entry)) > 0
and not self.
label(entry)
in foundin:
510 foundin += [self.
label(entry)]
518 """ Find config objects that use this as input """
519 if not object
in self._usedByDict.keys():
522 for uses
in self.
uses(entry):
523 if self.
label(object) == uses
and not self.
label(entry)
in usedby:
524 usedby += [self.
label(entry)]
534 if name !=
"" and not isinstance(object, typ.PSet):
536 partyp=str(type(object)).
split(
"'")[1].
replace(
"FWCore.ParameterSet.Types",
"cms")
537 if isinstance(object, cms.InputTag):
538 inputtagValue=object.pythonValue()
539 for i
in range(3-len(inputtagValue.split(
","))):
540 inputtagValue+=
', ""'
541 properties += [(
"String", name,
"cms.InputTag("+inputtagValue+
")", partyp, readonly)]
542 elif isinstance(object, cms.bool):
543 properties += [(
"Boolean", name, object.value(), partyp, readonly)]
544 elif isinstance(object, (cms.int32, cms.uint32, cms.int64, cms.uint64)):
545 properties += [(
"Integer", name, object.value(), partyp, readonly)]
546 elif isinstance(object, cms.double):
547 properties += [(
"Double", name, object.value(), partyp, readonly)]
548 elif hasattr(object,
"pythonValue"):
549 properties += [(
"String", name, str(object.pythonValue()).strip(
"\"'"), partyp, readonly)]
550 elif hasattr(object,
"value"):
551 properties += [(
"MultilineString", name, str(object.value()), partyp, readonly)]
553 properties += [(
"MultilineString", name, str(object), partyp, readonly)]
557 if isinstance(object, ConfigFolder):
561 params.sort(
lambda x, y: cmp(x[0].lower(), y[0].lower()))
562 for key, value
in params:
571 """ Make list of all properties """
574 properties += [(
"Category",
"Object info",
"")]
575 if self.
label(object) !=
"":
576 properties += [(
"String",
"label", self.
label(object),
None,
True)]
577 if self.
type(object) !=
"":
578 text = self.
type(object)
580 text +=
" <" + self.
classname(object) +
">"
581 properties += [(
"String",
"type", text,
None,
True)]
586 properties += [(
"String",
"file", text,
None,
True)]
588 properties += [(
"String",
"package", self.
package(object),
None,
True)]
590 properties += [(
"String",
"full filename", self.
fullFilename(object),
None,
True)]
594 for entry
in foundIn:
598 properties += [(
"String",
"in sequence", text,
"This module/sequence is used the listed sequences",
True)]
599 uses=self.
uses(object)
600 usedBy=self.
usedBy(object)
601 if len(uses) + len(usedBy) > 0:
602 properties += [(
"Category",
"Connections",
"")]
609 properties += [(
"MultilineString",
"uses", text,
"This module/sequence depends on the output of the listes modules/seuquences",
True)]
617 properties += [(
"MultilineString",
"used by", text,
"The listed modules/sequences depend on the output of this module/sequence",
True)]
619 properties += [(
"Category",
"Parameters",
"")]
621 return tuple(properties)
624 """ Sets a property with given name to value.
626 if hasattr(object,
"_seq")
and name==
"sequence":
627 return "Modification of sequences not supported yet."
631 if isinstance(value,str)
and\
632 not value[0]==
"[" and\
633 not value[0:4]==
"cms.":
634 exec
"object." + name +
"='''" + value +
"'''"
636 exec
"object." + name +
"=" + str(value)
638 error=
"Cannot set parameter "+name+
" (see logfile for details):\n"+str(e)
639 logging.warning(__name__ +
": setProperty: Cannot set parameter "+name+
": "+
exception_traceback())
648 for key, value
in self.
inputTags(object):
649 elements=str(value).
split(
":")
652 product = elements[1]
656 process = elements[2]
659 if not module
in allLabels:
660 if not (
"*",module,product,process)
in content:
661 content += [(
"*",module,product,process)]
662 if "*_"+module+
"_"+product+
"_"+process
in content_objects.keys():
663 content_objects[
"*_"+module+
"_"+product+
"_"+process]+=
","+self.
label(object)
665 content_objects[
"*_"+module+
"_"+product+
"_"+process]=self.
label(object)
666 return (content,content_objects)
670 if self.
type(object)
in [
"EDProducer",
"EDFilter",
"EDAnalyzer"]]
674 inputModules = [object
for object
in self.
_allObjects\
675 if self.
type(object) ==
"Source"]
676 if len(inputModules) > 0
and hasattr(inputModules[0],
"inputCommands"):
677 return inputModules[0].inputCommands
682 outputModules = [object
for object
in self.
_allObjects\
683 if self.
type(object) ==
"OutputModule"]
684 if len(outputModules) > 0
and hasattr(outputModules[0],
"outputCommands"):
685 return outputModules[0].outputCommands
691 if len(outputCommands)>0
and outputCommands[0]!=
"keep *":
692 for object
in content:
695 for object
in content:
697 for o
in outputCommands:
698 command, filter = o.split(
" ")
699 if len(filter.split(
"_")) > 1:
700 module = filter.split(
"_")[1]
701 product = filter.split(
"_")[2]
702 process = filter.split(
"_")[3]
707 for object
in content:
709 match = module.strip(
"*")
in object[1]
711 match = module == object[1]
713 match = match
and product.strip(
"*")
in object[2]
715 match = match
and product == object[2]
717 match = match
and process.strip(
"*")
in object[3]
719 match = match
and process == object[3]
721 keep[object] = command ==
"keep"
722 return [object
for object
in content
if keep[object]]
def recursePSetProperties
static std::string join(char **cmd)
def _readInputTagsRecursive