Belle II Software development
CalculationProcess Class Reference
Inheritance diagram for CalculationProcess:
Basf2CalculationProcess

Public Member Functions

def __init__ (self, result_queue, log_file_name, parameters)
 
def save_log (self)
 
def get_log (self)
 
def get (self, name)
 
def get_keys (self)
 
def start_process (self)
 
def prepare (self)
 

Public Attributes

 already_run
 True if already started/run.
 
 log_file_name
 Name of the log file to use.
 
 log_file_content
 Saved log file content after the run.
 
 result_queue
 Result queue as a reference.
 
 parameters
 Parameters in process_parameter_space.
 
 progress_queue_remote
 Create the queue for the progress python module.
 
 is_valid
 Set to false, if you do not want this process to show up in the process bar calculations.
 

Detailed Description

Abstract base class for doing the real processing of a calculation. Is used by the handler to
process the calculation you requested. Overload the start_process and prepare method to implement your calculation
and maybe also the __init__ method if you need to store more information on your process (like what to calculate).

See ipython_handler_basf2/calculation_process.py for an example implementation.

Definition at line 12 of file calculation_process.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  result_queue,
  log_file_name,
  parameters 
)
Create a new calculation process instance. The parameters here are the absolute standard. You probably have to redefine the
constructor in your own class.

Reimplemented in Basf2CalculationProcess.

Definition at line 21 of file calculation_process.py.

21 def __init__(self, result_queue, log_file_name, parameters):
22 """
23 Create a new calculation process instance. The parameters here are the absolute standard. You probably have to redefine the
24 constructor in your own class.
25 """
26 if result_queue is None:
27 raise ValueError("Invalid result_queue")
28
29
30 self.already_run = False
31
32
33 self.log_file_name = log_file_name
34
35
36 self.log_file_content = None
37
38
39 self.result_queue = result_queue
40
41
42 self.parameters = parameters
43
44
45 self.progress_queue_local, self.progress_queue_remote = Pipe()
46
47
48 self.is_valid = True
49
50 # Prepare the environment.
51 self.prepare()
52
53 # Call the constructor of the base class.
54 Process.__init__(self, target=self.start_process)
55

Member Function Documentation

◆ get()

def get (   self,
  name 
)
Return an item from the result queue. Only gives a result if the calculation has finished.
Use the Calculation for a better handling.

Definition at line 76 of file calculation_process.py.

76 def get(self, name):
77 """
78 Return an item from the result queue. Only gives a result if the calculation has finished.
79 Use the Calculation for a better handling.
80 """
81 if not self.is_alive():
82 return self.result_queue.get(name)
83

◆ get_keys()

def get_keys (   self)
Return the names of all item from the result queue. Only gives a result if the calculation has finished.
Use the Calculation for a better handling.

Definition at line 84 of file calculation_process.py.

84 def get_keys(self):
85 """
86 Return the names of all item from the result queue. Only gives a result if the calculation has finished.
87 Use the Calculation for a better handling.
88 """
89 if not self.is_alive():
90 return self.result_queue.get_keys()
91

◆ get_log()

def get_log (   self)
Return the log file content.
Use the methods of the Calculation for a better handling.

Definition at line 65 of file calculation_process.py.

65 def get_log(self):
66 """
67 Return the log file content.
68 Use the methods of the Calculation for a better handling.
69 """
70 if self.is_alive():
71 return open(self.log_file_name).read()
72 else:
73 self.save_log()
74 return self.log_file_content
75

◆ prepare()

def prepare (   self)
Overload this function if you need to process some preparations
before doing the real calculation.

Reimplemented in Basf2CalculationProcess.

Definition at line 100 of file calculation_process.py.

100 def prepare(self):
101 """
102 Overload this function if you need to process some preparations
103 before doing the real calculation.
104 """

◆ save_log()

def save_log (   self)
Delete the log file and copy its content to the class.

Definition at line 56 of file calculation_process.py.

56 def save_log(self):
57 """
58 Delete the log file and copy its content to the class.
59 """
60 if self.log_file_content is None:
61 self.log_file_content = open(self.log_file_name).read()
62 os.unlink(self.log_file_name)
63 self.log_file_name = None
64

◆ start_process()

def start_process (   self)
The function given to the process to start the calculation.
Do not call by yourself.
Resets the logging system, logs onto console and a file and sets the queues
(the result queue and the process queue) correctly.

Reimplemented in Basf2CalculationProcess.

Definition at line 92 of file calculation_process.py.

92 def start_process(self):
93 """
94 The function given to the process to start the calculation.
95 Do not call by yourself.
96 Resets the logging system, logs onto console and a file and sets the queues
97 (the result queue and the process queue) correctly.
98 """
99

Member Data Documentation

◆ already_run

already_run

True if already started/run.

Create a new calculation process instance. The parameters here are the absolute standard. You probably have to redefine the
constructor in your own class.

Definition at line 30 of file calculation_process.py.

◆ is_valid

is_valid

Set to false, if you do not want this process to show up in the process bar calculations.

Definition at line 48 of file calculation_process.py.

◆ log_file_content

log_file_content

Saved log file content after the run.

Delete the log file and copy its content to the class.

Definition at line 36 of file calculation_process.py.

◆ log_file_name

log_file_name

Name of the log file to use.

Definition at line 33 of file calculation_process.py.

◆ parameters

parameters

Parameters in process_parameter_space.

Definition at line 42 of file calculation_process.py.

◆ progress_queue_remote

progress_queue_remote

Create the queue for the progress python module.

Definition at line 45 of file calculation_process.py.

◆ result_queue

result_queue

Result queue as a reference.

Definition at line 39 of file calculation_process.py.


The documentation for this class was generated from the following file: