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

Public Member Functions

def __init__ (self, result_queue, log_file_name, parameters, path, random_seed=None, max_event=0)
 
def prepare (self)
 
def initialize_output (self)
 
def start_process (self)
 

Public Attributes

 random_seed
 Random seed to set.
 
 path
 Path to process.
 
 max_event
 The maximum number of events to process.
 
 is_valid
 Set is_valid to false to not show this process in any listings.
 

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__()

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

Reimplemented from CalculationProcess.

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

◆ initialize_output()

def 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()

def 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

◆ 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 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:54
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.
Definition: PyStoreArray.cc:28

Member Data Documentation

◆ is_valid

is_valid

Set is_valid to false to not show this process in any listings.

Definition at line 48 of file calculation_process.py.

◆ 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.

◆ path

path

Path to process.

Definition at line 28 of file calculation_process.py.

◆ random_seed

random_seed

Random seed to set.

None will not set it.

Definition at line 26 of file calculation_process.py.


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