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