CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
helpers.CloneSequenceVisitor Class Reference
Inheritance diagram for helpers.CloneSequenceVisitor:

Public Member Functions

def __init__ (self, process, label, postfix, removePostfix="", noClones=[], addToTask=False)
 
def clonedSequence (self)
 
def enter (self, visitee)
 
def leave (self, visitee)
 

Private Member Functions

def __appendToTopSequence (self, visitee)
 
def _newLabel (self, label)
 

Private Attributes

 _addToTask
 
 _clonedSequence
 
 _moduleLabels
 
 _noClones
 
 _patAlgosToolsTask
 
 _postfix
 
 _process
 
 _removePostfix
 

Detailed Description

Visitor that travels within a cms.Sequence, and returns a cloned version of the Sequence.
All modules and sequences are cloned and a postfix is added

Definition at line 154 of file helpers.py.

Constructor & Destructor Documentation

def helpers.CloneSequenceVisitor.__init__ (   self,
  process,
  label,
  postfix,
  removePostfix = "",
  noClones = [],
  addToTask = False 
)

Definition at line 157 of file helpers.py.

157  def __init__(self, process, label, postfix, removePostfix="", noClones = [], addToTask = False):
158  self._process = process
159  self._postfix = postfix
160  self._removePostfix = removePostfix
161  self._noClones = noClones
162  self._addToTask = addToTask
163  self._moduleLabels = []
164  self._clonedSequence = cms.Sequence()
165  setattr(process, self._newLabel(label), self._clonedSequence)
166  if addToTask:
168 
def _newLabel(self, label)
Definition: helpers.py:194
def __init__(self, process, label, postfix, removePostfix="", noClones=[], addToTask=False)
Definition: helpers.py:157
def getPatAlgosToolsTask(process)
Definition: helpers.py:12

Member Function Documentation

def helpers.CloneSequenceVisitor.__appendToTopSequence (   self,
  visitee 
)
private
def helpers.CloneSequenceVisitor._newLabel (   self,
  label 
)
private

Definition at line 194 of file helpers.py.

References helpers.CloneSequenceVisitor._postfix, and helpers.CloneSequenceVisitor._removePostfix.

Referenced by helpers.CloneSequenceVisitor.enter().

194  def _newLabel(self, label):
195  if self._removePostfix != "":
196  if label[-len(self._removePostfix):] == self._removePostfix:
197  label = label[0:-len(self._removePostfix)]
198  else:
199  raise Exception("Tried to remove postfix %s from label %s, but it wasn't there" % (self._removePostfix, label))
200  return label + self._postfix
201 
def _newLabel(self, label)
Definition: helpers.py:194
def helpers.CloneSequenceVisitor.clonedSequence (   self)

Definition at line 188 of file helpers.py.

188  def clonedSequence(self):
189  for label in self._moduleLabels:
190  massSearchReplaceAnyInputTag(self._clonedSequence, label, self._newLabel(label), moduleLabelOnly=True, verbose=False)
191  self._moduleLabels = [] # prevent the InputTag replacement next time the 'clonedSequence' function is called.
192  return self._clonedSequence
193 
def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag, verbose=False, moduleLabelOnly=False, skipLabelTest=False)
Definition: MassReplace.py:72
def _newLabel(self, label)
Definition: helpers.py:194
def helpers.CloneSequenceVisitor.enter (   self,
  visitee 
)

Definition at line 169 of file helpers.py.

References helpers.CloneSequenceVisitor.__appendToTopSequence(), helpers.CloneSequenceVisitor._addToTask, helpers.CloneSequenceVisitor._moduleLabels, helpers.CloneSequenceVisitor._newLabel(), helpers.CloneSequenceVisitor._noClones, and helpers.CloneSequenceVisitor._process.

169  def enter(self, visitee):
170  if isinstance(visitee, cms._Module):
171  label = visitee.label()
172  newModule = None
173  if label in self._noClones: #keep unchanged
174  newModule = getattr(self._process, label)
175  elif label in self._moduleLabels: # has the module already been cloned ?
176  newModule = getattr(self._process, self._newLabel(label))
177  else:
178  self._moduleLabels.append(label)
179  newModule = visitee.clone()
180  setattr(self._process, self._newLabel(label), newModule)
181  if self._addToTask:
182  self._patAlgosToolsTask.add(getattr(self._process, self._newLabel(label)))
183  self.__appendToTopSequence(newModule)
184 
def _newLabel(self, label)
Definition: helpers.py:194
def enter(self, visitee)
Definition: helpers.py:169
def __appendToTopSequence(self, visitee)
Definition: helpers.py:202
def helpers.CloneSequenceVisitor.leave (   self,
  visitee 
)

Definition at line 185 of file helpers.py.

185  def leave(self, visitee):
186  pass
187 
def leave(self, visitee)
Definition: helpers.py:185

Member Data Documentation

helpers.CloneSequenceVisitor._addToTask
private

Definition at line 162 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

helpers.CloneSequenceVisitor._clonedSequence
private
helpers.CloneSequenceVisitor._moduleLabels
private
helpers.CloneSequenceVisitor._noClones
private

Definition at line 161 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

helpers.CloneSequenceVisitor._patAlgosToolsTask
private

Definition at line 167 of file helpers.py.

helpers.CloneSequenceVisitor._postfix
private
helpers.CloneSequenceVisitor._process
private
helpers.CloneSequenceVisitor._removePostfix
private

Definition at line 160 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor._newLabel().