CMS 3D CMS Logo

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