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
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  scheduleTaskValidator = ScheduleTaskValidator()
922  task.visit(scheduleTaskValidator)
923  task.visit(nodeVisitor)
924  processPSet.addVString(True, "@end_paths", endpaths)
925  processPSet.addVString(True, "@paths", scheduledPaths)
926  # trigger_paths are a little different
927  p = processPSet.newPSet()
928  p.addVString(True, "@trigger_paths", triggerPaths)
929  processPSet.addPSet(True, "@trigger_paths", p)
930  # add all these paths
931  pathValidator = PathValidator()
932  endpathValidator = EndPathValidator()
933  decoratedList = []
934  lister = DecoratedNodeNameVisitor(decoratedList)
935  pathCompositeVisitor = CompositeVisitor(pathValidator, nodeVisitor, lister)
936  endpathCompositeVisitor = CompositeVisitor(endpathValidator, nodeVisitor, lister)
937  for triggername in triggerPaths:
938  iPath = self.paths_()[triggername]
939  iPath.resolve(self.__dict__)
940  pathValidator.setLabel(triggername)
941  lister.initialize()
942  iPath.visit(pathCompositeVisitor)
943  iPath.insertInto(processPSet, triggername, decoratedList)
944  for endpathname in endpaths:
945  iEndPath = self.endpaths_()[endpathname]
946  iEndPath.resolve(self.__dict__)
947  endpathValidator.setLabel(endpathname)
948  lister.initialize()
949  iEndPath.visit(endpathCompositeVisitor)
950  iEndPath.insertInto(processPSet, endpathname, decoratedList)
951  processPSet.addVString(False, "@filters_on_endpaths", endpathValidator.filtersOnEndpaths)
952 
953  def resolve(self,keepUnresolvedSequencePlaceholders=False):
954  for x in self.paths.itervalues():
955  x.resolve(self.__dict__,keepUnresolvedSequencePlaceholders)
956  for x in self.endpaths.itervalues():
957  x.resolve(self.__dict__,keepUnresolvedSequencePlaceholders)
958 
959  def prune(self,verbose=False,keepUnresolvedSequencePlaceholders=False):
960  """ Remove clutter from the process that we think is unnecessary:
961  tracked PSets, VPSets and unused modules and sequences. If a Schedule has been set, then Paths and EndPaths
962  not in the schedule will also be removed, along with an modules and sequences used only by
963  those removed Paths and EndPaths."""
964 # need to update this to only prune psets not on refToPSets
965 # but for now, remove the delattr
966 # for name in self.psets_():
967 # if getattr(self,name).isTracked():
968 # delattr(self, name)
969  for name in self.vpsets_():
970  delattr(self, name)
971  #first we need to resolve any SequencePlaceholders being used
972  self.resolve(keepUnresolvedSequencePlaceholders)
973  usedModules = set()
974  unneededPaths = set()
975  if self.schedule_():
976  usedModules=set(self.schedule_().moduleNames())
977  #get rid of unused paths
978  schedNames = set(( x.label_() for x in self.schedule_()))
979  names = set(self.paths)
980  names.update(set(self.endpaths))
981  unneededPaths = names - schedNames
982  for n in unneededPaths:
983  delattr(self,n)
984  else:
985  pths = list(self.paths.itervalues())
986  pths.extend(self.endpaths.itervalues())
987  temp = Schedule(*pths)
988  usedModules=set(temp.moduleNames())
989  unneededModules = self._pruneModules(self.producers_(), usedModules)
990  unneededModules.update(self._pruneModules(self.filters_(), usedModules))
991  unneededModules.update(self._pruneModules(self.analyzers_(), usedModules))
992  #remove sequences that do not appear in remaining paths and endpaths
993  seqs = list()
994  sv = SequenceVisitor(seqs)
995  for p in self.paths.itervalues():
996  p.visit(sv)
997  for p in self.endpaths.itervalues():
998  p.visit(sv)
999  keepSeqSet = set(( s for s in seqs if s.hasLabel_()))
1000  availableSeqs = set(self.sequences.itervalues())
1001  unneededSeqs = availableSeqs-keepSeqSet
1002  unneededSeqLabels = []
1003  for s in unneededSeqs:
1004  unneededSeqLabels.append(s.label_())
1005  delattr(self,s.label_())
1006  if verbose:
1007  print "prune removed the following:"
1008  print " modules:"+",".join(unneededModules)
1009  print " sequences:"+",".join(unneededSeqLabels)
1010  print " paths/endpaths:"+",".join(unneededPaths)
1011  def _pruneModules(self, d, scheduledNames):
1012  moduleNames = set(d.keys())
1013  junk = moduleNames - scheduledNames
1014  for name in junk:
1015  delattr(self, name)
1016  return junk
1017 
1018  def fillProcessDesc(self, processPSet):
1019  """Used by the framework to convert python to C++ objects"""
1020  class ServiceInjectorAdaptor(object):
1021  def __init__(self,ppset,thelist):
1022  self.__thelist = thelist
1023  self.__processPSet = ppset
1024  def addService(self,pset):
1025  self.__thelist.append(pset)
1026  def newPSet(self):
1027  return self.__processPSet.newPSet()
1028  #This adaptor is used to 'add' the method 'getTopPSet_'
1029  # to the ProcessDesc and PythonParameterSet C++ classes.
1030  # This method is needed for the PSet refToPSet_ functionality.
1031  class TopLevelPSetAcessorAdaptor(object):
1032  def __init__(self,ppset,process):
1033  self.__ppset = ppset
1034  self.__process = process
1035  def __getattr__(self,attr):
1036  return getattr(self.__ppset,attr)
1037  def getTopPSet_(self,label):
1038  return getattr(self.__process,label)
1039  def newPSet(self):
1040  return TopLevelPSetAcessorAdaptor(self.__ppset.newPSet(),self.__process)
1041  def addPSet(self,tracked,name,ppset):
1042  return self.__ppset.addPSet(tracked,name,self.__extractPSet(ppset))
1043  def addVPSet(self,tracked,name,vpset):
1044  return self.__ppset.addVPSet(tracked,name,[self.__extractPSet(x) for x in vpset])
1045  def __extractPSet(self,pset):
1046  if isinstance(pset,TopLevelPSetAcessorAdaptor):
1047  return pset.__ppset
1048  return pset
1049 
1050  self.validate()
1051  processPSet.addString(True, "@process_name", self.name_())
1052  all_modules = self.producers_().copy()
1053  all_modules.update(self.filters_())
1054  all_modules.update(self.analyzers_())
1055  all_modules.update(self.outputModules_())
1056  adaptor = TopLevelPSetAcessorAdaptor(processPSet,self)
1057  self._insertInto(adaptor, self.psets_())
1058  self._insertInto(adaptor, self.vpsets_())
1059  self._insertOneInto(adaptor, "@all_sources", self.source_(), True)
1060  self._insertOneInto(adaptor, "@all_loopers", self.looper_(), True)
1061  self._insertSubProcessesInto(adaptor, "@all_subprocesses", self.subProcesses_(), False)
1062  self._insertManyInto(adaptor, "@all_esprefers", self.es_prefers_(), True)
1063  self._insertManyInto(adaptor, "@all_aliases", self.aliases_(), True)
1064  # This will visit all the paths and endpaths that are scheduled to run,
1065  # as well as the Tasks associated to them and the schedule. It remembers
1066  # the modules, ESSources, ESProducers, and services it visits.
1067  nodeVisitor = NodeVisitor()
1068  self._insertPaths(adaptor, nodeVisitor)
1069  all_modules_onTasksOrScheduled = { key:value for key, value in all_modules.iteritems() if value in nodeVisitor.modules }
1070  self._insertManyInto(adaptor, "@all_modules", all_modules_onTasksOrScheduled, True)
1071  # Same as nodeVisitor except this one visits all the Tasks attached
1072  # to the process.
1073  processNodeVisitor = NodeVisitor()
1074  for pTask in self.tasks.itervalues():
1075  pTask.visit(processNodeVisitor)
1076  esProducersToEnable = {}
1077  for esProducerName, esProducer in self.es_producers_().iteritems():
1078  if esProducer in nodeVisitor.esProducers or not (esProducer in processNodeVisitor.esProducers):
1079  esProducersToEnable[esProducerName] = esProducer
1080  self._insertManyInto(adaptor, "@all_esmodules", esProducersToEnable, True)
1081  esSourcesToEnable = {}
1082  for esSourceName, esSource in self.es_sources_().iteritems():
1083  if esSource in nodeVisitor.esSources or not (esSource in processNodeVisitor.esSources):
1084  esSourcesToEnable[esSourceName] = esSource
1085  self._insertManyInto(adaptor, "@all_essources", esSourcesToEnable, True)
1086  #handle services differently
1087  services = []
1088  for serviceName, serviceObject in self.services_().iteritems():
1089  if serviceObject in nodeVisitor.services or not (serviceObject in processNodeVisitor.services):
1090  serviceObject.insertInto(ServiceInjectorAdaptor(adaptor,services))
1091  adaptor.addVPSet(False,"services",services)
1092  return processPSet
1093 
1094  def validate(self):
1095  # check if there's some input
1096  # Breaks too many unit tests for now
1097  #if self.source_() == None and self.looper_() == None:
1098  # raise RuntimeError("No input source was found for this process")
1099  pass
1100 
1101  def prefer(self, esmodule,*args,**kargs):
1102  """Prefer this ES source or producer. The argument can
1103  either be an object label, e.g.,
1104  process.prefer(process.juicerProducer) (not supported yet)
1105  or a name of an ESSource or ESProducer
1106  process.prefer("juicer")
1107  or a type of unnamed ESSource or ESProducer
1108  process.prefer("JuicerProducer")
1109  In addition, you can pass as a labelled arguments the name of the Record you wish to
1110  prefer where the type passed is a cms.vstring and that vstring can contain the
1111  name of the C++ types in the Record that are being preferred, e.g.,
1112  #prefer all data in record 'OrangeRecord' from 'juicer'
1113  process.prefer("juicer", OrangeRecord=cms.vstring())
1114  or
1115  #prefer only "Orange" data in "OrangeRecord" from "juicer"
1116  process.prefer("juicer", OrangeRecord=cms.vstring("Orange"))
1117  or
1118  #prefer only "Orange" data with label "ExtraPulp" in "OrangeRecord" from "juicer"
1119  ESPrefer("ESJuicerProd", OrangeRecord=cms.vstring("Orange/ExtraPulp"))
1120  """
1121  # see if this refers to a named ESProducer
1122  if isinstance(esmodule, ESSource) or isinstance(esmodule, ESProducer):
1123  raise RuntimeError("Syntax of process.prefer(process.esmodule) not supported yet")
1124  elif self._findPreferred(esmodule, self.es_producers_(),*args,**kargs) or \
1125  self._findPreferred(esmodule, self.es_sources_(),*args,**kargs):
1126  pass
1127  else:
1128  raise RuntimeError("Cannot resolve prefer for "+repr(esmodule))
1129 
1130  def _findPreferred(self, esname, d,*args,**kargs):
1131  # is esname a name in the dictionary?
1132  if esname in d:
1133  typ = d[esname].type_()
1134  if typ == esname:
1135  self.__setattr__( esname+"_prefer", ESPrefer(typ,*args,**kargs) )
1136  else:
1137  self.__setattr__( esname+"_prefer", ESPrefer(typ, esname,*args,**kargs) )
1138  return True
1139  else:
1140  # maybe it's an unnamed ESModule?
1141  found = False
1142  for name, value in d.iteritems():
1143  if value.type_() == esname:
1144  if found:
1145  raise RuntimeError("More than one ES module for "+esname)
1146  found = True
1147  self.__setattr__(esname+"_prefer", ESPrefer(d[esname].type_()) )
1148  return found
1149 
1150 
1152  def __init__(self, process):
1153  if isinstance(process, Process):
1154  self.__process = process
1155  elif isinstance(process, str):
1156  self.__process = Process(process)
1157  else:
1158  raise TypeError('a ProcessFragment can only be constructed from an existig Process or from process name')
1159  def __dir__(self):
1160  return [ x for x in dir(self.__process) if isinstance(getattr(self.__process, x), _ConfigureComponent) ]
1161  def __getattribute__(self, name):
1162  if name == '_ProcessFragment__process':
1163  return object.__getattribute__(self, '_ProcessFragment__process')
1164  else:
1165  return getattr(self.__process, name)
1166  def __setattr__(self, name, value):
1167  if name == '_ProcessFragment__process':
1168  object.__setattr__(self, name, value)
1169  else:
1170  setattr(self.__process, name, value)
1171  def __delattr__(self, name):
1172  if name == '_ProcessFragment__process':
1173  pass
1174  else:
1175  return delattr(self.__process, name)
1176 
1177 
1179  """a dictionary with fixed keys"""
1181  raise AttributeError("An FilteredStream defintion cannot be modified after creation.")
1182  _blocked_attribute = property(_blocked_attribute)
1183  __setattr__ = __delitem__ = __setitem__ = clear = _blocked_attribute
1184  pop = popitem = setdefault = update = _blocked_attribute
1185  def __new__(cls, *args, **kw):
1186  new = dict.__new__(cls)
1187  dict.__init__(new, *args, **kw)
1188  keys = kw.keys()
1189  keys.sort()
1190  if keys != ['content', 'dataTier', 'name', 'paths', 'responsible', 'selectEvents']:
1191  raise ValueError("The needed parameters are: content, dataTier, name, paths, responsible, selectEvents")
1192  if not isinstance(kw['name'],str):
1193  raise ValueError("name must be of type string")
1194  if not isinstance(kw['content'], vstring) and not isinstance(kw['content'],str):
1195  raise ValueError("content must be of type vstring or string")
1196  if not isinstance(kw['dataTier'], string):
1197  raise ValueError("dataTier must be of type string")
1198  if not isinstance(kw['selectEvents'], PSet):
1199  raise ValueError("selectEvents must be of type PSet")
1200  if not isinstance(kw['paths'],(tuple, Path)):
1201  raise ValueError("'paths' must be a tuple of paths")
1202  return new
1203  def __init__(self, *args, **kw):
1204  pass
1205  def __repr__(self):
1206  return "FilteredStream object: %s" %self["name"]
1207  def __getattr__(self,attr):
1208  return self[attr]
1209 
1211  """Allows embedding another process within a parent process. This allows one to
1212  chain processes together directly in one cmsRun job rather than having to run
1213  separate jobs that are connected via a temporary file.
1214  """
1215  def __init__(self,process, SelectEvents = untracked.PSet(), outputCommands = untracked.vstring()):
1216  """
1217  """
1218  if not isinstance(process, Process):
1219  raise ValueError("the 'process' argument must be of type cms.Process")
1220  if not isinstance(SelectEvents,PSet):
1221  raise ValueError("the 'SelectEvents' argument must be of type cms.untracked.PSet")
1222  if not isinstance(outputCommands,vstring):
1223  raise ValueError("the 'outputCommands' argument must be of type cms.untracked.vstring")
1224  self.__process = process
1225  self.__SelectEvents = SelectEvents
1226  self.__outputCommands = outputCommands
1227  def dumpPython(self,options=PrintOptions()):
1228  out = "parentProcess"+str(hash(self))+" = process\n"
1229  out += self.__process.dumpPython()
1230  out += "childProcess = process\n"
1231  out += "process = parentProcess"+str(hash(self))+"\n"
1232  out += "process.addSubProcess(cms.SubProcess(process = childProcess, SelectEvents = "+self.__SelectEvents.dumpPython(options) +", outputCommands = "+self.__outputCommands.dumpPython(options) +"))"
1233  return out
1234  def getProcessName(self):
1235  return self.__process.name_()
1236  def process(self):
1237  return self.__process
1238  def SelectEvents(self):
1239  return self.__SelectEvents
1240  def outputCommands(self):
1241  return self.__outputCommands
1242  def type_(self):
1243  return 'subProcess'
1244  def nameInProcessDesc_(self,label):
1245  return label
1246  def _place(self,label,process):
1247  process._placeSubProcess('subProcess',self)
1248  def getSubProcessPSet(self,parameterSet):
1249  topPSet = parameterSet.newPSet()
1250  self.__process.fillProcessDesc(topPSet)
1251  subProcessPSet = parameterSet.newPSet()
1252  self.__SelectEvents.insertInto(subProcessPSet,"SelectEvents")
1253  self.__outputCommands.insertInto(subProcessPSet,"outputCommands")
1254  subProcessPSet.addPSet(False,"process",topPSet)
1255  return subProcessPSet
1256 
1258  """Helper class for Modifier that takes key/value pairs and uses them to reset parameters of the object"""
1259  def __init__(self,args):
1260  self.__args = args
1261  def __call__(self,obj):
1262  params = {}
1263  for k in self.__args.iterkeys():
1264  if hasattr(obj,k):
1265  params[k] = getattr(obj,k)
1267  for k in self.__args.iterkeys():
1268  if k in params:
1269  setattr(obj,k,params[k])
1270  else:
1271  #the parameter must have been removed
1272  delattr(obj,k)
1273  @staticmethod
1275  raise KeyError("Unknown parameter name "+key+" specified while calling Modifier")
1276 
1278  """A modifier which only applies if multiple Modifiers are chosen"""
1279  def __init__(self, lhs, rhs):
1280  self.__lhs = lhs
1281  self.__rhs = rhs
1282  def isChosen(self):
1283  return self.__lhs.isChosen() and self.__rhs.isChosen()
1284  def toModify(self,obj, func=None,**kw):
1285  if not self.isChosen():
1286  return
1287  self.__lhs.toModify(obj,func, **kw)
1288  def makeProcessModifier(self,func):
1289  """This is used to create a ProcessModifer that can perform actions on the process as a whole.
1290  This takes as argument a callable object (e.g. function) that takes as its sole argument an instance of Process.
1291  In order to work, the value returned from this function must be assigned to a uniquely named variable."""
1292  return ProcessModifier(self,func)
1293  def __and__(self, other):
1294  return _AndModifier(self,other)
1295 
1296 
1297 
1299  """This class is used to define standard modifications to a Process.
1300  An instance of this class is declared to denote a specific modification,e.g. era2017 could
1301  reconfigure items in a process to match our expectation of running in 2017. Once declared,
1302  these Modifier instances are imported into a configuration and items that need to be modified
1303  are then associated with the Modifier and with the action to do the modification.
1304  The registered modifications will only occur if the Modifier was passed to
1305  the cms.Process' constructor.
1306  """
1307  def __init__(self):
1309  self.__chosen = False
1310  def makeProcessModifier(self,func):
1311  """This is used to create a ProcessModifer that can perform actions on the process as a whole.
1312  This takes as argument a callable object (e.g. function) that takes as its sole argument an instance of Process.
1313  In order to work, the value returned from this function must be assigned to a uniquely named variable.
1314  """
1315  return ProcessModifier(self,func)
1316  def toModify(self,obj, func=None,**kw):
1317  """This is used to register an action to be performed on the specific object. Two different forms are allowed
1318  Form 1: A callable object (e.g. function) can be passed as the second. This callable object is expected to take one argument
1319  that will be the object passed in as the first argument.
1320  Form 2: A list of parameter name, value pairs can be passed
1321  mod.toModify(foo, fred=cms.int32(7), barney = cms.double(3.14))
1322  This form can also be used to remove a parameter by passing the value of None
1323  #remove the parameter foo.fred
1324  mod.toModify(foo, fred = None)
1325  Additionally, parameters embedded within PSets can also be modified using a dictionary
1326  #change foo.fred.pebbles to 3 and foo.fred.friend to "barney"
1327  mod.toModify(foo, fred = dict(pebbles = 3, friend = "barney)) )
1328  """
1329  if func is not None and len(kw) != 0:
1330  raise TypeError("toModify takes either two arguments or one argument and key/value pairs")
1331  if not self.isChosen():
1332  return
1333  if func is not None:
1334  func(obj)
1335  else:
1336  temp =_ParameterModifier(kw)
1337  temp(obj)
1338  def toReplaceWith(self,toObj,fromObj):
1339  """If the Modifier is chosen the internals of toObj will be associated with the internals of fromObj
1340  """
1341  if type(fromObj) != type(toObj):
1342  raise TypeError("toReplaceWith requires both arguments to be the same class type")
1343  if not self.isChosen():
1344  return
1345  if isinstance(fromObj,_ModuleSequenceType):
1346  toObj._seq = fromObj._seq
1347  toObj._tasks = fromObj._tasks
1348  elif isinstance(fromObj,Task):
1349  toObj._collection = fromObj._collection
1350  elif isinstance(fromObj,_Parameterizable):
1351  #clear old items just incase fromObj is not a complete superset of toObj
1352  for p in toObj.parameterNames_():
1353  delattr(toObj,p)
1354  for p in fromObj.parameterNames_():
1355  setattr(toObj,p,getattr(fromObj,p))
1356  if isinstance(fromObj,_TypedParameterizable):
1357  toObj._TypedParameterizable__type = fromObj._TypedParameterizable__type
1358 
1359  else:
1360  raise TypeError("toReplaceWith does not work with type "+str(type(toObj)))
1361 
1362  def _setChosen(self):
1363  """Should only be called by cms.Process instances"""
1364  self.__chosen = True
1365  def isChosen(self):
1366  return self.__chosen
1367  def __and__(self, other):
1368  return _AndModifier(self,other)
1369  def _isOrContains(self, other):
1370  return self == other
1371 
1372 
1374  """A Modifier made up of a list of Modifiers
1375  """
1376  def __init__(self, *chainedModifiers):
1377  self.__chosen = False
1378  self.__chain = chainedModifiers
1379  def _applyNewProcessModifiers(self,process):
1380  """Should only be called by cms.Process instances
1381  applies list of accumulated changes to the process"""
1382  for m in self.__chain:
1383  m._applyNewProcessModifiers(process)
1384  def _setChosen(self):
1385  """Should only be called by cms.Process instances"""
1386  self.__chosen = True
1387  for m in self.__chain:
1388  m._setChosen()
1389  def isChosen(self):
1390  return self.__chosen
1391  def copyAndExclude(self, toExclude):
1392  """Creates a new ModifierChain which is a copy of
1393  this ModifierChain but excludes any Modifier or
1394  ModifierChain in the list toExclude.
1395  The exclusion is done recursively down the chain.
1396  """
1397  newMods = []
1398  for m in self.__chain:
1399  if m not in toExclude:
1400  s = m
1401  if isinstance(m,ModifierChain):
1402  s = m.__copyIfExclude(toExclude)
1403  newMods.append(s)
1404  return ModifierChain(*newMods)
1405  def __copyIfExclude(self,toExclude):
1406  shouldCopy = False
1407  for m in toExclude:
1408  if self._isOrContains(m):
1409  shouldCopy = True
1410  break
1411  if shouldCopy:
1412  return self.copyAndExclude(toExclude)
1413  return self
1414  def _isOrContains(self, other):
1415  if self is other:
1416  return True
1417  for m in self.__chain:
1418  if m._isOrContains(other):
1419  return True
1420  return False
1421 
1423  """A class used by a Modifier to affect an entire Process instance.
1424  When a Process 'loads' a module containing a ProcessModifier, that
1425  ProcessModifier will be applied to the Process if and only if the
1426  Modifier passed to the constructor has been chosen.
1427  """
1428  def __init__(self, modifier, func):
1429  self.__modifier = modifier
1430  self.__func = func
1431  self.__seenProcesses = set()
1432  def apply(self,process):
1433  if self.__modifier.isChosen():
1434  if process not in self.__seenProcesses:
1435  self.__func(process)
1436  self.__seenProcesses.add(process)
1437 
1438 if __name__=="__main__":
1439  import unittest
1440  import copy
1441 
1443  """Has same interface as the C++ object that creates PSets
1444  """
1445  def __init__(self):
1446  self.values = dict()
1447  def __insertValue(self,tracked,label,value):
1448  self.values[label]=(tracked,value)
1449  def addInt32(self,tracked,label,value):
1450  self.__insertValue(tracked,label,value)
1451  def addVInt32(self,tracked,label,value):
1452  self.__insertValue(tracked,label,value)
1453  def addUInt32(self,tracked,label,value):
1454  self.__insertValue(tracked,label,value)
1455  def addVUInt32(self,tracked,label,value):
1456  self.__insertValue(tracked,label,value)
1457  def addInt64(self,tracked,label,value):
1458  self.__insertValue(tracked,label,value)
1459  def addVInt64(self,tracked,label,value):
1460  self.__insertValue(tracked,label,value)
1461  def addUInt64(self,tracked,label,value):
1462  self.__insertValue(tracked,label,value)
1463  def addVUInt64(self,tracked,label,value):
1464  self.__insertValue(tracked,label,value)
1465  def addDouble(self,tracked,label,value):
1466  self.__insertValue(tracked,label,value)
1467  def addVDouble(self,tracked,label,value):
1468  self.__insertValue(tracked,label,value)
1469  def addBool(self,tracked,label,value):
1470  self.__insertValue(tracked,label,value)
1471  def addString(self,tracked,label,value):
1472  self.__insertValue(tracked,label,value)
1473  def addVString(self,tracked,label,value):
1474  self.__insertValue(tracked,label,value)
1475  def addInputTag(self,tracked,label,value):
1476  self.__insertValue(tracked,label,value)
1477  def addVInputTag(self,tracked,label,value):
1478  self.__insertValue(tracked,label,value)
1479  def addESInputTag(self,tracked,label,value):
1480  self.__insertValue(tracked,label,value)
1481  def addVESInputTag(self,tracked,label,value):
1482  self.__insertValue(tracked,label,value)
1483  def addEventID(self,tracked,label,value):
1484  self.__insertValue(tracked,label,value)
1485  def addVEventID(self,tracked,label,value):
1486  self.__insertValue(tracked,label,value)
1487  def addLuminosityBlockID(self,tracked,label,value):
1488  self.__insertValue(tracked,label,value)
1489  def addLuminosityBlockID(self,tracked,label,value):
1490  self.__insertValue(tracked,label,value)
1491  def addEventRange(self,tracked,label,value):
1492  self.__insertValue(tracked,label,value)
1493  def addVEventRange(self,tracked,label,value):
1494  self.__insertValue(tracked,label,value)
1495  def addPSet(self,tracked,label,value):
1496  self.__insertValue(tracked,label,value)
1497  def addVPSet(self,tracked,label,value):
1498  self.__insertValue(tracked,label,value)
1499  def addFileInPath(self,tracked,label,value):
1500  self.__insertValue(tracked,label,value)
1501  def newPSet(self):
1502  return TestMakePSet()
1503 
1504  class TestModuleCommand(unittest.TestCase):
1505  def setUp(self):
1506  """Nothing to do """
1507  None
1509  p = _Parameterizable()
1510  self.assertEqual(len(p.parameterNames_()),0)
1511  p.a = int32(1)
1512  self.assert_('a' in p.parameterNames_())
1513  self.assertEqual(p.a.value(), 1)
1514  p.a = 10
1515  self.assertEqual(p.a.value(), 10)
1516  p.a = untracked(int32(1))
1517  self.assertEqual(p.a.value(), 1)
1518  self.failIf(p.a.isTracked())
1519  p.a = untracked.int32(1)
1520  self.assertEqual(p.a.value(), 1)
1521  self.failIf(p.a.isTracked())
1522  p = _Parameterizable(foo=int32(10), bar = untracked(double(1.0)))
1523  self.assertEqual(p.foo.value(), 10)
1524  self.assertEqual(p.bar.value(),1.0)
1525  self.failIf(p.bar.isTracked())
1526  self.assertRaises(TypeError,setattr,(p,'c',1))
1527  p = _Parameterizable(a=PSet(foo=int32(10), bar = untracked(double(1.0))))
1528  self.assertEqual(p.a.foo.value(),10)
1529  self.assertEqual(p.a.bar.value(),1.0)
1530  p.b = untracked(PSet(fii = int32(1)))
1531  self.assertEqual(p.b.fii.value(),1)
1532  self.failIf(p.b.isTracked())
1533  #test the fact that values can be shared
1534  v = int32(10)
1535  p=_Parameterizable(a=v)
1536  v.setValue(11)
1537  self.assertEqual(p.a.value(),11)
1538  p.a = 12
1539  self.assertEqual(p.a.value(),12)
1540  self.assertEqual(v.value(),12)
1542  p = _TypedParameterizable("blah", b=int32(1))
1543  #see if copy works deeply
1544  other = p.copy()
1545  other.b = 2
1546  self.assertNotEqual(p.b,other.b)
1547 
1549  p = Process("test")
1550  p.a = EDAnalyzer("MyAnalyzer")
1551  self.assert_( 'a' in p.analyzers_() )
1552  self.assert_( 'a' in p.analyzers)
1553  p.add_(Service("MessageLogger"))
1554  self.assert_('MessageLogger' in p.services_())
1555  self.assertEqual(p.MessageLogger.type_(), "MessageLogger")
1556  p.Tracer = Service("Tracer")
1557  self.assert_('Tracer' in p.services_())
1558  self.assertRaises(TypeError, setattr, *(p,'b',"this should fail"))
1559  self.assertRaises(TypeError, setattr, *(p,'bad',Service("MessageLogger")))
1560  self.assertRaises(ValueError, setattr, *(p,'bad',Source("PoolSource")))
1561  p.out = OutputModule("Outer")
1562  self.assertEqual(p.out.type_(), 'Outer')
1563  self.assert_( 'out' in p.outputModules_() )
1564 
1565  p.geom = ESSource("GeomProd")
1566  self.assert_('geom' in p.es_sources_())
1567  p.add_(ESSource("ConfigDB"))
1568  self.assert_('ConfigDB' in p.es_sources_())
1569 
1570  p.aliasfoo1 = EDAlias(foo1 = VPSet(PSet(type = string("Foo1"))))
1571  self.assert_('aliasfoo1' in p.aliases_())
1572 
1574  class FromArg(object):
1575  def __init__(self,*arg,**args):
1576  for name in args.iterkeys():
1577  self.__dict__[name]=args[name]
1578 
1579  a=EDAnalyzer("MyAnalyzer")
1580  t=EDAnalyzer("MyAnalyzer")
1581  t.setLabel("foo")
1582  s1 = Sequence(a)
1583  s2 = Sequence(s1)
1584  s3 = Sequence(s2)
1585  d = FromArg(
1586  a=a,
1587  b=Service("Full"),
1588  c=Path(a),
1589  d=s2,
1590  e=s1,
1591  f=s3,
1592  g=Sequence(s1+s2+s3)
1593  )
1594  p = Process("Test")
1595  p.extend(d)
1596  self.assertEqual(p.a.type_(),"MyAnalyzer")
1597  self.assertEqual(p.a.label_(),"a")
1598  self.assertRaises(AttributeError,getattr,p,'b')
1599  self.assertEqual(p.Full.type_(),"Full")
1600  self.assertEqual(str(p.c),'a')
1601  self.assertEqual(str(p.d),'a')
1602 
1603  z1 = FromArg(
1604  a=a,
1605  b=Service("Full"),
1606  c=Path(a),
1607  d=s2,
1608  e=s1,
1609  f=s3,
1610  s4=s3,
1611  g=Sequence(s1+s2+s3)
1612  )
1613 
1614  p1 = Process("Test")
1615  #p1.extend(z1)
1616  self.assertRaises(ValueError, p1.extend, z1)
1617 
1618  z2 = FromArg(
1619  a=a,
1620  b=Service("Full"),
1621  c=Path(a),
1622  d=s2,
1623  e=s1,
1624  f=s3,
1625  aaa=copy.deepcopy(a),
1626  s4=copy.deepcopy(s3),
1627  g=Sequence(s1+s2+s3),
1628  t=t
1629  )
1630  p2 = Process("Test")
1631  p2.extend(z2)
1632  #self.assertRaises(ValueError, p2.extend, z2)
1633  self.assertEqual(p2.s4.label_(),"s4")
1634  #p2.s4.setLabel("foo")
1635  self.assertRaises(ValueError, p2.s4.setLabel, "foo")
1636  p2.s4.setLabel("s4")
1637  p2.s4.setLabel(None)
1638  p2.s4.setLabel("foo")
1639  p2._Process__setObjectLabel(p2.s4, "foo")
1640  p2._Process__setObjectLabel(p2.s4, None)
1641  p2._Process__setObjectLabel(p2.s4, "bar")
1642 
1644  p = Process("test")
1645  p.a = EDAnalyzer("MyAnalyzer")
1646  p.p = Path(p.a)
1647  p.s = Sequence(p.a)
1648  p.r = Sequence(p.s)
1649  p.p2 = Path(p.s)
1650  p.schedule = Schedule(p.p2,p.p)
1651  d=p.dumpPython()
1652  self.assertEqual(d,
1653 """import FWCore.ParameterSet.Config as cms
1654 
1655 process = cms.Process("test")
1656 
1657 process.a = cms.EDAnalyzer("MyAnalyzer")
1658 
1659 
1660 process.s = cms.Sequence(process.a)
1661 
1662 
1663 process.r = cms.Sequence(process.s)
1664 
1665 
1666 process.p = cms.Path(process.a)
1667 
1668 
1669 process.p2 = cms.Path(process.s)
1670 
1671 
1672 process.schedule = cms.Schedule(*[ process.p2, process.p ])
1673 """)
1674  #Reverse order of 'r' and 's'
1675  p = Process("test")
1676  p.a = EDAnalyzer("MyAnalyzer")
1677  p.p = Path(p.a)
1678  p.r = Sequence(p.a)
1679  p.s = Sequence(p.r)
1680  p.p2 = Path(p.r)
1681  p.schedule = Schedule(p.p2,p.p)
1682  p.b = EDAnalyzer("YourAnalyzer")
1683  d=p.dumpPython()
1684  self.assertEqual(d,
1685 """import FWCore.ParameterSet.Config as cms
1686 
1687 process = cms.Process("test")
1688 
1689 process.a = cms.EDAnalyzer("MyAnalyzer")
1690 
1691 
1692 process.b = cms.EDAnalyzer("YourAnalyzer")
1693 
1694 
1695 process.r = cms.Sequence(process.a)
1696 
1697 
1698 process.s = cms.Sequence(process.r)
1699 
1700 
1701 process.p = cms.Path(process.a)
1702 
1703 
1704 process.p2 = cms.Path(process.r)
1705 
1706 
1707 process.schedule = cms.Schedule(*[ process.p2, process.p ])
1708 """)
1709  #use an anonymous sequence
1710  p = Process("test")
1711  p.a = EDAnalyzer("MyAnalyzer")
1712  p.p = Path(p.a)
1713  s = Sequence(p.a)
1714  p.r = Sequence(s)
1715  p.p2 = Path(p.r)
1716  p.schedule = Schedule(p.p2,p.p)
1717  d=p.dumpPython()
1718  self.assertEqual(d,
1719  """import FWCore.ParameterSet.Config as cms
1720 
1721 process = cms.Process("test")
1722 
1723 process.a = cms.EDAnalyzer("MyAnalyzer")
1724 
1725 
1726 process.r = cms.Sequence((process.a))
1727 
1728 
1729 process.p = cms.Path(process.a)
1730 
1731 
1732 process.p2 = cms.Path(process.r)
1733 
1734 
1735 process.schedule = cms.Schedule(*[ process.p2, process.p ])
1736 """)
1737 
1738  # include some tasks
1739  p = Process("test")
1740  p.a = EDAnalyzer("MyAnalyzer")
1741  p.b = EDProducer("bProducer")
1742  p.c = EDProducer("cProducer")
1743  p.d = EDProducer("dProducer")
1744  p.e = EDProducer("eProducer")
1745  p.f = EDProducer("fProducer")
1746  p.g = EDProducer("gProducer")
1747  p.task5 = Task()
1748  p.task3 = Task()
1749  p.task2 = Task(p.c, p.task3)
1750  p.task4 = Task(p.f, p.task2)
1751  p.task1 = Task(p.task5)
1752  p.task3.add(p.task1)
1753  p.p = Path(p.a)
1754  s = Sequence(p.a)
1755  p.r = Sequence(s)
1756  p.p2 = Path(p.r, p.task1, p.task2)
1757  p.schedule = Schedule(p.p2,p.p,tasks=[p.task3,p.task4, p.task5])
1758  d=p.dumpPython()
1759  self.assertEqual(d,
1760  """import FWCore.ParameterSet.Config as cms
1761 
1762 process = cms.Process("test")
1763 
1764 process.b = cms.EDProducer("bProducer")
1765 
1766 
1767 process.c = cms.EDProducer("cProducer")
1768 
1769 
1770 process.d = cms.EDProducer("dProducer")
1771 
1772 
1773 process.e = cms.EDProducer("eProducer")
1774 
1775 
1776 process.f = cms.EDProducer("fProducer")
1777 
1778 
1779 process.g = cms.EDProducer("gProducer")
1780 
1781 
1782 process.a = cms.EDAnalyzer("MyAnalyzer")
1783 
1784 
1785 process.task5 = cms.Task()
1786 
1787 
1788 process.task1 = cms.Task(process.task5)
1789 
1790 
1791 process.task3 = cms.Task(process.task1)
1792 
1793 
1794 process.task2 = cms.Task(process.c, process.task3)
1795 
1796 
1797 process.task4 = cms.Task(process.f, process.task2)
1798 
1799 
1800 process.r = cms.Sequence((process.a))
1801 
1802 
1803 process.p = cms.Path(process.a)
1804 
1805 
1806 process.p2 = cms.Path(process.r, process.task1, process.task2)
1807 
1808 
1809 process.schedule = cms.Schedule(*[ process.p2, process.p ], tasks=[process.task3, process.task4, process.task5])
1810 """)
1811  # only tasks
1812  p = Process("test")
1813  p.d = EDProducer("dProducer")
1814  p.e = EDProducer("eProducer")
1815  p.f = EDProducer("fProducer")
1816  p.g = EDProducer("gProducer")
1817  p.task1 = Task(p.d, p.e)
1818  task2 = Task(p.f, p.g)
1819  p.schedule = Schedule(tasks=[p.task1,task2])
1820  d=p.dumpPython()
1821  self.assertEqual(d,
1822  """import FWCore.ParameterSet.Config as cms
1823 
1824 process = cms.Process("test")
1825 
1826 process.d = cms.EDProducer("dProducer")
1827 
1828 
1829 process.e = cms.EDProducer("eProducer")
1830 
1831 
1832 process.f = cms.EDProducer("fProducer")
1833 
1834 
1835 process.g = cms.EDProducer("gProducer")
1836 
1837 
1838 process.task1 = cms.Task(process.d, process.e)
1839 
1840 
1841 process.schedule = cms.Schedule(tasks=[cms.Task(process.f, process.g), process.task1])
1842 """)
1843  # empty schedule
1844  p = Process("test")
1845  p.schedule = Schedule()
1846  d=p.dumpPython()
1847  self.assertEqual(d,
1848  """import FWCore.ParameterSet.Config as cms
1849 
1850 process = cms.Process("test")
1851 
1852 process.schedule = cms.Schedule()
1853 """)
1854 
1855  s = Sequence()
1856  a = EDProducer("A")
1857  s2 = Sequence(a)
1858  s2 += s
1859  process = Process("DUMP")
1860  process.a = a
1861  process.s2 = s2
1862  d=process.dumpPython()
1863  self.assertEqual(d,
1864  """import FWCore.ParameterSet.Config as cms
1865 
1866 process = cms.Process("DUMP")
1867 
1868 process.a = cms.EDProducer("A")
1869 
1870 
1871 process.s2 = cms.Sequence(process.a)
1872 
1873 
1874 """)
1875  s = Sequence()
1876  s1 = Sequence(s)
1877  a = EDProducer("A")
1878  s3 = Sequence(a+a)
1879  s2 = Sequence(a+s3)
1880  s2 += s1
1881  process = Process("DUMP")
1882  process.a = a
1883  process.s2 = s2
1884  d=process.dumpPython()
1885  self.assertEqual(d,
1886  """import FWCore.ParameterSet.Config as cms
1887 
1888 process = cms.Process("DUMP")
1889 
1890 process.a = cms.EDProducer("A")
1891 
1892 
1893 process.s2 = cms.Sequence(process.a+(process.a+process.a))
1894 
1895 
1896 """)
1897 
1898  def testSecSource(self):
1899  p = Process('test')
1900  p.a = SecSource("MySecSource")
1901  self.assertEqual(p.dumpPython().replace('\n',''),'import FWCore.ParameterSet.Config as cmsprocess = cms.Process("test")process.a = cms.SecSource("MySecSource")')
1902 
1904  p = Process('test')
1905  p.a = EDAnalyzer("MyAnalyzer")
1906  old = p.a
1907  p.b = EDAnalyzer("YourAnalyzer")
1908  p.c = EDAnalyzer("OurAnalyzer")
1909  p.d = EDProducer("MyProducer")
1910  old2 = p.d
1911  p.t1 = Task(p.d)
1912  t2 = Task(p.d)
1913  t3 = Task(p.d)
1914  t4 = Task(p.d)
1915  t5 = Task(p.d)
1916  t6 = Task(p.d)
1917  s = Sequence(p.a*p.b)
1918  p.s4 = Sequence(p.a*p.b)
1919  s.associate(t2)
1920  p.s4.associate(t2)
1921  p.p = Path(p.c+s+p.a)
1922  p.e3 = EndPath(p.c+s+p.a)
1923  new = EDAnalyzer("NewAnalyzer")
1924  new2 = EDProducer("NewProducer")
1925  visitor1 = NodeVisitor()
1926  p.p.visit(visitor1)
1927  self.assertTrue(visitor1.modules == set([old,old2,p.b,p.c]))
1928  p.schedule = Schedule(tasks=[t6])
1929  p.globalReplace("a",new)
1930  p.globalReplace("d",new2)
1931  visitor2 = NodeVisitor()
1932  p.p.visit(visitor2)
1933  self.assertTrue(visitor2.modules == set([new,new2,p.b,p.c]))
1934  visitor3 = NodeVisitor()
1935  p.e3.visit(visitor3)
1936  self.assertTrue(visitor3.modules == set([new,new2,p.b,p.c]))
1937  visitor4 = NodeVisitor()
1938  p.s4.visit(visitor4)
1939  self.assertTrue(visitor4.modules == set([new,new2,p.b]))
1940  visitor5 = NodeVisitor()
1941  p.t1.visit(visitor5)
1942  self.assertTrue(visitor5.modules == set([new2]))
1943  visitor6 = NodeVisitor()
1944  listOfTasks = list(p.schedule._tasks)
1945  listOfTasks[0].visit(visitor6)
1946  self.assertTrue(visitor6.modules == set([new2]))
1947 
1948  def testSequence(self):
1949  p = Process('test')
1950  p.a = EDAnalyzer("MyAnalyzer")
1951  p.b = EDAnalyzer("YourAnalyzer")
1952  p.c = EDAnalyzer("OurAnalyzer")
1953  p.s = Sequence(p.a*p.b)
1954  self.assertEqual(str(p.s),'a+b')
1955  self.assertEqual(p.s.label_(),'s')
1956  path = Path(p.c+p.s)
1957  self.assertEqual(str(path),'c+a+b')
1958  p._validateSequence(path, 'p1')
1959  notInProcess = EDAnalyzer('NotInProcess')
1960  p2 = Path(p.c+p.s*notInProcess)
1961  self.assertRaises(RuntimeError, p._validateSequence, p2, 'p2')
1962 
1963  def testSequence2(self):
1964  p = Process('test')
1965  p.a = EDAnalyzer("MyAnalyzer")
1966  p.b = EDAnalyzer("YourAnalyzer")
1967  p.c = EDAnalyzer("OurAnalyzer")
1968  testseq = Sequence(p.a*p.b)
1969  p.s = testseq
1970  #p.y = testseq
1971  self.assertRaises(ValueError, p.__setattr__, "y", testseq)
1972 
1974  service = Service("d")
1975  self.assertFalse(service._inProcess)
1976  process = Process("test")
1977  process.d = service
1978  self.assertTrue(service._inProcess)
1979  service2 = Service("d")
1980  process.d = service2
1981  self.assertFalse(service._inProcess)
1982  self.assertTrue(service2._inProcess)
1983  del process.d
1984  self.assertFalse(service2._inProcess)
1985 
1986  def testTask(self):
1987 
1988  # create some objects to use in tests
1989  edanalyzer = EDAnalyzer("a")
1990  edproducer = EDProducer("b")
1991  edproducer2 = EDProducer("b2")
1992  edproducer3 = EDProducer("b3")
1993  edproducer4 = EDProducer("b4")
1994  edproducer8 = EDProducer("b8")
1995  edproducer9 = EDProducer("b9")
1996  edfilter = EDFilter("c")
1997  service = Service("d")
1998  service3 = Service("d")
1999  essource = ESSource("e")
2000  esproducer = ESProducer("f")
2001  testTask2 = Task()
2002 
2003  # test adding things to Tasks
2004  testTask1 = Task(edproducer, edfilter)
2005  self.assertRaises(RuntimeError, testTask1.add, edanalyzer)
2006  testTask1.add(essource, service)
2007  testTask1.add(essource, esproducer)
2008  testTask1.add(testTask2)
2009  coll = testTask1._collection
2010  self.assertTrue(edproducer in coll)
2011  self.assertTrue(edfilter in coll)
2012  self.assertTrue(service in coll)
2013  self.assertTrue(essource in coll)
2014  self.assertTrue(esproducer in coll)
2015  self.assertTrue(testTask2 in coll)
2016  self.assertTrue(len(coll) == 6)
2017  self.assertTrue(len(testTask2._collection) == 0)
2018 
2019  taskContents = []
2020  for i in testTask1:
2021  taskContents.append(i)
2022  self.assertTrue(taskContents == [edproducer, edfilter, essource, service, esproducer, testTask2])
2023 
2024  # test attaching Task to Process
2025  process = Process("test")
2026 
2027  process.mproducer = edproducer
2028  process.mproducer2 = edproducer2
2029  process.mfilter = edfilter
2030  process.messource = essource
2031  process.mesproducer = esproducer
2032  process.d = service
2033 
2034  testTask3 = Task(edproducer, edproducer2)
2035  testTask1.add(testTask3)
2036  process.myTask1 = testTask1
2037 
2038  # test the validation that occurs when attaching a Task to a Process
2039  # first a case that passes, then one the fails on an EDProducer
2040  # then one that fails on a service
2041  l = set()
2042  visitor = NodeNameVisitor(l)
2043  testTask1.visit(visitor)
2044  self.assertTrue(l == set(['mesproducer', 'mproducer', 'mproducer2', 'mfilter', 'd', 'messource']))
2045  l2 = testTask1.moduleNames
2046  self.assertTrue(l == set(['mesproducer', 'mproducer', 'mproducer2', 'mfilter', 'd', 'messource']))
2047 
2048  testTask4 = Task(edproducer3)
2049  l.clear()
2050  self.assertRaises(RuntimeError, testTask4.visit, visitor)
2051  try:
2052  process.myTask4 = testTask4
2053  self.assertTrue(False)
2054  except RuntimeError:
2055  pass
2056 
2057  testTask5 = Task(service3)
2058  l.clear()
2059  self.assertRaises(RuntimeError, testTask5.visit, visitor)
2060  try:
2061  process.myTask5 = testTask5
2062  self.assertTrue(False)
2063  except RuntimeError:
2064  pass
2065 
2066  process.d = service3
2067  process.myTask5 = testTask5
2068 
2069  # test placement into the Process and the tasks property
2070  expectedDict = { 'myTask1' : testTask1, 'myTask5' : testTask5 }
2071  expectedFixedDict = DictTypes.FixedKeysDict(expectedDict);
2072  self.assertTrue(process.tasks == expectedFixedDict)
2073  self.assertTrue(process.tasks['myTask1'] == testTask1)
2074  self.assertTrue(process.myTask1 == testTask1)
2075 
2076  # test replacing an EDProducer in a Task when calling __settattr__
2077  # for the EDProducer on the Process.
2078  process.mproducer2 = edproducer4
2079  process.d = service
2080  l = list()
2081  visitor1 = ModuleNodeVisitor(l)
2082  testTask1.visit(visitor1)
2083  l.sort()
2084  expectedList = [edproducer,essource,esproducer,service,edfilter,edproducer,edproducer4]
2085  expectedList.sort()
2086  self.assertTrue(expectedList == l)
2087 
2088  process.myTask6 = Task()
2089  process.myTask7 = Task()
2090  process.mproducer8 = edproducer8
2091  process.myTask8 = Task(process.mproducer8)
2092  process.myTask6.add(process.myTask7)
2093  process.myTask7.add(process.myTask8)
2094  process.myTask1.add(process.myTask6)
2095  process.myTask8.add(process.myTask5)
2096 
2097  testDict = process._itemsInDependencyOrder(process.tasks)
2098  expectedLabels = ["myTask5", "myTask8", "myTask7", "myTask6", "myTask1"]
2099  expectedTasks = [process.myTask5, process.myTask8, process.myTask7, process.myTask6, process.myTask1]
2100  index = 0
2101  for testLabel, testTask in testDict.items():
2102  self.assertTrue(testLabel == expectedLabels[index])
2103  self.assertTrue(testTask == expectedTasks[index])
2104  index += 1
2105 
2106  pythonDump = testTask1.dumpPython(PrintOptions())
2107 
2108 
2109  expectedPythonDump = 'cms.Task(process.d, process.mesproducer, process.messource, process.mfilter, process.mproducer, process.mproducer2, process.myTask6)\n'
2110  self.assertTrue(pythonDump == expectedPythonDump)
2111 
2112  process.myTask5 = Task()
2113  process.myTask100 = Task()
2114  process.mproducer9 = edproducer9
2115  sequence1 = Sequence(process.mproducer8, process.myTask1, process.myTask5, testTask2, testTask3)
2116  sequence2 = Sequence(process.mproducer8 + process.mproducer9)
2117  process.sequence3 = Sequence((process.mproducer8 + process.mfilter))
2118  sequence4 = Sequence()
2119  process.path1 = Path(process.mproducer+process.mproducer8+sequence1+sequence2+process.sequence3+sequence4)
2120  process.path1.associate(process.myTask1, process.myTask5, testTask2, testTask3)
2121  process.path11 = Path(process.mproducer+process.mproducer8+sequence1+sequence2+process.sequence3+ sequence4,process.myTask1, process.myTask5, testTask2, testTask3, process.myTask100)
2122  process.path2 = Path(process.mproducer)
2123  process.path3 = Path(process.mproducer9+process.mproducer8,testTask2)
2124 
2125  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')
2126 
2127  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')
2128 
2129  # test NodeNameVisitor and moduleNames
2130  l = set()
2131  nameVisitor = NodeNameVisitor(l)
2132  process.path1.visit(nameVisitor)
2133  self.assertTrue(l == set(['mproducer', 'd', 'mesproducer', None, 'mproducer9', 'mproducer8', 'messource', 'mproducer2', 'mfilter']))
2134  self.assertTrue(process.path1.moduleNames() == set(['mproducer', 'd', 'mesproducer', None, 'mproducer9', 'mproducer8', 'messource', 'mproducer2', 'mfilter']))
2135 
2136  # test copy
2137  process.mproducer10 = EDProducer("b10")
2138  process.path21 = process.path11.copy()
2139  process.path21.replace(process.mproducer, process.mproducer10)
2140 
2141  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')
2142 
2143  # Some peculiarities of the way things work show up here. dumpPython sorts tasks and
2144  # removes duplication at the level of strings. The Task and Sequence objects themselves
2145  # remove duplicate tasks in their contents if the instances are the same (exact same python
2146  # object id which is not the same as the string representation being the same).
2147  # Also note that the mutating visitor replaces sequences and tasks that have
2148  # modified contents with their modified contents, it does not modify the sequence
2149  # or task itself.
2150  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')
2151 
2152  process.path22 = process.path21.copyAndExclude([process.d, process.mesproducer, process.mfilter])
2153  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')
2154 
2155  process.path23 = process.path22.copyAndExclude([process.messource, process.mproducer10])
2156  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')
2157 
2158  process.a = EDAnalyzer("MyAnalyzer")
2159  process.b = OutputModule("MyOutputModule")
2160  process.c = EDFilter("MyFilter")
2161  process.d = EDProducer("MyProducer")
2162  process.e = ESProducer("MyESProducer")
2163  process.f = ESSource("MyESSource")
2164  process.g = ESProducer("g")
2165  process.path24 = Path(process.a+process.b+process.c+process.d)
2166  process.path25 = process.path24.copyAndExclude([process.a,process.b,process.c])
2167  self.assertTrue(process.path25.dumpPython(None) == 'cms.Path(process.d)\n')
2168  #print process.path3
2169  #print process.dumpPython()
2170 
2171  process.path200 = EndPath(Sequence(process.c,Task(process.e)))
2172  process.path200.replace(process.c,process.b)
2173  process.path200.replace(process.e,process.f)
2174  self.assertEqual(process.path200.dumpPython(None), "cms.EndPath(process.b, cms.Task(process.f))\n")
2175  process.path200.replace(process.b,process.c)
2176  process.path200.replace(process.f,process.e)
2177  self.assertEqual(process.path200.dumpPython(None), "cms.EndPath(process.c, cms.Task(process.e))\n")
2178  process.path200.replace(process.c,process.a)
2179  process.path200.replace(process.e,process.g)
2180  self.assertEqual(process.path200.dumpPython(None), "cms.EndPath(process.a, cms.Task(process.g))\n")
2181  process.path200.replace(process.a,process.c)
2182  process.path200.replace(process.g,process.e)
2183  self.assertEqual(process.path200.dumpPython(None), "cms.EndPath(process.c, cms.Task(process.e))\n")
2184 
2185 
2186  def testPath(self):
2187  p = Process("test")
2188  p.a = EDAnalyzer("MyAnalyzer")
2189  p.b = EDAnalyzer("YourAnalyzer")
2190  p.c = EDAnalyzer("OurAnalyzer")
2191  path = Path(p.a)
2192  path *= p.b
2193  path += p.c
2194  self.assertEqual(str(path),'a+b+c')
2195  path = Path(p.a*p.b+p.c)
2196  self.assertEqual(str(path),'a+b+c')
2197 # path = Path(p.a)*p.b+p.c #This leads to problems with sequences
2198 # self.assertEqual(str(path),'((a*b)+c)')
2199  path = Path(p.a+ p.b*p.c)
2200  self.assertEqual(str(path),'a+b+c')
2201  path = Path(p.a*(p.b+p.c))
2202  self.assertEqual(str(path),'a+b+c')
2203  path = Path(p.a*(p.b+~p.c))
2204  pathx = Path(p.a*(p.b+ignore(p.c)))
2205  self.assertEqual(str(path),'a+b+~c')
2206  p.es = ESProducer("AnESProducer")
2207  self.assertRaises(TypeError,Path,p.es)
2208 
2209  t = Path()
2210  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path()\n')
2211 
2212  t = Path(p.a)
2213  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path(process.a)\n')
2214 
2215  t = Path(Task())
2216  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path(cms.Task())\n')
2217 
2218  t = Path(p.a, Task())
2219  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path(process.a, cms.Task())\n')
2220 
2221  p.prod = EDProducer("prodName")
2222  p.t1 = Task(p.prod)
2223  t = Path(p.a, p.t1, Task(), p.t1)
2224  self.assertTrue(t.dumpPython(PrintOptions()) == 'cms.Path(process.a, cms.Task(), process.t1)\n')
2225 
2227  p = Process("test")
2228  a = EDAnalyzer("MyAnalyzer")
2229  p.a = a
2230  a.setLabel("a")
2231  b = EDAnalyzer("YOurAnalyzer")
2232  p.b = b
2233  b.setLabel("b")
2234  path = Path(a * b)
2235  p.path = Path(p.a*p.b)
2236  lookuptable = {id(a): p.a, id(b): p.b}
2237  #self.assertEqual(str(path),str(path._postProcessFixup(lookuptable)))
2238  #lookuptable = p._cloneToObjectDict
2239  #self.assertEqual(str(path),str(path._postProcessFixup(lookuptable)))
2240  self.assertEqual(str(path),str(p.path))
2241 
2242  def testSchedule(self):
2243  p = Process("test")
2244  p.a = EDAnalyzer("MyAnalyzer")
2245  p.b = EDAnalyzer("YourAnalyzer")
2246  p.c = EDAnalyzer("OurAnalyzer")
2247  p.d = EDAnalyzer("OurAnalyzer")
2248  p.path1 = Path(p.a)
2249  p.path2 = Path(p.b)
2250  p.path3 = Path(p.d)
2251 
2252  s = Schedule(p.path1,p.path2)
2253  self.assertEqual(s[0],p.path1)
2254  self.assertEqual(s[1],p.path2)
2255  p.schedule = s
2256  self.assert_('b' in p.schedule.moduleNames())
2257  self.assert_(hasattr(p, 'b'))
2258  self.assert_(hasattr(p, 'c'))
2259  self.assert_(hasattr(p, 'd'))
2260  self.assert_(hasattr(p, 'path1'))
2261  self.assert_(hasattr(p, 'path2'))
2262  self.assert_(hasattr(p, 'path3'))
2263  p.prune()
2264  self.assert_('b' in p.schedule.moduleNames())
2265  self.assert_(hasattr(p, 'b'))
2266  self.assert_(not hasattr(p, 'c'))
2267  self.assert_(not hasattr(p, 'd'))
2268  self.assert_(hasattr(p, 'path1'))
2269  self.assert_(hasattr(p, 'path2'))
2270  self.assert_(not hasattr(p, 'path3'))
2271 
2272  self.assertTrue(len(p.schedule._tasks) == 0)
2273 
2274  p = Process("test")
2275  p.a = EDAnalyzer("MyAnalyzer")
2276  p.b = EDAnalyzer("YourAnalyzer")
2277  p.c = EDAnalyzer("OurAnalyzer")
2278  p.d = EDAnalyzer("dAnalyzer")
2279  p.e = EDProducer("eProducer")
2280  p.f = EDProducer("fProducer")
2281  p.Tracer = Service("Tracer")
2282  p.path1 = Path(p.a)
2283  p.path2 = Path(p.b)
2284  p.path3 = Path(p.d)
2285  p.task1 = Task(p.e)
2286  p.task2 = Task(p.f, p.Tracer)
2287  s = Schedule(p.path1,p.path2,tasks=[p.task1,p.task2,p.task1])
2288  self.assertEqual(s[0],p.path1)
2289  self.assertEqual(s[1],p.path2)
2290  self.assertTrue(len(s._tasks) == 2)
2291  self.assertTrue(p.task1 in s._tasks)
2292  self.assertTrue(p.task2 in s._tasks)
2293  listOfTasks = list(s._tasks)
2294  self.assertTrue(len(listOfTasks) == 2)
2295  self.assertTrue(p.task1 == listOfTasks[0])
2296  self.assertTrue(p.task2 == listOfTasks[1])
2297  p.schedule = s
2298  self.assert_('b' in p.schedule.moduleNames())
2299 
2300  process2 = Process("test")
2301  process2.a = EDAnalyzer("MyAnalyzer")
2302  process2.e = EDProducer("eProducer")
2303  process2.path1 = Path(process2.a)
2304  process2.task1 = Task(process2.e)
2305  process2.schedule = Schedule(process2.path1,tasks=process2.task1)
2306  listOfTasks = list(process2.schedule._tasks)
2307  self.assertTrue(listOfTasks[0] == process2.task1)
2308 
2309  # test Schedule copy
2310  s2 = s.copy()
2311  self.assertEqual(s2[0],p.path1)
2312  self.assertEqual(s2[1],p.path2)
2313  self.assertTrue(len(s2._tasks) == 2)
2314  self.assertTrue(p.task1 in s2._tasks)
2315  self.assertTrue(p.task2 in s2._tasks)
2316  listOfTasks = list(s2._tasks)
2317  self.assertTrue(len(listOfTasks) == 2)
2318  self.assertTrue(p.task1 == listOfTasks[0])
2319  self.assertTrue(p.task2 == listOfTasks[1])
2320 
2321  names = s.moduleNames()
2322  self.assertTrue(names == set(['a', 'b', 'e', 'Tracer', 'f']))
2323  #adding a path not attached to the Process should cause an exception
2324  p = Process("test")
2325  p.a = EDAnalyzer("MyAnalyzer")
2326  path1 = Path(p.a)
2327  s = Schedule(path1)
2328  self.assertRaises(RuntimeError, lambda : p.setSchedule_(s) )
2329 
2330  #make sure anonymous sequences work
2331  p = Process("test")
2332  p.a = EDAnalyzer("MyAnalyzer")
2333  p.b = EDAnalyzer("MyOtherAnalyzer")
2334  p.c = EDProducer("MyProd")
2335  path1 = Path(p.c*Sequence(p.a+p.b))
2336  s = Schedule(path1)
2337  self.assert_('a' in s.moduleNames())
2338  self.assert_('b' in s.moduleNames())
2339  self.assert_('c' in s.moduleNames())
2340  p.path1 = path1
2341  p.schedule = s
2342  p.prune()
2343  self.assert_('a' in s.moduleNames())
2344  self.assert_('b' in s.moduleNames())
2345  self.assert_('c' in s.moduleNames())
2346 
2348  p = Process("test")
2349  p.a = EDAnalyzer("MyAnalyzer")
2350  p.b = EDAnalyzer("YourAnalyzer")
2351  p.c = EDAnalyzer("OurAnalyzer")
2352  p.path1 = Path(p.a)
2353  p.path2 = Path(p.b)
2354  self.assert_(p.schedule is None)
2355  pths = p.paths
2356  keys = pths.keys()
2357  self.assertEqual(pths[keys[0]],p.path1)
2358  self.assertEqual(pths[keys[1]],p.path2)
2359  p.prune()
2360  self.assert_(hasattr(p, 'a'))
2361  self.assert_(hasattr(p, 'b'))
2362  self.assert_(not hasattr(p, 'c'))
2363  self.assert_(hasattr(p, 'path1'))
2364  self.assert_(hasattr(p, 'path2'))
2365 
2366 
2367  p = Process("test")
2368  p.a = EDAnalyzer("MyAnalyzer")
2369  p.b = EDAnalyzer("YourAnalyzer")
2370  p.c = EDAnalyzer("OurAnalyzer")
2371  p.path2 = Path(p.b)
2372  p.path1 = Path(p.a)
2373  self.assert_(p.schedule is None)
2374  pths = p.paths
2375  keys = pths.keys()
2376  self.assertEqual(pths[keys[1]],p.path1)
2377  self.assertEqual(pths[keys[0]],p.path2)
2378 
2379 
2380  def testUsing(self):
2381  p = Process('test')
2382  p.block = PSet(a = int32(1))
2383  p.modu = EDAnalyzer('Analyzer', p.block, b = int32(2))
2384  self.assertEqual(p.modu.a.value(),1)
2385  self.assertEqual(p.modu.b.value(),2)
2386 
2387  def testOverride(self):
2388  p = Process('test')
2389  a = EDProducer("A", a1=int32(0))
2390  self.assert_(not a.isModified())
2391  a.a1 = 1
2392  self.assert_(a.isModified())
2393  p.a = a
2394  self.assertEqual(p.a.a1.value(), 1)
2395  # try adding an unmodified module.
2396  # should accept it
2397  p.a = EDProducer("A", a1=int32(2))
2398  self.assertEqual(p.a.a1.value(), 2)
2399  # try adding a modified module. Should throw
2400  # no longer, since the same (modified) say, geometry
2401  # could come from more than one cff
2402  b = EDProducer("A", a1=int32(3))
2403  b.a1 = 4
2404  #self.assertRaises(RuntimeError, setattr, *(p,'a',b))
2405  ps1 = PSet(a = int32(1))
2406  ps2 = PSet(a = int32(2))
2407  self.assertRaises(ValueError, EDProducer, 'C', ps1, ps2)
2408  self.assertRaises(ValueError, EDProducer, 'C', ps1, a=int32(3))
2409 
2410  def testExamples(self):
2411  p = Process("Test")
2412  p.source = Source("PoolSource",fileNames = untracked(string("file:reco.root")))
2413  p.foos = EDProducer("FooProducer")
2414  p.bars = EDProducer("BarProducer", foos=InputTag("foos"))
2415  p.out = OutputModule("PoolOutputModule",fileName=untracked(string("file:foos.root")))
2416  p.bars.foos = 'Foosball'
2417  self.assertEqual(p.bars.foos, InputTag('Foosball'))
2418  p.p = Path(p.foos*p.bars)
2419  p.e = EndPath(p.out)
2420  p.add_(Service("MessageLogger"))
2421 
2422  def testPrefers(self):
2423  p = Process("Test")
2424  p.add_(ESSource("ForceSource"))
2425  p.juicer = ESProducer("JuicerProducer")
2426  p.prefer("ForceSource")
2427  p.prefer("juicer")
2428  self.assertEqual(p.dumpConfig(),
2429 """process Test = {
2430  es_module juicer = JuicerProducer {
2431  }
2432  es_source = ForceSource {
2433  }
2434  es_prefer = ForceSource {
2435  }
2436  es_prefer juicer = JuicerProducer {
2437  }
2438 }
2439 """)
2440  p.prefer("juicer",fooRcd=vstring("Foo"))
2441  self.assertEqual(p.dumpConfig(),
2442 """process Test = {
2443  es_module juicer = JuicerProducer {
2444  }
2445  es_source = ForceSource {
2446  }
2447  es_prefer = ForceSource {
2448  }
2449  es_prefer juicer = JuicerProducer {
2450  vstring fooRcd = {
2451  'Foo'
2452  }
2453 
2454  }
2455 }
2456 """)
2457  self.assertEqual(p.dumpPython(),
2458 """import FWCore.ParameterSet.Config as cms
2459 
2460 process = cms.Process("Test")
2461 
2462 process.juicer = cms.ESProducer("JuicerProducer")
2463 
2464 
2465 process.ForceSource = cms.ESSource("ForceSource")
2466 
2467 
2468 process.prefer("ForceSource")
2469 
2470 process.prefer("juicer",
2471  fooRcd = cms.vstring('Foo')
2472 )
2473 
2474 """)
2475 
2476  def testFreeze(self):
2477  process = Process("Freeze")
2478  m = EDProducer("M", p=PSet(i = int32(1)))
2479  m.p.i = 2
2480  process.m = m
2481  # should be frozen
2482  #self.assertRaises(ValueError, setattr, m.p, 'i', 3)
2483  #self.assertRaises(ValueError, setattr, m, 'p', PSet(i=int32(1)))
2484  #self.assertRaises(ValueError, setattr, m.p, 'j', 1)
2485  #self.assertRaises(ValueError, setattr, m, 'j', 1)
2486  # But OK to change through the process
2487  process.m.p.i = 4
2488  self.assertEqual(process.m.p.i.value(), 4)
2489  process.m.p = PSet(j=int32(1))
2490  # should work to clone it, though
2491  m2 = m.clone(p = PSet(i = int32(5)), j = int32(8))
2492  m2.p.i = 6
2493  m2.j = 8
2494  def testSubProcess(self):
2495  process = Process("Parent")
2496  subProcess = Process("Child")
2497  subProcess.a = EDProducer("A")
2498  subProcess.p = Path(subProcess.a)
2499  subProcess.add_(Service("Foo"))
2500  process.addSubProcess(SubProcess(subProcess))
2501  d = process.dumpPython()
2502  equalD ="""import FWCore.ParameterSet.Config as cms
2503 
2504 process = cms.Process("Parent")
2505 
2506 parentProcess = process
2507 import FWCore.ParameterSet.Config as cms
2508 
2509 process = cms.Process("Child")
2510 
2511 process.a = cms.EDProducer("A")
2512 
2513 
2514 process.Foo = cms.Service("Foo")
2515 
2516 
2517 process.p = cms.Path(process.a)
2518 
2519 
2520 childProcess = process
2521 process = parentProcess
2522 process.addSubProcess(cms.SubProcess(process = childProcess, SelectEvents = cms.untracked.PSet(
2523 
2524 ), outputCommands = cms.untracked.vstring()))
2525 
2526 """
2527  equalD = equalD.replace("parentProcess","parentProcess"+str(hash(process.subProcesses_()[0])))
2528  self.assertEqual(d,equalD)
2529  p = TestMakePSet()
2530  process.fillProcessDesc(p)
2531  self.assertEqual((True,['a']),p.values["subProcesses"][1][0].values["process"][1].values['@all_modules'])
2532  self.assertEqual((True,['p']),p.values["subProcesses"][1][0].values["process"][1].values['@paths'])
2533  self.assertEqual({'@service_type':(True,'Foo')}, p.values["subProcesses"][1][0].values["process"][1].values["services"][1][0].values)
2534  def testRefToPSet(self):
2535  proc = Process("test")
2536  proc.top = PSet(a = int32(1))
2537  proc.ref = PSet(refToPSet_ = string("top"))
2538  proc.ref2 = PSet( a = int32(1), b = PSet( refToPSet_ = string("top")))
2539  proc.ref3 = PSet(refToPSet_ = string("ref"))
2540  proc.ref4 = VPSet(PSet(refToPSet_ = string("top")),
2541  PSet(refToPSet_ = string("ref2")))
2542  p = TestMakePSet()
2543  proc.fillProcessDesc(p)
2544  self.assertEqual((True,1),p.values["ref"][1].values["a"])
2545  self.assertEqual((True,1),p.values["ref3"][1].values["a"])
2546  self.assertEqual((True,1),p.values["ref2"][1].values["a"])
2547  self.assertEqual((True,1),p.values["ref2"][1].values["b"][1].values["a"])
2548  self.assertEqual((True,1),p.values["ref4"][1][0].values["a"])
2549  self.assertEqual((True,1),p.values["ref4"][1][1].values["a"])
2550  def testPrune(self):
2551  p = Process("test")
2552  p.a = EDAnalyzer("MyAnalyzer")
2553  p.b = EDAnalyzer("YourAnalyzer")
2554  p.c = EDAnalyzer("OurAnalyzer")
2555  p.d = EDAnalyzer("OurAnalyzer")
2556  p.s = Sequence(p.d)
2557  p.path1 = Path(p.a)
2558  p.path2 = Path(p.b)
2559  self.assert_(p.schedule is None)
2560  pths = p.paths
2561  keys = pths.keys()
2562  self.assertEqual(pths[keys[0]],p.path1)
2563  self.assertEqual(pths[keys[1]],p.path2)
2564  p.pset1 = PSet(parA = string("pset1"))
2565  p.pset2 = untracked.PSet(parA = string("pset2"))
2566  p.vpset1 = VPSet()
2567  p.vpset2 = untracked.VPSet()
2568  p.prune()
2569  self.assert_(hasattr(p, 'a'))
2570  self.assert_(hasattr(p, 'b'))
2571  self.assert_(not hasattr(p, 'c'))
2572  self.assert_(not hasattr(p, 'd'))
2573  self.assert_(not hasattr(p, 's'))
2574  self.assert_(hasattr(p, 'path1'))
2575  self.assert_(hasattr(p, 'path2'))
2576 # self.assert_(not hasattr(p, 'pset1'))
2577 # self.assert_(hasattr(p, 'pset2'))
2578 # self.assert_(not hasattr(p, 'vpset1'))
2579 # self.assert_(not hasattr(p, 'vpset2'))
2580 
2581  p = Process("test")
2582  p.a = EDAnalyzer("MyAnalyzer")
2583  p.b = EDAnalyzer("YourAnalyzer")
2584  p.c = EDAnalyzer("OurAnalyzer")
2585  p.d = EDAnalyzer("OurAnalyzer")
2586  p.e = EDAnalyzer("OurAnalyzer")
2587  p.s = Sequence(p.d)
2588  p.s2 = Sequence(p.b)
2589  p.s3 = Sequence(p.e)
2590  p.path1 = Path(p.a)
2591  p.path2 = Path(p.b)
2592  p.path3 = Path(p.b+p.s2)
2593  p.path4 = Path(p.b+p.s3)
2594  p.schedule = Schedule(p.path1,p.path2,p.path3)
2595  pths = p.paths
2596  keys = pths.keys()
2597  self.assertEqual(pths[keys[0]],p.path1)
2598  self.assertEqual(pths[keys[1]],p.path2)
2599  p.prune()
2600  self.assert_(hasattr(p, 'a'))
2601  self.assert_(hasattr(p, 'b'))
2602  self.assert_(not hasattr(p, 'c'))
2603  self.assert_(not hasattr(p, 'd'))
2604  self.assert_(not hasattr(p, 'e'))
2605  self.assert_(not hasattr(p, 's'))
2606  self.assert_(hasattr(p, 's2'))
2607  self.assert_(not hasattr(p, 's3'))
2608  self.assert_(hasattr(p, 'path1'))
2609  self.assert_(hasattr(p, 'path2'))
2610  self.assert_(hasattr(p, 'path3'))
2611  self.assert_(not hasattr(p, 'path4'))
2612  #test SequencePlaceholder
2613  p = Process("test")
2614  p.a = EDAnalyzer("MyAnalyzer")
2615  p.b = EDAnalyzer("YourAnalyzer")
2616  p.s = Sequence(SequencePlaceholder("a")+p.b)
2617  p.pth = Path(p.s)
2618  p.prune()
2619  self.assert_(hasattr(p, 'a'))
2620  self.assert_(hasattr(p, 'b'))
2621  self.assert_(hasattr(p, 's'))
2622  self.assert_(hasattr(p, 'pth'))
2623  #test unresolved SequencePlaceholder
2624  p = Process("test")
2625  p.b = EDAnalyzer("YourAnalyzer")
2626  p.s = Sequence(SequencePlaceholder("a")+p.b)
2627  p.pth = Path(p.s)
2628  p.prune(keepUnresolvedSequencePlaceholders=True)
2629  self.assert_(hasattr(p, 'b'))
2630  self.assert_(hasattr(p, 's'))
2631  self.assert_(hasattr(p, 'pth'))
2632  self.assertEqual(p.s.dumpPython(''),'cms.Sequence(cms.SequencePlaceholder("a")+process.b)\n')
2633  def testDelete(self):
2634  p = Process("test")
2635  p.a = EDAnalyzer("MyAnalyzer")
2636  p.b = EDAnalyzer("YourAnalyzer")
2637  p.c = EDAnalyzer("OurAnalyzer")
2638  p.d = EDAnalyzer("OurAnalyzer")
2639  p.e = EDAnalyzer("OurAnalyzer")
2640  p.f = EDAnalyzer("OurAnalyzer")
2641  p.g = EDProducer("OurProducer")
2642  p.h = EDProducer("YourProducer")
2643  p.t1 = Task(p.g, p.h)
2644  t2 = Task(p.g, p.h)
2645  t3 = Task(p.g, p.h)
2646  p.s = Sequence(p.d+p.e)
2647  p.path1 = Path(p.a+p.f+p.s,t2)
2648  p.endpath1 = EndPath(p.b+p.f)
2649  p.schedule = Schedule(tasks=[t3])
2650  self.assertTrue(hasattr(p, 'f'))
2651  self.assertTrue(hasattr(p, 'g'))
2652  del p.e
2653  del p.f
2654  del p.g
2655  self.assertFalse(hasattr(p, 'f'))
2656  self.assertFalse(hasattr(p, 'g'))
2657  self.assertTrue(p.t1.dumpPython(None) == 'cms.Task(process.h)\n')
2658  self.assertTrue(p.s.dumpPython(None) == 'cms.Sequence(process.d)\n')
2659  self.assertTrue(p.path1.dumpPython(None) == 'cms.Path(process.a+process.s, cms.Task(process.h))\n')
2660  self.assertTrue(p.endpath1.dumpPython(None) == 'cms.EndPath(process.b)\n')
2661  del p.s
2662  self.assertTrue(p.path1.dumpPython(None) == 'cms.Path(process.a+(process.d), cms.Task(process.h))\n')
2663  self.assertTrue(p.schedule_().dumpPython(None) == 'cms.Schedule(tasks=[cms.Task(process.h)])\n')
2664  def testModifier(self):
2665  m1 = Modifier()
2666  p = Process("test",m1)
2667  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1))
2668  def _mod_fred(obj):
2669  obj.fred = 2
2670  m1.toModify(p.a,_mod_fred)
2671  self.assertEqual(p.a.fred.value(),2)
2672  p.b = EDAnalyzer("YourAnalyzer", wilma = int32(1))
2673  m1.toModify(p.b, wilma = 2)
2674  self.assertEqual(p.b.wilma.value(),2)
2675  self.assert_(p.isUsingModifier(m1))
2676  #check that Modifier not attached to a process doesn't run
2677  m1 = Modifier()
2678  p = Process("test")
2679  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1))
2680  m1.toModify(p.a,_mod_fred)
2681  p.b = EDAnalyzer("YourAnalyzer", wilma = int32(1))
2682  m1.toModify(p.b, wilma = 2)
2683  self.assertEqual(p.a.fred.value(),1)
2684  self.assertEqual(p.b.wilma.value(),1)
2685  self.assertEqual(p.isUsingModifier(m1),False)
2686  #make sure clones get the changes
2687  m1 = Modifier()
2688  p = Process("test",m1)
2689  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
2690  m1.toModify(p.a, fred = int32(2))
2691  p.b = p.a.clone(wilma = int32(3))
2692  self.assertEqual(p.a.fred.value(),2)
2693  self.assertEqual(p.a.wilma.value(),1)
2694  self.assertEqual(p.b.fred.value(),2)
2695  self.assertEqual(p.b.wilma.value(),3)
2696  #test removal of parameter
2697  m1 = Modifier()
2698  p = Process("test",m1)
2699  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
2700  m1.toModify(p.a, fred = None)
2701  self.assertEqual(hasattr(p.a, "fred"), False)
2702  self.assertEqual(p.a.wilma.value(),1)
2703  #test adding a parameter
2704  m1 = Modifier()
2705  p = Process("test",m1)
2706  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1))
2707  m1.toModify(p.a, wilma = int32(2))
2708  self.assertEqual(p.a.fred.value(), 1)
2709  self.assertEqual(p.a.wilma.value(),2)
2710  #test setting of value in PSet
2711  m1 = Modifier()
2712  p = Process("test",m1)
2713  p.a = EDAnalyzer("MyAnalyzer", flintstones = PSet(fred = int32(1), wilma = int32(1)))
2714  m1.toModify(p.a, flintstones = dict(fred = int32(2)))
2715  self.assertEqual(p.a.flintstones.fred.value(),2)
2716  self.assertEqual(p.a.flintstones.wilma.value(),1)
2717  #test proper exception from nonexisting parameter name
2718  m1 = Modifier()
2719  p = Process("test",m1)
2720  p.a = EDAnalyzer("MyAnalyzer", flintstones = PSet(fred = PSet(wilma = int32(1))))
2721  self.assertRaises(KeyError, lambda: m1.toModify(p.a, flintstones = dict(imnothere = dict(wilma=2))))
2722  self.assertRaises(KeyError, lambda: m1.toModify(p.a, foo = 1))
2723  #test setting a value in a VPSet
2724  m1 = Modifier()
2725  p = Process("test",m1)
2726  p.a = EDAnalyzer("MyAnalyzer", flintstones = VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
2727  m1.toModify(p.a, flintstones = {1:dict(wilma = int32(2))})
2728  self.assertEqual(p.a.flintstones[0].fred.value(),1)
2729  self.assertEqual(p.a.flintstones[1].wilma.value(),2)
2730  #test setting a value in a list of values
2731  m1 = Modifier()
2732  p = Process("test",m1)
2733  p.a = EDAnalyzer("MyAnalyzer", fred = vuint32(1,2,3))
2734  m1.toModify(p.a, fred = {1:7})
2735  self.assertEqual(p.a.fred[0],1)
2736  self.assertEqual(p.a.fred[1],7)
2737  self.assertEqual(p.a.fred[2],3)
2738  #test IndexError setting a value in a list to an item key not in the list
2739  m1 = Modifier()
2740  p = Process("test",m1)
2741  p.a = EDAnalyzer("MyAnalyzer", fred = vuint32(1,2,3))
2742  raised = False
2743  try: m1.toModify(p.a, fred = {5:7})
2744  except IndexError as e: raised = True
2745  self.assertEqual(raised, True)
2746  #test TypeError setting a value in a list using a key that is not an int
2747  m1 = Modifier()
2748  p = Process("test",m1)
2749  p.a = EDAnalyzer("MyAnalyzer", flintstones = VPSet(PSet(fred = int32(1)), PSet(wilma = int32(1))))
2750  raised = False
2751  try: m1.toModify(p.a, flintstones = dict(bogus = int32(37)))
2752  except TypeError as e: raised = True
2753  self.assertEqual(raised, True)
2754  #test that load causes process wide methods to run
2755  def _rem_a(proc):
2756  del proc.a
2757  class ProcModifierMod(object):
2758  def __init__(self,modifier,func):
2759  self.proc_mod_ = modifier.makeProcessModifier(func)
2760  class DummyMod(object):
2761  def __init__(self):
2762  self.a = EDAnalyzer("Dummy")
2763  testMod = DummyMod()
2764  p.extend(testMod)
2765  self.assert_(hasattr(p,"a"))
2766  m1 = Modifier()
2767  p = Process("test",m1)
2768  testProcMod = ProcModifierMod(m1,_rem_a)
2769  p.extend(testMod)
2770  p.extend(testProcMod)
2771  self.assert_(not hasattr(p,"a"))
2772  #test ModifierChain
2773  m1 = Modifier()
2774  mc = ModifierChain(m1)
2775  p = Process("test",mc)
2776  self.assert_(p.isUsingModifier(m1))
2777  self.assert_(p.isUsingModifier(mc))
2778  testMod = DummyMod()
2779  p.b = EDAnalyzer("Dummy2", fred = int32(1))
2780  m1.toModify(p.b, fred = int32(3))
2781  p.extend(testMod)
2782  testProcMod = ProcModifierMod(m1,_rem_a)
2783  p.extend(testProcMod)
2784  self.assert_(not hasattr(p,"a"))
2785  self.assertEqual(p.b.fred.value(),3)
2786  #check cloneAndExclude
2787  m1 = Modifier()
2788  m2 = Modifier()
2789  mc = ModifierChain(m1,m2)
2790  mclone = mc.copyAndExclude([m2])
2791  self.assert_(not mclone._isOrContains(m2))
2792  self.assert_(mclone._isOrContains(m1))
2793  m3 = Modifier()
2794  mc2 = ModifierChain(mc,m3)
2795  mclone = mc2.copyAndExclude([m2])
2796  self.assert_(not mclone._isOrContains(m2))
2797  self.assert_(mclone._isOrContains(m1))
2798  self.assert_(mclone._isOrContains(m3))
2799  #check combining
2800  m1 = Modifier()
2801  m2 = Modifier()
2802  p = Process("test",m1)
2803  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
2804  (m1 & m2).toModify(p.a, fred = int32(2))
2805  self.assertEqual(p.a.fred, 1)
2806  m1 = Modifier()
2807  m2 = Modifier()
2808  p = Process("test",m1,m2)
2809  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
2810  (m1 & m2).toModify(p.a, fred = int32(2))
2811  self.assertEqual(p.a.fred, 2)
2812  m1 = Modifier()
2813  m2 = Modifier()
2814  m3 = Modifier()
2815  p = Process("test",m1,m2,m3)
2816  p.a = EDAnalyzer("MyAnalyzer", fred = int32(1), wilma = int32(1))
2817  (m1 & m2 & m3).toModify(p.a, fred = int32(2))
2818  self.assertEqual(p.a.fred, 2)
2819  #check toReplaceWith
2820  m1 = Modifier()
2821  p = Process("test",m1)
2822  p.a =EDAnalyzer("MyAnalyzer", fred = int32(1))
2823  m1.toReplaceWith(p.a, EDAnalyzer("YourAnalyzer", wilma = int32(3)))
2824  p.b =EDAnalyzer("BAn")
2825  p.c =EDProducer("c")
2826  p.d =EDProducer("d")
2827  p.tc = Task(p.c)
2828  p.td = Task(p.d)
2829  p.s = Sequence(p.a, p.tc)
2830  m1.toReplaceWith(p.s, Sequence(p.a+p.b, p.td))
2831  self.assertEqual(p.a.wilma.value(),3)
2832  self.assertEqual(p.a.type_(),"YourAnalyzer")
2833  self.assertEqual(hasattr(p,"fred"),False)
2834  self.assertTrue(p.s.dumpPython("") == "cms.Sequence(process.a+process.b, process.td)\n")
2835  p.e =EDProducer("e")
2836  m1.toReplaceWith(p.td, Task(p.e))
2837  self.assertTrue(p.td._collection == OrderedSet([p.e]))
2838  #check toReplaceWith doesn't activate not chosen
2839  m1 = Modifier()
2840  p = Process("test")
2841  p.a =EDAnalyzer("MyAnalyzer", fred = int32(1))
2842  m1.toReplaceWith(p.a, EDAnalyzer("YourAnalyzer", wilma = int32(3)))
2843  self.assertEqual(p.a.type_(),"MyAnalyzer")
2844  unittest.main()
def __setstate__(self, pkldict)
Definition: Config.py:154
def addVString(self, tracked, label, value)
Definition: Config.py:1473
def _dumpConfigOptionallyNamedList(self, items, typeName, options)
Definition: Config.py:652
def addEventRange(self, tracked, label, value)
Definition: Config.py:1491
def testExamples(self)
Definition: Config.py:2410
def __getattribute__(self, name)
Definition: Config.py:1161
def _place(self, label, process)
Definition: Config.py:1246
def getProcessName(self)
Definition: Config.py:1234
def testServiceInProcess(self)
Definition: Config.py:1973
def outputCommands(self)
Definition: Config.py:1240
def _setChosen(self)
Definition: Config.py:1384
def producerNames(self)
Definition: Config.py:141
def _dumpConfigUnnamedList(self, items, typeName, options)
Definition: Config.py:647
def newPSet(self)
Definition: Config.py:1501
def _placeAnalyzer(self, name, mod)
Definition: Config.py:523
def addString(self, tracked, label, value)
Definition: Config.py:1471
def __findFirstUsingModule(self, seqsOrTasks, mod)
Definition: Config.py:409
def subProcesses_(self)
Definition: Config.py:198
def makeProcessModifier(self, func)
Definition: Config.py:1288
def __repr__(self)
Definition: Config.py:1205
def _pruneModules(self, d, scheduledNames)
Definition: Config.py:1011
def _modifyParametersFromDict(params, newParams, errorRaiser, keyDepth="")
Definition: Mixins.py:630
def vpsets_(self)
Definition: Config.py:269
def setName_(self, name)
Definition: Config.py:177
def _placeESPrefer(self, name, mod)
Definition: Config.py:544
def testSequence2(self)
Definition: Config.py:1963
def __and__(self, other)
Definition: Config.py:1293
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 pathNames(self)
Definition: Config.py:150
def addVESInputTag(self, tracked, label, value)
Definition: Config.py:1481
def __and__(self, other)
Definition: Config.py:1367
def _placeSequence(self, name, mod)
Definition: Config.py:539
def __call__(self, obj)
Definition: Config.py:1261
def _setChosen(self)
Definition: Config.py:1362
def _validateSequence(self, sequence, label)
Definition: Config.py:740
def __getattr__(self, attr)
Definition: Config.py:1207
def tasks_(self)
Definition: Config.py:222
def setStrict(self, value)
Definition: Config.py:136
def addDouble(self, tracked, label, value)
Definition: Config.py:1465
def isChosen(self)
Definition: Config.py:1389
def producers_(self)
Definition: Config.py:182
def _findPreferred(self, esname, d, args, kargs)
Definition: Config.py:1130
def replace(string, replacements)
def testModifier(self)
Definition: Config.py:2664
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:1463
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:1541
def addUInt64(self, tracked, label, value)
Definition: Config.py:1461
def _itemsInDependencyOrder(self, processDictionaryOfItems)
Definition: Config.py:756
def source_(self)
Definition: Config.py:186
def addVPSet(self, tracked, label, value)
Definition: Config.py:1497
def nameInProcessDesc_(self, label)
Definition: Config.py:1244
def psets_(self)
Definition: Config.py:265
def testSecSource(self)
Definition: Config.py:1898
def __init__(self, args)
Definition: Config.py:1259
def format_outerframe(number)
def __init__(self, args, kw)
Definition: Config.py:1203
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:1453
def _dumpConfigESPrefers(self, options)
Definition: Config.py:721
def __setattr__(self, name, value)
Definition: Config.py:1166
def setLooper_(self, lpr)
Definition: Config.py:195
def setSource_(self, src)
Definition: Config.py:189
def __init__(self, process)
Definition: Config.py:1152
def extend(self, other, items=())
Definition: Config.py:584
def _okToPlace(self, name, mod, d)
Definition: Config.py:488
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:1451
def _placeFilter(self, name, mod)
Definition: Config.py:521
def schedule_(self)
Definition: Config.py:226
def validate(self)
Definition: Config.py:1094
def addVInputTag(self, tracked, label, value)
Definition: Config.py:1477
def _applyNewProcessModifiers(self, process)
Definition: Config.py:1379
def analyzerNames(self)
Definition: Config.py:144
def testSchedule(self)
Definition: Config.py:2242
def addLuminosityBlockID(self, tracked, label, value)
Definition: Config.py:1487
def addESInputTag(self, tracked, label, value)
Definition: Config.py:1479
def __new__(cls, args, kw)
Definition: Config.py:1185
def endpaths_(self)
Definition: Config.py:214
def SelectEvents(self)
Definition: Config.py:1238
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:1459
def addVEventID(self, tracked, label, value)
Definition: Config.py:1485
def toModify(self, obj, func=None, kw)
Definition: Config.py:1316
def testGlobalReplace(self)
Definition: Config.py:1903
def _placeOutputModule(self, name, mod)
Definition: Config.py:517
def addFileInPath(self, tracked, label, value)
Definition: Config.py:1499
def testRefToPSet(self)
Definition: Config.py:2534
def testOverride(self)
Definition: Config.py:2387
def _placeSource(self, name, mod)
Definition: Config.py:557
def __init__(self)
Definition: Config.py:1307
def _dumpPythonSubProcesses(self, l, options)
Definition: Config.py:726
def checkImportPermission(minLevel=2, allowedPatterns=[])
Definition: Config.py:26
def ignore(seq)
def __init__(self, modifier, func)
Definition: Config.py:1428
def isUsingModifier(self, mod)
Definition: Config.py:274
def dumpPython(self, options=PrintOptions())
Definition: Config.py:1227
def __copyIfExclude(self, toExclude)
Definition: Config.py:1405
def sequences_(self)
Definition: Config.py:218
def _validateTask(self, task, label)
Definition: Config.py:748
def testParameterizable(self)
Definition: Config.py:1508
def testSubProcess(self)
Definition: Config.py:2494
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:1495
def testProcessDumpPython(self)
Definition: Config.py:1643
def _placeService(self, typeName, mod)
Definition: Config.py:575
def resolve(self, keepUnresolvedSequencePlaceholders=False)
Definition: Config.py:953
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:1369
def getSubProcessPSet(self, parameterSet)
Definition: Config.py:1248
def copyAndExclude(self, toExclude)
Definition: Config.py:1391
def addVUInt32(self, tracked, label, value)
Definition: Config.py:1455
def addVEventRange(self, tracked, label, value)
Definition: Config.py:1493
def __init__(self, lhs, rhs)
Definition: Config.py:1279
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 testSequence(self)
Definition: Config.py:1948
def toReplaceWith(self, toObj, fromObj)
Definition: Config.py:1338
def _placeProducer(self, name, mod)
Definition: Config.py:519
def prefer(self, esmodule, args, kargs)
Definition: Config.py:1101
def __delattr__(self, name)
Definition: Config.py:1171
def _dumpConfigNamedList(self, items, typeName, options)
Definition: Config.py:642
def addInputTag(self, tracked, label, value)
Definition: Config.py:1475
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:1432
def testCloneSequence(self)
Definition: Config.py:2226
def process(self)
Definition: Config.py:1236
def _placeTask(self, name, task)
Definition: Config.py:548
def isChosen(self)
Definition: Config.py:1282
def addSubProcess(self, mod)
Definition: Config.py:573
def _placePSet(self, name, mod)
Definition: Config.py:553
def _isOrContains(self, other)
Definition: Config.py:1414
def addInt64(self, tracked, label, value)
Definition: Config.py:1457
def name_(self)
Definition: Config.py:175
def _place(self, name, mod, d)
Definition: Config.py:509
def testProcessExtend(self)
Definition: Config.py:1573
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:1447
def _placeVPSet(self, name, mod)
Definition: Config.py:555
def globalReplace(self, label, new)
Definition: Config.py:863
def toModify(self, obj, func=None, kw)
Definition: Config.py:1284
def addBool(self, tracked, label, value)
Definition: Config.py:1469
def paths_(self)
Definition: Config.py:210
def addEventID(self, tracked, label, value)
Definition: Config.py:1483
def outputModules_(self)
Definition: Config.py:206
def _placeLooper(self, name, mod)
Definition: Config.py:565
def testImplicitSchedule(self)
Definition: Config.py:2347
def prune(self, verbose=False, keepUnresolvedSequencePlaceholders=False)
Definition: Config.py:959
def addVDouble(self, tracked, label, value)
Definition: Config.py:1467
def _insertInto(self, parameterSet, itemDict)
Definition: Config.py:868
def _delattrFromSetattr(self, name)
Definition: Config.py:464
def makeProcessModifier(self, func)
Definition: Config.py:1310
def __init__(self, process, SelectEvents=untracked.PSet(), outputCommands=untracked.vstring())
Definition: Config.py:1215
def type_(self)
Definition: Config.py:1242
def __init__(self, chainedModifiers)
Definition: Config.py:1376
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:1449
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:1018
def findProcess(module)
Definition: Config.py:79
def isChosen(self)
Definition: Config.py:1365
def testProcessInsertion(self)
Definition: Config.py:1548
def __init__(self)
Definition: Config.py:1445
def aliases_(self)
Definition: Config.py:261