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