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

Constructor & Destructor Documentation

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

Definition at line 57 of file HiHelperTools.py.

57  def __init__(self, process, label, postfix):
58  self._process = process
59  self._postfix = postfix
60  self._sequenceStack = [label]
61  self._moduleLabels = []
62  self._sequenceLabels = []
63  self._waitForSequenceToClose = None # modules will only be cloned or added if this is None
64 
def __init__(self, process, label, postfix)

Member Function Documentation

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

Definition at line 103 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().

103  def __appendToTopSequence(self, visitee):#this is darn ugly because empty cms.Sequences are not supported
104  if isinstance(self._sequenceStack[-1], basestring):#we have the name of an empty sequence on the stack. create it!
105  oldSequenceLabel = self._sequenceStack.pop()
106  newSequenceLabel = oldSequenceLabel + self._postfix
107  self._sequenceStack.append(cms.Sequence(visitee))
108  if hasattr(self._process, newSequenceLabel):
109  raise Exception("Cloning the sequence "+self._sequenceStack[-1].label()+" would overwrite existing object." )
110  setattr(self._process, newSequenceLabel, self._sequenceStack[-1])
111  self._sequenceLabels.append(oldSequenceLabel)
112  else:
113  self._sequenceStack[-1] += visitee
114 
def __appendToTopSequence(self, visitee)
def HiHelperTools.CloneSequenceVisitor.clonedSequence (   self)

Definition at line 95 of file HiHelperTools.py.

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

95  def clonedSequence(self):
96  if not len(self._sequenceStack) == 1:
97  raise Exception("someting went wrong, the sequence stack looks like: %s"%self._sequenceStack)
98  for label in self._moduleLabels:
99  massSearchReplaceAnyInputTag(self._sequenceStack[-1], label, label+self._postfix, moduleLabelOnly=True, verbose=False)
100  self._moduleLabels = [] #prevent the InputTag replacement next time this is called.
101  return self._sequenceStack[-1]
102 
def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag, verbose=False, moduleLabelOnly=False, skipLabelTest=False)
Definition: MassReplace.py:71
def HiHelperTools.CloneSequenceVisitor.enter (   self,
  visitee 
)

Definition at line 65 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.

65  def enter(self,visitee):
66  if not self._waitForSequenceToClose is None:
67  return #we are in a already cloned sequence
68  if isinstance(visitee,cms._Module):
69  label = visitee.label()
70  newModule = None
71  if label in self._moduleLabels:
72  newModule = getattr(self._process, label+self._postfix)
73  else:
74  self._moduleLabels.append(label)
75 
76  newModule = visitee.clone()
77  setattr(self._process, label+self._postfix, newModule)
78  self.__appendToTopSequence(newModule)
79 
80  if isinstance(visitee,cms.Sequence):
81  if visitee.label() in self._sequenceLabels: # is the sequence allready cloned?
82  self._waitForSequenceToClose = visitee.label()
83  self._sequenceStack.append( getattr(self._process, visitee.label()+self._postfix) )
84  else:
85  self._sequenceStack.append(visitee.label())#save desired label as placeholder until we have a module to create the sequence
86 
def __appendToTopSequence(self, visitee)
def HiHelperTools.CloneSequenceVisitor.leave (   self,
  visitee 
)

Definition at line 87 of file HiHelperTools.py.

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

87  def leave(self,visitee):
88  if isinstance(visitee,cms.Sequence):
89  if self._waitForSequenceToClose == visitee.label():
90  self._waitForSequenceToClose = None
91  if not isinstance(self._sequenceStack[-1], cms.Sequence):
92  raise Exception("empty Sequence encountered during cloneing. sequnece stack: %s"%self._sequenceStack)
93  self.__appendToTopSequence( self._sequenceStack.pop() )
94 
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 62 of file HiHelperTools.py.

Referenced by HiHelperTools.CloneSequenceVisitor.enter().

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