CMS 3D CMS Logo

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