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 155 of file helpers.py.

Constructor & Destructor Documentation

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

Definition at line 158 of file helpers.py.

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

Member Function Documentation

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

Definition at line 195 of file helpers.py.

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

Referenced by helpers.CloneSequenceVisitor.enter().

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

Definition at line 189 of file helpers.py.

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

Definition at line 170 of file helpers.py.

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

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

Definition at line 186 of file helpers.py.

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

Member Data Documentation

helpers.CloneSequenceVisitor._addToTask
private

Definition at line 163 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

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

Definition at line 162 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

helpers.CloneSequenceVisitor._patAlgosToolsTask
private

Definition at line 168 of file helpers.py.

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

Definition at line 161 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor._newLabel().