CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Attributes | Private Attributes
Vispa.Share.ThreadChain.ThreadChain Class Reference
Inheritance diagram for Vispa.Share.ThreadChain.ThreadChain:

Public Member Functions

def __init__
 
def addCommand
 
def clearReturnValue
 
def clearReturnValues
 
def returnValue
 
def run
 
def start
 

Static Public Attributes

 NO_THREADS_FLAG = False
 

Private Attributes

 _commandCounter
 
 _commandTuples
 
 _returnValues
 

Detailed Description

Holds a list of commands that shall be executed in one Thread in a chain.

    The chain can run in two modes: Eighter it receives a command with optional attributes on construction. The return value can be accessed by calling returnValue() without arguments.
    In the second mode the constructor does not receive any arguments and commands are passed to the chain with addComand().
    This function returns an id unique for the command making the return value of the command available through retrunValue(id).
    Start the ThreadChain using start().
    
    One can check if the thread is still running using isRunning().
    When all commands are executed a signal "finishedThreadChain" will be emitted.

Definition at line 5 of file ThreadChain.py.

Constructor & Destructor Documentation

def Vispa.Share.ThreadChain.ThreadChain.__init__ (   self,
  command = None,
  attr 
)

Definition at line 17 of file ThreadChain.py.

17 
18  def __init__(self, command=None, *attr):
19  QThread.__init__(self, None)
20  self._commandTuples = []
21  self._commandCounter = -1
22  self._returnValues = {}
23  if command:
24  self.addCommand(command, *attr)
25  self.start()

Member Function Documentation

def Vispa.Share.ThreadChain.ThreadChain.addCommand (   self,
  command,
  attr 
)
Adds a command to this ThreadChain 

and returns an id which is required to obtain the return value of this command.

*attr is a optional tuple of arguments which will be passed to the command on execution.

Definition at line 26 of file ThreadChain.py.

References Vispa.Share.ThreadChain.ThreadChain._commandCounter, Vispa.Share.ThreadChain.ThreadChain._commandTuples, Vispa.Share.ThreadChain.ThreadChain._returnValues, edm::ELlog4cplus.emit(), and Vispa.Share.ThreadChain.ThreadChain.NO_THREADS_FLAG.

26 
27  def addCommand(self, command, *attr):
28  """ Adds a command to this ThreadChain
29 
30  and returns an id which is required to obtain the return value of this command.
31 
32  *attr is a optional tuple of arguments which will be passed to the command on execution.
33  """
34  self._commandCounter += 1
35  id = self._commandCounter
36  self._commandTuples += [(id, command, attr)]
37  if self.NO_THREADS_FLAG:
38  self._returnValues[id] = command.__call__(*attr)
39  self.emit(SIGNAL('finishedThreadChain'), self._returnValues.values())
40  return
def Vispa.Share.ThreadChain.ThreadChain.clearReturnValue (   self,
  command 
)

Definition at line 44 of file ThreadChain.py.

44 
45  def clearReturnValue(self, command):
46  if command in self._returnValues.keys():
47  self._returnValues.pop(command)
48  return True
49  return False
def Vispa.Share.ThreadChain.ThreadChain.clearReturnValues (   self)

Definition at line 41 of file ThreadChain.py.

41 
42  def clearReturnValues(self):
43  self._returnValues.clear()
def Vispa.Share.ThreadChain.ThreadChain.returnValue (   self,
  id = None 
)
Returns return value of command with given id.

The id is returned by addCommand().
If id is None the return value of the last command will be returned.

Definition at line 50 of file ThreadChain.py.

References Vispa.Share.ThreadChain.ThreadChain._returnValues.

50 
51  def returnValue(self, id=None):
52  """ Returns return value of command with given id.
53 
54  The id is returned by addCommand().
55  If id is None the return value of the last command will be returned.
56  """
57  if id in self._returnValues.keys():
58  return self._returnValues[id]
59  valueLength = len(self._returnValues)
60  if valueLength == 0:
61  return []
62  # TODO: maybe raise exception to distinguish from None return value?
63  return self._returnValues[self._returnValues.keys()[valueLength-1]]
def Vispa.Share.ThreadChain.ThreadChain.run (   self)

Definition at line 70 of file ThreadChain.py.

References Vispa.Share.ThreadChain.ThreadChain._commandTuples, Vispa.Share.ThreadChain.ThreadChain._returnValues, edm::ELlog4cplus.emit(), and Vispa.Share.ThreadChain.ThreadChain.NO_THREADS_FLAG.

Referenced by Types.LuminosityBlockID.cppID().

70 
71  def run(self):
72  if self.NO_THREADS_FLAG:
73  return
74  while self._commandTuples != []:
75  id, command, attr = self._commandTuples.pop(0)
76  self._returnValues[id] = command.__call__(*attr)
77 
78  # signal contains list of return values
79  # for compatibility with old implementation
80  self.emit(SIGNAL('finishedThreadChain'), self._returnValues.values())
def Vispa.Share.ThreadChain.ThreadChain.start (   self)

Definition at line 64 of file ThreadChain.py.

References CSGContinuousAction.isRunning(), and Vispa.Share.ThreadChain.ThreadChain.NO_THREADS_FLAG.

Referenced by progressbar.ProgressBar.__next__(), Types.LuminosityBlockRange.cppID(), and Types.EventRange.cppID().

64 
65  def start(self):
66  if self.NO_THREADS_FLAG:
67  return
68  if not self.isRunning():
69  QThread.start(self)

Member Data Documentation

Vispa.Share.ThreadChain.ThreadChain._commandCounter
private

Definition at line 20 of file ThreadChain.py.

Referenced by Vispa.Share.ThreadChain.ThreadChain.addCommand().

Vispa.Share.ThreadChain.ThreadChain._commandTuples
private

Definition at line 19 of file ThreadChain.py.

Referenced by Vispa.Share.ThreadChain.ThreadChain.addCommand(), and Vispa.Share.ThreadChain.ThreadChain.run().

Vispa.Share.ThreadChain.ThreadChain._returnValues
private

Definition at line 21 of file ThreadChain.py.

Referenced by Vispa.Share.ThreadChain.ThreadChain.addCommand(), Vispa.Share.ThreadChain.ThreadChain.returnValue(), and Vispa.Share.ThreadChain.ThreadChain.run().

Vispa.Share.ThreadChain.ThreadChain.NO_THREADS_FLAG = False
static

Definition at line 16 of file ThreadChain.py.

Referenced by Vispa.Share.ThreadChain.ThreadChain.addCommand(), Vispa.Share.ThreadChain.ThreadChain.run(), and Vispa.Share.ThreadChain.ThreadChain.start().