CMS 3D CMS Logo

ConfigDataAccessor.py
Go to the documentation of this file.
1 import sys
2 import os.path
3 import logging
4 import re
5 
6 from Vispa.Share.BasicDataAccessor import BasicDataAccessor
7 from Vispa.Share.RelativeDataAccessor import RelativeDataAccessor
8 from Vispa.Main.Exceptions import PluginIgnoredException,exception_traceback
9 
11 import FWCore.ParameterSet.Config as cms
12 import FWCore.ParameterSet.Modules as mod
13 import FWCore.ParameterSet.Types as typ
14 
15 import six
16 imported_configs = {}
17 file_dict = {}
18 
20  def __init__(self, label, parent=None, parameters=None):
21  self._label = label
22  self._configChildren = []
23  self._parameters = {}
24  if parent != None:
25  parent._configChildren += [self]
26  if parameters != None:
27  self._parameters = parameters
28  def label_(self):
29  return self._label
30  def parameters_(self):
31  return self._parameters
32  def _configChildren(self):
33  return self._configChildren
34 
36  def __init__(self):
37  logging.debug(__name__ + ": __init__")
38 
39  self._file = None
40  self._filename=""
41  self._isReplaceConfig = False
42  self._history=None
43  self._cancelOperationsFlag = False
44  self._initLists()
45 
46  def _initLists(self):
47  self._allObjects = []
49  self._connections = {}
50  self._topLevelObjects = []
51  self._inputTagsDict = {}
52  self._foundInDict = {}
53  self._usesDict = {}
54  self._usedByDict = {}
57 
58  def cancelOperations(self):
59  self._cancelOperationsFlag = True
60 
61  def isReplaceConfig(self):
62  return self._isReplaceConfig
63 
64  def setIsReplaceConfig(self):
65  self._isReplaceConfig = True
66 
67  def topLevelObjects(self):
68  return self._topLevelObjects
69 
70  def _readRecursive(self, mother, pth):
71  """ Read cms objects recursively from path """
72  entry = None
73  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 = pth
75  entry._configChildren=[]
76  self._allObjects += [pth]
77  if mother != None:
78  if not pth in mother._configChildren:
79  mother._configChildren += [pth]
80  else:
81  self._topLevelObjects += [pth]
82  next_mother = entry
83  if entry == None:
84  next_mother = mother
85  if isinstance(pth, list):
86  for i in pth:
87  self._readRecursive(next_mother, i)
88  if hasattr(sqt,"_SequenceCollection"):
89  # since CMSSW_3_11_X
90  if isinstance(pth, (sqt._ModuleSequenceType)):
91  if isinstance(pth._seq, (sqt._SequenceCollection)):
92  for o in pth._seq._collection:
93  self._readRecursive(next_mother, o)
94  else:
95  self._readRecursive(next_mother, pth._seq)
96  elif isinstance(pth, sqt._UnarySequenceOperator):
97  self._readRecursive(next_mother, pth._operand)
98  else:
99  # for backwards-compatibility with CMSSW_3_10_X
100  for i in dir(pth):
101  o = getattr(pth, i)
102  if isinstance(o, sqt._Sequenceable):
103  self._readRecursive(next_mother, o)
104 
105  def readConnections(self, objects,toNeighbors=False):
106  """ Read connection between objects """
107  connections={}
108  checkedObjects = set()
109  self._motherRelationsDict={}
110  self._daughterRelationsDict={}
111  if toNeighbors:
112  compareObjectList=[]
113  for obj in objects:
114  compareObjectList+=[(obj,o) for o in self._allObjects]
115  compareObjectList+=[(o,obj) for o in self._allObjects]
116  else:
117  compareObjectList=[(o1,o2) for o1 in objects for o2 in objects]
118  for connection in compareObjectList:
119  if self._cancelOperationsFlag:
120  break
121  try:
122  if (not connection in checkedObjects) and (connection not in self._connections):
123  checkedObjects.add(connection)
124  for key, value in self.inputTags(connection[1]):
125  s = str(value)
126  index = s.find(':')
127  if -1 != index:
128  module = s[:index]
129  else:
130  module = s
131  if module == self.label(connection[0]):
132  product = ".".join(str(value).split(":")[1:])
133  self._connections[connection]=(product, key)
134  if connection in self._connections:
135  connections[connection]=self._connections[connection]
136  if connection[1] not in self._motherRelationsDict:
137  self._motherRelationsDict[connection[1]]=[]
138  self._motherRelationsDict[connection[1]]+=[connection[0]]
139  if connection[0] not in self._daughterRelationsDict:
140  self._daughterRelationsDict[connection[0]]=[]
141  self._daughterRelationsDict[connection[0]]+=[connection[1]]
142  except TypeError:
143  return {}
144  return connections
145 
146  def connections(self):
147  return self._connections
148 
149  def _sort_list(self, l):
150  result = l[:]
151  result.sort(lambda x, y: cmp(self.label(x).lower(), self.label(y).lower()))
152  return result
153 
154  def open(self, filename=None):
155  """ Open config file and read it.
156  """
157  logging.debug(__name__ + ": open")
158  if filename != None:
159  self._filename = str(filename)
160  global imported_configs
161  self._isReplaceConfig = False
162  self._history=None
163 
164 # import input-config and make list of all imported configs
165  for i in imported_configs.iterkeys():
166  if i in sys.modules.keys():
167  del sys.modules[i]
168  sys.path.insert(0, os.path.dirname(self._filename))
169  common_imports = sys.modules.copy()
170 
171  import imp
172  theFile = open(self._filename)
173  self._file = imp.load_module(os.path.splitext(os.path.basename(self._filename))[0].replace(".", "_"), theFile, self._filename, ("py", "r", 1))
174  theFile.close()
175 
176  imported_configs = sys.modules.copy()
177  for i in common_imports.iterkeys():
178  del imported_configs[i]
179 
180 # make dictionary that connects every cms-object with the file in which it is defined
181  for j in six.itervalues(imported_configs):
182  setj = set(dir(j))
183  for entry in setj:
184  if entry[0] != "_" and entry != "cms":
185  source = 1
186  for k in six.itervalues(imported_configs):
187  if hasattr(k, entry):
188  setk = set(dir(k))
189  if len(setk) < len(setj) and setk < setj:
190  source = 0
191  if source == 1:
192  filen = self._filename
193  if hasattr(j, "__file__"):
194  filen = j.__file__
195  file_dict[entry] = filen
196 
197 # collect all path/sequences/modules of the input-config in a list
198  if self.process():
199  self.setProcess(self.process())
200  self._readHeaderInfo()
201  self._history=self.process().dumpHistory()
202  if not self._isReplaceConfig and hasattr(self.process(),"resetHistory"):
203  self.process().resetHistory()
204  else:
205  self._initLists()
206  for entry in dir(self._file):
207  o=getattr(self._file, entry)
208  if entry[0] != "_" and entry != "cms" and hasattr(o, "label_"):
209  getattr(self._file, entry).setLabel(entry)
210  text = os.path.splitext(os.path.basename(file_dict[o.label_()]))[0]
211  if text == os.path.splitext(os.path.basename(self._filename))[0] and not o in self._allObjects:
212  self._readRecursive(None, o)
213  return True
214 
215  def _scheduleRecursive(self,object):
216  if object in self._scheduledObjects:
217  return
218  if self.isContainer(object):
219  for obj in reversed(self.children(object)):
220  self._scheduleRecursive(obj)
221  else:
222  self._scheduledObjects+=[object]
223  for used in self.motherRelations(object):
224  self._scheduleRecursive(used)
225 
226  def setProcess(self,process):
227  self._file.process=process
228  self._initLists()
229  parameters = {"name": self.process().process}
230  process_folder = ConfigFolder("process", None, parameters)
231 
232  self._allObjects += [process_folder]
233  self._topLevelObjects += [process_folder]
234 
235  folder_list = []
236  folder_list += [("source", [self.process().source])]
237  if self.process().schedule != None:
238  folder_list += [("paths", self.process().schedule)]
239  else:
240  folder_list += [("paths", six.itervalues(self.process().paths))]
241  folder_list += [("endpaths", six.itervalues(self.process().endpaths))]
242  folder_list += [("modules", self._sort_list(self.process().producers.values()+self.process().filters.values()+self.process().analyzers.values()))]
243  folder_list += [("services", self._sort_list(self.process().services.values()))]
244  folder_list += [("psets", self._sort_list(self.process().psets.values()))]
245  folder_list += [("vpsets", self._sort_list(self.process().vpsets.values()))]
246  folder_list += [("essources", self._sort_list(self.process().es_sources.values()))]
247  folder_list += [("esproducers", self._sort_list(self.process().es_producers.values()))]
248  folder_list += [("esprefers", self._sort_list(self.process().es_prefers.values()))]
249  folders={}
250  for foldername, entry in folder_list:
251  folder = ConfigFolder(foldername, process_folder)
252  self._allObjects += [folder]
253  folders[foldername]=folder
254  for path in entry:
255  self._readRecursive(folder, path)
256  if True:
257  print "Creating schedule...",
258  self.readConnections(self.allChildren(folders["modules"]))
259  self._scheduleRecursive(folders["paths"])
260  self._scheduledObjects.reverse()
261  names = [l for t,l,p,pr in self.applyCommands(self.outputEventContent(),self.outputCommands())]
262  for obj in self.allChildren(folders["modules"]):
263  if str(obj) in names:
264  self._scheduledObjects+=[obj]
265  scheduled_folder = ConfigFolder("scheduled", folders["paths"])
266  self._allObjects += [scheduled_folder]
267  folders["paths"]._configChildren.remove(scheduled_folder)
268  folders["paths"]._configChildren.insert(0,scheduled_folder)
269  scheduled_folder._configChildren=self._scheduledObjects
270  print "done"
271  else:
273 
274  def process(self):
275  if hasattr(self._file, "process"):
276  return self._file.process
277  return None
278 
279  def _readHeaderInfo(self):
280  theFile = open(self._filename)
281  foundHeaderPart1 = False
282  foundHeaderPart2 = False
283  lines = 10
284  search_paths=[os.path.abspath(os.path.dirname(self._filename))]
285  while theFile and not (foundHeaderPart1 and foundHeaderPart2) and lines > 0:
286  line = theFile.readline()
287  lines -= 1
288  if "Generated by ConfigEditor" in line:
289  foundHeaderPart1 = True
290  splitline = line.split("'")
291  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":
292  search_paths+=[os.path.abspath(os.path.expandvars(os.path.join(splitline[1],splitline[3])))]
293  splitline = line.split()
294  if foundHeaderPart1 and len(splitline) == 4 and splitline[0] == "from" and splitline[2] == "import":
295  for search_path in search_paths:
296  if os.path.exists(os.path.join(search_path,splitline[1]+".py")):
297  self._filename = os.path.join(search_path,splitline[1]+".py")
298  break
299  self._isReplaceConfig = True
300  foundHeaderPart2 = True
301  theFile.close()
302 
303  def dumpPython(self):
304  """ dump python configuration """
305  logging.debug(__name__ + ": dumpPython")
306  text = None
307  if self.process():
308  text = self.process().dumpPython()
309  return text
310 
311  def history(self):
312  """ configuration history """
313  logging.debug(__name__ + ": history")
314  return self._history
315 
316  def configFile(self):
317  return self._filename
318 
319  def label(self, object):
320  """ Get label of an object """
321  text = ""
322  if hasattr(object, "label_") and (not hasattr(object,"hasLabel_") or object.hasLabel_()):
323  text = str(object.label_())
324  if text:
325  return text
326  if text == "":
327  if hasattr(object, "_name"):
328  text = str(object._name)
329  if text == "":
330  if hasattr(object, "type_"):
331  text = str(object.type_())
332  if text == "":
333  text = "NoLabel"
334  return text
335 
336  def children(self, object):
337  """ Get children of an object """
338  if hasattr(object, "_configChildren"):
339  return tuple(object._configChildren)
340  else:
341  return ()
342 
343  def isContainer(self, object):
344  return isinstance(object, (ConfigFolder, list, cms.Path, cms.EndPath, cms.Sequence)) # cms.SequencePlaceholder assumed to be a module
345 
346  def nonSequenceChildren(self, object):
347  objects=[]
348  if self.isContainer(object):
349  for o in self.allChildren(object):
350  if not self.isContainer(o) and len(self.children(o)) == 0 and not o in objects:
351  objects += [o]
352  else:
353  for o in self.motherRelations(object)+[object]+self.daughterRelations(object):
354  if not o in objects:
355  objects += [o]
356  return objects
357 
358  def motherRelations(self, object):
359  """ Get motherRelations of an object """
360  if object in self._motherRelationsDict.keys():
361  try:
362  return self._motherRelationsDict[object]
363  except TypeError:
364  return []
365  else:
366  return []
367 
368  def daughterRelations(self, object):
369  """ Get daughterRelations of an object """
370  if object in self._daughterRelationsDict.keys():
371  try:
372  return self._daughterRelationsDict[object]
373  except TypeError:
374  return []
375  else:
376  return []
377 
378  def type(self, object):
379  """ Get type of an object """
380  return object.__class__.__name__
381 
382  def classname(self, object):
383  """ Get classname of an object """
384  text = ""
385  if hasattr(object, "type_"):
386  text = object.type_()
387  return text
388 
389  def fullFilename(self, object):
390  """ Get full filename """
391  text = ""
392 # if hasattr(object,"_filename"):
393 # text=object._filename
394  if text == "" or text.find("FWCore/ParameterSet") >= 0 or text.find("/build/") >= 0:
395  if self.label(object) in file_dict:
396  text = file_dict[self.label(object)]
397  else:
398  text = self._filename
399  root = os.path.splitext(text)[0]
400  if root != "":
401  text = root + ".py"
402  return text
403 
404  def lineNumber(self, object):
405  """ Get linenumber """
406  text = ""
407  if hasattr(object, "_filename"):
408  if object._filename.find("FWCore/ParameterSet") < 0 and object._filename.find("ConfigEditor") < 0:
409  if hasattr(object, "_lineNumber"):
410  text = str(object._lineNumber)
411  return text
412 
413  def filename(self, object):
414  """ Get filename """
415  text = os.path.splitext(os.path.basename(self.fullFilename(object)))[0]
416  return text
417 
418  def pypackage(self,object):
419  match_compiled = re.match(r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/)*\w*)\.py$',self.fullFilename(object))
420  if match_compiled:
421  return match_compiled.group(1).replace('/','.')
422 
423  match_norm = re.match(r'(?:^|.*?/)(\w*)/(\w*)/(?:test|python)/((?:\w*/)*)(\w*)\.py$',self.fullFilename(object))
424  if match_norm:
425  return '%s.%s.%s%s' % (match_norm.group(1),match_norm.group(2),match_norm.group(3).replace('/','.'),match_norm.group(4))
426  return ''
427 
428  def pypath(self,object):
429  match_compiled = re.match(r'(?:^|.*?/)CMSSW[0-9_]*/python/((?:\w*/){2})((?:\w*/)*)(\w*\.py)$',self.fullFilename(object))
430  if match_compiled:
431  return '%spython/%s%s' % (match_compiled.group(1),match_compiled.group(2),match_compiled.group(3))
432  match_norm = re.match(r'(?:^|.*?/)(\w*/\w*/(?:test|python)/(?:\w*/)*\w*\.py)$',self.fullFilename(object))
433  if match_norm:
434  return match_norm.group(1)
435  return ''
436 
437  def package(self, object):
438  """ Get Package of an object file """
439  shortdirname = os.path.dirname(self.fullFilename(object)).split('python/')
440  text = ""
441  if len(shortdirname) > 1:
442  text = shortdirname[1]
443  return text
444 
445  def parameters(self, object):
446  """ Get parameters of an object """
447  this_parameters = []
448  if hasattr(object, "parameters_"):
449  this_parameters = object.parameters_().items()
450  elif hasattr(object, "_seq"):
451  if hasattr(object._seq,"dumpSequencePython"):
452  this_parameters = [('sequence', object._seq.dumpSequencePython())]
453  else:
454  this_parameters = [('sequence', 'WARNING: object was removed from a sequence.')]
455  if hasattr(object, "tarlabel_"):
456  this_parameters += [('tarlabel', object.tarlabel_())]
457  return this_parameters
458 
459  def _addInputTag(self, value, this_key, this_inputtags):
460  """ Add alls inputtags of value to a list """
461  if isinstance(value, cms.VInputTag):
462  for i in range(len(value)):
463  if isinstance(value[i], str):
464  self._addInputTag(cms.InputTag(value[i]), this_key+"["+str(i)+"]", this_inputtags)
465  else:
466  self._addInputTag(value[i], this_key+"["+str(i)+"]", this_inputtags)
467  elif isinstance(value, list):
468  for i in value:
469  self._addInputTag(i, this_key, this_inputtags)
470  if hasattr(value, "parameters_"):
471  this_inputtags += self._readInputTagsRecursive(value.parameters_().items(), this_key)
472  if isinstance(value, cms.InputTag):
473  pythonValue = value.value()
474  this_inputtags += [(str(this_key), value.value())]
475 
476  def _readInputTagsRecursive(self, this_parameters, start_key=""):
477  """ Make list of inputtags from parameter dict """
478  this_inputtags = []
479  for key, value in this_parameters:
480  this_key = start_key
481  if this_key != "":
482  this_key += "."
483  this_key += key
484  self._addInputTag(value, this_key, this_inputtags)
485  return this_inputtags
486 
487  def inputTags(self, object):
488  """ Make list of inputtags from parameter dict """
489  try:
490  v = self._inputTagsDict.get(object)
491  if v is None:
492  v = self._readInputTagsRecursive(self.parameters(object))
493  self._inputTagsDict[object]=v
494  except TypeError:
495  v = []
496  return v
497 
498  def uses(self, object):
499  """ Get list of all config objects that are used as input """
500  if not object in self._usesDict.keys():
501  uses = []
502  for key, value in self.inputTags(object):
503  module = str(value).split(":")[0]
504  product = ".".join(str(value).split(":")[1:])
505  if module not in uses:
506  uses += [module]
507  try:
508  self._usesDict[object]=uses
509  except TypeError:
510  return []
511  return self._usesDict[object]
512 
513  def foundIn(self, object):
514  """ Make list of all mother sequences """
515  if not object in self._foundInDict.keys():
516  foundin = []
517  for entry in self._allObjects:
518  for daughter in self.children(entry):
519  if self.label(object) == self.label(daughter) and len(self.children(entry)) > 0 and not self.label(entry) in foundin:
520  foundin += [self.label(entry)]
521  try:
522  self._foundInDict[object]=foundin
523  except TypeError:
524  return []
525  return self._foundInDict[object]
526 
527  def usedBy(self, object):
528  """ Find config objects that use this as input """
529  if not object in self._usedByDict.keys():
530  usedby = []
531  for entry in self._allObjects:
532  for uses in self.uses(entry):
533  if self.label(object) == uses and not self.label(entry) in usedby:
534  usedby += [self.label(entry)]
535  try:
536  self._usedByDict[object]=usedby
537  except TypeError:
538  return []
539  return self._usedByDict[object]
540 
541  def recursePSetProperties(self, name, object, readonly=None):
542  #logging.debug(__name__ + ": recursePSetProperties: " + name)
543  properties = []
544  if name != "" and not isinstance(object, typ.PSet):
545  try:
546  partyp=str(type(object)).split("'")[1].replace("FWCore.ParameterSet.Types","cms")
547  if isinstance(object, cms.InputTag):
548  inputtagValue=object.pythonValue()
549  for i in range(3-len(inputtagValue.split(","))):
550  inputtagValue+=', ""'
551  properties += [("String", name, "cms.InputTag("+inputtagValue+")", partyp, readonly)]
552  elif isinstance(object, cms.bool):
553  properties += [("Boolean", name, object.value(), partyp, readonly)]
554  elif isinstance(object, (cms.int32, cms.uint32, cms.int64, cms.uint64)):
555  properties += [("Integer", name, object.value(), partyp, readonly)]
556  elif isinstance(object, cms.double):
557  properties += [("Double", name, object.value(), partyp, readonly)]
558  elif hasattr(object, "pythonValue"):
559  properties += [("String", name, str(object.pythonValue()).strip("\"'"), partyp, readonly)]
560  elif hasattr(object, "value"):
561  properties += [("MultilineString", name, str(object.value()), partyp, readonly)]
562  else:
563  properties += [("MultilineString", name, str(object), partyp, readonly)]
564  except Exception:
565  logging.error(__name__ + ": " + exception_traceback())
566 
567  if isinstance(object, ConfigFolder):
568  readonly = True
569 
570  params = self.parameters(object)[:]
571  params.sort(lambda x, y: cmp(x[0].lower(), y[0].lower()))
572  for key, value in params:
573  keyname = name
574  if name != "":
575  keyname += "."
576  keyname += key
577  properties += self.recursePSetProperties(keyname, value, readonly)
578  return properties
579 
580  def properties(self, object):
581  """ Make list of all properties """
582  #logging.debug(__name__ + ": properties")
583  properties = []
584  properties += [("Category", "Object info", "")]
585  if self.label(object) != "":
586  properties += [("String", "label", self.label(object), None, True)]
587  if self.type(object) != "":
588  text = self.type(object)
589  if self.classname(object) != "":
590  text += " <" + self.classname(object) + ">"
591  properties += [("String", "type", text, None, True)]
592  if self.filename(object) != "":
593  text = self.filename(object)
594  if self.lineNumber(object) != "":
595  text += " : " + self.lineNumber(object)
596  properties += [("String", "file", text, None, True)]
597  if self.package(object) != "":
598  properties += [("String", "package", self.package(object), None, True)]
599  if self.fullFilename(object) != "":
600  properties += [("String", "full filename", self.fullFilename(object), None, True)]
601  foundIn=self.foundIn(object)
602  if len(foundIn) > 0:
603  text = ""
604  for entry in foundIn:
605  if text != "":
606  text += ", "
607  text += entry
608  properties += [("String", "in sequence", text, "This module/sequence is used the listed sequences", True)]
609  uses=self.uses(object)
610  usedBy=self.usedBy(object)
611  if len(uses) + len(usedBy) > 0:
612  properties += [("Category", "Connections", "")]
613  if len(uses) > 0:
614  text = ""
615  for label in uses:
616  if text != "":
617  text += ", "
618  text += label
619  properties += [("MultilineString", "uses", text, "This module/sequence depends on the output of the listes modules/seuquences", True)]
620  if len(usedBy) > 0:
621  text = ""
622  usedby = []
623  for entry in usedBy:
624  if text != "":
625  text += ", "
626  text += entry
627  properties += [("MultilineString", "used by", text, "The listed modules/sequences depend on the output of this module/sequence", True)]
628  if len(self.parameters(object)) > 0:
629  properties += [("Category", "Parameters", "")]
630  properties += self.recursePSetProperties("", object)
631  return tuple(properties)
632 
633  def setProperty(self, object, name, value, categoryName):
634  """ Sets a property with given name to value.
635  """
636  if hasattr(object, "_seq") and name=="sequence":
637  return "Modification of sequences not supported yet."
638  else:
639  process=self.process()
640  try:
641  if isinstance(value,str) and\
642  not value[0]=="[" and\
643  not value[0:4]=="cms.":
644  exec("object." + name + "='''" + value + "'''")
645  else:
646  exec("object." + name + "=" + str(value))
647  except Exception as e:
648  error="Cannot set parameter "+name+" (see logfile for details):\n"+str(e)
649  logging.warning(__name__ + ": setProperty: Cannot set parameter "+name+": "+exception_traceback())
650  return error
651  return True
652 
653  def inputEventContent(self):
654  content = []
655  allLabels = [self.label(object) for object in self._scheduledObjects]
656  content_objects = {}
657  for object in self._scheduledObjects:
658  for key, value in self.inputTags(object):
659  elements=str(value).split(":")
660  module = elements[0]
661  if len(elements)>1:
662  product = elements[1]
663  else:
664  product = ""
665  if len(elements)>2:
666  process = elements[2]
667  else:
668  process = "*"
669  if not module in allLabels:
670  if not ("*",module,product,process) in content:
671  content += [("*",module,product,process)]
672  if "*_"+module+"_"+product+"_"+process in content_objects.keys():
673  content_objects["*_"+module+"_"+product+"_"+process]+=","+self.label(object)
674  else:
675  content_objects["*_"+module+"_"+product+"_"+process]=self.label(object)
676  return (content,content_objects)
677 
679  content = [("*",self.label(object),"*",self.process().process) for object in self._allObjects\
680  if self.type(object) in ["EDProducer", "EDFilter", "EDAnalyzer"]]
681  return content
682 
683  def inputCommands(self):
684  inputModules = [object for object in self._allObjects\
685  if self.type(object) == "Source"]
686  if len(inputModules) > 0 and hasattr(inputModules[0], "inputCommands"):
687  return inputModules[0].inputCommands
688  else:
689  return []
690 
691  def outputCommands(self):
692  outputModules = [object for object in self._allObjects\
693  if self.type(object) == "OutputModule"]
694  if len(outputModules) > 0 and hasattr(outputModules[0], "outputCommands"):
695  return outputModules[0].outputCommands
696  else:
697  return []
698 
699  def applyCommands(self, content, outputCommands):
700  keep = {}
701  if len(outputCommands)>0 and outputCommands[0]!="keep *":
702  for object in content:
703  keep[object] = False
704  else:
705  for object in content:
706  keep[object] = True
707  for o in outputCommands:
708  #skip multiple spaces
709  command, filter = [ x for x in o.split(" ") if x]
710  if len(filter.split("_")) > 1:
711  module = filter.split("_")[1]
712  product = filter.split("_")[2]
713  process = filter.split("_")[3]
714  else:
715  module = filter
716  product = "*"
717  process = "*"
718  for object in content:
719  if "*" in module:
720  match = module.strip("*") in object[1]
721  else:
722  match = module == object[1]
723  if "*" in product:
724  match = match and product.strip("*") in object[2]
725  else:
726  match = match and product == object[2]
727  if "*" in process:
728  match = match and process.strip("*") in object[3]
729  else:
730  match = match and process == object[3]
731  if match:
732  keep[object] = command == "keep"
733  return [object for object in content if keep[object]]
def replace(string, replacements)
def _readInputTagsRecursive(self, this_parameters, start_key="")
def setProperty(self, object, name, value, categoryName)
def __init__(self, label, parent=None, parameters=None)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
dbl *** dir
Definition: mlp_gen.cc:35
#define str(s)
double split
Definition: MVATrainer.cc:139