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

Public Member Functions

 __init__ (self, result_queue, log_file_name, parameters, path, random_seed=None, max_event=0)
 
 prepare (self)
 
 initialize_output (self)
 
 start_process (self)
 
 save_log (self)
 
 get_log (self)
 
 get (self, name)
 
 get_keys (self)
 

Public Attributes

 random_seed = random_seed
 Random seed to set.
 
 path = path
 Path to process.
 
 max_event = max_event
 The maximum number of events to process.
 
bool already_run = False
 True if already started/run.
 
 log_file_name = log_file_name
 Name of the log file to use.
 
 log_file_content = None
 Saved log file content after the run.
 
 result_queue = result_queue
 Result queue as a reference.
 
 parameters = parameters
 Parameters in process_parameter_space.
 
 progress_queue_local
 Create the queue for the progress python module.
 
 progress_queue_remote = Pipe()
 Create the queue for the progress python module.
 
bool is_valid = True
 Set to false, if you do not want this process to show up in the process bar calculations.
 

Detailed Description

Overload implementation of the HEPProcess with the correct handling of the path calculation.

Definition at line 17 of file calculation_process.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
result_queue,
log_file_name,
parameters,
path,
random_seed = None,
max_event = 0 )
Create a new basf2 calculation process.

Definition at line 23 of file calculation_process.py.

23 def __init__(self, result_queue, log_file_name, parameters, path, random_seed=None, max_event=0):
24 """Create a new basf2 calculation process."""
25
26 self.random_seed = random_seed
27
28 self.path = path
29
30 self.max_event = max_event
31
32 super().__init__(result_queue=result_queue, log_file_name=log_file_name,
33 parameters=parameters)
34

Member Function Documentation

◆ get()

get ( self,
name )
inherited
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()

get_keys ( self)
inherited
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()

get_log ( self)
inherited
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

◆ initialize_output()

initialize_output ( self)
Make sure all output by python and or C is written to the same output file

Definition at line 50 of file calculation_process.py.

50 def initialize_output(self):
51 """
52 Make sure all output by python and or C is written to the same output file
53 """
54 # reset stdout/stderr (notebooks forward them over zmq)
55 sys.stdout = sys.__stdout__
56 sys.stderr = sys.__stderr__
57
58 # open filename
59 logfile = open(self.log_file_name, "wb", 0)
60
61 # redirect stdout/stderr to logfile
62 os.dup2(logfile.fileno(), sys.stdout.fileno())
63 os.dup2(logfile.fileno(), sys.stderr.fileno())
64
65 # reset logging to use the new file descriptors
66 _basf2.reset_log()
67 _basf2.logging.zero_counters()
68 _basf2.logging.add_json()
69

◆ prepare()

prepare ( self)
A function to prepare a path with the modules given in path.

Reimplemented from CalculationProcess.

Definition at line 35 of file calculation_process.py.

35 def prepare(self):
36 """
37 A function to prepare a path with the modules given in path.
38 """
39 if self.path:
40 # import late due to side effects with importing ROOT
41 from hep_ipython_tools.ipython_handler_basf2 import python_modules
42 # Add the progress python module
43 self.path.add_module(python_modules.ProgressPython(self.progress_queue_remote))
44 # Add the print collections python module
45 self.path.add_module(python_modules.PrintCollections(self.result_queue))
46 else:
47
48 self.is_valid = False
49

◆ save_log()

save_log ( self)
inherited
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()

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 from CalculationProcess.

Definition at line 70 of file calculation_process.py.

70 def start_process(self):
71 """
72 The function given to the process to start the calculation.
73 Do not call by yourself.
74 Resets the logging system, logs onto console and a file and sets the queues
75 (the result queue and the process queue) correctly.
76 """
77
78 if not self.path:
79 return
80
81 try:
82 if self.random_seed is not None:
83 _basf2.set_random_seed(self.random_seed)
84
85 # setup output capture
86 self.initialize_output()
87
88 # and start processing
89 _basf2.process(self.path, self.max_event)
90
91 self.result_queue.put("ipython.statistics", Basf2CalculationQueueStatistics(_basf2.statistics))
92
93 # import ROOT late due to all the side effects
94 from ROOT import Belle2 # noqa
95 store_arrays = list(Belle2.PyStoreArray.list())
96 all_arrays = list(dict(Belle2.DataStore.Instance().getStoreEntryMap(Belle2.DataStore.c_Event)).keys())
97
98 nodes = dict(
99 name="",
100 children=[
101 dict(
102 index=i,
103 name=store_array,
104 key=store_array,
105 relation=[
106 other_store_array for other_store_array in store_arrays if Belle2.DataStore.relationName(
107 store_array,
108 other_store_array) in all_arrays]) for i,
109 store_array in enumerate(store_arrays)])
110 nodes_json = json.dumps(nodes)
111 self.result_queue.put("ipython.dependencies", nodes_json)
112
113 finally:
114 self.result_queue.queue.close()
115
116 self.progress_queue_remote.send("end")
117 self.progress_queue_remote.close()
static DataStore & Instance()
Instance of singleton Store.
Definition DataStore.cc:53
static std::string relationName(const std::string &fromName, const std::string &toName, std::string const &namedRelation="")
Return storage name for a relation between two arrays of the given names.
Definition DataStore.h:180
static std::vector< std::string > list(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Return list of available arrays for given durability.

Member Data Documentation

◆ already_run

bool already_run = False
inherited

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

bool is_valid = True
inherited

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 = None
inherited

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 = log_file_name
inherited

Name of the log file to use.

Delete the log file and copy its content to the class.
Return the log file content.
Use the methods of the Calculation for a better handling.

Definition at line 33 of file calculation_process.py.

◆ max_event

max_event = max_event

The maximum number of events to process.

Leave 0 to process al events

Definition at line 30 of file calculation_process.py.

◆ parameters

parameters = parameters
inherited

Parameters in process_parameter_space.

Definition at line 42 of file calculation_process.py.

◆ path

path = path

Path to process.

Definition at line 28 of file calculation_process.py.

◆ progress_queue_local

progress_queue_local
inherited

Create the queue for the progress python module.

Definition at line 45 of file calculation_process.py.

◆ progress_queue_remote

progress_queue_remote = Pipe()
inherited

Create the queue for the progress python module.

Definition at line 45 of file calculation_process.py.

◆ random_seed

random_seed = random_seed

Random seed to set.

None will not set it.

Definition at line 26 of file calculation_process.py.

◆ result_queue

result_queue = result_queue
inherited

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: