CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

helpers::CloneSequenceVisitor Class Reference

List of all members.

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.

00132                                                :
00133         self._process = process
00134         self._postfix = postfix
00135         self._sequenceStack = [label]
00136         self._moduleLabels = []
00137         self._sequenceLabels = []
00138         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.

00177                                             :#this is darn ugly because empty cms.Sequences are not supported
00178         if isinstance(self._sequenceStack[-1], basestring):#we have the name of an empty sequence on the stack. create it!
00179             oldSequenceLabel = self._sequenceStack.pop()
00180             newSequenceLabel = oldSequenceLabel + self._postfix
00181             self._sequenceStack.append(cms.Sequence(visitee))
00182             if hasattr(self._process, newSequenceLabel):
00183                 raise StandardError("Cloning the sequence "+self._sequenceStack[-1].label()+" would overwrite existing object." )
00184             setattr(self._process, newSequenceLabel, self._sequenceStack[-1])
00185             self._sequenceLabels.append(oldSequenceLabel)
00186         else:
00187             self._sequenceStack[-1] += visitee
00188         
def helpers::CloneSequenceVisitor::clonedSequence (   self)

Definition at line 169 of file helpers.py.

00170                             :
00171         if not len(self._sequenceStack) == 1:
00172             raise StandardError, "someting went wrong, the sequence stack looks like: %s"%self._sequenceStack
00173         for label in self._moduleLabels:
00174             massSearchReplaceAnyInputTag(self._sequenceStack[-1], label, label+self._postfix, moduleLabelOnly=True, verbose=False)
00175         self._moduleLabels = [] #prevent the InputTag replacement next time this is called.
00176         return self._sequenceStack[-1]

def helpers::CloneSequenceVisitor::enter (   self,
  visitee 
)

Definition at line 139 of file helpers.py.

00140                            :
00141         if not self._waitForSequenceToClose is None:
00142             return #we are in a already cloned sequence
00143         if isinstance(visitee,cms._Module):
00144             label = visitee.label()
00145             newModule = None
00146             if label in self._moduleLabels:
00147                 newModule = getattr(self._process, label+self._postfix)
00148             else:
00149                 self._moduleLabels.append(label)
00150                 
00151                 newModule = visitee.clone()
00152                 setattr(self._process, label+self._postfix, newModule)
00153             self.__appendToTopSequence(newModule)
00154 
00155         if isinstance(visitee,cms.Sequence):
00156             if visitee.label() in self._sequenceLabels: # is the sequence allready cloned?
00157                 self._waitForSequenceToClose = visitee.label()
00158                 self._sequenceStack.append(  getattr(self._process, visitee.label()+self._postfix) )
00159             else:
00160                 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.

00162                            :
00163         if isinstance(visitee,cms.Sequence):
00164             if self._waitForSequenceToClose == visitee.label():
00165                 self._waitForSequenceToClose = None
00166             if not isinstance(self._sequenceStack[-1], cms.Sequence):
00167                 raise StandardError, "empty Sequence encountered during cloneing. sequnece stack: %s"%self._sequenceStack
00168             self.__appendToTopSequence( self._sequenceStack.pop() )


Member Data Documentation

Definition at line 131 of file helpers.py.

Definition at line 131 of file helpers.py.

Definition at line 131 of file helpers.py.

Definition at line 131 of file helpers.py.

Definition at line 131 of file helpers.py.

Definition at line 131 of file helpers.py.