CMS 3D CMS Logo

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