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, verbose=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
 
 _verbose
 

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

◆ __init__()

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

Definition at line 158 of file helpers.py.

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

Member Function Documentation

◆ __appendToTopSequence()

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

Definition at line 204 of file helpers.py.

204  def __appendToTopSequence(self, visitee):
205  self._clonedSequence += visitee
206 

References helpers.CloneSequenceVisitor._clonedSequence.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _newLabel()

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

Definition at line 196 of file helpers.py.

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

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

Referenced by helpers.CloneSequenceVisitor.enter().

◆ clonedSequence()

def helpers.CloneSequenceVisitor.clonedSequence (   self)

Definition at line 190 of file helpers.py.

190  def clonedSequence(self):
191  for label in self._moduleLabels:
192  massSearchReplaceAnyInputTag(self._clonedSequence, label, self._newLabel(label), moduleLabelOnly=True, verbose=self._verbose)
193  self._moduleLabels = [] # prevent the InputTag replacement next time the 'clonedSequence' function is called.
194  return self._clonedSequence
195 

◆ enter()

def helpers.CloneSequenceVisitor.enter (   self,
  visitee 
)

Definition at line 171 of file helpers.py.

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

References helpers.CloneSequenceVisitor.__appendToTopSequence(), helpers.CloneSequenceVisitor._addToTask, helpers.CloneSequenceVisitor._moduleLabels, helpers.CloneSequenceVisitor._newLabel(), helpers.CloneSequenceVisitor._noClones, helpers.CloneSequenceVisitor._patAlgosToolsTask, helpers.CloneSequenceVisitor._process, PVValHelper.add(), and mps_setup.append.

◆ leave()

def helpers.CloneSequenceVisitor.leave (   self,
  visitee 
)

Definition at line 187 of file helpers.py.

187  def leave(self, visitee):
188  pass
189 

Member Data Documentation

◆ _addToTask

helpers.CloneSequenceVisitor._addToTask
private

Definition at line 163 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _clonedSequence

helpers.CloneSequenceVisitor._clonedSequence
private

Definition at line 166 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.__appendToTopSequence().

◆ _moduleLabels

helpers.CloneSequenceVisitor._moduleLabels
private

Definition at line 165 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _noClones

helpers.CloneSequenceVisitor._noClones
private

Definition at line 162 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _patAlgosToolsTask

helpers.CloneSequenceVisitor._patAlgosToolsTask
private

Definition at line 169 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _postfix

helpers.CloneSequenceVisitor._postfix
private

Definition at line 160 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor._newLabel().

◆ _process

helpers.CloneSequenceVisitor._process
private

Definition at line 159 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _removePostfix

helpers.CloneSequenceVisitor._removePostfix
private

Definition at line 161 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor._newLabel().

◆ _verbose

helpers.CloneSequenceVisitor._verbose
private

Definition at line 164 of file helpers.py.

helpers.getPatAlgosToolsTask
def getPatAlgosToolsTask(process)
Definition: helpers.py:13
PVValHelper::add
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: PVValidationHelpers.cc:12
Exception
mps_setup.append
append
Definition: mps_setup.py:85
MassReplace.massSearchReplaceAnyInputTag
def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag, verbose=False, moduleLabelOnly=False, skipLabelTest=False)
Definition: MassReplace.py:79