test
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
HiHelperTools.CloneSequenceVisitor Class Reference
Inheritance diagram for HiHelperTools.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 123 of file HiHelperTools.py.

Constructor & Destructor Documentation

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

Definition at line 126 of file HiHelperTools.py.

127  def __init__(self, process, label, postfix):
128  self._process = process
129  self._postfix = postfix
130  self._sequenceStack = [label]
131  self._moduleLabels = []
132  self._sequenceLabels = []
133  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.

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

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

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

Definition at line 164 of file HiHelperTools.py.

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

165  def clonedSequence(self):
166  if not len(self._sequenceStack) == 1:
167  raise Exception("someting went wrong, the sequence stack looks like: %s"%self._sequenceStack)
168  for label in self._moduleLabels:
169  massSearchReplaceAnyInputTag(self._sequenceStack[-1], label, label+self._postfix, moduleLabelOnly=True, verbose=False)
170  self._moduleLabels = [] #prevent the InputTag replacement next time this is called.
171  return self._sequenceStack[-1]
def massSearchReplaceAnyInputTag
def HiHelperTools.CloneSequenceVisitor.enter (   self,
  visitee 
)

Definition at line 134 of file HiHelperTools.py.

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

135  def enter(self,visitee):
136  if not self._waitForSequenceToClose is None:
137  return #we are in a already cloned sequence
138  if isinstance(visitee,cms._Module):
139  label = visitee.label()
140  newModule = None
141  if label in self._moduleLabels:
142  newModule = getattr(self._process, label+self._postfix)
143  else:
144  self._moduleLabels.append(label)
145 
146  newModule = visitee.clone()
147  setattr(self._process, label+self._postfix, newModule)
148  self.__appendToTopSequence(newModule)
149 
150  if isinstance(visitee,cms.Sequence):
151  if visitee.label() in self._sequenceLabels: # is the sequence allready cloned?
152  self._waitForSequenceToClose = visitee.label()
153  self._sequenceStack.append( getattr(self._process, visitee.label()+self._postfix) )
154  else:
155  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.

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

157  def leave(self,visitee):
158  if isinstance(visitee,cms.Sequence):
159  if self._waitForSequenceToClose == visitee.label():
160  self._waitForSequenceToClose = None
161  if not isinstance(self._sequenceStack[-1], cms.Sequence):
162  raise Exception("empty Sequence encountered during cloneing. sequnece stack: %s"%self._sequenceStack)
163  self.__appendToTopSequence( self._sequenceStack.pop() )

Member Data Documentation

HiHelperTools.CloneSequenceVisitor._moduleLabels
private

Definition at line 130 of file HiHelperTools.py.

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

HiHelperTools.CloneSequenceVisitor._postfix
private

Definition at line 128 of file HiHelperTools.py.

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

HiHelperTools.CloneSequenceVisitor._process
private

Definition at line 127 of file HiHelperTools.py.

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

HiHelperTools.CloneSequenceVisitor._sequenceLabels
private

Definition at line 131 of file HiHelperTools.py.

Referenced by HiHelperTools.CloneSequenceVisitor.enter().

HiHelperTools.CloneSequenceVisitor._sequenceStack
private

Definition at line 129 of file HiHelperTools.py.

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

HiHelperTools.CloneSequenceVisitor._waitForSequenceToClose
private

Definition at line 132 of file HiHelperTools.py.

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