CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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__
 
def clonedSequence
 
def enter
 
def leave
 

Private Member Functions

def __appendToTopSequence
 

Private Attributes

 _moduleLabels
 
 _postfix
 
 _process
 
 _sequenceLabels
 
 _sequenceStack
 
 _waitForSequenceToClose
 

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

Constructor & Destructor Documentation

def helpers.CloneSequenceVisitor.__init__ (   self,
  process,
  label,
  postfix 
)

Definition at line 131 of file helpers.py.

132  def __init__(self, process, label, postfix):
133  self._process = process
134  self._postfix = postfix
135  self._sequenceStack = [label]
136  self._moduleLabels = []
137  self._sequenceLabels = []
138  self._waitForSequenceToClose = None # modules will only be cloned or added if this is None

Member Function Documentation

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

Definition at line 177 of file helpers.py.

References helpers.CloneSequenceVisitor._postfix, helpers.CloneSequenceVisitor._process, helpers.CloneSequenceVisitor._sequenceStack, and diffTwoXMLs.label.

Referenced by HiHelperTools.CloneSequenceVisitor.enter(), helpers.CloneSequenceVisitor.enter(), HiHelperTools.CloneSequenceVisitor.leave(), and helpers.CloneSequenceVisitor.leave().

178  def __appendToTopSequence(self, visitee):#this is darn ugly because empty cms.Sequences are not supported
179  if isinstance(self._sequenceStack[-1], basestring):#we have the name of an empty sequence on the stack. create it!
180  oldSequenceLabel = self._sequenceStack.pop()
181  newSequenceLabel = oldSequenceLabel + self._postfix
182  self._sequenceStack.append(cms.Sequence(visitee))
183  if hasattr(self._process, newSequenceLabel):
184  raise StandardError("Cloning the sequence "+self._sequenceStack[-1].label()+" would overwrite existing object." )
185  setattr(self._process, newSequenceLabel, self._sequenceStack[-1])
186  self._sequenceLabels.append(oldSequenceLabel)
187  else:
188  self._sequenceStack[-1] += visitee
def helpers.CloneSequenceVisitor.clonedSequence (   self)

Definition at line 169 of file helpers.py.

References helpers.CloneSequenceVisitor._moduleLabels, helpers.CloneSequenceVisitor._postfix, helpers.CloneSequenceVisitor._sequenceStack, and helpers.massSearchReplaceAnyInputTag().

170  def clonedSequence(self):
171  if not len(self._sequenceStack) == 1:
172  raise StandardError, "someting went wrong, the sequence stack looks like: %s"%self._sequenceStack
173  for label in self._moduleLabels:
174  massSearchReplaceAnyInputTag(self._sequenceStack[-1], label, label+self._postfix, moduleLabelOnly=True, verbose=False)
175  self._moduleLabels = [] #prevent the InputTag replacement next time this is called.
176  return self._sequenceStack[-1]
def massSearchReplaceAnyInputTag
Definition: helpers.py:218
def helpers.CloneSequenceVisitor.enter (   self,
  visitee 
)

Definition at line 139 of file helpers.py.

References helpers.CloneSequenceVisitor.__appendToTopSequence(), helpers.CloneSequenceVisitor._moduleLabels, helpers.CloneSequenceVisitor._postfix, helpers.CloneSequenceVisitor._process, helpers.CloneSequenceVisitor._sequenceLabels, and helpers.CloneSequenceVisitor._waitForSequenceToClose.

140  def enter(self,visitee):
141  if not self._waitForSequenceToClose is None:
142  return #we are in a already cloned sequence
143  if isinstance(visitee,cms._Module):
144  label = visitee.label()
145  newModule = None
146  if label in self._moduleLabels:
147  newModule = getattr(self._process, label+self._postfix)
148  else:
149  self._moduleLabels.append(label)
150 
151  newModule = visitee.clone()
152  setattr(self._process, label+self._postfix, newModule)
153  self.__appendToTopSequence(newModule)
154 
155  if isinstance(visitee,cms.Sequence):
156  if visitee.label() in self._sequenceLabels: # is the sequence allready cloned?
157  self._waitForSequenceToClose = visitee.label()
158  self._sequenceStack.append( getattr(self._process, visitee.label()+self._postfix) )
159  else:
160  self._sequenceStack.append(visitee.label())#save desired label as placeholder until we have a module to create the sequence
def helpers.CloneSequenceVisitor.leave (   self,
  visitee 
)

Definition at line 161 of file helpers.py.

References helpers.CloneSequenceVisitor.__appendToTopSequence(), helpers.CloneSequenceVisitor._sequenceStack, and helpers.CloneSequenceVisitor._waitForSequenceToClose.

162  def leave(self,visitee):
163  if isinstance(visitee,cms.Sequence):
164  if self._waitForSequenceToClose == visitee.label():
165  self._waitForSequenceToClose = None
166  if not isinstance(self._sequenceStack[-1], cms.Sequence):
167  raise StandardError, "empty Sequence encountered during cloneing. sequnece stack: %s"%self._sequenceStack
168  self.__appendToTopSequence( self._sequenceStack.pop() )

Member Data Documentation

helpers.CloneSequenceVisitor._moduleLabels
private

Definition at line 135 of file helpers.py.

Referenced by HiHelperTools.CloneSequenceVisitor.clonedSequence(), helpers.CloneSequenceVisitor.clonedSequence(), HiHelperTools.CloneSequenceVisitor.enter(), and helpers.CloneSequenceVisitor.enter().

helpers.CloneSequenceVisitor._postfix
private

Definition at line 133 of file helpers.py.

Referenced by HiHelperTools.CloneSequenceVisitor.__appendToTopSequence(), helpers.CloneSequenceVisitor.__appendToTopSequence(), HiHelperTools.CloneSequenceVisitor.clonedSequence(), helpers.CloneSequenceVisitor.clonedSequence(), HiHelperTools.CloneSequenceVisitor.enter(), and helpers.CloneSequenceVisitor.enter().

helpers.CloneSequenceVisitor._process
private

Definition at line 132 of file helpers.py.

Referenced by HiHelperTools.CloneSequenceVisitor.__appendToTopSequence(), helpers.CloneSequenceVisitor.__appendToTopSequence(), HiHelperTools.CloneSequenceVisitor.enter(), and helpers.CloneSequenceVisitor.enter().

helpers.CloneSequenceVisitor._sequenceLabels
private

Definition at line 136 of file helpers.py.

Referenced by HiHelperTools.CloneSequenceVisitor.enter(), and helpers.CloneSequenceVisitor.enter().

helpers.CloneSequenceVisitor._sequenceStack
private

Definition at line 134 of file helpers.py.

Referenced by HiHelperTools.CloneSequenceVisitor.__appendToTopSequence(), helpers.CloneSequenceVisitor.__appendToTopSequence(), HiHelperTools.CloneSequenceVisitor.clonedSequence(), helpers.CloneSequenceVisitor.clonedSequence(), HiHelperTools.CloneSequenceVisitor.leave(), and helpers.CloneSequenceVisitor.leave().

helpers.CloneSequenceVisitor._waitForSequenceToClose
private

Definition at line 137 of file helpers.py.

Referenced by HiHelperTools.CloneSequenceVisitor.enter(), helpers.CloneSequenceVisitor.enter(), HiHelperTools.CloneSequenceVisitor.leave(), and helpers.CloneSequenceVisitor.leave().