CMS 3D CMS Logo

Config.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ### command line options helper
4 from Options import Options
5 options = Options()
6 
7 
8 ## imports
9 import sys
10 from Mixins import PrintOptions,_ParameterTypeBase,_SimpleParameterTypeBase, _Parameterizable, _ConfigureComponent, _TypedParameterizable, _Labelable, _Unlabelable, _ValidatingListBase, _modifyParametersFromDict
11 from Mixins import *
12 from Types import *
13 from Modules import *
14 from Modules import _Module
15 from SequenceTypes import *
16 from SequenceTypes import _ModuleSequenceType, _Sequenceable #extend needs it
17 from SequenceVisitors import PathValidator, EndPathValidator, ScheduleTaskValidator, NodeVisitor, CompositeVisitor, ModuleNamesFromGlobalsVisitor
18 import DictTypes
19 
20 from ExceptionHandling import *
21 
22 #when building RECO paths we have hit the default recursion limit
23 if sys.getrecursionlimit()<5000:
24  sys.setrecursionlimit(5000)
25 
26 def checkImportPermission(minLevel = 2, allowedPatterns = []):
27  """
28  Raise an exception if called by special config files. This checks
29  the call or import stack for the importing file. An exception is raised if
30  the importing module is not in allowedPatterns and if it is called too deeply:
31  minLevel = 2: inclusion by top lvel cfg only
32  minLevel = 1: No inclusion allowed
33  allowedPatterns = ['Module1','Module2/SubModule1'] allows import
34  by any module in Module1 or Submodule1
35  """
36 
37  import inspect
38  import os
39 
40  ignorePatterns = ['FWCore/ParameterSet/Config.py','<string>']
41  CMSSWPath = [os.environ['CMSSW_BASE'],os.environ['CMSSW_RELEASE_BASE']]
42 
43  # Filter the stack to things in CMSSWPath and not in ignorePatterns
44  trueStack = []
45  for item in inspect.stack():
46  inPath = False
47  ignore = False
48 
49  for pattern in CMSSWPath:
50  if item[1].find(pattern) != -1:
51  inPath = True
52  break
53  if item[1].find('/') == -1: # The base file, no path
54  inPath = True
55 
56  for pattern in ignorePatterns:
57  if item[1].find(pattern) != -1:
58  ignore = True
59  break
60 
61  if inPath and not ignore:
62  trueStack.append(item[1])
63 
64  importedFile = trueStack[0]
65  importedBy = ''
66  if len(trueStack) > 1:
67  importedBy = trueStack[1]
68 
69  for pattern in allowedPatterns:
70  if importedBy.find(pattern) > -1:
71  return True
72 
73  if len(trueStack) <= minLevel: # Imported directly
74  return True
75 
76  raise ImportError("Inclusion of %s is allowed only by cfg or specified cfi files."
77  % importedFile)
78 
79 def findProcess(module):
80  """Look inside the module and find the Processes it contains"""
81  class Temp(object):
82  pass
83  process = None
84  if isinstance(module,dict):
85  if 'process' in module:
86  p = module['process']
87  module = Temp()
88  module.process = p
89  if hasattr(module,'process'):
90  if isinstance(module.process,Process):
91  process = module.process
92  else:
93  raise RuntimeError("The attribute named 'process' does not inherit from the Process class")
94  else:
95  raise RuntimeError("no 'process' attribute found in the module, please add one")
96  return process
97 
98 class Process(object):
99  """Root class for a CMS configuration process"""
100  def __init__(self,name,*Mods):
101  """The argument 'name' will be the name applied to this Process
102  Can optionally pass as additional arguments cms.Modifier instances
103  that will be used to modify the Process as it is built
104  """
105  self.__dict__['_Process__name'] = name
106  if not name.isalnum():
107  raise RuntimeError("Error: The process name is an empty string or contains non-alphanumeric characters")
108  self.__dict__['_Process__filters'] = {}
109  self.__dict__['_Process__producers'] = {}
110  self.__dict__['_Process__source'] = None
111  self.__dict__['_Process__looper'] = None
112  self.__dict__['_Process__subProcesses'] = []
113  self.__dict__['_Process__schedule'] = None
114  self.__dict__['_Process__analyzers'] = {}
115  self.__dict__['_Process__outputmodules'] = {}
116  self.__dict__['_Process__paths'] = DictTypes.SortedKeysDict() # have to keep the order
117  self.__dict__['_Process__endpaths'] = DictTypes.SortedKeysDict() # of definition
118  self.__dict__['_Process__sequences'] = {}
119  self.__dict__['_Process__tasks'] = {}
120  self.__dict__['_Process__services'] = {}
121  self.__dict__['_Process__essources'] = {}
122  self.__dict__['_Process__esproducers'] = {}
123  self.__dict__['_Process__esprefers'] = {}
124  self.__dict__['_Process__aliases'] = {}
125  self.__dict__['_Process__psets']={}
126  self.__dict__['_Process__vpsets']={}
127  self.__dict__['_cloneToObjectDict'] = {}
128  # policy switch to avoid object overwriting during extend/load
129  self.__dict__['_Process__InExtendCall'] = False
130  self.__dict__['_Process__partialschedules'] = {}
131  self.__isStrict = False
132  self.__dict__['_Process__modifiers'] = Mods
133  for m in self.__modifiers:
134  m._setChosen()
135 
136  def setStrict(self, value):
137  self.__isStrict = value
138  _Module.__isStrict__ = True
139 
140  # some user-friendly methods for command-line browsing
141  def producerNames(self):
142  """Returns a string containing all the EDProducer labels separated by a blank"""
143  return ' '.join(self.producers_().keys())
144  def analyzerNames(self):
145  """Returns a string containing all the EDAnalyzer labels separated by a blank"""
146  return ' '.join(self.analyzers_().keys())
147  def filterNames(self):
148  """Returns a string containing all the EDFilter labels separated by a blank"""
149  return ' '.join(self.filters_().keys())
150  def pathNames(self):
151  """Returns a string containing all the Path names separated by a blank"""
152  return ' '.join(self.paths_().keys())
153 
154  def __setstate__(self, pkldict):
155  """
156  Unpickling hook.
157 
158  Since cloneToObjectDict stores a hash of objects by their
159  id() it needs to be updated when unpickling to use the
160  new object id values instantiated during the unpickle.
161 
162  """
163  self.__dict__.update(pkldict)
164  tmpDict = {}
165  for value in self._cloneToObjectDict.values():
166  tmpDict[id(value)] = value
167  self.__dict__['_cloneToObjectDict'] = tmpDict
168 
169 
170 
171  def filters_(self):
172  """returns a dict of the filters that have been added to the Process"""
173  return DictTypes.FixedKeysDict(self.__filters)
174  filters = property(filters_, doc="dictionary containing the filters for the process")
175  def name_(self):
176  return self.__name
177  def setName_(self,name):
178  if not name.isalnum():
179  raise RuntimeError("Error: The process name is an empty string or contains non-alphanumeric characters")
180  self.__dict__['_Process__name'] = name
181  process = property(name_,setName_, doc="name of the process")
182  def producers_(self):
183  """returns a dict of the producers that have been added to the Process"""
184  return DictTypes.FixedKeysDict(self.__producers)
185  producers = property(producers_,doc="dictionary containing the producers for the process")
186  def source_(self):
187  """returns the source that has been added to the Process or None if none have been added"""
188  return self.__source
189  def setSource_(self,src):
190  self._placeSource('source',src)
191  source = property(source_,setSource_,doc='the main source or None if not set')
192  def looper_(self):
193  """returns the looper that has been added to the Process or None if none have been added"""
194  return self.__looper
195  def setLooper_(self,lpr):
196  self._placeLooper('looper',lpr)
197  looper = property(looper_,setLooper_,doc='the main looper or None if not set')
198  def subProcesses_(self):
199  """returns a list of the subProcesses that have been added to the Process"""
200  return self.__subProcesses
201  subProcesses = property(subProcesses_,doc='the SubProcesses that have been added to the Process')
202  def analyzers_(self):
203  """returns a dict of the analyzers that have been added to the Process"""
204  return DictTypes.FixedKeysDict(self.__analyzers)
205  analyzers = property(analyzers_,doc="dictionary containing the analyzers for the process")
206  def outputModules_(self):
207  """returns a dict of the output modules that have been added to the Process"""
208  return DictTypes.FixedKeysDict(self.__outputmodules)
209  outputModules = property(outputModules_,doc="dictionary containing the output_modules for the process")
210  def paths_(self):
211  """returns a dict of the paths that have been added to the Process"""
212  return DictTypes.SortedAndFixedKeysDict(self.__paths)
213  paths = property(paths_,doc="dictionary containing the paths for the process")
214  def endpaths_(self):
215  """returns a dict of the endpaths that have been added to the Process"""
216  return DictTypes.SortedAndFixedKeysDict(self.__endpaths)
217  endpaths = property(endpaths_,doc="dictionary containing the endpaths for the process")
218  def sequences_(self):
219  """returns a dict of the sequences that have been added to the Process"""
220  return DictTypes.FixedKeysDict(self.__sequences)
221  sequences = property(sequences_,doc="dictionary containing the sequences for the process")
222  def tasks_(self):
223  """returns a dict of the tasks that have been added to the Process"""
224  return DictTypes.FixedKeysDict(self.__tasks)
225  tasks = property(tasks_,doc="dictionary containing the tasks for the process")
226  def schedule_(self):
227  """returns the schedule that has been added to the Process or None if none have been added"""
228  return self.__schedule
229  def setPartialSchedule_(self,sch,label):
230  if label == "schedule":
231  self.setSchedule_(sch)
232  else:
233  self._place(label, sch, self.__partialschedules)
234  def setSchedule_(self,sch):
235  # See if every path and endpath has been inserted into the process
236  index = 0
237  try:
238  for p in sch:
239  p.label_()
240  index +=1
241  except:
242  raise RuntimeError("The path at index "+str(index)+" in the Schedule was not attached to the process.")
243  self.__dict__['_Process__schedule'] = sch
244  schedule = property(schedule_,setSchedule_,doc='the schedule or None if not set')
245  def services_(self):
246  """returns a dict of the services that have been added to the Process"""
247  return DictTypes.FixedKeysDict(self.__services)
248  services = property(services_,doc="dictionary containing the services for the process")
249  def es_producers_(self):
250  """returns a dict of the esproducers that have been added to the Process"""
251  return DictTypes.FixedKeysDict(self.__esproducers)
252  es_producers = property(es_producers_,doc="dictionary containing the es_producers for the process")
253  def es_sources_(self):
254  """returns a the es_sources that have been added to the Process"""
255  return DictTypes.FixedKeysDict(self.__essources)
256  es_sources = property(es_sources_,doc="dictionary containing the es_sources for the process")
257  def es_prefers_(self):
258  """returns a dict of the es_prefers that have been added to the Process"""
259  return DictTypes.FixedKeysDict(self.__esprefers)
260  es_prefers = property(es_prefers_,doc="dictionary containing the es_prefers for the process")
261  def aliases_(self):
262  """returns a dict of the aliases that have been added to the Process"""
263  return DictTypes.FixedKeysDict(self.__aliases)
264  aliases = property(aliases_,doc="dictionary containing the aliases for the process")
265  def psets_(self):
266  """returns a dict of the PSets that have been added to the Process"""
267  return DictTypes.FixedKeysDict(self.__psets)
268  psets = property(psets_,doc="dictionary containing the PSets for the process")
269  def vpsets_(self):
270  """returns a dict of the VPSets that have been added to the Process"""
271  return DictTypes.FixedKeysDict(self.__vpsets)
272  vpsets = property(vpsets_,doc="dictionary containing the PSets for the process")
273 
274  def isUsingModifier(self,mod):
275  """returns True if the Modifier is in used by this Process"""
276  if mod.isChosen():
277  for m in self.__modifiers:
278  if m._isOrContains(mod):
279  return True
280  return False
281 
282  def __setObjectLabel(self, object, newLabel) :
283  if not object.hasLabel_() :
284  object.setLabel(newLabel)
285  return
286  if newLabel == object.label_() :
287  return
288  if newLabel is None :
289  object.setLabel(None)
290  return
291  if (hasattr(self, object.label_()) and id(getattr(self, object.label_())) == id(object)) :
292  msg100 = "Attempting to change the label of an attribute of the Process\n"
293  msg101 = "Old label = "+object.label_()+" New label = "+newLabel+"\n"
294  msg102 = "Type = "+str(type(object))+"\n"
295  msg103 = "Some possible solutions:\n"
296  msg104 = " 1. Clone modules instead of using simple assignment. Cloning is\n"
297  msg105 = " also preferred for other types when possible.\n"
298  msg106 = " 2. Declare new names starting with an underscore if they are\n"
299  msg107 = " for temporaries you do not want propagated into the Process. The\n"
300  msg108 = " underscore tells \"from x import *\" and process.load not to import\n"
301  msg109 = " the name.\n"
302  msg110 = " 3. Reorganize so the assigment is not necessary. Giving a second\n"
303  msg111 = " name to the same object usually causes confusion and problems.\n"
304  msg112 = " 4. Compose Sequences: newName = cms.Sequence(oldName)\n"
305  raise ValueError(msg100+msg101+msg102+msg103+msg104+msg105+msg106+msg107+msg108+msg109+msg110+msg111+msg112)
306  object.setLabel(None)
307  object.setLabel(newLabel)
308 
309  def __setattr__(self,name,value):
310  # check if the name is well-formed (only _ and alphanumerics are allowed)
311  if not name.replace('_','').isalnum():
312  raise ValueError('The label '+name+' contains forbiden characters')
313 
314  # private variable exempt from all this
315  if name.startswith('_Process__'):
316  self.__dict__[name]=value
317  return
318  if not isinstance(value,_ConfigureComponent):
319  raise TypeError("can only assign labels to an object that inherits from '_ConfigureComponent'\n"
320  +"an instance of "+str(type(value))+" will not work - requested label is "+name)
321  if not isinstance(value,_Labelable) and not isinstance(value,Source) and not isinstance(value,Looper) and not isinstance(value,Schedule):
322  if name == value.type_():
323  # Only Services get handled here
324  self.add_(value)
325  return
326  else:
327  raise TypeError("an instance of "+str(type(value))+" can not be assigned the label '"+name+"'.\n"+
328  "Please either use the label '"+value.type_()+" or use the 'add_' method instead.")
329  #clone the item
330  if self.__isStrict:
331  newValue =value.copy()
332  try:
333  newValue._filename = value._filename
334  except:
335  pass
336  value.setIsFrozen()
337  else:
338  newValue =value
339  if not self._okToPlace(name, value, self.__dict__):
340  newFile='top level config'
341  if hasattr(value,'_filename'):
342  newFile = value._filename
343  oldFile='top level config'
344  oldValue = getattr(self,name)
345  if hasattr(oldValue,'_filename'):
346  oldFile = oldValue._filename
347  msg = "Trying to override definition of process."+name
348  msg += "\n new object defined in: "+newFile
349  msg += "\n existing object defined in: "+oldFile
350  raise ValueError(msg)
351  # remove the old object of the name (if there is one)
352  if hasattr(self,name) and not (getattr(self,name)==newValue):
353  # Complain if items in sequences or tasks from load() statements have
354  # degenerate names, but if the user overwrites a name in the
355  # main config, replace it everywhere
356  if newValue._isTaskComponent():
357  if not self.__InExtendCall:
358  self._replaceInTasks(name, newValue)
359  self._replaceInSchedule(name, newValue)
360  else:
361  if not isinstance(newValue, Task):
362  #should check to see if used in task before complaining
363  newFile='top level config'
364  if hasattr(value,'_filename'):
365  newFile = value._filename
366  oldFile='top level config'
367  oldValue = getattr(self,name)
368  if hasattr(oldValue,'_filename'):
369  oldFile = oldValue._filename
370  msg1 = "Trying to override definition of "+name+" while it is used by the task "
371  msg2 = "\n new object defined in: "+newFile
372  msg2 += "\n existing object defined in: "+oldFile
373  s = self.__findFirstUsingModule(self.tasks,oldValue)
374  if s is not None:
375  raise ValueError(msg1+s.label_()+msg2)
376 
377  if isinstance(newValue, _Sequenceable) or newValue._isTaskComponent():
378  if not self.__InExtendCall:
379  self._replaceInSequences(name, newValue)
380  else:
381  #should check to see if used in sequence before complaining
382  newFile='top level config'
383  if hasattr(value,'_filename'):
384  newFile = value._filename
385  oldFile='top level config'
386  oldValue = getattr(self,name)
387  if hasattr(oldValue,'_filename'):
388  oldFile = oldValue._filename
389  msg1 = "Trying to override definition of "+name+" while it is used by the "
390  msg2 = "\n new object defined in: "+newFile
391  msg2 += "\n existing object defined in: "+oldFile
392  s = self.__findFirstUsingModule(self.sequences,oldValue)
393  if s is not None:
394  raise ValueError(msg1+"sequence "+s.label_()+msg2)
395  s = self.__findFirstUsingModule(self.paths,oldValue)
396  if s is not None:
397  raise ValueError(msg1+"path "+s.label_()+msg2)
398  s = self.__findFirstUsingModule(self.endpaths,oldValue)
399  if s is not None:
400  raise ValueError(msg1+"endpath "+s.label_()+msg2)
401  self._delattrFromSetattr(name)
402  self.__dict__[name]=newValue
403  if isinstance(newValue,_Labelable):
404  self.__setObjectLabel(newValue, name)
405  self._cloneToObjectDict[id(value)] = newValue
406  self._cloneToObjectDict[id(newValue)] = newValue
407  #now put in proper bucket
408  newValue._place(name,self)
409  def __findFirstUsingModule(self, seqsOrTasks, mod):
410  """Given a container of sequences or tasks, find the first sequence or task
411  containing mod and return it. If none is found, return None"""
412  from FWCore.ParameterSet.SequenceTypes import ModuleNodeVisitor
413  l = list()
414  for seqOrTask in seqsOrTasks.itervalues():
415  l[:] = []
416  v = ModuleNodeVisitor(l)
417  seqOrTask.visit(v)
418  if mod in l:
419  return seqOrTask
420  return None
421 
422  def _delHelper(self,name):
423  if not hasattr(self,name):
424  raise KeyError('process does not know about '+name)
425  elif name.startswith('_Process__'):
426  raise ValueError('this attribute cannot be deleted')
427 
428  # we have to remove it from all dictionaries/registries
429  dicts = [item for item in self.__dict__.values() if (type(item)==dict or type(item)==DictTypes.SortedKeysDict)]
430  for reg in dicts:
431  if name in reg: del reg[name]
432  # if it was a labelable object, the label needs to be removed
433  obj = getattr(self,name)
434  if isinstance(obj,_Labelable):
435  obj.setLabel(None)
436  if isinstance(obj,Service):
437  obj._inProcess = False
438 
439  def __delattr__(self,name):
440  self._delHelper(name)
441  obj = getattr(self,name)
442  if not obj is None:
443  if not isinstance(obj, Sequence) and not isinstance(obj, Task):
444  # For modules, ES modules and services we can also remove
445  # the deleted object from Sequences, Paths, EndPaths, and
446  # Tasks. Note that for Sequences and Tasks that cannot be done
447  # reliably as the places where the Sequence or Task was used
448  # might have been expanded so we do not even try. We considered
449  # raising an exception if a Sequences or Task was explicitly
450  # deleted, but did not because when done carefully deletion
451  # is sometimes OK (for example in the prune function where it
452  # has been checked that the deleted Sequence is not used).
453  if obj._isTaskComponent():
454  self._replaceInTasks(name, None)
455  self._replaceInSchedule(name, None)
456  if isinstance(obj, _Sequenceable) or obj._isTaskComponent():
457  self._replaceInSequences(name, None)
458  # now remove it from the process itself
459  try:
460  del self.__dict__[name]
461  except:
462  pass
463 
464  def _delattrFromSetattr(self,name):
465  """Similar to __delattr__ but we need different behavior when called from __setattr__"""
466  self._delHelper(name)
467  # now remove it from the process itself
468  try:
469  del self.__dict__[name]
470  except:
471  pass
472 
473  def add_(self,value):
474  """Allows addition of components that do not have to have a label, e.g. Services"""
475  if not isinstance(value,_ConfigureComponent):
476  raise TypeError
477  if not isinstance(value,_Unlabelable):
478  raise TypeError
479  #clone the item
480  #clone the item
481  if self.__isStrict:
482  newValue =value.copy()
483  value.setIsFrozen()
484  else:
485  newValue =value
486  newValue._place('',self)
487 
488  def _okToPlace(self, name, mod, d):
489  if not self.__InExtendCall:
490  # if going
491  return True
492  elif not self.__isStrict:
493  return True
494  elif name in d:
495  # if there's an old copy, and the new one
496  # hasn't been modified, we're done. Still
497  # not quite safe if something has been defined twice.
498  # Need to add checks
499  if mod._isModified:
500  if d[name]._isModified:
501  return False
502  else:
503  return True
504  else:
505  return True
506  else:
507  return True
508 
509  def _place(self, name, mod, d):
510  if self._okToPlace(name, mod, d):
511  if self.__isStrict and isinstance(mod, _ModuleSequenceType):
512  d[name] = mod._postProcessFixup(self._cloneToObjectDict)
513  else:
514  d[name] = mod
515  if isinstance(mod,_Labelable):
516  self.__setObjectLabel(mod, name)
517  def _placeOutputModule(self,name,mod):
518  self._place(name, mod, self.__outputmodules)
519  def _placeProducer(self,name,mod):
520  self._place(name, mod, self.__producers)
521  def _placeFilter(self,name,mod):
522  self._place(name, mod, self.__filters)
523  def _placeAnalyzer(self,name,mod):
524  self._place(name, mod, self.__analyzers)
525  def _placePath(self,name,mod):
526  self._validateSequence(mod, name)
527  try:
528  self._place(name, mod, self.__paths)
529  except ModuleCloneError as msg:
530  context = format_outerframe(4)
531  raise Exception("%sThe module %s in path %s is unknown to the process %s." %(context, msg, name, self._Process__name))
532  def _placeEndPath(self,name,mod):
533  self._validateSequence(mod, name)
534  try:
535  self._place(name, mod, self.__endpaths)
536  except ModuleCloneError as msg:
537  context = format_outerframe(4)
538  raise Exception("%sThe module %s in endpath %s is unknown to the process %s." %(context, msg, name, self._Process__name))
539  def _placeSequence(self,name,mod):
540  self._validateSequence(mod, name)
541  self._place(name, mod, self.__sequences)
542  def _placeESProducer(self,name,mod):
543  self._place(name, mod, self.__esproducers)
544  def _placeESPrefer(self,name,mod):
545  self._place(name, mod, self.__esprefers)
546  def _placeESSource(self,name,mod):
547  self._place(name, mod, self.__essources)
548  def _placeTask(self,name,task):
549  self._validateTask(task, name)
550  self._place(name, task, self.__tasks)
551  def _placeAlias(self,name,mod):
552  self._place(name, mod, self.__aliases)
553  def _placePSet(self,name,mod):
554  self._place(name, mod, self.__psets)
555  def _placeVPSet(self,name,mod):
556  self._place(name, mod, self.__vpsets)
557  def _placeSource(self,name,mod):
558  """Allow the source to be referenced by 'source' or by type name"""
559  if name != 'source':
560  raise ValueError("The label '"+name+"' can not be used for a Source. Only 'source' is allowed.")
561  if self.__dict__['_Process__source'] is not None :
562  del self.__dict__[self.__dict__['_Process__source'].type_()]
563  self.__dict__['_Process__source'] = mod
564  self.__dict__[mod.type_()] = mod
565  def _placeLooper(self,name,mod):
566  if name != 'looper':
567  raise ValueError("The label '"+name+"' can not be used for a Looper. Only 'looper' is allowed.")
568  self.__dict__['_Process__looper'] = mod
569  self.__dict__[mod.type_()] = mod
570  def _placeSubProcess(self,name,mod):
571  self.__dict__['_Process__subProcess'] = mod
572  self.__dict__[mod.type_()] = mod
573  def addSubProcess(self,mod):
574  self.__subProcesses.append(mod)
575  def _placeService(self,typeName,mod):
576  self._place(typeName, mod, self.__services)
577  if typeName in self.__dict__:
578  self.__dict__[typeName]._inProcess = False
579  self.__dict__[typeName]=mod
580  def load(self, moduleName):
581  moduleName = moduleName.replace("/",".")
582  module = __import__(moduleName)
583  self.extend(sys.modules[moduleName])
584  def extend(self,other,items=()):
585  """Look in other and find types that we can use"""
586  # enable explicit check to avoid overwriting of existing objects
587  self.__dict__['_Process__InExtendCall'] = True
588 
589  seqs = dict()
590  tasksToAttach = dict()
591  mods = []
592  for name in dir(other):
593  #'from XX import *' ignores these, and so should we.
594  if name.startswith('_'):
595  continue
596  item = getattr(other,name)
597  if name == "source" or name == "looper":
598  # In these cases 'item' could be None if the specific object was not defined
599  if item is not None:
600  self.__setattr__(name,item)
601  elif isinstance(item,_ModuleSequenceType):
602  seqs[name]=item
603  elif isinstance(item,Task):
604  tasksToAttach[name] = item
605  elif isinstance(item,_Labelable):
606  self.__setattr__(name,item)
607  if not item.hasLabel_() :
608  item.setLabel(name)
609  elif isinstance(item,Schedule):
610  self.__setattr__(name,item)
611  elif isinstance(item,_Unlabelable):
612  self.add_(item)
613  elif isinstance(item,ProcessModifier):
614  mods.append(item)
615  elif isinstance(item,ProcessFragment):
616  self.extend(item)
617 
618  #now create a sequence that uses the newly made items
619  for name in seqs.iterkeys():
620  seq = seqs[name]
621  #newSeq = seq.copy()
622  #
623  if id(seq) not in self._cloneToObjectDict:
624  self.__setattr__(name,seq)
625  else:
626  newSeq = self._cloneToObjectDict[id(seq)]
627  self.__dict__[name]=newSeq
628  self.__setObjectLabel(newSeq, name)
629  #now put in proper bucket
630  newSeq._place(name,self)
631 
632  for name in tasksToAttach.iterkeys():
633  task = tasksToAttach[name]
634  self.__setattr__(name, task)
635 
636  #apply modifiers now that all names have been added
637  for item in mods:
638  item.apply(self)
639 
640  self.__dict__['_Process__InExtendCall'] = False
641 
642  def _dumpConfigNamedList(self,items,typeName,options):
643  returnValue = ''
644  for name,item in items:
645  returnValue +=options.indentation()+typeName+' '+name+' = '+item.dumpConfig(options)
646  return returnValue
647  def _dumpConfigUnnamedList(self,items,typeName,options):
648  returnValue = ''
649  for name,item in items:
650  returnValue +=options.indentation()+typeName+' = '+item.dumpConfig(options)
651  return returnValue
652  def _dumpConfigOptionallyNamedList(self,items,typeName,options):
653  returnValue = ''
654  for name,item in items:
655  if name == item.type_():
656  name = ''
657  returnValue +=options.indentation()+typeName+' '+name+' = '+item.dumpConfig(options)
658  return returnValue
659  def dumpConfig(self, options=PrintOptions()):
660  """return a string containing the equivalent process defined using the old configuration language"""
661  config = "process "+self.__name+" = {\n"
662  options.indent()
663  if self.source_():
664  config += options.indentation()+"source = "+self.source_().dumpConfig(options)
665  if self.looper_():
666  config += options.indentation()+"looper = "+self.looper_().dumpConfig(options)
667 
668  config+=self._dumpConfigNamedList(self.subProcesses_(),
669  'subProcess',
670  options)
671  config+=self._dumpConfigNamedList(self.producers_().iteritems(),
672  'module',
673  options)
674  config+=self._dumpConfigNamedList(self.filters_().iteritems(),
675  'module',
676  options)
677  config+=self._dumpConfigNamedList(self.analyzers_().iteritems(),
678  'module',
679  options)
680  config+=self._dumpConfigNamedList(self.outputModules_().iteritems(),
681  'module',
682  options)
683  config+=self._dumpConfigNamedList(self.sequences_().iteritems(),
684  'sequence',
685  options)
686  config+=self._dumpConfigNamedList(self.paths_().iteritems(),
687  'path',
688  options)
689  config+=self._dumpConfigNamedList(self.endpaths_().iteritems(),
690  'endpath',
691  options)
692  config+=self._dumpConfigUnnamedList(self.services_().iteritems(),
693  'service',
694  options)
695  config+=self._dumpConfigNamedList(self.aliases_().iteritems(),
696  'alias',
697  options)
698  config+=self._dumpConfigOptionallyNamedList(
699  self.es_producers_().iteritems(),
700  'es_module',
701  options)
702  config+=self._dumpConfigOptionallyNamedList(
703  self.es_sources_().iteritems(),
704  'es_source',
705  options)
706  config += self._dumpConfigESPrefers(options)
707  for name,item in self.psets.iteritems():
708  config +=options.indentation()+item.configTypeName()+' '+name+' = '+item.configValue(options)
709  for name,item in self.vpsets.iteritems():
710  config +=options.indentation()+'VPSet '+name+' = '+item.configValue(options)
711  if self.schedule:
712  pathNames = [p.label_() for p in self.schedule]
713  config +=options.indentation()+'schedule = {'+','.join(pathNames)+'}\n'
714 
715 # config+=self._dumpConfigNamedList(self.vpsets.iteritems(),
716 # 'VPSet',
717 # options)
718  config += "}\n"
719  options.unindent()
720  return config
721  def _dumpConfigESPrefers(self, options):
722  result = ''
723  for item in self.es_prefers_().itervalues():
724  result +=options.indentation()+'es_prefer '+item.targetLabel_()+' = '+item.dumpConfig(options)
725  return result
726  def _dumpPythonSubProcesses(self, l, options):
727  returnValue = ''
728  for item in l:
729  returnValue += item.dumpPython(options)+'\n\n'
730  return returnValue
731  def _dumpPythonList(self, d, options):
732  returnValue = ''
733  if isinstance(d, DictTypes.SortedKeysDict):
734  for name,item in d.items():
735  returnValue +='process.'+name+' = '+item.dumpPython(options)+'\n\n'
736  else:
737  for name,item in sorted(d.items()):
738  returnValue +='process.'+name+' = '+item.dumpPython(options)+'\n\n'
739  return returnValue
740  def _validateSequence(self, sequence, label):
741  # See if every module has been inserted into the process
742  try:
743  l = set()
744  visitor = NodeNameVisitor(l)
745  sequence.visit(visitor)
746  except:
747  raise RuntimeError("An entry in sequence "+label + ' has no label')
748  def _validateTask(self, task, label):
749  # See if every module and service has been inserted into the process
750  try:
751  l = set()
752  visitor = NodeNameVisitor(l)
753  task.visit(visitor)
754  except:
755  raise RuntimeError("An entry in task " + label + ' has not been attached to the process')
756  def _itemsInDependencyOrder(self, processDictionaryOfItems):
757  # The items can be Sequences or Tasks and the input
758  # argument should either be the dictionary of sequences
759  # or the dictionary of tasks from the process.
760 
761  returnValue=DictTypes.SortedKeysDict()
762 
763  # For each item, see what other items it depends upon
764  # For our purpose here, an item depends on the items it contains.
765  dependencies = {}
766  for label,item in processDictionaryOfItems.iteritems():
767  containedItems = []
768  if isinstance(item, Task):
769  v = TaskVisitor(containedItems)
770  else:
771  v = SequenceVisitor(containedItems)
772  try:
773  item.visit(v)
774  except RuntimeError:
775  if isinstance(item, Task):
776  raise RuntimeError("Failed in a Task visitor. Probably " \
777  "a circular dependency discovered in Task with label " + label)
778  else:
779  raise RuntimeError("Failed in a Sequence visitor. Probably a " \
780  "circular dependency discovered in Sequence with label " + label)
781  for containedItem in containedItems:
782  # Check for items that both have labels and are not in the process.
783  # This should not normally occur unless someone explicitly assigns a
784  # label without putting the item in the process (which should not ever
785  # be done). We check here because this problem could cause the code
786  # in the 'while' loop below to go into an infinite loop.
787  if containedItem.hasLabel_():
788  testItem = processDictionaryOfItems.get(containedItem.label_())
789  if testItem is None or containedItem != testItem:
790  if isinstance(item, Task):
791  raise RuntimeError("Task has a label, but using its label to get an attribute" \
792  " from the process yields a different object or None\n"+
793  "label = " + containedItem.label_())
794  else:
795  raise RuntimeError("Sequence has a label, but using its label to get an attribute" \
796  " from the process yields a different object or None\n"+
797  "label = " + containedItem.label_())
798  dependencies[label]=[dep.label_() for dep in containedItems if dep.hasLabel_()]
799 
800  # keep looping until we get rid of all dependencies
801  while dependencies:
802  oldDeps = dict(dependencies)
803  for label,deps in oldDeps.iteritems():
804  if len(deps)==0:
805  returnValue[label]=processDictionaryOfItems[label]
806  #remove this as a dependency for all other tasks
807  del dependencies[label]
808  for lb2,deps2 in dependencies.iteritems():
809  while deps2.count(label):
810  deps2.remove(label)
811  return returnValue
812  def _dumpPython(self, d, options):
813  result = ''
814  for name, value in sorted(d.iteritems()):
815  result += value.dumpPythonAs(name,options)+'\n'
816  return result
817  def dumpPython(self, options=PrintOptions()):
818  """return a string containing the equivalent process defined using python"""
819  result = "import FWCore.ParameterSet.Config as cms\n\n"
820  result += "process = cms.Process(\""+self.__name+"\")\n\n"
821  if self.source_():
822  result += "process.source = "+self.source_().dumpPython(options)
823  if self.looper_():
824  result += "process.looper = "+self.looper_().dumpPython()
825  result+=self._dumpPythonList(self.psets, options)
826  result+=self._dumpPythonList(self.vpsets, options)
827  result+=self._dumpPythonSubProcesses(self.subProcesses_(), options)
828  result+=self._dumpPythonList(self.producers_(), options)
829  result+=self._dumpPythonList(self.filters_() , options)
830  result+=self._dumpPythonList(self.analyzers_(), options)
831  result+=self._dumpPythonList(self.outputModules_(), options)
832  result+=self._dumpPythonList(self.services_(), options)
833  result+=self._dumpPythonList(self.es_producers_(), options)
834  result+=self._dumpPythonList(self.es_sources_(), options)
835  result+=self._dumpPython(self.es_prefers_(), options)
836  result+=self._dumpPythonList(self._itemsInDependencyOrder(self.tasks), options)
837  result+=self._dumpPythonList(self._itemsInDependencyOrder(self.sequences), options)
838  result+=self._dumpPythonList(self.paths_(), options)
839  result+=self._dumpPythonList(self.endpaths_(), options)
840  result+=self._dumpPythonList(self.aliases_(), options)
841  if not self.schedule_() == None:
842  result += 'process.schedule = ' + self.schedule.dumpPython(options)
843  return result
844  def _replaceInSequences(self, label, new):
845  old = getattr(self,label)
846  #TODO - replace by iterator concatenation
847  for sequenceable in self.sequences.itervalues():
848  sequenceable.replace(old,new)
849  for sequenceable in self.paths.itervalues():
850  sequenceable.replace(old,new)
851  for sequenceable in self.endpaths.itervalues():
852  sequenceable.replace(old,new)
853  def _replaceInTasks(self, label, new):
854  old = getattr(self,label)
855  for task in self.tasks.itervalues():
856  task.replace(old, new)
857  def _replaceInSchedule(self, label, new):
858  if self.schedule_() == None:
859  return
860  old = getattr(self,label)
861  for task in self.schedule_()._tasks:
862  task.replace(old, new)
863  def globalReplace(self,label,new):
864  """ Replace the item with label 'label' by object 'new' in the process and all sequences/paths/tasks"""
865  if not hasattr(self,label):
866  raise LookupError("process has no item of label "+label)
867  setattr(self,label,new)
868  def _insertInto(self, parameterSet, itemDict):
869  for name,value in itemDict.iteritems():
870  value.insertInto(parameterSet, name)
871  def _insertOneInto(self, parameterSet, label, item, tracked):
872  vitems = []
873  if not item == None:
874  newlabel = item.nameInProcessDesc_(label)
875  vitems = [newlabel]
876  item.insertInto(parameterSet, newlabel)
877  parameterSet.addVString(tracked, label, vitems)
878  def _insertManyInto(self, parameterSet, label, itemDict, tracked):
879  l = []
880  for name,value in itemDict.iteritems():
881  newLabel = value.nameInProcessDesc_(name)
882  l.append(newLabel)
883  value.insertInto(parameterSet, name)
884  # alphabetical order is easier to compare with old language
885  l.sort()
886  parameterSet.addVString(tracked, label, l)
887  def _insertSubProcessesInto(self, parameterSet, label, itemList, tracked):
888  l = []
889  subprocs = []
890  for value in itemList:
891  name = value.getProcessName()
892  newLabel = value.nameInProcessDesc_(name)
893  l.append(newLabel)
894  pset = value.getSubProcessPSet(parameterSet)
895  subprocs.append(pset)
896  # alphabetical order is easier to compare with old language
897  l.sort()
898  parameterSet.addVString(tracked, label, l)
899  parameterSet.addVPSet(False,"subProcesses",subprocs)
900  def _insertPaths(self, processPSet, nodeVisitor):
901  scheduledPaths = []
902  triggerPaths = []
903  endpaths = []
904  if self.schedule_() == None:
905  # make one from triggerpaths & endpaths
906  for name in self.paths_():
907  scheduledPaths.append(name)
908  triggerPaths.append(name)
909  for name in self.endpaths_():
910  scheduledPaths.append(name)
911  endpaths.append(name)
912  else:
913  for path in self.schedule_():
914  pathname = path.label_()
915  scheduledPaths.append(pathname)
916  if pathname in self.endpaths_():
917  endpaths.append(pathname)
918  else:
919  triggerPaths.append(pathname)
920  for task in self.schedule_()._tasks:
921  task.resolve(self.__dict__)
922  scheduleTaskValidator = ScheduleTaskValidator()
923  task.visit(scheduleTaskValidator)
924  task.visit(nodeVisitor)
925  processPSet.addVString(True, "@end_paths", endpaths)
926  processPSet.addVString(True, "@paths", scheduledPaths)
927  # trigger_paths are a little different
928  p = processPSet.newPSet()
929  p.addVString(True, "@trigger_paths", triggerPaths)
930  processPSet.addPSet(True, "@trigger_paths", p)
931  # add all these paths
932  pathValidator = PathValidator()
933  endpathValidator = EndPathValidator()
934  decoratedList = []
935  lister = DecoratedNodeNameVisitor(decoratedList)
936  pathCompositeVisitor = CompositeVisitor(pathValidator, nodeVisitor, lister)
937  endpathCompositeVisitor = CompositeVisitor(endpathValidator, nodeVisitor, lister)
938  for triggername in triggerPaths:
939  iPath = self.paths_()[triggername]
940  iPath.resolve(self.__dict__)
941  pathValidator.setLabel(triggername)
942  lister.initialize()
943  iPath.visit(pathCompositeVisitor)
944  iPath.insertInto(processPSet, triggername, decoratedList)
945  for endpathname in endpaths:
946  iEndPath = self.endpaths_()[endpathname]
947  iEndPath.resolve(self.__dict__)
948  endpathValidator.setLabel(endpathname)
949  lister.initialize()
950  iEndPath.visit(endpathCompositeVisitor)
951  iEndPath.insertInto(processPSet, endpathname, decoratedList)
952  processPSet.addVString(False, "@filters_on_endpaths", endpathValidator.filtersOnEndpaths)
953 
954  def resolve(self,keepUnresolvedSequencePlaceholders=False):
955  for x in self.paths.itervalues():
956  x.resolve(self.__dict__,keepUnresolvedSequencePlaceholders)
957  for x in self.endpaths.itervalues():
958  x.resolve(self.__dict__,keepUnresolvedSequencePlaceholders)
959  if not self.schedule_() == None:
960  for task in self.schedule_()._tasks:
961  task.resolve(self.__dict__,keepUnresolvedSequencePlaceholders)
962 
963  def prune(self,verbose=False,keepUnresolvedSequencePlaceholders=False):
964  """ Remove clutter from the process that we think is unnecessary:
965  tracked PSets, VPSets and unused modules and sequences. If a Schedule has been set, then Paths and EndPaths
966  not in the schedule will also be removed, along with an modules and sequences used only by
967  those removed Paths and EndPaths."""
968 # need to update this to only prune psets not on refToPSets
969 # but for now, remove the delattr
970 # for name in self.psets_():
971 # if getattr(self,name).isTracked():
972 # delattr(self, name)
973  for name in self.vpsets_():
974  delattr(self, name)
975  #first we need to resolve any SequencePlaceholders being used
976  self.resolve(keepUnresolvedSequencePlaceholders)
977  usedModules = set()
978  unneededPaths = set()
979  if self.schedule_():
980  usedModules=set(self.schedule_().moduleNames())
981  #get rid of unused paths
982  schedNames = set(( x.label_() for x in self.schedule_()))
983  names = set(self.paths)
984  names.update(set(self.endpaths))
985  unneededPaths = names - schedNames
986  for n in unneededPaths:
987  delattr(self,n)
988  else:
989  pths = list(self.paths.itervalues())
990  pths.extend(self.endpaths.itervalues())
991  temp = Schedule(*pths)
992  usedModules=set(temp.moduleNames())
993  unneededModules = self._pruneModules(self.producers_(), usedModules)
994  unneededModules.update(self._pruneModules(self.filters_(), usedModules))
995  unneededModules.update(self._pruneModules(self.analyzers_(), usedModules))
996  #remove sequences that do not appear in remaining paths and endpaths
997  seqs = list()
998  sv = SequenceVisitor(seqs)
999  for p in self.paths.itervalues():
1000  p.visit(sv)
1001  for p in self.endpaths.itervalues():
1002  p.visit(sv)
1003  keepSeqSet = set(( s for s in seqs if s.hasLabel_()))
1004  availableSeqs = set(self.sequences.itervalues())
1005  unneededSeqs = availableSeqs-keepSeqSet
1006  unneededSeqLabels = []
1007  for s in unneededSeqs:
1008  unneededSeqLabels.append(s.label_())
1009  delattr(self,s.label_())
1010  if verbose:
1011  print "prune removed the following:"
1012  print " modules:"+",".join(unneededModules)
1013  print " sequences:"+",".join(unneededSeqLabels)
1014  print " paths/endpaths:"+",".join(unneededPaths)
1015  def _pruneModules(self, d, scheduledNames):
1016  moduleNames = set(d.keys())
1017  junk = moduleNames - scheduledNames
1018  for name in junk:
1019  delattr(self, name)
1020  return junk
1021 
1022  def fillProcessDesc(self, processPSet):
1023  """Used by the framework to convert python to C++ objects"""
1024  class ServiceInjectorAdaptor(object):
1025  def __init__(self,ppset,thelist):
1026  self.__thelist = thelist
1027  self.__processPSet = ppset
1028  def addService(self,pset):
1029  self.__thelist.append(pset)
1030  def newPSet(self):
1031  return self.__processPSet.newPSet()
1032  #This adaptor is used to 'add' the method 'getTopPSet_'
1033  # to the ProcessDesc and PythonParameterSet C++ classes.
1034  # This method is needed for the PSet refToPSet_ functionality.
1035  class TopLevelPSetAcessorAdaptor(object):
1036  def __init__(self,ppset,process):
1037  self.__ppset = ppset
1038  self.__process = process
1039  def __getattr__(self,attr):
1040  return getattr(self.__ppset,attr)
1041  def getTopPSet_(self,label):
1042  return getattr(self.__process,label)
1043  def newPSet(self):
1044  return TopLevelPSetAcessorAdaptor(self.__ppset.newPSet(),self.__process)
1045  def addPSet(self,tracked,name,ppset):
1046  return self.__ppset.addPSet(tracked,name,self.__extractPSet(ppset))
1047  def addVPSet(self,tracked,name,vpset):
1048  return self.__ppset.addVPSet(tracked,name,[self.__extractPSet(x) for x in vpset])
1049  def __extractPSet(self,pset):
1050  if isinstance(pset,TopLevelPSetAcessorAdaptor):
1051  return pset.__ppset
1052  return pset
1053 
1054  self.validate()
1055  processPSet.addString(True, "@process_name", self.name_())
1056  all_modules = self.producers_().copy()
1057  all_modules.update(self.filters_())
1058  all_modules.update(self.analyzers_())
1059  all_modules.update(self.outputModules_())
1060  adaptor = TopLevelPSetAcessorAdaptor(processPSet,self)
1061  self._insertInto(adaptor, self.psets_())
1062  self._insertInto(adaptor, self.vpsets_())
1063  self._insertOneInto(adaptor, "@all_sources", self.source_(), True)
1064  self._insertOneInto(adaptor, "@all_loopers", self.looper_(), True)
1065  self._insertSubProcessesInto(adaptor, "@all_subprocesses", self.subProcesses_(), False)
1066  self._insertManyInto(adaptor, "@all_esprefers", self.es_prefers_(), True)
1067  self._insertManyInto(adaptor, "@all_aliases", self.aliases_(), True)
1068  # This will visit all the paths and endpaths that are scheduled to run,
1069  # as well as the Tasks associated to them and the schedule. It remembers
1070  # the modules, ESSources, ESProducers, and services it visits.
1071  nodeVisitor = NodeVisitor()
1072  self._insertPaths(adaptor, nodeVisitor)
1073  all_modules_onTasksOrScheduled = { key:value for key, value in all_modules.iteritems() if value in nodeVisitor.modules }
1074  self._insertManyInto(adaptor, "@all_modules", all_modules_onTasksOrScheduled, True)
1075  # Same as nodeVisitor except this one visits all the Tasks attached
1076  # to the process.
1077  processNodeVisitor = NodeVisitor()
1078  for pTask in self.tasks.itervalues():
1079  pTask.visit(processNodeVisitor)
1080  esProducersToEnable = {}
1081  for esProducerName, esProducer in self.es_producers_().iteritems():
1082  if esProducer in nodeVisitor.esProducers or not (esProducer in processNodeVisitor.esProducers):
1083  esProducersToEnable[esProducerName] = esProducer
1084  self._insertManyInto(adaptor, "@all_esmodules", esProducersToEnable, True)
1085  esSourcesToEnable = {}
1086  for esSourceName, esSource in self.es_sources_().iteritems():
1087  if esSource in nodeVisitor.esSources or not (esSource in processNodeVisitor.esSources):
1088  esSourcesToEnable[esSourceName] = esSource
1089  self._insertManyInto(adaptor, "@all_essources", esSourcesToEnable, True)
1090  #handle services differently
1091  services = []
1092  for serviceName, serviceObject in self.services_().iteritems():
1093  if serviceObject in nodeVisitor.services or not (serviceObject in processNodeVisitor.services):
1094  serviceObject.insertInto(ServiceInjectorAdaptor(adaptor,services))
1095  adaptor.addVPSet(False,"services",services)
1096  return processPSet
1097 
1098  def validate(self):
1099  # check if there's some input
1100  # Breaks too many unit tests for now
1101  #if self.source_() == None and self.looper_() == None:
1102  # raise RuntimeError("No input source was found for this process")
1103  pass
1104 
1105  def prefer(self, esmodule,*args,**kargs):
1106  """Prefer this ES source or producer. The argument can
1107  either be an object label, e.g.,
1108  process.prefer(process.juicerProducer) (not supported yet)
1109  or a name of an ESSource or ESProducer
1110  process.prefer("juicer")
1111  or a type of unnamed ESSource or ESProducer
1112  process.prefer("JuicerProducer")
1113  In addition, you can pass as a labelled arguments the name of the Record you wish to
1114  prefer where the type passed is a cms.vstring and that vstring can contain the
1115  name of the C++ types in the Record that are being preferred, e.g.,
1116  #prefer all data in record 'OrangeRecord' from 'juicer'
1117  process.prefer("juicer", OrangeRecord=cms.vstring())
1118  or
1119  #prefer only "Orange" data in "OrangeRecord" from "juicer"
1120  process.prefer("juicer", OrangeRecord=cms.vstring("Orange"))
1121  or
1122  #prefer only "Orange" data with label "ExtraPulp" in "OrangeRecord" from "juicer"
1123  ESPrefer("ESJuicerProd", OrangeRecord=cms.vstring("Orange/ExtraPulp"))
1124  """
1125  # see if this refers to a named ESProducer
1126  if isinstance(esmodule, ESSource) or isinstance(esmodule, ESProducer):
1127  raise RuntimeError("Syntax of process.prefer(process.esmodule) not supported yet")
1128  elif self._findPreferred(esmodule, self.es_producers_(),*args,**kargs) or \
1129  self._findPreferred(esmodule, self.es_sources_(),*args,**kargs):
1130  pass
1131  else:
1132  raise RuntimeError("Cannot resolve prefer for "+repr(esmodule))
1133 
1134  def _findPreferred(self, esname, d,*args,**kargs):
1135  # is esname a name in the dictionary?
1136  if esname in d:
1137  typ = d[esname].type_()
1138  if typ == esname:
1139  self.__setattr__( esname+"_prefer", ESPrefer(typ,*args,**kargs) )
1140  else:
1141  self.__setattr__( esname+"_prefer", ESPrefer(typ, esname,*args,**kargs) )
1142  return True
1143  else:
1144  # maybe it's an unnamed ESModule?
1145  found = False
1146  for name, value in d.iteritems():
1147  if value.type_() == esname:
1148  if found:
1149  raise RuntimeError("More than one ES module for "+esname)
1150  found = True
1151  self.__setattr__(esname+"_prefer", ESPrefer(d[esname].type_()) )
1152  return found
1153 
1154 
1156  def __init__(self, process):
1157  if isinstance(process, Process):
1158  self.__process = process
1159  elif isinstance(process, str):
1160  self.__process = Process(process)
1161  else:
1162  raise TypeError('a ProcessFragment can only be constructed from an existig Process or from process name')
1163  def __dir__(self):
1164  return [ x for x in dir(self.__process) if isinstance(getattr(self.__process, x), _ConfigureComponent) ]
1165  def __getattribute__(self, name):
1166  if name == '_ProcessFragment__process':
1167  return object.__getattribute__(self, '_ProcessFragment__process')
1168  else:
1169  return getattr(self.__process, name)
1170  def __setattr__(self, name, value):
1171  if name == '_ProcessFragment__process':
1172  object.__setattr__(self, name, value)
1173  else:
1174  setattr(self.__process, name, value)
1175  def __delattr__(self, name):
1176  if name == '_ProcessFragment__process':
1177  pass
1178  else:
1179  return delattr(self.__process, name)
1180 
1181 
1183  """a dictionary with fixed keys"""
1185  raise AttributeError("An FilteredStream defintion cannot be modified after creation.")
1186  _blocked_attribute = property(_blocked_attribute)
1187  __setattr__ = __delitem__ = __setitem__ = clear = _blocked_attribute
1188  pop = popitem = setdefault = update = _blocked_attribute
1189  def __new__(cls, *args, **kw):
1190  new = dict.__new__(cls)
1191  dict.__init__(new, *args, **kw)
1192  keys = kw.keys()
1193  keys.sort()
1194  if keys != ['content', 'dataTier', 'name', 'paths', 'responsible', 'selectEvents']:
1195  raise ValueError("The needed parameters are: content, dataTier, name, paths, responsible, selectEvents")
1196  if not isinstance(kw['name'],str):
1197  raise ValueError("name must be of type string")
1198  if not isinstance(kw['content'], vstring) and not isinstance(kw['content'],str):
1199  raise ValueError("content must be of type vstring or string")
1200  if not isinstance(kw['dataTier'], string):
1201  raise ValueError("dataTier must be of type string")
1202  if not isinstance(kw['selectEvents'], PSet):
1203  raise ValueError("selectEvents must be of type PSet")
1204  if not isinstance(kw['paths'],(tuple, Path)):
1205  raise ValueError("'paths' must be a tuple of paths")
1206  return new
1207  def __init__(self, *args, **kw):
1208  pass
1209  def __repr__(self):
1210  return "FilteredStream object: %s" %self["name"]
1211  def __getattr__(self,attr):
1212  return self[attr]
1213 
1215  """Allows embedding another process within a parent process. This allows one to
1216  chain processes together directly in one cmsRun job rather than having to run
1217  separate jobs that are connected via a temporary file.
1218  """
1219  def __init__(self,process, SelectEvents = untracked.PSet(), outputCommands = untracked.vstring()):
1220  """
1221  """
1222  if not isinstance(process, Process):
1223  raise ValueError("the 'process' argument must be of type cms.Process")
1224  if not isinstance(SelectEvents,PSet):
1225  raise ValueError("the 'SelectEvents' argument must be of type cms.untracked.PSet")
1226  if not isinstance(outputCommands,vstring):
1227  raise ValueError("the 'outputCommands' argument must be of type cms.untracked.vstring")
1228  self.__process = process
1229  self.__SelectEvents = SelectEvents
1230  self.__outputCommands = outputCommands
1231  def dumpPython(self,options=PrintOptions()):
1232  out = "parentProcess"+str(hash(self))+" = process\n"
1233  out += self.__process.dumpPython()
1234  out += "childProcess = process\n"
1235  out += "process = parentProcess"+str(hash(self))+"\n"
1236  out += "process.addSubProcess(cms.SubProcess(process = childProcess, SelectEvents = "+self.__SelectEvents.dumpPython(options) +", outputCommands = "+self.__outputCommands.dumpPython(options) +"))"
1237  return out
1238  def getProcessName(self):
1239  return self.__process.name_()
1240  def process(self):
1241  return self.__process
1242  def SelectEvents(self):
1243  return self.__SelectEvents
1244  def outputCommands(self):
1245  return self.__outputCommands
1246  def type_(self):
1247  return 'subProcess'
1248  def nameInProcessDesc_(self,label):
1249  return label
1250  def _place(self,label,process):
1251  process._placeSubProcess('subProcess',self)
1252  def getSubProcessPSet(self,parameterSet):
1253  topPSet = parameterSet.newPSet()
1254  self.__process.fillProcessDesc(topPSet)
1255  subProcessPSet = parameterSet.newPSet()
1256  self.__SelectEvents.insertInto(subProcessPSet,"SelectEvents")
1257  self.__outputCommands.insertInto(subProcessPSet,"outputCommands")
1258  subProcessPSet.addPSet(False,"process",topPSet)
1259  return subProcessPSet
1260 
1262  """Helper class for Modifier that takes key/value pairs and uses them to reset parameters of the object"""
1263  def __init__(self,args):
1264  self.__args = args
1265  def __call__(self,obj):
1266  params = {}
1267  for k in self.__args.iterkeys():
1268  if hasattr(obj,k):
1269  params[k] = getattr(obj,k)
1271  for k in self.__args.iterkeys():
1272  if k in params:
1273  setattr(obj,k,params[k])
1274  else:
1275  #the parameter must have been removed
1276  delattr(obj,k)
1277  @staticmethod
1279  raise KeyError("Unknown parameter name "+key+" specified while calling Modifier")
1280 
1282  """A helper base class for _AndModifier, _InvertModifier, and _OrModifier to contain the common code"""
1283  def __init__(self, lhs, rhs=None):
1284  self._lhs = lhs
1285  if rhs is not None:
1286  self._rhs = rhs
1287  def toModify(self,obj, func=None,**kw):
1288  Modifier._toModifyCheck(obj,func,**kw)
1289  if not self.isChosen():
1290  return
1291  Modifier._toModify(obj,func,**kw)
1292  def toReplaceWith(self,toObj,fromObj):
1293  Modifier._toReplaceWithCheck(toObj,fromObj)
1294  if not self.isChosen():
1295  return
1296  Modifier._toReplaceWith(toObj,fromObj)
1297  def makeProcessModifier(self,func):
1298  """This is used to create a ProcessModifer that can perform actions on the process as a whole.
1299  This takes as argument a callable object (e.g. function) that takes as its sole argument an instance of Process.
1300  In order to work, the value returned from this function must be assigned to a uniquely named variable."""
1301  return ProcessModifier(self,func)
1302  def __and__(self, other):
1303  return _AndModifier(self,other)
1304  def __invert__(self):
1305  return _InvertModifier(self)
1306  def __or__(self, other):
1307  return _OrModifier(self,other)
1308 
1310  """A modifier which only applies if multiple Modifiers are chosen"""
1311  def __init__(self, lhs, rhs):
1312  super(_AndModifier,self).__init__(lhs, rhs)
1313  def isChosen(self):
1314  return self._lhs.isChosen() and self._rhs.isChosen()
1315 
1317  """A modifier which only applies if a Modifier is not chosen"""
1318  def __init__(self, lhs):
1319  super(_InvertModifier,self).__init__(lhs)
1320  def isChosen(self):
1321  return not self._lhs.isChosen()
1322 
1324  """A modifier which only applies if at least one of multiple Modifiers is chosen"""
1325  def __init__(self, lhs, rhs):
1326  super(_OrModifier,self).__init__(lhs, rhs)
1327  def isChosen(self):
1328  return self._lhs.isChosen() or self._rhs.isChosen()
1329 
1330 
1332  """This class is used to define standard modifications to a Process.
1333  An instance of this class is declared to denote a specific modification,e.g. era2017 could
1334  reconfigure items in a process to match our expectation of running in 2017. Once declared,
1335  these Modifier instances are imported into a configuration and items that need to be modified
1336  are then associated with the Modifier and with the action to do the modification.
1337  The registered modifications will only occur if the Modifier was passed to
1338  the cms.Process' constructor.
1339  """
1340  def __init__(self):
1342  self.__chosen = False
1343  def makeProcessModifier(self,func):
1344  """This is used to create a ProcessModifer that can perform actions on the process as a whole.
1345  This takes as argument a callable object (e.g. function) that takes as its sole argument an instance of Process.
1346  In order to work, the value returned from this function must be assigned to a uniquely named variable.
1347  """
1348  return ProcessModifier(self,func)
1349  @staticmethod
1350  def _toModifyCheck(obj,func,**kw):
1351  if func is not None and len(kw) != 0:
1352  raise TypeError("toModify takes either two arguments or one argument and key/value pairs")
1353  def toModify(self,obj, func=None,**kw):
1354  """This is used to register an action to be performed on the specific object. Two different forms are allowed
1355  Form 1: A callable object (e.g. function) can be passed as the second. This callable object is expected to take one argument
1356  that will be the object passed in as the first argument.
1357  Form 2: A list of parameter name, value pairs can be passed
1358  mod.toModify(foo, fred=cms.int32(7), barney = cms.double(3.14))
1359  This form can also be used to remove a parameter by passing the value of None
1360  #remove the parameter foo.fred
1361  mod.toModify(foo, fred = None)
1362  Additionally, parameters embedded within PSets can also be modified using a dictionary
1363  #change foo.fred.pebbles to 3 and foo.fred.friend to "barney"
1364  mod.toModify(foo, fred = dict(pebbles = 3, friend = "barney)) )
1365  """
1366  Modifier._toModifyCheck(obj,func,**kw)
1367  if not self.isChosen():
1368  return
1369  Modifier._toModify(obj,func,**kw)
1370  @staticmethod
1371  def _toModify(obj,func,**kw):
1372  if func is not None:
1373  func(obj)
1374  else:
1375  temp =_ParameterModifier(kw)
1376  temp(obj)
1377  @staticmethod
1378  def _toReplaceWithCheck(toObj,fromObj):
1379  if type(fromObj) != type(toObj):
1380  raise TypeError("toReplaceWith requires both arguments to be the same class type")
1381  def toReplaceWith(self,toObj,fromObj):
1382  """If the Modifier is chosen the internals of toObj will be associated with the internals of fromObj
1383  """
1384  Modifier._toReplaceWithCheck(toObj,fromObj)
1385  if not self.isChosen():
1386  return
1387  Modifier._toReplaceWith(toObj,fromObj)
1388  @staticmethod
1389  def _toReplaceWith(toObj,fromObj):
1390  if isinstance(fromObj,_ModuleSequenceType):
1391  toObj._seq = fromObj._seq
1392  toObj._tasks = fromObj._tasks
1393  elif isinstance(fromObj,Task):
1394  toObj._collection = fromObj._collection
1395  elif isinstance(fromObj,_Parameterizable):
1396  #clear old items just incase fromObj is not a complete superset of toObj
1397  for p in toObj.parameterNames_():
1398  delattr(toObj,p)
1399  for p in fromObj.parameterNames_():
1400  setattr(toObj,p,getattr(fromObj,p))
1401  if isinstance(fromObj,_TypedParameterizable):
1402  toObj._TypedParameterizable__type = fromObj._TypedParameterizable__type
1403 
1404  else:
1405  raise TypeError("toReplaceWith does not work with type "+str(type(toObj)))
1406 
1407  def _setChosen(self):
1408  """Should only be called by cms.Process instances"""
1409  self.__chosen = True
1410  def isChosen(self):
1411  return self.__chosen
1412  def __and__(self, other):
1413  return _AndModifier(self,other)
1414  def __invert__(self):
1415  return _InvertModifier(self)
1416  def __or__(self, other):
1417  return _OrModifier(self,other)
1418  def _isOrContains(self, other):
1419  return self == other
1420 
1421 
1423  """A Modifier made up of a list of Modifiers
1424  """
1425  def __init__(self, *chainedModifiers):
1426  self.__chosen = False
1427  self.__chain = chainedModifiers
1428  def _applyNewProcessModifiers(self,process):
1429  """Should only be called by cms.Process instances
1430  applies list of accumulated changes to the process"""
1431  for m in self.__chain:
1432  m._applyNewProcessModifiers(process)
1433  def _setChosen(self):
1434  """Should only be called by cms.Process instances"""
1435  self.__chosen = True
1436  for m in self.__chain:
1437  m._setChosen()
1438  def isChosen(self):
1439  return self.__chosen
1440  def copyAndExclude(self, toExclude):
1441  """Creates a new ModifierChain which is a copy of
1442  this ModifierChain but excludes any Modifier or
1443  ModifierChain in the list toExclude.
1444  The exclusion is done recursively down the chain.
1445  """
1446  newMods = []
1447  for m in self.__chain:
1448  if m not in toExclude:
1449  s = m
1450  if isinstance(m,ModifierChain):
1451  s = m.__copyIfExclude(toExclude)
1452  newMods.append(s)
1453  return ModifierChain(*newMods)
1454  def __copyIfExclude(self,toExclude):
1455  shouldCopy = False
1456  for m in toExclude:
1457  if self._isOrContains(m):
1458  shouldCopy = True
1459  break
1460  if shouldCopy:
1461  return self.copyAndExclude(toExclude)
1462  return self
1463  def _isOrContains(self, other):
1464  if self is other:
1465  return True
1466  for m in self.__chain:
1467  if m._isOrContains(other):
1468  return True
1469  return False
1470 
1472  """A class used by a Modifier to affect an entire Process instance.
1473  When a Process 'loads' a module containing a ProcessModifier, that
1474  ProcessModifier will be applied to the Process if and only if the
1475  Modifier passed to the constructor has been chosen.
1476  """
1477  def __init__(self, modifier, func):
1478  self.__modifier = modifier
1479  self.__func = func
1480  self.__seenProcesses = set()
1481  def apply(self,process):
1482  if self.__modifier.isChosen():
1483  if process not in self.__seenProcesses:
1484  self.__func(process)
1485  self.__seenProcesses.add(process)
1486 
1487 if __name__=="__main__":
1488  import unittest
1489  import copy
1490 
1492  """Has same interface as the C++ object that creates PSets
1493  """
1494  def __init__(self):
1495  self.values = dict()
1496  def __insertValue(self,tracked,label,value):
1497  self.values[label]=(tracked,value)
1498  def addInt32(self,tracked,label,value):
1499  self.__insertValue(tracked,label,value)
1500  def addVInt32(self,tracked,label,value):
1501  self.__insertValue(tracked,label,value)
1502  def addUInt32(self,tracked,label,value):
1503  self.__insertValue(tracked,label,value)
1504  def addVUInt32(self,tracked,label,value):
1505  self.__insertValue(tracked,label,value)
1506  def addInt64(self,tracked,label,value):
1507  self.__insertValue(tracked,label,value)
1508  def addVInt64(self,tracked,label,value):
1509  self.__insertValue(tracked,label,value)
1510  def addUInt64(self,tracked,label,value):
1511  self.__insertValue(tracked,label,value)
1512  def addVUInt64(self,tracked,label,value):
1513  self.__insertValue(tracked,label,value)
1514  def addDouble(self,tracked,label,value):
1515  self.__insertValue(tracked,label,value)
1516  def addVDouble(self,tracked,label,value):
1517  self.__insertValue(tracked,label,value)
1518  def addBool(self,tracked,label,value):
1519  self.__insertValue(tracked,label,value)
1520  def addString(self,tracked,label,value):
1521  self.__insertValue(tracked,label,value)
1522  def addVString(self,tracked,label,value):
1523  self.__insertValue(tracked,label,value)
1524  def addInputTag(self,tracked,label,value):
1525  self.__insertValue(tracked,label,value)
1526  def addVInputTag(self,tracked,label,value):
1527  self.__insertValue(tracked,label,value)
1528  def addESInputTag(self,tracked,label,value):
1529  self.__insertValue(tracked,label,value)
1530  def addVESInputTag(self,tracked,label,value):
1531  self.__insertValue(tracked,label,value)
1532  def addEventID(self,tracked,label,value):
1533  self.__insertValue(tracked,label,value)
1534  def addVEventID(self,tracked,label,value):
1535  self.__insertValue(tracked,label,value)
1536  def addLuminosityBlockID(self,tracked,label,value):
1537  self.__insertValue(tracked,label,value)
1538  def addLuminosityBlockID(self,tracked,label,value):
1539  self.__insertValue(tracked,label,value)
1540  def addEventRange(self,tracked,label,value):
1541  self.__insertValue(tracked,label,value)
1542  def addVEventRange(self,tracked,label,value):
1543  self.__insertValue(tracked,label,value)
1544  def addPSet(self,tracked,label,value):
1545  self.__insertValue(tracked,label,value)
1546  def addVPSet(self,tracked,label,value):
1547  self.__insertValue(tracked,label,value)
1548  def addFileInPath(self,tracked,label,value):
1549  self.__insertValue(tracked,label,value)
1550  def newPSet(self):
1551  return TestMakePSet()
1552 
1553  class TestModuleCommand(unittest.TestCase):
1554  def setUp(self):
1555  """Nothing to do """
1556  None
1558  p = _Parameterizable()
1559  self.assertEqual(len(p.parameterNames_()),0)
1560  p.a = int32(1)
1561  self.assert_('a' in p.parameterNames_())
1562  self.assertEqual(p.a.value(), 1)
1563  p.a = 10
1564  self.assertEqual(p.a.value(), 10)
1565  p.a = untracked(int32(1))
1566  self.assertEqual(p.a.value(), 1)
1567  self.failIf(p.a.isTracked())
1568  p.a = untracked.int32(1)
1569  self.assertEqual(p.a.value(), 1)
1570  self.failIf(p.a.isTracked())
1571  p = _Parameterizable(foo=int32(10), bar = untracked(double(1.0)))
1572  self.assertEqual(p.foo.value(), 10)
1573  self.assertEqual(p.bar.value(),1.0)
1574  self.failIf(p.bar.isTracked())
1575  self.assertRaises(TypeError,setattr,(p,'c',1))
1576  p = _Parameterizable(a=PSet(foo=int32(10), bar = untracked(double(1.0))))
1577  self.assertEqual(p.a.foo.value(),10)
1578  self.assertEqual(p.a.bar.value(),1.0)
1579  p.b = untracked(PSet(fii = int32(1)))
1580  self.assertEqual(p.b.fii.value(),1)
1581  self.failIf(p.b.isTracked())
1582  #test the fact that values can be shared
1583  v = int32(10)
1584  p=_Parameterizable(a=v)
1585  v.setValue(11)
1586  self.assertEqual(p.a.value(),11)
1587  p.a = 12
1588  self.assertEqual(p.a.value(),12)
1589  self.assertEqual(v.value(),12)
1591  p = _TypedParameterizable("blah", b=int32(1))
1592  #see if copy works deeply
1593  other = p.copy()
1594  other.b = 2
1595  self.assertNotEqual(p.b,other.b)
1596 
1598  p = Process("test")
1599  p.a = EDAnalyzer("MyAnalyzer")
1600  self.assert_( 'a' in p.analyzers_() )
1601  self.assert_( 'a' in p.analyzers)
1602  p.add_(Service("MessageLogger"))
1603  self.assert_('MessageLogger' in p.services_())
1604  self.assertEqual(p.MessageLogger.type_(), "MessageLogger")
1605  p.Tracer = Service("Tracer")
1606  self.assert_('Tracer' in p.services_())
1607  self.assertRaises(TypeError, setattr, *(p,'b',"this should fail"))
1608  self.assertRaises(TypeError, setattr, *(p,'bad',Service("MessageLogger")))
1609  self.assertRaises(ValueError, setattr, *(p,'bad',Source("PoolSource")))
1610  p.out = OutputModule("Outer")
1611  self.assertEqual(p.out.type_(), 'Outer')
1612  self.assert_( 'out' in p.outputModules_() )
1613 
1614  p.geom = ESSource("GeomProd")
1615  self.assert_('geom' in p.es_sources_())
1616  p.add_(ESSource("ConfigDB"))
1617  self.assert_('ConfigDB' in p.es_sources_())
1618 
1619  p.aliasfoo1 = EDAlias(foo1 = VPSet(PSet(type = string("Foo1"))))
1620  self.assert_('aliasfoo1' in p.aliases_())
1621 
1623  class FromArg(object):
1624  def __init__(self,*arg,**args):
1625  for name in args.iterkeys():
1626  self.__dict__[name]=args[name]
1627 
1628  a=EDAnalyzer("MyAnalyzer")
1629  t=EDAnalyzer("MyAnalyzer")
1630  t.setLabel("foo")
1631  s1 = Sequence(a)
1632  s2 = Sequence(s1)
1633  s3 = Sequence(s2)
1634  d = FromArg(
1635  a=a,
1636  b=Service("Full"),
1637  c=Path(a),
1638  d=s2,
1639  e=s1,
1640  f=s3,
1641  g=Sequence(s1+s2+s3)
1642  )
1643  p = Process("Test")
1644  p.extend(d)
1645  self.assertEqual(p.a.type_(),"MyAnalyzer")
1646  self.assertEqual(p.a.label_(),"a")
1647  self.assertRaises(AttributeError,getattr,p,'b')
1648  self.assertEqual(p.Full.type_(),"Full")
1649  self.assertEqual(str(p.c),'a')
1650  self.assertEqual(str(p.d),'a')
1651 
1652  z1 = FromArg(
1653  a=a,
1654  b=Service("Full"),
1655  c=Path(a),
1656  d=s2,
1657  e=s1,
1658  f=s3,
1659  s4=s3,
1660  g=Sequence(s1+s2+s3)
1661  )
1662 
1663  p1 = Process("Test")
1664  #p1.extend(z1)
1665  self.assertRaises(ValueError, p1.extend, z1)
1666 
1667  z2 = FromArg(
1668  a=a,
1669  b=Service("Full"),
1670  c=Path(a),
1671  d=s2,
1672  e=s1,
1673  f=s3,
1674  aaa=copy.deepcopy(a),
1675  s4=copy.deepcopy(s3),
1676  g=Sequence(s1+s2+s3),
1677  t=t
1678  )
1679  p2 = Process("Test")
1680  p2.extend(z2)
1681  #self.assertRaises(ValueError, p2.extend, z2)
1682  self.assertEqual(p2.s4.label_(),"s4")
1683  #p2.s4.setLabel("foo")
1684  self.assertRaises(ValueError, p2.s4.setLabel, "foo")
1685  p2.s4.setLabel("s4")
1686  p2.s4.setLabel(None)
1687  p2.s4.setLabel("foo")
1688  p2._Process__setObjectLabel(p2.s4, "foo")
1689  p2._Process__setObjectLabel(p2.s4, None)
1690  p2._Process__setObjectLabel(p2.s4, "bar")
1691 
1693  p = Process("test")
1694  p.a = EDAnalyzer("MyAnalyzer")
1695  p.p = Path(p.a)
1696  p.s = Sequence(p.a)
1697  p.r = Sequence(p.s)
1698  p.p2 = Path(p.s)
1699  p.schedule = Schedule(p.p2,p.p)
1700  d=p.dumpPython()
1701  self.assertEqual(d,
1702 """import FWCore.ParameterSet.Config as cms
1703 
1704 process = cms.Process("test")
1705 
1706 process.a = cms.EDAnalyzer("MyAnalyzer")
1707 
1708 
1709 process.s = cms.Sequence(process.a)
1710 
1711 
1712 process.r = cms.Sequence(process.s)
1713 
1714 
1715 process.p = cms.Path(process.a)
1716 
1717 
1718 process.p2 = cms.Path(process.s)
1719 
1720 
1721 process.schedule = cms.Schedule(*[ process.p2, process.p ])
1722 """)
1723  #Reverse order of 'r' and 's'
1724  p = Process("test")
1725  p.a = EDAnalyzer("MyAnalyzer")
1726  p.p = Path(p.a)
1727  p.r = Sequence(p.a)
1728  p.s = Sequence(p.r)
1729  p.p2 = Path(p.r)
1730  p.schedule = Schedule(p.p2,p.p)
1731  p.b = EDAnalyzer("YourAnalyzer")
1732  d=p.dumpPython()
1733  self.assertEqual(d,
1734 """import FWCore.ParameterSet.Config as cms
1735 
1736 process = cms.Process("test")
1737 
1738 process.a = cms.EDAnalyzer("MyAnalyzer")
1739 
1740 
1741 process.b = cms.EDAnalyzer("YourAnalyzer")
1742 
1743 
1744 process.r = cms.Sequence(process.a)
1745 
1746 
1747 process.s = cms.Sequence(process.r)
1748 
1749 
1750 process.p = cms.Path(process.a)
1751 
1752 
1753 process.p2 = cms.Path(process.r)
1754 
1755 
1756 process.schedule = cms.Schedule(*[ process.p2, process.p ])
1757 """)
1758  #use an anonymous sequence
1759  p = Process("test")
1760  p.a = EDAnalyzer("MyAnalyzer")
1761  p.p = Path(p.a)
1762  s = Sequence(p.a)
1763  p.r = Sequence(s)
1764  p.p2 = Path(p.r)
1765  p.schedule = Schedule(p.p2,p.p)
1766  d=p.dumpPython()
1767  self.assertEqual(d,
1768  """import FWCore.ParameterSet.Config as cms
1769 
1770 process = cms.Process("test")
1771 
1772 process.a = cms.EDAnalyzer("MyAnalyzer")
1773 
1774 
1775 process.r = cms.Sequence((process.a))
1776 
1777 
1778 process.p = cms.Path(process.a)
1779 
1780 
1781 process.p2 = cms.Path(process.r)
1782 
1783 
1784 process.schedule = cms.Schedule(*[ process.p2, process.p ])
1785 """)
1786 
1787  # include some tasks
1788  p = Process("test")
1789  p.a = EDAnalyzer("MyAnalyzer")
1790  p.b = EDProducer("bProducer")
1791  p.c = EDProducer("cProducer")
1792  p.d = EDProducer("dProducer")
1793  p.e = EDProducer("eProducer")
1794  p.f = EDProducer("fProducer")
1795  p.g = EDProducer("gProducer")
1796  p.task5 = Task()
1797  p.task3 = Task()
1798  p.task2 = Task(p.c, p.task3)
1799  p.task4 = Task(p.f, p.task2)
1800  p.task1 = Task(p.task5)
1801  p.task3.add(p.task1)
1802  p.p = Path(p.a)
1803  s = Sequence(p.a)
1804  p.r = Sequence(s)
1805  p.p2 = Path(p.r, p.task1, p.task2)
1806  p.schedule = Schedule(p.p2,p.p,tasks=[p.task3,p.task4, p.task5])
1807  d=p.dumpPython()
1808  self.assertEqual(d,
1809  """import FWCore.ParameterSet.Config as cms
1810 
1811 process = cms.Process("test")
1812 
1813 process.b = cms.EDProducer("bProducer")
1814 
1815 
1816 process.c = cms.EDProducer("cProducer")
1817 
1818 
1819 process.d = cms.EDProducer("dProducer")
1820 
1821 
1822 process.e = cms.EDProducer("eProducer")
1823 
1824 
1825 process.f = cms.EDProducer("fProducer")
1826 
1827 
1828 process.g = cms.EDProducer("gProducer")
1829 
1830 
1831 process.a = cms.EDAnalyzer("MyAnalyzer")
1832 
1833 
1834 process.task5 = cms.Task()
1835 
1836 
1837 process.task1 = cms.Task(process.task5)
1838 
1839 
1840 process.task3 = cms.Task(process.task1)
1841 
1842 
1843 process.task2 = cms.Task(process.c, process.task3)
1844 
1845 
1846 process.task4 = cms.Task(process.f, process.task2)
1847 
1848 
1849 process.r = cms.Sequence((process.a))
1850 
1851 
1852 process.p = cms.Path(process.a)
1853 
1854 
1855 process.p2 = cms.Path(process.r, process.task1, process.task2)
1856 
1857 
1858 process.schedule = cms.Schedule(*[ process.p2, process.p ], tasks=[process.task3, process.task4, process.task5])
1859 """)
1860  # only tasks
1861  p = Process("test")
1862  p.d = EDProducer("dProducer")
1863  p.e = EDProducer("eProducer")
1864  p.f = EDProducer("fProducer")
1865  p.g = EDProducer("gProducer")
1866  p.task1 = Task(p.d, p.e)
1867  task2 = Task(p.f, p.g)
1868  p.schedule = Schedule(tasks=[p.task1,task2])
1869  d=p.dumpPython()
1870  self.assertEqual(d,
1871  """import FWCore.ParameterSet.Config as cms
1872 
1873 process = cms.Process("test")
1874 
1875 process.d = cms.EDProducer("dProducer")
1876 
1877 
1878 process.e = cms.EDProducer("eProducer")
1879 
1880 
1881 process.f = cms.EDProducer("fProducer")
1882 
1883 
1884 process.g = cms.EDProducer("gProducer")
1885 
1886 
1887 process.task1 = cms.Task(process.d, process.e)
1888 
1889 
1890 process.schedule = cms.Schedule(tasks=[cms.Task(process.f, process.g), process.task1])
1891 """)
1892  # empty schedule
1893  p = Process("test")
1894  p.schedule = Schedule()
1895  d=p.dumpPython()
1896  self.assertEqual(d,
1897  """import FWCore.ParameterSet.Config as cms
1898 
1899 process = cms.Process("test")
1900 
1901 process.schedule = cms.Schedule()
1902 """)
1903 
1904  s = Sequence()
1905  a = EDProducer("A")
1906  s2 = Sequence(a)
1907  s2 += s
1908  process = Process("DUMP")
1909  process.a = a
1910  process.s2 = s2
1911  d=process.dumpPython()
1912  self.assertEqual(d,
1913  """import FWCore.ParameterSet.Config as cms
1914 
1915 process = cms.Process("DUMP")
1916 
1917 process.a = cms.EDProducer("A")
1918 
1919 
1920 process.s2 = cms.Sequence(process.a)
1921 
1922 
1923 """)
1924  s = Sequence()
1925  s1 = Sequence(s)
1926  a = EDProducer("A")
1927  s3 = Sequence(a+a)
1928  s2 = Sequence(a+s3)
1929  s2 += s1
1930  process = Process("DUMP")
1931  process.a = a
1932  process.s2 = s2
1933  d=process.dumpPython()
1934  self.assertEqual(d,
1935  """import FWCore.ParameterSet.Config as cms
1936 
1937 process = cms.Process("DUMP")
1938 
1939 process.a = cms.EDProducer("A")
1940 
1941 
1942 process.s2 = cms.Sequence(process.a+(process.a+process.a))
1943 
1944 
1945 """)
1946 
1947  def testSecSource(self):
1948  p = Process('test')
1949  p.a = SecSource("MySecSource")
1950  self.assertEqual(p.dumpPython().replace('\n',''),'import FWCore.ParameterSet.Config as cmsprocess = cms.Process("test")process.a = cms.SecSource("MySecSource")')
1951 
1953  p = Process('test')
1954  p.a = EDAnalyzer("MyAnalyzer")
1955  old = p.a
1956  p.b = EDAnalyzer("YourAnalyzer")
1957  p.c = EDAnalyzer("OurAnalyzer")
1958  p.d = EDProducer("MyProducer")
1959  old2 = p.d
1960  p.t1 = Task(p.d)
1961  t2 = Task(p.d)
1962  t3 = Task(p.d)
1963  t4 = Task(p.d)
1964  t5 = Task(p.d)
1965  t6 = Task(p.d)
1966  s = Sequence(p.a*p.b)
1967  p.s4 = Sequence(p.a*p.b)
1968  s.associate(t2)
1969  p.s4.associate(t2)
1970  p.p = Path(p.c+s+p.a)
1971  p.e3 = EndPath(p.c+s+p.a)
1972  new = EDAnalyzer("NewAnalyzer")
1973  new2 = EDProducer("NewProducer")
1974  visitor1 = NodeVisitor()
1975  p.p.visit(visitor1)
1976  self.assertTrue(visitor1.modules == set([old,old2,p.b,p.c]))
1977  p.schedule = Schedule(tasks=[t6])
1978  p.globalReplace("a",new)
1979  p.globalReplace("d",new2)
1980  visitor2 = NodeVisitor()
1981  p.p.visit(visitor2)
1982  self.assertTrue(visitor2.modules == set([new,new2,p.b,p.c]))
1983  visitor3 = NodeVisitor()
1984  p.e3.visit(visitor3)
1985  self.assertTrue(visitor3.modules == set([new,new2,p.b,p.c]))
1986  visitor4 = NodeVisitor()
1987  p.s4.visit(visitor4)
1988  self.assertTrue(visitor4.modules == set([new,new2,p.b]))
1989  visitor5 = NodeVisitor()
1990  p.t1.visit(visitor5)
1991  self.assertTrue(visitor5.modules == set([new2]))
1992  visitor6 = NodeVisitor()
1993  listOfTasks = list(p.schedule._tasks)
1994  listOfTasks[0].visit(visitor6)
1995  self.assertTrue(visitor6.modules == set([new2]))
1996 
1997  def testSequence(self):
1998  p = Process('test')
1999  p.a = EDAnalyzer("MyAnalyzer")
2000  p.b = EDAnalyzer("YourAnalyzer")
2001  p.c = EDAnalyzer("OurAnalyzer")
2002  p.s = Sequence(p.a*p.b)
2003  self.assertEqual(str(p.s),'a+b')
2004  self.assertEqual(p.s.label_(),'s')
2005  path = Path(p.c+p.s)
2006  self.assertEqual(str(path),'c+a+b')
2007  p._validateSequence(path, 'p1')
2008  notInProcess = EDAnalyzer('NotInProcess')
2009  p2 = Path(p.c+p.s*notInProcess)
2010  self.assertRaises(RuntimeError, p._validateSequence, p2, 'p2')
2011 
2012  def testSequence2(self):
2013  p = Process('test')
2014  p.a = EDAnalyzer("MyAnalyzer")
2015  p.b = EDAnalyzer("YourAnalyzer")
2016  p.c = EDAnalyzer("OurAnalyzer")
2017  testseq = Sequence(p.a*p.b)
2018  p.s = testseq
2019  #p.y = testseq
2020  self.assertRaises(ValueError, p.__setattr__, "y", testseq)
2021 
2023  service = Service("d")
2024  self.assertFalse(service._inProcess)
2025  process = Process("test")
2026  process.d = service
2027  self.assertTrue(service._inProcess)
2028  service2 = Service("d")
2029  process.d = service2
2030  self.assertFalse(service._inProcess)
2031  self.assertTrue(service2._inProcess)
2032  del process.d
2033  self.assertFalse(service2._inProcess)
2034 
2035  def testTask(self):
2036 
2037  # create some objects to use in tests
2038  edanalyzer = EDAnalyzer("a")
2039  edproducer = EDProducer("b")
2040  edproducer2 = EDProducer("b2")
2041  edproducer3 = EDProducer("b3")
2042  edproducer4 = EDProducer("b4")
2043  edproducer8 = EDProducer("b8")
2044  edproducer9 = EDProducer("b9")
2045  edfilter = EDFilter("c")
2046  service = Service("d")
2047  service3 = Service("d")
2048  essource = ESSource("e")
2049  esproducer = ESProducer("f")
2050  testTask2 = Task()
2051 
2052  # test adding things to Tasks
2053  testTask1 = Task(edproducer, edfilter)
2054  self.assertRaises(RuntimeError, testTask1.add, edanalyzer)
2055  testTask1.add(essource, service)
2056  testTask1.add(essource, esproducer)
2057  testTask1.add(testTask2)
2058  coll = testTask1._collection
2059  self.assertTrue(edproducer in coll)
2060  self.assertTrue(edfilter in coll)
2061  self.assertTrue(service in coll)
2062  self.assertTrue(essource in coll)
2063  self.assertTrue(esproducer in coll)
2064  self.assertTrue(testTask2 in coll)
2065  self.assertTrue(len(coll) == 6)
2066  self.assertTrue(len(testTask2._collection) == 0)
2067 
2068  taskContents = []
2069  for i in testTask1:
2070  taskContents.append(i)
2071  self.assertTrue(taskContents == [edproducer, edfilter, essource, service, esproducer, testTask2])
2072 
2073  # test attaching Task to Process
2074  process = Process("test")
2075 
2076  process.mproducer = edproducer
2077  process.mproducer2 = edproducer2
2078  process.mfilter = edfilter
2079  process.messource = essource
2080  process.mesproducer = esproducer
2081  process.d = service
2082 
2083  testTask3 = Task(edproducer, edproducer2)
2084  testTask1.add(testTask3)
2085  process.myTask1 = testTask1
2086 
2087  # test the validation that occurs when attaching a Task to a Process
2088  # first a case that passes, then one the fails on an EDProducer
2089  # then one that fails on a service
2090  l = set()
2091  visitor = NodeNameVisitor(l)
2092  testTask1.visit(visitor)
2093  self.assertTrue(l == set(['mesproducer', 'mproducer', 'mproducer2', 'mfilter', 'd', 'messource']))
2094  l2 = testTask1.moduleNames
2095  self.assertTrue(l == set(['mesproducer', 'mproducer', 'mproducer2', 'mfilter', 'd', 'messource']))
2096 
2097  testTask4 = Task(edproducer3)
2098  l.clear()
2099  self.assertRaises(RuntimeError, testTask4.visit, visitor)
2100  try:
2101  process.myTask4 = testTask4
2102  self.assertTrue(False)
2103  except RuntimeError:
2104  pass
2105 
2106  testTask5 = Task(service3)
2107  l.clear()
2108  self.assertRaises(RuntimeError, testTask5.visit, visitor)
2109  try:
2110  process.myTask5 = testTask5
2111  self.assertTrue(False)
2112  except RuntimeError:
2113  pass
2114 
2115  process.d = service3
2116  process.myTask5 = testTask5
2117 
2118  # test placement into the Process and the tasks property
2119  expectedDict = { 'myTask1' : testTask1, 'myTask5' : testTask5 }
2120  expectedFixedDict = DictTypes.FixedKeysDict(expectedDict);
2121  self.assertTrue(process.tasks == expectedFixedDict)
2122  self.assertTrue(process.tasks['myTask1'] == testTask1)
2123  self.assertTrue(process.myTask1 == testTask1)
2124 
2125  # test replacing an EDProducer in a Task when calling __settattr__
2126  # for the EDProducer on the Process.
2127  process.mproducer2 = edproducer4
2128  process.d = service
2129  l = list()
2130  visitor1 = ModuleNodeVisitor(l)
2131  testTask1.visit(visitor1)
2132  l.sort()
2133  expectedList = [edproducer,essource,esproducer,service,edfilter,edproducer,edproducer4]
2134  expectedList.sort()
2135  self.assertTrue(expectedList == l)
2136 
2137  process.myTask6 = Task()
2138  process.myTask7 = Task()
2139  process.mproducer8 = edproducer8
2140  process.myTask8 = Task(process.mproducer8)
2141  process.myTask6.add(process.myTask7)
2142  process.myTask7.add(process.myTask8)
2143  process.myTask1.add(process.myTask6)
2144  process.myTask8.add(process.myTask5)
2145 
2146  testDict = process._itemsInDependencyOrder(process.tasks)
2147  expectedLabels = ["myTask5", "myTask8", "myTask7", "myTask6", "myTask1"]
2148  expectedTasks = [process.myTask5, process.myTask8, process.myTask7, process.myTask6, process.myTask1]
2149  index = 0
2150  for testLabel, testTask in testDict.items():
2151  self.assertTrue(testLabel == expectedLabels[index])
2152  self.assertTrue(testTask == expectedTasks[index])
2153  index += 1
2154 
2155  pythonDump = testTask1.dumpPython(PrintOptions())
2156 
2157 
2158  expectedPythonDump = 'cms.Task(process.d, process.mesproducer, process.messource, process.mfilter, process.mproducer, process.mproducer2, process.myTask6)\n'
2159  self.assertTrue(pythonDump == expectedPythonDump)
2160 
2161  process.myTask5 = Task()
2162  process.myTask100 = Task()
2163  process.mproducer9 = edproducer9
2164  sequence1 = Sequence(process.mproducer8, process.myTask1, process.myTask5, testTask2, testTask3)
2165  sequence2 = Sequence(process.mproducer8 + process.mproducer9)
2166  process.sequence3 = Sequence((process.mproducer8 + process.mfilter))
2167  sequence4 = Sequence()
2168  process.path1 = Path(process.mproducer+process.mproducer8+sequence1+sequence2+process.sequence3+sequence4)
2169  process.path1.associate(process.myTask1, process.myTask5, testTask2, testTask3)
2170  process.path11 = Path(process.mproducer+process.mproducer8+sequence1+sequence2+process.sequence3+ sequence4,process.myTask1, process.myTask5, testTask2, testTask3, process.myTask100)
2171  process.path2 = Path(process.mproducer)
2172  process.path3 = Path(process.mproducer9+process.mproducer8,testTask2)
2173 
2174  self.assertTrue(process.path1.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer+process.mproducer8+cms.Sequence(process.mproducer8, cms.Task(), cms.Task(process.None, process.mproducer), process.myTask1, process.myTask5)+(process.mproducer8+process.mproducer9)+process.sequence3, cms.Task(), cms.Task(process.None, process.mproducer), process.myTask1, process.myTask5)\n')
2175 
2176  self.assertTrue(process.path11.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer+process.mproducer8+cms.Sequence(process.mproducer8, cms.Task(), cms.Task(process.None, process.mproducer), process.myTask1, process.myTask5)+(process.mproducer8+process.mproducer9)+process.sequence3, cms.Task(), cms.Task(process.None, process.mproducer), process.myTask1, process.myTask100, process.myTask5)\n')
2177 
2178  # test NodeNameVisitor and moduleNames
2179  l = set()
2180  nameVisitor = NodeNameVisitor(l)
2181  process.path1.visit(nameVisitor)
2182  self.assertTrue(l == set(['mproducer', 'd', 'mesproducer', None, 'mproducer9', 'mproducer8', 'messource', 'mproducer2', 'mfilter']))
2183  self.assertTrue(process.path1.moduleNames() == set(['mproducer', 'd', 'mesproducer', None, 'mproducer9', 'mproducer8', 'messource', 'mproducer2', 'mfilter']))
2184 
2185  # test copy
2186  process.mproducer10 = EDProducer("b10")
2187  process.path21 = process.path11.copy()
2188  process.path21.replace(process.mproducer, process.mproducer10)
2189 
2190  self.assertTrue(process.path11.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer+process.mproducer8+cms.Sequence(process.mproducer8, cms.Task(), cms.Task(process.None, process.mproducer), process.myTask1, process.myTask5)+(process.mproducer8+process.mproducer9)+process.sequence3, cms.Task(), cms.Task(process.None, process.mproducer), process.myTask1, process.myTask100, process.myTask5)\n')
2191 
2192  # Some peculiarities of the way things work show up here. dumpPython sorts tasks and
2193  # removes duplication at the level of strings. The Task and Sequence objects themselves
2194  # remove duplicate tasks in their contents if the instances are the same (exact same python
2195  # object id which is not the same as the string representation being the same).
2196  # Also note that the mutating visitor replaces sequences and tasks that have
2197  # modified contents with their modified contents, it does not modify the sequence
2198  # or task itself.
2199  self.assertTrue(process.path21.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer10+process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.sequence3, cms.Task(), cms.Task(process.None, process.mproducer10), cms.Task(process.d, process.mesproducer, process.messource, process.mfilter, process.mproducer10, process.mproducer2, process.myTask6), process.myTask100, process.myTask5)\n')
2200 
2201  process.path22 = process.path21.copyAndExclude([process.d, process.mesproducer, process.mfilter])
2202  self.assertTrue(process.path22.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer10+process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.mproducer8, cms.Task(), cms.Task(process.None, process.mproducer10), cms.Task(process.messource, process.mproducer10, process.mproducer2, process.myTask6), process.myTask100, process.myTask5)\n')
2203 
2204  process.path23 = process.path22.copyAndExclude([process.messource, process.mproducer10])
2205  self.assertTrue(process.path23.dumpPython(PrintOptions()) == 'cms.Path(process.mproducer8+process.mproducer8+(process.mproducer8+process.mproducer9)+process.mproducer8, cms.Task(), cms.Task(process.None), cms.Task(process.mproducer2, process.myTask6), process.myTask100, process.myTask5)\n')
2206 
2207  process.a = EDAnalyzer("MyAnalyzer")
2208  process.b = OutputModule("MyOutputModule")
2209  process.c = EDFilter("MyFilter")
2210  process.d = EDProducer("MyProducer")
2211  process.e = ESProducer("MyESProducer")
2212  process.f = ESSource("MyESSource")
2213  process.g = ESProducer("g")
2214  process.path24 = Path(process.a+process.b+process.c+process.d)
2215  process.path25 = process.path24.copyAndExclude([process.a,process.b,process.c])
2216  self.assertTrue(process.path25.dumpPython(None) == 'cms.Path(process.d)\n')
2217  #print process.path3
2218  #print process.dumpPython()
2219 
2220  process.path200 = EndPath(Sequence(process.c,Task(process.e)))
2221  process.path200.replace(process.c,process.b)
2222  process.path200.replace(process.e,process.f)
2223  self.assertEqual(process.path200.dumpPython(None), "cms.EndPath(process.b, cms.Task(process.f))\n")
2224  process.path200.replace(process.b,process.c)
2225  process.path200.replace(process.f,process.e)
2226  self.assertEqual(process.path200.dumpPython(None), "cms.EndPath(process.c, cms.Task(process.e))\n")
2227  process.path200.replace(process.c,process.a)
2228  process.path200.replace(process.e,process.g)
2229  self.assertEqual(process.path200.dumpPython(None), "cms.EndPath(process.a, cms.Task(process.g))\n")
2230  process.path200.replace(process.a,process.c)
2231  process.path200.replace(process.g,process.e)
2232  self.assertEqual(process.path200.dumpPython(None), "cms.EndPath(process.c, cms.Task(process.e))\n")
2233 
2234 
2235  def testPath(self):
2236  p = Process("test")
2237  p.a = EDAnalyzer("MyAnalyzer")
2238  p.b = EDAnalyzer("YourAnalyzer")
2239  p.c = EDAnalyzer("OurAnalyzer")
2240  path = Path(p.a)
2241  path *= p.b
2242  path += p.c
2243  self.assertEqual(str(path),'a+b+c')
2244  path = Path(p.a*p.b+p.c)
2245  self.assertEqual(str(path),'a+b+c')
2246 # path = Path(p.a)*p.b+p.c #This leads to problems with sequences
2247 # self.assertEqual(str(path),'((a*b)+c)')
2248  path = Path(p.a+ p.b*p.c)
2249  self.assertEqual(str(path),'a+b+c')
2250  path = Path(p.a*(p.b+p.c))
2251  self.assertEqual(str(path),'a+b+c')
2252  path = Path(p.a*(p.b+~p.c))
2253  pathx = Path(p.a*(p.b+ignore(p.c)))
2254  self.assertEqual(str(path),'a+b+~c')
2255  p.es = ESProducer("AnESProducer")
2256  self.assertRaises(TypeError,Path,p.es)
2257 
2258  t = Path()
2259  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path()\n')
2260 
2261  t = Path(p.a)
2262  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path(process.a)\n')
2263 
2264  t = Path(Task())
2265  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path(cms.Task())\n')
2266 
2267  t = Path(p.a, Task())
2268  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path(process.a, cms.Task())\n')
2269 
2270  p.prod = EDProducer("prodName")
2271  p.t1 = Task(p.prod)
2272  t = Path(p.a, p.t1, Task(), p.t1)
2273  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path(process.a, cms.Task(), process.t1)\n')
2274 
2276  p = Process("test")
2277  a = EDAnalyzer("MyAnalyzer")
2278  p.a = a
2279  a.setLabel("a")
2280  b = EDAnalyzer("YOurAnalyzer")
2281  p.b = b
2282  b.setLabel("b")
2283  path = Path(a * b)
2284  p.path = Path(p.a*p.b)
2285  lookuptable = {id(a): p.a, id(b): p.b}
2286  #self.assertEqual(str(path),str(path._postProcessFixup(lookuptable)))
2287  #lookuptable = p._cloneToObjectDict
2288  #self.assertEqual(str(path),str(path._postProcessFixup(lookuptable)))
2289  self.assertEqual(str(path),str(p.path))
2290 
2291  def testContains(self):
2292 
2293  a = EDProducer("a")
2294  b = EDProducer("b")
2295  c = EDProducer("c")
2296  d = EDProducer("d")
2297  e = EDProducer("e")
2298  f = EDProducer("f")
2299  g = EDProducer("g")
2300  h = EDProducer("h")
2301  i = EDProducer("i")
2302  j = EDProducer("j")
2303  k = EDProducer("k")
2304  l = EDProducer("l")
2305  m = EDProducer("m")
2306  n = EDProducer("n")
2307 
2308  seq1 = Sequence(e)
2309  task1 = Task(g)
2310  path = Path(a * c * seq1, task1)
2311 
2312  self.assertTrue(path.contains(a))
2313  self.assertFalse(path.contains(b))
2314  self.assertTrue(path.contains(c))
2315  self.assertFalse(path.contains(d))
2316  self.assertTrue(path.contains(e))
2317  self.assertFalse(path.contains(f))
2318  self.assertTrue(path.contains(g))
2319 
2320  endpath = EndPath(h * i)
2321  self.assertFalse(endpath.contains(b))
2322  self.assertTrue(endpath.contains(i))
2323 
2324  seq = Sequence(a * c)
2325  self.assertFalse(seq.contains(b))
2326  self.assertTrue(seq.contains(c))
2327 
2328  task2 = Task(l)
2329  task = Task(j, k, task2)
2330  self.assertFalse(task.contains(b))
2331  self.assertTrue(task.contains(j))
2332  self.assertTrue(task.contains(k))
2333  self.assertTrue(task.contains(l))
2334 
2335  task3 = Task(m)
2336  path2 = Path(n)
2337  sch = Schedule(path, path2, tasks=[task,task3])
2338  self.assertFalse(sch.contains(b))
2339  self.assertTrue(sch.contains(a))
2340  self.assertTrue(sch.contains(c))
2341  self.assertTrue(sch.contains(e))
2342  self.assertTrue(sch.contains(g))
2343  self.assertTrue(sch.contains(n))
2344  self.assertTrue(sch.contains(j))
2345  self.assertTrue(sch.contains(k))
2346  self.assertTrue(sch.contains(l))
2347  self.assertTrue(sch.contains(m))
2348 
2349  def testSchedule(self):
2350  p = Process("test")
2351  p.a = EDAnalyzer("MyAnalyzer")
2352  p.b = EDAnalyzer("YourAnalyzer")
2353  p.c = EDAnalyzer("OurAnalyzer")
2354  p.d = EDAnalyzer("OurAnalyzer")
2355  p.path1 = Path(p.a)
2356  p.path2 = Path(p.b)
2357  p.path3 = Path(p.d)
2358 
2359  s = Schedule(p.path1,p.path2)
2360  self.assertEqual(s[0],p.path1)
2361  self.assertEqual(s[1],p.path2)
2362  p.schedule = s
2363  self.assert_('b' in p.schedule.moduleNames())
2364  self.assert_(hasattr(p, 'b'))
2365  self.assert_(hasattr(p, 'c'))
2366  self.assert_(hasattr(p, 'd'))
2367  self.assert_(hasattr(p, 'path1'))
2368  self.assert_(hasattr(p, 'path2'))
2369  self.assert_(hasattr(p, 'path3'))
2370  p.prune()
2371  self.assert_('b' in p.schedule.moduleNames())
2372  self.assert_(hasattr(p, 'b'))
2373  self.assert_(not hasattr(p, 'c'))
2374  self.assert_(not hasattr(p, 'd'))
2375  self.assert_(hasattr(p, 'path1'))
2376  self.assert_(hasattr(p, 'path2'))
2377  self.assert_(not hasattr(p, 'path3'))
2378 
2379  self.assertTrue(len(p.schedule._tasks) == 0)
2380 
2381  p = Process("test")
2382  p.a = EDAnalyzer("MyAnalyzer")
2383  p.b = EDAnalyzer("YourAnalyzer")
2384  p.c = EDAnalyzer("OurAnalyzer")
2385  p.d = EDAnalyzer("dAnalyzer")
2386  p.e = EDProducer("eProducer")
2387  p.f = EDProducer("fProducer")
2388  p.Tracer = Service("Tracer")
2389  p.path1 = Path(p.a)
2390  p.path2 = Path(p.b)
2391  p.path3 = Path(p.d)
2392  p.task1 = Task(p.e)
2393  p.task2 = Task(p.f, p.Tracer)
2394  s = Schedule(p.path1,p.path2,tasks=[p.task1,p.task2,p.task1])
2395  self.assertEqual(s[0],p.path1)
2396  self.assertEqual(s[1],p.path2)
2397  self.assertTrue(len(s._tasks) == 2)
2398  self.assertTrue(p.task1 in s._tasks)
2399  self.assertTrue(p.task2 in s._tasks)
2400  listOfTasks = list(s._tasks)
2401  self.assertTrue(len(listOfTasks) == 2)
2402  self.assertTrue(p.task1 == listOfTasks[0])
2403  self.assertTrue(p.task2 == listOfTasks[1])
2404  p.schedule = s
2405  self.assert_('b' in p.schedule.moduleNames())
2406 
2407  process2 = Process("test")
2408  process2.a = EDAnalyzer("MyAnalyzer")
2409  process2.e = EDProducer("eProducer")
2410  process2.path1 = Path(process2.a)
2411  process2.task1 = Task(process2.e)
2412  process2.schedule = Schedule(process2.path1,tasks=process2.task1)
2413  listOfTasks = list(process2.schedule._tasks)
2414  self.assertTrue(listOfTasks[0] == process2.task1)
2415 
2416  # test Schedule copy
2417  s2 = s.copy()
2418  self.assertEqual(s2[0],p.path1)
2419  self.assertEqual(s2[1],p.path2)
2420  self.assertTrue(len(s2._tasks) == 2)
2421  self.assertTrue(p.task1 in s2._tasks)
2422  self.assertTrue(p.task2 in s2._tasks)
2423  listOfTasks = list(s2._tasks)
2424  self.assertTrue(len(listOfTasks) == 2)
2425  self.assertTrue(p.task1 == listOfTasks[0])
2426  self.assertTrue(p.task2 == listOfTasks[1])
2427 
2428  names = s.moduleNames()
2429  self.assertTrue(names == set(['a', 'b', 'e', 'Tracer', 'f']))
2430  #adding a path not attached to the Process should cause an exception
2431  p = Process("test")
2432  p.a = EDAnalyzer("MyAnalyzer")
2433  path1 = Path(p.a)
2434  s = Schedule(path1)
2435  self.assertRaises(RuntimeError, lambda : p.setSchedule_(s) )
2436 
2437  #make sure anonymous sequences work
2438  p = Process("test")
2439  p.a = EDAnalyzer("MyAnalyzer")
2440  p.b = EDAnalyzer("MyOtherAnalyzer")
2441  p.c = EDProducer("MyProd")
2442  path1 = Path(p.c*Sequence(p.a+p.b))
2443  s = Schedule(path1)
2444  self.assert_('a' in s.moduleNames())
2445  self.assert_('b' in s.moduleNames())
2446  self.assert_('c' in s.moduleNames())
2447  p.path1 = path1
2448  p.schedule = s
2449  p.prune()
2450  self.assert_('a' in s.moduleNames())
2451  self.assert_('b' in s.moduleNames())
2452  self.assert_('c' in s.moduleNames())
2453 
2455  p = Process("test")
2456  p.a = EDAnalyzer("MyAnalyzer")
2457  p.b = EDAnalyzer("YourAnalyzer")
2458  p.c = EDAnalyzer("OurAnalyzer")
2459  p.path1 = Path(p.a)
2460  p.path2 = Path(p.b)
2461  self.assert_(p.schedule is None)
2462  pths = p.paths
2463  keys = pths.keys()
2464  self.assertEqual(pths[keys[0]],p.path1)
2465  self.assertEqual(pths[keys[1]],p.path2)
2466  p.prune()
2467  self.assert_(hasattr(p, 'a'))
2468  self.assert_(hasattr(p, 'b'))
2469  self.assert_(not hasattr(p, 'c'))
2470  self.assert_(hasattr(p, 'path1'))
2471  self.assert_(hasattr(p, 'path2'))
2472 
2473 
2474  p = Process("test")
2475  p.a = EDAnalyzer("MyAnalyzer")
2476  p.b = EDAnalyzer("YourAnalyzer")
2477  p.c = EDAnalyzer("OurAnalyzer")
2478  p.path2 = Path(p.b)
2479  p.path1 = Path(p.a)
2480  self.assert_(p.schedule is None)
2481  pths = p.paths
2482  keys = pths.keys()
2483  self.assertEqual(pths[keys[1]],p.path1)
2484  self.assertEqual(pths[keys[0]],p.path2)
2485 
2486 
2487  def testUsing(self):
2488  p = Process('test')
2489  p.block = PSet(a = int32(1))
2490  p.modu = EDAnalyzer('Analyzer', p.block, b = int32(2))
2491  self.assertEqual(p.modu.a.value(),1)
2492  self.assertEqual(p.modu.b.value(),2)
2493 
2494  def testOverride(self):
2495  p = Process('test')
2496  a = EDProducer("A", a1=int32(0))
2497  self.assert_(not a.isModified())
2498  a.a1 = 1
2499  self.assert_(a.isModified())
2500  p.a = a
2501  self.assertEqual(p.a.a1.value(), 1)
2502  # try adding an unmodified module.
2503  # should accept it
2504  p.a = EDProducer("A", a1=int32(2))
2505  self.assertEqual(p.a.a1.value(), 2)
2506  # try adding a modified module. Should throw
2507  # no longer, since the same (modified) say, geometry
2508  # could come from more than one cff
2509  b = EDProducer("A", a1=int32(3))
2510  b.a1 = 4
2511  #self.assertRaises(RuntimeError, setattr, *(p,'a',b))
2512  ps1 = PSet(a = int32(1))
2513  ps2 = PSet(a = int32(2))
2514  self.assertRaises(ValueError, EDProducer, 'C', ps1, ps2)
2515  self.assertRaises(ValueError, EDProducer, 'C', ps1, a=int32(3))
2516 
2517  def testExamples(self):
2518  p = Process("Test")
2519  p.source = Source("PoolSource",fileNames = untracked(string("file:reco.root")))
2520  p.foos = EDProducer("FooProducer")
2521  p.bars = EDProducer("BarProducer", foos=InputTag("foos"))
2522  p.out = OutputModule("PoolOutputModule",fileName=untracked(string("file:foos.root")))
2523  p.bars.foos = 'Foosball'
2524  self.assertEqual(p.bars.foos, InputTag('Foosball'))
2525  p.p = Path(p.foos*p.bars)
2526  p.e = EndPath(p.out)
2527  p.add_(Service("MessageLogger"))
2528 
2529  def testPrefers(self):
2530  p = Process("Test")
2531  p.add_(ESSource("ForceSource"))
2532  p.juicer = ESProducer("JuicerProducer")
2533  p.prefer("ForceSource")
2534  p.prefer("juicer")
2535  self.assertEqual(p.dumpConfig(),
2536 """process Test = {
2537  es_module juicer = JuicerProducer {
2538  }
2539  es_source = ForceSource {
2540  }
2541  es_prefer = ForceSource {
2542  }
2543  es_prefer juicer = JuicerProducer {
2544  }
2545 }
2546 """)
2547  p.prefer("juicer",fooRcd=vstring("Foo"))
2548  self.assertEqual(p.dumpConfig(),
2549 """process Test = {
2550  es_module juicer = JuicerProducer {
2551  }
2552  es_source = ForceSource {
2553  }
2554  es_prefer = ForceSource {
2555  }
2556  es_prefer juicer = JuicerProducer {
2557  vstring fooRcd = {
2558  'Foo'
2559  }
2560 
2561  }
2562 }
2563 """)
2564  self.assertEqual(p.dumpPython(),
2565 """import FWCore.ParameterSet.Config as cms
2566 
2567 process = cms.Process("Test")
2568 
2569 process.juicer = cms.ESProducer("JuicerProducer")
2570 
2571 
2572 process.ForceSource = cms.ESSource("ForceSource")
2573 
2574 
2575 process.prefer("ForceSource")
2576 
2577 process.prefer("juicer",
2578  fooRcd = cms.vstring('Foo')
2579 )
2580 
2581 """)
2582 
2583  def testFreeze(self):
2584  process = Process("Freeze")
2585  m = EDProducer("M", p=PSet(i = int32(1)))
2586  m.p.i = 2
2587  process.m = m
2588  # should be frozen
2589  #self.assertRaises(ValueError, setattr, m.p, 'i', 3)
2590  #self.assertRaises(ValueError, setattr, m, 'p', PSet(i=int32(1)))
2591  #self.assertRaises(ValueError, setattr, m.p, 'j', 1)
2592  #self.assertRaises(ValueError, setattr, m, 'j', 1)
2593  # But OK to change through the process
2594  process.m.p.i = 4
2595  self.assertEqual(process.m.p.i.value(), 4)
2596  process.m.p = PSet(j=int32(1))
2597  # should work to clone it, though
2598  m2 = m.clone(p = PSet(i = int32(5)), j = int32(8))
2599  m2.p.i = 6
2600  m2.j = 8
2601  def testSubProcess(self):
2602  process = Process("Parent")
2603  subProcess = Process("Child")
2604  subProcess.a = EDProducer("A")
2605  subProcess.p = Path(subProcess.a)
2606  subProcess.add_(Service("Foo"))
2607  process.addSubProcess(SubProcess(subProcess))
2608  d = process.dumpPython()
2609  equalD ="""import FWCore.ParameterSet.Config as cms
2610 
2611 process = cms.Process("Parent")
2612 
2613 parentProcess = process
2614 import FWCore.ParameterSet.Config as cms
2615 
2616 process = cms.Process("Child")
2617 
2618 process.a = cms.EDProducer("A")
2619 
2620 
2621 process.Foo = cms.Service("Foo")
2622 
2623 
2624 process.p = cms.Path(process.a)
2625 
2626 
2627 childProcess = process
2628 process = parentProcess
2629 process.addSubProcess(cms.SubProcess(process = childProcess, SelectEvents = cms.untracked.PSet(
2630 
2631 ), outputCommands = cms.untracked.vstring()))
2632 
2633 """
2634  equalD = equalD.replace("parentProcess","parentProcess"+str(hash(process.subProcesses_()[0])))
2635  self.assertEqual(d,equalD)
2636  p = TestMakePSet()
2637  process.fillProcessDesc(p)
2638  self.assertEqual((True,['a']),p.values["subProcesses"][1][0].values["process"][1].values['@all_modules'])
2639  self.assertEqual((True,['p']),p.values["subProcesses"][1][0].values["process"][1].values['@paths'])
2640  self.assertEqual({'@service_type':(True,'Foo')}, p.values["subProcesses"][1][0].values["process"][1].values["services"][1][0].values)
2641  def testRefToPSet(self):
2642  proc = Process("test")
2643  proc.top = PSet(a = int32(1))
2644  proc.ref = PSet(refToPSet_ = string("top"))
2645  proc.ref2 = PSet( a = int32(1), b = PSet( refToPSet_ = string("top")))
2646  proc.ref3 = PSet(refToPSet_ = string("ref"))
2647  proc.ref4 = VPSet(PSet(refToPSet_ = string("top")),
2648  PSet(refToPSet_ = string("ref2")))
2649  p = TestMakePSet()
2650  proc.fillProcessDesc(p)
2651  self.assertEqual((True,1),p.values["ref"][1].values["a"])
2652  self.assertEqual((True,1),p.values["ref3"][1].values["a"])
2653  self.assertEqual((True,1),p.values["ref2"][1].values["a"])
2654  self.assertEqual((True,1),p.values["ref2"][1].values["b"][1].values["a"])
2655  self.assertEqual((True,1),p.values["ref4"][1][0].values["a"])
2656  self.assertEqual((True,1),p.values["ref4"][1][1].values["a"])
2657  def testPrune(self):
2658  p = Process("test")
2659  p.a = EDAnalyzer("MyAnalyzer")
2660  p.b = EDAnalyzer("YourAnalyzer")
2661  p.c = EDAnalyzer("OurAnalyzer")
2662  p.d = EDAnalyzer("OurAnalyzer")
2663  p.s = Sequence(p.d)
2664  p.path1 = Path(p.a)
2665  p.path2 = Path(p.b)
2666  self.assert_(p.schedule is None)
2667  pths = p.paths
2668  keys = pths.keys()
2669  self.assertEqual(pths[keys[0]],p.path1)
2670  self.assertEqual(pths[keys[1]],p.path2)
2671  p.pset1 = PSet(parA = string("pset1"))
2672  p.pset2 = untracked.PSet(parA = string("pset2"))
2673  p.vpset1 = VPSet()
2674  p.vpset2 = untracked.VPSet()
2675  p.prune()
2676  self.assert_(hasattr(p, 'a'))
2677  self.assert_(hasattr(p, 'b'))
2678  self.assert_(not hasattr(p, 'c'))
2679  self.assert_(not hasattr(p, 'd'))
2680  self.assert_(not hasattr(p, 's'))
2681  self.assert_(hasattr(p, 'path1'))
2682  self.assert_(hasattr(p, 'path2'))
2683 # self.assert_(not hasattr(p, 'pset1'))
2684 # self.assert_(hasattr(p, 'pset2'))
2685 # self.assert_(not hasattr(p, 'vpset1'))
2686 # self.assert_(not hasattr(p, 'vpset2'))
2687 
2688  p = Process("test")
2689  p.a = EDAnalyzer("MyAnalyzer")
2690  p.b = EDAnalyzer("YourAnalyzer")
2691  p.c = EDAnalyzer("OurAnalyzer")
2692  p.d = EDAnalyzer("OurAnalyzer")
2693  p.e = EDAnalyzer("OurAnalyzer")
2694  p.s = Sequence(p.d)
2695  p.s2 = Sequence(p.b)
2696  p.s3 = Sequence(p.e)
2697  p.path1 = Path(p.a)
2698  p.path2 = Path(p.b)
2699  p.path3 = Path(p.b+p.s2)
2700  p.path4 = Path(p.b+p.s3)
2701  p.schedule = Schedule(p.path1,p.path2,p.path3)
2702  pths = p.paths
2703  keys = pths.keys()
2704  self.assertEqual(pths[keys[0]],p.path1)
2705  self.assertEqual(pths[keys[1]],p.path2)
2706  p.prune()
2707  self.assert_(hasattr(p, 'a'))
2708  self.assert_(hasattr(p, 'b'))
2709  self.assert_(not hasattr(p, 'c'))
2710  self.assert_(not hasattr(p, 'd'))
2711  self.assert_(not hasattr(p, 'e'))
2712  self.assert_(not hasattr(p, 's'))
2713  self.assert_(hasattr(p, 's2'))
2714  self.assert_(not hasattr(p, 's3'))
2715  self.assert_(hasattr(p, 'path1'))
2716  self.assert_(hasattr(p, 'path2'))
2717  self.assert_(hasattr(p, 'path3'))
2718  self.assert_(not hasattr(p, 'path4'))
2719  #test SequencePlaceholder
2720  p = Process("test")
2721  p.a = EDAnalyzer("MyAnalyzer")
2722  p.b = EDAnalyzer("YourAnalyzer")
2723  p.s = Sequence(SequencePlaceholder("a")+p.b)
2724  p.pth = Path(p.s)
2725  p.prune()
2726  self.assert_(hasattr(p, 'a'))
2727  self.assert_(hasattr(p, 'b'))
2728  self.assert_(hasattr(p, 's'))
2729  self.assert_(hasattr(p, 'pth'))
2730  #test unresolved SequencePlaceholder
2731  p = Process("test")
2732  p.b = EDAnalyzer("YourAnalyzer")
2733  p.s = Sequence(SequencePlaceholder("a")+p.b)
2734  p.pth = Path(p.s)
2735  p.prune(keepUnresolvedSequencePlaceholders=True)
2736  self.assert_(hasattr(p, 'b'))
2737  self.assert_(hasattr(p, 's'))
2738  self.assert_(hasattr(p, 'pth'))
2739  self.assertEqual(p.s.dumpPython(''),'cms.Sequence(cms.SequencePlaceholder("a")+process.b)\n')
2741  p = Process("test")
2742  p.a = EDProducer("ma")
2743  p.b = EDAnalyzer("mb")
2744  p.t1 = Task(TaskPlaceholder("c"))
2745  p.t2 = Task(p.a, TaskPlaceholder("d"), p.t1)
2746  p.t3 = Task(TaskPlaceholder("e"))
2747  p.path1 = Path(p.b, p.t2, p.t3)
2748  p.t5 = Task(p.a, TaskPlaceholder("g"), TaskPlaceholder("t4"))
2749  p.t4 = Task(TaskPlaceholder("f"))
2750  p.endpath1 = EndPath(p.b, p.t5)
2751  p.t6 = Task(TaskPlaceholder("h"))
2752  p.t7 = Task(p.a, TaskPlaceholder("i"), p.t6)
2753  p.t8 = Task(TaskPlaceholder("j"))
2754  p.schedule = Schedule(p.path1, p.endpath1,tasks=[p.t7,p.t8])
2755  p.c = EDProducer("mc")
2756  p.d = EDProducer("md")
2757  p.e = EDProducer("me")
2758  p.f = EDProducer("mf")
2759  p.g = EDProducer("mg")
2760  p.h = EDProducer("mh")
2761  p.i = EDProducer("mi")
2762  p.j = EDProducer("mj")
2763  self.assertEqual(p.dumpPython(),
2764 """import FWCore.ParameterSet.Config as cms
2765 
2766 process = cms.Process("test")
2767 
2768 process.a = cms.EDProducer("ma")
2769 
2770 
2771 process.c = cms.EDProducer("mc")
2772 
2773 
2774 process.d = cms.EDProducer("md")
2775 
2776 
2777 process.e = cms.EDProducer("me")
2778 
2779 
2780 process.f = cms.EDProducer("mf")
2781 
2782 
2783 process.g = cms.EDProducer("mg")
2784 
2785 
2786 process.h = cms.EDProducer("mh")
2787 
2788 
2789 process.i = cms.EDProducer("mi")
2790 
2791 
2792 process.j = cms.EDProducer("mj")
2793 
2794 
2795 process.b = cms.EDAnalyzer("mb")
2796 
2797 
2798 process.t8 = cms.Task(cms.TaskPlaceholder("j"))
2799 
2800 
2801 process.t6 = cms.Task(cms.TaskPlaceholder("h"))
2802 
2803 
2804 process.t7 = cms.Task(cms.TaskPlaceholder("i"), process.a, process.t6)
2805 
2806 
2807 process.t4 = cms.Task(cms.TaskPlaceholder("f"))
2808 
2809 
2810 process.t5 = cms.Task(cms.TaskPlaceholder("g"), cms.TaskPlaceholder("t4"), process.a)
2811 
2812 
2813 process.t3 = cms.Task(cms.TaskPlaceholder("e"))
2814 
2815 
2816 process.t1 = cms.Task(cms.TaskPlaceholder("c"))
2817 
2818 
2819 process.t2 = cms.Task(cms.TaskPlaceholder("d"), process.a, process.t1)
2820 
2821 
2822 process.path1 = cms.Path(process.b, process.t2, process.t3)
2823 
2824 
2825 process.endpath1 = cms.EndPath(process.b, process.t5)
2826 
2827 
2828 process.schedule = cms.Schedule(*[ process.path1, process.endpath1 ], tasks=[process.t7, process.t8])
2829 """)
2830  p.resolve()
2831  self.assertEqual(p.dumpPython(),
2832 """import FWCore.ParameterSet.Config as cms
2833 
2834 process = cms.Process("test")
2835 
2836 process.a = cms.EDProducer("ma")
2837 
2838 
2839 process.c = cms.EDProducer("mc")
2840 
2841 
2842 process.d = cms.EDProducer("md")
2843 
2844 
2845 process.e = cms.EDProducer("me")
2846 
2847 
2848 process.f = cms.EDProducer("mf")
2849 
2850 
2851 process.g = cms.EDProducer("mg")
2852 
2853 
2854 process.h = cms.EDProducer("mh")
2855 
2856 
2857 process.i = cms.EDProducer("mi")
2858 
2859 
2860 process.j = cms.EDProducer("mj")
2861 
2862 
2863 process.b = cms.EDAnalyzer("mb")
2864 
2865 
2866 process.t8 = cms.Task(process.j)
2867 
2868 
2869 process.t6 = cms.Task(process.h)
2870 
2871 
2872 process.t7 = cms.Task(process.a, process.i, process.t6)
2873 
2874 
2875 process.t4 = cms.Task(process.f)
2876 
2877 
2878 process.t5 = cms.Task(process.a, process.g, process.t4)
2879 
2880 
2881 process.t3 = cms.Task(process.e)
2882 
2883 
2884 process.t1 = cms.Task(process.c)
2885 
2886 
2887 process.t2 = cms.Task(process.a, process.d, process.t1)
2888 
2889 
2890 process.path1 = cms.Path(process.b, process.t2, process.t3)
2891 
2892 
2893 process.endpath1 = cms.EndPath(process.b, process.t5)
2894 
2895 
2896 process.schedule = cms.Schedule(*[ process.path1, process.endpath1 ], tasks=[process.t7, process.t8])
2897 """)
2898 
2899  def testDelete(self):
2900  p = Process("test")
2901  p.a = EDAnalyzer("MyAnalyzer")
2902  p.b = EDAnalyzer("YourAnalyzer")
2903  p.c = EDAnalyzer("OurAnalyzer")
2904  p.d = EDAnalyzer("OurAnalyzer")
2905  p.e = EDAnalyzer("OurAnalyzer")
2906  p.f = EDAnalyzer("OurAnalyzer")
2907  p.g = EDProducer("OurProducer")
2908  p.h = EDProducer("YourProducer")
2909  p.t1 = Task(p.g, p.h)
2910  t2 = Task(p.g, p.h)
2911  t3 = Task(p.g, p.h)
2912  p.s = Sequence(p.d+p.e)
2913  p.path1 = Path(p.a+p.f+p.s,t2)
2914  p.endpath1 = EndPath(p.b+p.f)
2915  p.schedule = Schedule(tasks=[t3])
2916  self.assertTrue(hasattr(p, 'f'))
2917  self.assertTrue(hasattr(p, 'g'))
2918  del p.e
2919  del p.f
2920  del p.g
2921  self.assertFalse(hasattr(p, 'f'))
2922  self.assertFalse(hasattr(p, 'g'))
2923  self.assertTrue(p.t1.dumpPython(None) == 'cms.Task(process.h)\n')
2924  self.assertTrue(p.s.dumpPython(None) == 'cms.Sequence(process.d)\n')
2925  self.assertTrue(p.path1.dumpPython(None) == 'cms.Path(process.a+process.s, cms.Task(process.h))\n')
2926  self.assertTrue(p.endpath1.dumpPython(None) == 'cms.EndPath(process.b)\n')
2927  del p.s
2928  self.assertTrue(p.path1.dumpPython(None) == 'cms.Path(process.a+(process.d), cms.Task(process.h))\n')
2929  self.assertTrue(p.schedule_().dumpPython(None) == 'cms.Schedule(tasks=[cms.Task(process.h)])\n')
2930  def testModifier(self):
2931  m1 = Modifier()
2932  p = Process("test",m1)
2933  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1))
2934  def _mod_fred(obj):
2935  obj.fred = 2
2936  m1.toModify(p.a,_mod_fred)
2937  self.assertEqual(p.a.fred.value(),2)
2938  p.b = EDAnalyzer("YourAnalyzer", wilma = int32(1))
2939  m1.toModify(p.b, wilma = 2)
2940  self.assertEqual(p.b.wilma.value(),2)
2941  self.assert_(p.isUsingModifier(m1))
2942  #check that Modifier not attached to a process doesn't run
2943  m1 = Modifier()
2944  p = Process("test")
2945  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1))
2946  m1.toModify(p.a,_mod_fred)
2947  p.b = EDAnalyzer("YourAnalyzer", wilma = int32(1))
2948  m1.toModify(p.b, wilma = 2)
2949  self.assertEqual(p.a.fred.value(),1)
2950  self.assertEqual(p.b.wilma.value(),1)
2951  self.assertEqual(p.isUsingModifier(m1),False)
2952  #make sure clones get the changes
2953  m1 = Modifier()
2954  p = Process("test",m1)
2955  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
2956  m1.toModify(p.a, fred = int32(2))
2957  p.b = p.a.clone(wilma = int32(3))
2958  self.assertEqual(p.a.fred.value(),2)
2959  self.assertEqual(p.a.wilma.value(),1)
2960  self.assertEqual(p.b.fred.value(),2)
2961  self.assertEqual(p.b.wilma.value(),3)
2962  #test removal of parameter
2963  m1 = Modifier()
2964  p = Process("test",m1)
2965  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1), fintstones = PSet(fred = int32(1)))
2966  m1.toModify(p.a, fred = None, fintstones = dict(fred = None))
2967  self.assertEqual(hasattr(p.a, "fred"), False)
2968  self.assertEqual(hasattr(p.a.fintstones, "fred"), False)
2969  self.assertEqual(p.a.wilma.value(),1)
2970  #test adding a parameter
2971  m1 = Modifier()
2972  p = Process("test",m1)
2973  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1))
2974  m1.toModify(p.a, wilma = int32(2))
2975  self.assertEqual(p.a.fred.value(), 1)
2976  self.assertEqual(p.a.wilma.value(),2)
2977  #test setting of value in PSet
2978  m1 = Modifier()
2979  p = Process("test",m1)
2980  p.a = EDAnalyzer("MyAnalyzer", flintstones = PSet(fred = int32(1), wilma = int32(1)))
2981  m1.toModify(p.a, flintstones = dict(fred = int32(2)))
2982  self.assertEqual(p.a.flintstones.fred.value(),2)
2983  self.assertEqual(p.a.flintstones.wilma.value(),1)
2984  #test proper exception from nonexisting parameter name
2985  m1 = Modifier()
2986  p = Process("test",m1)
2987  p.a = EDAnalyzer("MyAnalyzer", flintstones = PSet(fred = PSet(wilma = int32(1))))
2988  self.assertRaises(KeyError, lambda: m1.toModify(p.a, flintstones = dict(imnothere = dict(wilma=2))))
2989  self.assertRaises(KeyError, lambda: m1.toModify(p.a, foo = 1))
2990  #test setting a value in a VPSet
2991  m1 = Modifier()
2992  p = Process("test",m1)
2993  p.a = EDAnalyzer("MyAnalyzer", flintstones = VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
2994  m1.toModify(p.a, flintstones = {1:dict(wilma = int32(2))})
2995  self.assertEqual(p.a.flintstones[0].fred.value(),1)
2996  self.assertEqual(p.a.flintstones[1].wilma.value(),2)
2997  #test setting a value in a list of values
2998  m1 = Modifier()
2999  p = Process("test",m1)
3000  p.a = EDAnalyzer("MyAnalyzer", fred = vuint32(1,2,3))
3001  m1.toModify(p.a, fred = {1:7})
3002  self.assertEqual(p.a.fred[0],1)
3003  self.assertEqual(p.a.fred[1],7)
3004  self.assertEqual(p.a.fred[2],3)
3005  #test IndexError setting a value in a list to an item key not in the list
3006  m1 = Modifier()
3007  p = Process("test",m1)
3008  p.a = EDAnalyzer("MyAnalyzer", fred = vuint32(1,2,3))
3009  raised = False
3010  try: m1.toModify(p.a, fred = {5:7})
3011  except IndexError as e: raised = True
3012  self.assertEqual(raised, True)
3013  #test TypeError setting a value in a list using a key that is not an int
3014  m1 = Modifier()
3015  p = Process("test",m1)
3016  p.a = EDAnalyzer("MyAnalyzer", flintstones = VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
3017  raised = False
3018  try: m1.toModify(p.a, flintstones = dict(bogus = int32(37)))
3019  except TypeError as e: raised = True
3020  self.assertEqual(raised, True)
3021  #test that load causes process wide methods to run
3022  def _rem_a(proc):
3023  del proc.a
3024  class ProcModifierMod(object):
3025  def __init__(self,modifier,func):
3026  self.proc_mod_ = modifier.makeProcessModifier(func)
3027  class DummyMod(object):
3028  def __init__(self):
3029  self.a = EDAnalyzer("Dummy")
3030  testMod = DummyMod()
3031  p.extend(testMod)
3032  self.assert_(hasattr(p,"a"))
3033  m1 = Modifier()
3034  p = Process("test",m1)
3035  testProcMod = ProcModifierMod(m1,_rem_a)
3036  p.extend(testMod)
3037  p.extend(testProcMod)
3038  self.assert_(not hasattr(p,"a"))
3039  #test ModifierChain
3040  m1 = Modifier()
3041  mc = ModifierChain(m1)
3042  p = Process("test",mc)
3043  self.assert_(p.isUsingModifier(m1))
3044  self.assert_(p.isUsingModifier(mc))
3045  testMod = DummyMod()
3046  p.b = EDAnalyzer("Dummy2", fred = int32(1))
3047  m1.toModify(p.b, fred = int32(3))
3048  p.extend(testMod)
3049  testProcMod = ProcModifierMod(m1,_rem_a)
3050  p.extend(testProcMod)
3051  self.assert_(not hasattr(p,"a"))
3052  self.assertEqual(p.b.fred.value(),3)
3053  #check cloneAndExclude
3054  m1 = Modifier()
3055  m2 = Modifier()
3056  mc = ModifierChain(m1,m2)
3057  mclone = mc.copyAndExclude([m2])
3058  self.assert_(not mclone._isOrContains(m2))
3059  self.assert_(mclone._isOrContains(m1))
3060  m3 = Modifier()
3061  mc2 = ModifierChain(mc,m3)
3062  mclone = mc2.copyAndExclude([m2])
3063  self.assert_(not mclone._isOrContains(m2))
3064  self.assert_(mclone._isOrContains(m1))
3065  self.assert_(mclone._isOrContains(m3))
3066  #check combining
3067  m1 = Modifier()
3068  m2 = Modifier()
3069  p = Process("test",m1)
3070  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
3071  (m1 & m2).toModify(p.a, fred = int32(2))
3072  self.assertRaises(TypeError, lambda: (m1 & m2).toModify(p.a, 1, wilma=2))
3073  self.assertEqual(p.a.fred, 1)
3074  m1 = Modifier()
3075  m2 = Modifier()
3076  p = Process("test",m1,m2)
3077  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
3078  (m1 & m2).toModify(p.a, fred = int32(2))
3079  self.assertEqual(p.a.fred, 2)
3080  m1 = Modifier()
3081  m2 = Modifier()
3082  m3 = Modifier()
3083  p = Process("test",m1,m2,m3)
3084  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
3085  (m1 & m2 & m3).toModify(p.a, fred = int32(2))
3086  self.assertEqual(p.a.fred, 2)
3087  (m1 & (m2 & m3)).toModify(p.a, fred = int32(3))
3088  self.assertEqual(p.a.fred, 3)
3089  ((m1 & m2) & m3).toModify(p.a, fred = int32(4))
3090  self.assertEqual(p.a.fred, 4)
3091  #check inverse
3092  m1 = Modifier()
3093  m2 = Modifier()
3094  p = Process("test", m1)
3095  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
3096  (~m1).toModify(p.a, fred=2)
3097  self.assertEqual(p.a.fred, 1)
3098  (~m2).toModify(p.a, wilma=2)
3099  self.assertEqual(p.a.wilma, 2)
3100  self.assertRaises(TypeError, lambda: (~m1).toModify(p.a, 1, wilma=2))
3101  self.assertRaises(TypeError, lambda: (~m2).toModify(p.a, 1, wilma=2))
3102  # check or
3103  m1 = Modifier()
3104  m2 = Modifier()
3105  m3 = Modifier()
3106  p = Process("test", m1)
3107  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
3108  (m1 | m2).toModify(p.a, fred=2)
3109  self.assertEqual(p.a.fred, 2)
3110  (m1 | m2 | m3).toModify(p.a, fred=3)
3111  self.assertEqual(p.a.fred, 3)
3112  (m3 | m2 | m1).toModify(p.a, fred=4)
3113  self.assertEqual(p.a.fred, 4)
3114  ((m1 | m2) | m3).toModify(p.a, fred=5)
3115  self.assertEqual(p.a.fred, 5)
3116  (m1 | (m2 | m3)).toModify(p.a, fred=6)
3117  self.assertEqual(p.a.fred, 6)
3118  (m2 | m3).toModify(p.a, fred=7)
3119  self.assertEqual(p.a.fred, 6)
3120  self.assertRaises(TypeError, lambda: (m1 | m2).toModify(p.a, 1, wilma=2))
3121  self.assertRaises(TypeError, lambda: (m2 | m3).toModify(p.a, 1, wilma=2))
3122  # check combinations
3123  m1 = Modifier()
3124  m2 = Modifier()
3125  m3 = Modifier()
3126  m4 = Modifier()
3127  p = Process("test", m1, m2)
3128  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
3129  (m1 & ~m2).toModify(p.a, fred=2)
3130  self.assertEqual(p.a.fred, 1)
3131  (m1 & ~m3).toModify(p.a, fred=2)
3132  self.assertEqual(p.a.fred, 2)
3133  (m1 | ~m2).toModify(p.a, fred=3)
3134  self.assertEqual(p.a.fred, 3)
3135  (~m1 | ~m2).toModify(p.a, fred=4)
3136  self.assertEqual(p.a.fred, 3)
3137  (~m3 & ~m4).toModify(p.a, fred=4)
3138  self.assertEqual(p.a.fred, 4)
3139  ((m1 & m3) | ~m4).toModify(p.a, fred=5)
3140  self.assertEqual(p.a.fred, 5)
3141  #check toReplaceWith
3142  m1 = Modifier()
3143  p = Process("test",m1)
3144  p.a =EDAnalyzer("MyAnalyzer", fred = int32(1))
3145  m1.toReplaceWith(p.a, EDAnalyzer("YourAnalyzer", wilma = int32(3)))
3146  self.assertRaises(TypeError, lambda: m1.toReplaceWith(p.a, EDProducer("YourProducer")))
3147  p.b =EDAnalyzer("BAn")
3148  p.c =EDProducer("c")
3149  p.d =EDProducer("d")
3150  p.tc = Task(p.c)
3151  p.td = Task(p.d)
3152  p.s = Sequence(p.a, p.tc)
3153  m1.toReplaceWith(p.s, Sequence(p.a+p.b, p.td))
3154  self.assertEqual(p.a.wilma.value(),3)
3155  self.assertEqual(p.a.type_(),"YourAnalyzer")
3156  self.assertEqual(hasattr(p,"fred"),False)
3157  self.assertTrue(p.s.dumpPython("") == "cms.Sequence(process.a+process.b, process.td)\n")
3158  p.e =EDProducer("e")
3159  m1.toReplaceWith(p.td, Task(p.e))
3160  self.assertTrue(p.td._collection == OrderedSet([p.e]))
3161  #check toReplaceWith doesn't activate not chosen
3162  m1 = Modifier()
3163  p = Process("test")
3164  p.a =EDAnalyzer("MyAnalyzer", fred = int32(1))
3165  m1.toReplaceWith(p.a, EDAnalyzer("YourAnalyzer", wilma = int32(3)))
3166  self.assertEqual(p.a.type_(),"MyAnalyzer")
3167  #check toReplaceWith and and/not/or combinations
3168  m1 = Modifier()
3169  m2 = Modifier()
3170  m3 = Modifier()
3171  m4 = Modifier()
3172  p = Process("test", m1, m2)
3173  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
3174  self.assertRaises(TypeError, lambda: (m1 & m2).toReplaceWith(p.a, EDProducer("YourProducer")))
3175  self.assertRaises(TypeError, lambda: (m3 & m4).toReplaceWith(p.a, EDProducer("YourProducer")))
3176  self.assertRaises(TypeError, lambda: (~m3).toReplaceWith(p.a, EDProducer("YourProducer")))
3177  self.assertRaises(TypeError, lambda: (~m1).toReplaceWith(p.a, EDProducer("YourProducer")))
3178  self.assertRaises(TypeError, lambda: (m1 | m3).toReplaceWith(p.a, EDProducer("YourProducer")))
3179  self.assertRaises(TypeError, lambda: (m3 | m4).toReplaceWith(p.a, EDProducer("YourProducer")))
3180  (m1 & m2).toReplaceWith(p.a, EDAnalyzer("YourAnalyzer1"))
3181  self.assertEqual(p.a.type_(), "YourAnalyzer1")
3182  (m1 & m3).toReplaceWith(p.a, EDAnalyzer("YourAnalyzer2"))
3183  self.assertEqual(p.a.type_(), "YourAnalyzer1")
3184  (~m1).toReplaceWith(p.a, EDAnalyzer("YourAnalyzer2"))
3185  self.assertEqual(p.a.type_(), "YourAnalyzer1")
3186  (~m3).toReplaceWith(p.a, EDAnalyzer("YourAnalyzer2"))
3187  self.assertEqual(p.a.type_(), "YourAnalyzer2")
3188  (m1 | m3).toReplaceWith(p.a, EDAnalyzer("YourAnalyzer3"))
3189  self.assertEqual(p.a.type_(), "YourAnalyzer3")
3190  (m3 | m4).toReplaceWith(p.a, EDAnalyzer("YourAnalyzer4"))
3191  self.assertEqual(p.a.type_(), "YourAnalyzer3")
3192  unittest.main()
def __setstate__(self, pkldict)
Definition: Config.py:154
def addVString(self, tracked, label, value)
Definition: Config.py:1522
def _dumpConfigOptionallyNamedList(self, items, typeName, options)
Definition: Config.py:652
def addEventRange(self, tracked, label, value)
Definition: Config.py:1540
def __init__(self, lhs, rhs)
Definition: Config.py:1325
def testExamples(self)
Definition: Config.py:2517
def __getattribute__(self, name)
Definition: Config.py:1165
def _place(self, label, process)
Definition: Config.py:1250
def getProcessName(self)
Definition: Config.py:1238
def testServiceInProcess(self)
Definition: Config.py:2022
def __or__(self, other)
Definition: Config.py:1416
def outputCommands(self)
Definition: Config.py:1244
def _setChosen(self)
Definition: Config.py:1433
def producerNames(self)
Definition: Config.py:141
def _dumpConfigUnnamedList(self, items, typeName, options)
Definition: Config.py:647
def newPSet(self)
Definition: Config.py:1550
def _placeAnalyzer(self, name, mod)
Definition: Config.py:523
def addString(self, tracked, label, value)
Definition: Config.py:1520
def __findFirstUsingModule(self, seqsOrTasks, mod)
Definition: Config.py:409
def subProcesses_(self)
Definition: Config.py:198
def __repr__(self)
Definition: Config.py:1209
def _pruneModules(self, d, scheduledNames)
Definition: Config.py:1015
def _modifyParametersFromDict(params, newParams, errorRaiser, keyDepth="")
Definition: Mixins.py:628
def vpsets_(self)
Definition: Config.py:269
def setName_(self, name)
Definition: Config.py:177
def copy(args, dbName)
def _placeESPrefer(self, name, mod)
Definition: Config.py:544
def testSequence2(self)
Definition: Config.py:2012
def _insertPaths(self, processPSet, nodeVisitor)
Definition: Config.py:900
def es_producers_(self)
Definition: Config.py:249
def _placeESProducer(self, name, mod)
Definition: Config.py:542
def __invert__(self)
Definition: Config.py:1414
def pathNames(self)
Definition: Config.py:150
def addVESInputTag(self, tracked, label, value)
Definition: Config.py:1530
def __and__(self, other)
Definition: Config.py:1412
def _placeSequence(self, name, mod)
Definition: Config.py:539
def __call__(self, obj)
Definition: Config.py:1265
def _setChosen(self)
Definition: Config.py:1407
def _validateSequence(self, sequence, label)
Definition: Config.py:740
def __getattr__(self, attr)
Definition: Config.py:1211
def tasks_(self)
Definition: Config.py:222
def setStrict(self, value)
Definition: Config.py:136
def addDouble(self, tracked, label, value)
Definition: Config.py:1514
def isChosen(self)
Definition: Config.py:1438
def producers_(self)
Definition: Config.py:182
def _findPreferred(self, esname, d, args, kargs)
Definition: Config.py:1134
def replace(string, replacements)
def testModifier(self)
Definition: Config.py:2930
def _insertOneInto(self, parameterSet, label, item, tracked)
Definition: Config.py:871
def filterNames(self)
Definition: Config.py:147
def __delattr__(self, name)
Definition: Config.py:439
def _placePath(self, name, mod)
Definition: Config.py:525
def addVUInt64(self, tracked, label, value)
Definition: Config.py:1512
def isChosen(self)
Definition: Config.py:1327
def _placeEndPath(self, name, mod)
Definition: Config.py:532
def es_sources_(self)
Definition: Config.py:253
def __init__(self, name, Mods)
Definition: Config.py:100
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
def testTypedParameterizable(self)
Definition: Config.py:1590
def addUInt64(self, tracked, label, value)
Definition: Config.py:1510
def _itemsInDependencyOrder(self, processDictionaryOfItems)
Definition: Config.py:756
def source_(self)
Definition: Config.py:186
def addVPSet(self, tracked, label, value)
Definition: Config.py:1546
def nameInProcessDesc_(self, label)
Definition: Config.py:1248
def psets_(self)
Definition: Config.py:265
def testSecSource(self)
Definition: Config.py:1947
def __init__(self, args)
Definition: Config.py:1263
def format_outerframe(number)
def __init__(self, args, kw)
Definition: Config.py:1207
def load(self, moduleName)
Definition: Config.py:580
def _insertSubProcessesInto(self, parameterSet, label, itemList, tracked)
Definition: Config.py:887
def addUInt32(self, tracked, label, value)
Definition: Config.py:1502
def _dumpConfigESPrefers(self, options)
Definition: Config.py:721
def __setattr__(self, name, value)
Definition: Config.py:1170
def setLooper_(self, lpr)
Definition: Config.py:195
def setSource_(self, src)
Definition: Config.py:189
def __init__(self, process)
Definition: Config.py:1156
def extend(self, other, items=())
Definition: Config.py:584
def _okToPlace(self, name, mod, d)
Definition: Config.py:488
def __or__(self, other)
Definition: Config.py:1306
def visit(visitdir)
Retrieve data from a perf suite output (sub) directory, only examines TimeSize at the moment...
def _replaceInTasks(self, label, new)
Definition: Config.py:853
def addVInt32(self, tracked, label, value)
Definition: Config.py:1500
def _placeFilter(self, name, mod)
Definition: Config.py:521
def schedule_(self)
Definition: Config.py:226
def validate(self)
Definition: Config.py:1098
def addVInputTag(self, tracked, label, value)
Definition: Config.py:1526
def _applyNewProcessModifiers(self, process)
Definition: Config.py:1428
def analyzerNames(self)
Definition: Config.py:144
def testSchedule(self)
Definition: Config.py:2349
def addLuminosityBlockID(self, tracked, label, value)
Definition: Config.py:1536
def addESInputTag(self, tracked, label, value)
Definition: Config.py:1528
def __init__(self, lhs)
Definition: Config.py:1318
def __new__(cls, args, kw)
Definition: Config.py:1189
def testContains(self)
Definition: Config.py:2291
def endpaths_(self)
Definition: Config.py:214
def toModify(self, obj, func=None, kw)
Definition: Config.py:1287
def SelectEvents(self)
Definition: Config.py:1242
def __setattr__(self, name, value)
Definition: Config.py:309
def _placeESSource(self, name, mod)
Definition: Config.py:546
def addVInt64(self, tracked, label, value)
Definition: Config.py:1508
def addVEventID(self, tracked, label, value)
Definition: Config.py:1534
def toModify(self, obj, func=None, kw)
Definition: Config.py:1353
def testGlobalReplace(self)
Definition: Config.py:1952
def toReplaceWith(self, toObj, fromObj)
Definition: Config.py:1292
def isChosen(self)
Definition: Config.py:1320
def _placeOutputModule(self, name, mod)
Definition: Config.py:517
def addFileInPath(self, tracked, label, value)
Definition: Config.py:1548
def testRefToPSet(self)
Definition: Config.py:2641
def testOverride(self)
Definition: Config.py:2494
def _placeSource(self, name, mod)
Definition: Config.py:557
def __init__(self)
Definition: Config.py:1340
def __init__(self, lhs, rhs=None)
Definition: Config.py:1283
def _dumpPythonSubProcesses(self, l, options)
Definition: Config.py:726
def checkImportPermission(minLevel=2, allowedPatterns=[])
Definition: Config.py:26
def ignore(seq)
def _toModify(obj, func, kw)
Definition: Config.py:1371
def __init__(self, modifier, func)
Definition: Config.py:1477
def _toReplaceWith(toObj, fromObj)
Definition: Config.py:1389
def _toModifyCheck(obj, func, kw)
Definition: Config.py:1350
def isUsingModifier(self, mod)
Definition: Config.py:274
def dumpPython(self, options=PrintOptions())
Definition: Config.py:1231
def __copyIfExclude(self, toExclude)
Definition: Config.py:1454
def sequences_(self)
Definition: Config.py:218
def _validateTask(self, task, label)
Definition: Config.py:748
def testParameterizable(self)
Definition: Config.py:1557
def testSubProcess(self)
Definition: Config.py:2601
def _placeSubProcess(self, name, mod)
Definition: Config.py:570
def setPartialSchedule_(self, sch, label)
Definition: Config.py:229
def addPSet(self, tracked, label, value)
Definition: Config.py:1544
def testProcessDumpPython(self)
Definition: Config.py:1692
def _placeService(self, typeName, mod)
Definition: Config.py:575
def resolve(self, keepUnresolvedSequencePlaceholders=False)
Definition: Config.py:954
def looper_(self)
Definition: Config.py:192
def es_prefers_(self)
Definition: Config.py:257
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def _isOrContains(self, other)
Definition: Config.py:1418
def getSubProcessPSet(self, parameterSet)
Definition: Config.py:1252
def copyAndExclude(self, toExclude)
Definition: Config.py:1440
def addVUInt32(self, tracked, label, value)
Definition: Config.py:1504
def addVEventRange(self, tracked, label, value)
Definition: Config.py:1542
def __init__(self, lhs, rhs)
Definition: Config.py:1311
def filters_(self)
Definition: Config.py:171
def dumpPython(process, name)
def __setObjectLabel(self, object, newLabel)
Definition: Config.py:282
def _delHelper(self, name)
Definition: Config.py:422
def _placeAlias(self, name, mod)
Definition: Config.py:551
def dumpPython(self, options=PrintOptions())
Definition: Config.py:817
def _replaceInSequences(self, label, new)
Definition: Config.py:844
def setSchedule_(self, sch)
Definition: Config.py:234
def analyzers_(self)
Definition: Config.py:202
def _toReplaceWithCheck(toObj, fromObj)
Definition: Config.py:1378
def testSequence(self)
Definition: Config.py:1997
def toReplaceWith(self, toObj, fromObj)
Definition: Config.py:1381
def _placeProducer(self, name, mod)
Definition: Config.py:519
def prefer(self, esmodule, args, kargs)
Definition: Config.py:1105
def __delattr__(self, name)
Definition: Config.py:1175
def _dumpConfigNamedList(self, items, typeName, options)
Definition: Config.py:642
def addInputTag(self, tracked, label, value)
Definition: Config.py:1524
def add_(self, value)
Definition: Config.py:473
def _insertManyInto(self, parameterSet, label, itemDict, tracked)
Definition: Config.py:878
def dumpConfig(self, options=PrintOptions())
Definition: Config.py:659
def apply(self, process)
Definition: Config.py:1481
def testCloneSequence(self)
Definition: Config.py:2275
def process(self)
Definition: Config.py:1240
def _placeTask(self, name, task)
Definition: Config.py:548
def makeProcessModifier(self, func)
Definition: Config.py:1297
def isChosen(self)
Definition: Config.py:1313
def addSubProcess(self, mod)
Definition: Config.py:573
def _placePSet(self, name, mod)
Definition: Config.py:553
def _isOrContains(self, other)
Definition: Config.py:1463
def addInt64(self, tracked, label, value)
Definition: Config.py:1506
def name_(self)
Definition: Config.py:175
def _place(self, name, mod, d)
Definition: Config.py:509
def testProcessExtend(self)
Definition: Config.py:1622
def _dumpPythonList(self, d, options)
Definition: Config.py:731
dbl *** dir
Definition: mlp_gen.cc:35
def __insertValue(self, tracked, label, value)
Definition: Config.py:1496
def _placeVPSet(self, name, mod)
Definition: Config.py:555
def __and__(self, other)
Definition: Config.py:1302
def globalReplace(self, label, new)
Definition: Config.py:863
def addBool(self, tracked, label, value)
Definition: Config.py:1518
def paths_(self)
Definition: Config.py:210
def addEventID(self, tracked, label, value)
Definition: Config.py:1532
def outputModules_(self)
Definition: Config.py:206
def _placeLooper(self, name, mod)
Definition: Config.py:565
def testImplicitSchedule(self)
Definition: Config.py:2454
def prune(self, verbose=False, keepUnresolvedSequencePlaceholders=False)
Definition: Config.py:963
def addVDouble(self, tracked, label, value)
Definition: Config.py:1516
def _insertInto(self, parameterSet, itemDict)
Definition: Config.py:868
def _delattrFromSetattr(self, name)
Definition: Config.py:464
def makeProcessModifier(self, func)
Definition: Config.py:1343
def __init__(self, process, SelectEvents=untracked.PSet(), outputCommands=untracked.vstring())
Definition: Config.py:1219
def type_(self)
Definition: Config.py:1246
def __init__(self, chainedModifiers)
Definition: Config.py:1425
def testTaskPlaceholder(self)
Definition: Config.py:2740
def services_(self)
Definition: Config.py:245
def _replaceInSchedule(self, label, new)
Definition: Config.py:857
def _dumpPython(self, d, options)
Definition: Config.py:812
def addInt32(self, tracked, label, value)
Definition: Config.py:1498
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def fillProcessDesc(self, processPSet)
Definition: Config.py:1022
def findProcess(module)
Definition: Config.py:79
def isChosen(self)
Definition: Config.py:1410
def testProcessInsertion(self)
Definition: Config.py:1597
def __init__(self)
Definition: Config.py:1494
def aliases_(self)
Definition: Config.py:261