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

Constructor & Destructor Documentation

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

Definition at line 153 of file helpers.py.

153  def __init__(self, process, label, postfix, removePostfix="", noClones = [], addToTask = False):
154  self._process = process
155  self._postfix = postfix
156  self._removePostfix = removePostfix
157  self._noClones = noClones
158  self._addToTask = addToTask
159  self._moduleLabels = []
160  self._clonedSequence = cms.Sequence()
161  setattr(process, self._newLabel(label), self._clonedSequence)
162  if addToTask:
164 
def _newLabel(self, label)
Definition: helpers.py:190
def __init__(self, process, label, postfix, removePostfix="", noClones=[], addToTask=False)
Definition: helpers.py:153
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 190 of file helpers.py.

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

Referenced by helpers.CloneSequenceVisitor.enter().

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

Definition at line 184 of file helpers.py.

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

Definition at line 165 of file helpers.py.

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

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

Definition at line 181 of file helpers.py.

181  def leave(self, visitee):
182  pass
183 
def leave(self, visitee)
Definition: helpers.py:181

Member Data Documentation

helpers.CloneSequenceVisitor._addToTask
private

Definition at line 158 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

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

Definition at line 157 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

helpers.CloneSequenceVisitor._patAlgosToolsTask
private

Definition at line 163 of file helpers.py.

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

Definition at line 156 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor._newLabel().