Skip to content

Commit

Permalink
ENH: feature stop conditions (maximum trigger number or seconds)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpartzsch committed Aug 7, 2024
1 parent 11c0905 commit fb73ea6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
8 changes: 7 additions & 1 deletion aidatlu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ Set the PMT control voltage. The possible range is between [0; 1] V.

### Data Handling and Online Monitor
Two settings concern the data handling. The creation of raw and interpreted data files.
At last, the ZMQ connection can be configured.
At last, the ZMQ connection can be configured.

### Stop Conditions
Two optional stop conditions can be set in tlu_configuration.yaml.
The maximum number of trigger events (max_trigger_number, e.g. max_trigger_number: 1000000)
and a timeout in seconds (timeout, e.g. timeout: 100) can be set.
These configurations are not included by default in the tlu_configuration file, so add them manually if needed.
18 changes: 18 additions & 0 deletions aidatlu/main/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ def get_data_handling(self) -> tuple:

return self.conf["save_data"], self.conf["save_data"]

def get_stop_condition(self) -> tuple:
"""Information about tlu stop condition.
Returns:
tuple: maximum trigger number and timeout in seconds.
"""
try:
max_number = int(self.conf["max_trigger_number"])
self.log.info('Stop condition maximum triggers: %s' %max_number)
except:
max_number = None
try:
timeout = float(self.conf["timeout"])
self.log.info('Stop condition timeout: %s s' %timeout)
except:
timeout = None
return max_number, timeout

def get_output_data_path(self) -> str:
"""Parses the output data path
Expand Down
19 changes: 16 additions & 3 deletions aidatlu/main/tlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ def handle_status(self) -> None:
self.log_sent_status(current_time)
# self.log_trigger_inputs(current_event)
# self.log.warning(str(current_event))
# Stops the TLU after some time in seconds.
if self.timeout != None:
if current_time > self.timeout:
self.stop_condition = True
if self.max_trigger != None:
if self.trigger_logic.get_post_veto_trigger() > self.max_trigger:
self.stop_condition = True

def log_sent_status(self, time: int) -> None:
"""Logs the status of the TLU run with trigger number, runtime usw.
Expand Down Expand Up @@ -423,9 +430,11 @@ def run(self) -> None:
self.last_triggers_freq = self.trigger_logic.get_post_veto_trigger()
self.last_particle_freq = self.trigger_logic.get_pre_veto_trigger()
first_event = True
self.stop_condition = False
# prepare data handling and zmq connection
save_data, interpret_data = self.config_parser.get_data_handling()
self.zmq_address = self.config_parser.get_zmq_connection()
self.max_trigger, self.timeout = self.config_parser.get_stop_condition()

if save_data:
self.path = self.config_parser.get_output_data_path()
Expand Down Expand Up @@ -455,6 +464,11 @@ def run(self) -> None:
try:
if save_data and np.size(current_event) > 1:
self.data_table.append(current_event)
# if t.do_run == False:
# run_active = False
# self.stop_run()
if self.stop_condition == True:
raise KeyboardInterrupt
except:
if KeyboardInterrupt:
run_active = False
Expand All @@ -471,9 +485,8 @@ def run(self) -> None:
self.log_trigger_inputs(current_event[0:6])
first_event = False

# Stops the TLU after some time in seconds.
# if current_time*25/1000000000 > 600:
# run_active = False


except:
KeyboardInterrupt
run_active = False
Expand Down

0 comments on commit fb73ea6

Please sign in to comment.