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

Constructor & Destructor Documentation

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

Definition at line 58 of file HiHelperTools.py.

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

Member Function Documentation

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

Definition at line 104 of file HiHelperTools.py.

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

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

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

Definition at line 96 of file HiHelperTools.py.

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

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

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

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

Definition at line 88 of file HiHelperTools.py.

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

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

Referenced by HiHelperTools.CloneSequenceVisitor.enter().

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