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

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

Member Function Documentation

◆ __appendToTopSequence()

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

Definition at line 205 of file helpers.py.

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

References helpers.CloneSequenceVisitor._clonedSequence.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _newLabel()

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

Definition at line 197 of file helpers.py.

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

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

Referenced by helpers.CloneSequenceVisitor.enter().

◆ clonedSequence()

def helpers.CloneSequenceVisitor.clonedSequence (   self)

Definition at line 191 of file helpers.py.

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

◆ enter()

def helpers.CloneSequenceVisitor.enter (   self,
  visitee 
)

Definition at line 172 of file helpers.py.

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

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

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

Member Data Documentation

◆ _addToTask

helpers.CloneSequenceVisitor._addToTask
private

Definition at line 164 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _clonedSequence

helpers.CloneSequenceVisitor._clonedSequence
private

Definition at line 167 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.__appendToTopSequence().

◆ _moduleLabels

helpers.CloneSequenceVisitor._moduleLabels
private

Definition at line 166 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _noClones

helpers.CloneSequenceVisitor._noClones
private

Definition at line 163 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _patAlgosToolsTask

helpers.CloneSequenceVisitor._patAlgosToolsTask
private

Definition at line 170 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _postfix

helpers.CloneSequenceVisitor._postfix
private

Definition at line 161 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor._newLabel().

◆ _process

helpers.CloneSequenceVisitor._process
private

Definition at line 160 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.enter().

◆ _removePostfix

helpers.CloneSequenceVisitor._removePostfix
private

Definition at line 162 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor._newLabel().

◆ _verbose

helpers.CloneSequenceVisitor._verbose
private

Definition at line 165 of file helpers.py.

helpers.getPatAlgosToolsTask
def getPatAlgosToolsTask(process)
Definition: helpers.py:14
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