CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

HiHelperTools::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 123 of file HiHelperTools.py.


Constructor & Destructor Documentation

def HiHelperTools::CloneSequenceVisitor::__init__ (   self,
  process,
  label,
  postfix 
)

Definition at line 126 of file HiHelperTools.py.

00127                                                :
00128         self._process = process
00129         self._postfix = postfix
00130         self._sequenceStack = [label]
00131         self._moduleLabels = []
00132         self._sequenceLabels = []
00133         self._waitForSequenceToClose = None # modules will only be cloned or added if this is None


Member Function Documentation

def HiHelperTools::CloneSequenceVisitor::__appendToTopSequence (   self,
  visitee 
) [private]

Definition at line 172 of file HiHelperTools.py.

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

Definition at line 164 of file HiHelperTools.py.

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

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

Definition at line 134 of file HiHelperTools.py.

00135                            :
00136         if not self._waitForSequenceToClose is None:
00137             return #we are in a already cloned sequence
00138         if isinstance(visitee,cms._Module):
00139             label = visitee.label()
00140             newModule = None
00141             if label in self._moduleLabels:
00142                 newModule = getattr(self._process, label+self._postfix)
00143             else:
00144                 self._moduleLabels.append(label)
00145                 
00146                 newModule = visitee.clone()
00147                 setattr(self._process, label+self._postfix, newModule)
00148             self.__appendToTopSequence(newModule)
00149 
00150         if isinstance(visitee,cms.Sequence):
00151             if visitee.label() in self._sequenceLabels: # is the sequence allready cloned?
00152                 self._waitForSequenceToClose = visitee.label()
00153                 self._sequenceStack.append(  getattr(self._process, visitee.label()+self._postfix) )
00154             else:
00155                 self._sequenceStack.append(visitee.label())#save desired label as placeholder until we have a module to create the sequence

def HiHelperTools::CloneSequenceVisitor::leave (   self,
  visitee 
)

Definition at line 156 of file HiHelperTools.py.

00157                            :
00158         if isinstance(visitee,cms.Sequence):
00159             if self._waitForSequenceToClose == visitee.label():
00160                 self._waitForSequenceToClose = None
00161             if not isinstance(self._sequenceStack[-1], cms.Sequence):
00162                 raise StandardError, "empty Sequence encountered during cloneing. sequnece stack: %s"%self._sequenceStack
00163             self.__appendToTopSequence( self._sequenceStack.pop() )


Member Data Documentation

Definition at line 126 of file HiHelperTools.py.

Definition at line 126 of file HiHelperTools.py.

Definition at line 126 of file HiHelperTools.py.

Definition at line 126 of file HiHelperTools.py.

Definition at line 126 of file HiHelperTools.py.

Definition at line 126 of file HiHelperTools.py.