CMS 3D CMS Logo

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__ (self, process, label, postfix)
 
def clonedSequence (self)
 
def enter (self, visitee)
 
def leave (self, visitee)
 

Private Member Functions

def __appendToTopSequence (self, visitee)
 

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.

126  def __init__(self, process, label, postfix):
127  self._process = process
128  self._postfix = postfix
129  self._sequenceStack = [label]
130  self._moduleLabels = []
131  self._sequenceLabels = []
132  self._waitForSequenceToClose = None # modules will only be cloned or added if this is None
133 
def __init__(self, process, label, postfix)

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().

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

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

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

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

Member Data Documentation

HiHelperTools.CloneSequenceVisitor._moduleLabels
private
HiHelperTools.CloneSequenceVisitor._postfix
private
HiHelperTools.CloneSequenceVisitor._process
private
HiHelperTools.CloneSequenceVisitor._sequenceLabels
private

Definition at line 131 of file HiHelperTools.py.

Referenced by HiHelperTools.CloneSequenceVisitor.enter().

HiHelperTools.CloneSequenceVisitor._sequenceStack
private
HiHelperTools.CloneSequenceVisitor._waitForSequenceToClose
private