diff --git a/aidatlu/README.md b/aidatlu/README.md index 87896cd..74a91db 100644 --- a/aidatlu/README.md +++ b/aidatlu/README.md @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/aidatlu/main/config_parser.py b/aidatlu/main/config_parser.py index 5a4cb7a..6d73262 100644 --- a/aidatlu/main/config_parser.py +++ b/aidatlu/main/config_parser.py @@ -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 diff --git a/aidatlu/main/tlu.py b/aidatlu/main/tlu.py index 76bb17b..14957ed 100644 --- a/aidatlu/main/tlu.py +++ b/aidatlu/main/tlu.py @@ -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. @@ -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() @@ -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 @@ -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