Skip to content

Commit

Permalink
Merge pull request #21 from cbespin/master
Browse files Browse the repository at this point in the history
ENH: Import from package
  • Loading branch information
YannickDieter authored Mar 10, 2022
2 parents 35b3846 + b87e9a4 commit a6d5546
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
16 changes: 9 additions & 7 deletions pymosa/m26.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
#

import logging
import signal
import os
from time import time, sleep, strftime
import signal
from contextlib import contextmanager
from threading import Timer
from time import sleep, strftime, time

import yaml
from tqdm import tqdm

from basil.dut import Dut
from basil.utils.BitLogic import BitLogic
from tqdm import tqdm

from m26_raw_data import open_raw_data_file, send_meta_data, save_configuration_dict
from m26_readout import M26Readout
import pymosa
from pymosa.m26_raw_data import open_raw_data_file, save_configuration_dict, send_meta_data
from pymosa.m26_readout import M26Readout

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -66,6 +66,8 @@ def init(self, init_conf=None, configure_m26=True):
self.output_filename = os.path.basename(self.output_filename)
self.run_number = self.telescope_conf.get('run_number', None)
self.m26_configuration_file = self.telescope_conf.get('m26_configuration_file', None)
if not self.m26_configuration_file:
self.m26_configuration_file = 'm26_config/m26_threshold_8.yaml'
self.m26_jtag_configuration = self.telescope_conf.get('m26_jtag_configuration', True) # default True
self.no_data_timeout = self.telescope_conf.get('no_data_timeout', 0) # default None: no data timeout
self.scan_timeout = self.telescope_conf.get('scan_timeout', 0) # default 0: no scan timeout
Expand Down Expand Up @@ -93,7 +95,7 @@ def configure_m26(self, m26_configuration_file=None, m26_jtag_configuration=None
if m26_configuration_file:
self.m26_configuration_file = m26_configuration_file
else:
m26_configuration_file = self.m26_configuration_file
m26_configuration_file = os.path.join(os.path.dirname(pymosa.__file__), self.m26_configuration_file)
if not self.m26_configuration_file:
raise ValueError('M26 configuration file not provided')
logger.info('Loading M26 configuration file %s', m26_configuration_file)
Expand Down
4 changes: 1 addition & 3 deletions pymosa/m26_configuration.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# *** hardware setup/configuration ***
run_number : # Base run number, will be automatically increased; if none is given, generate filename
output_folder : # Output folder for the telescope data; if none is given, the current working directory is used
m26_configuration_file : './m26_config/m26_threshold_8.yaml' # Configuration file for Mimosa26 sensors, default: threshold 8
m26_jtag_configuration : True # Send Mimosa26 configuration via JTAG, default: True
no_data_timeout : 30 # No data timeout after which the scan will be aborted, in seconds; if 0, the timeout is disabled
m26_configuration_file : # Configuration file for Mimosa26 sensors, default: 'm26_config/m26_threshold_8.yaml'
scan_timeout : 0 # Timeout after which the scan will be stopped, in seconds; if 0, the timeout is disabled; use Ctrl-C to stop run
max_triggers : 0 # Maximum number of triggers; if 0, there is no limit on the number of triggers; use Ctrl-C to stop run
send_data : 'tcp://127.0.0.1:8500' # TCP address to which the telescope data is send; to allow incoming connections on all interfaces use 0.0.0.0
Expand Down
2 changes: 1 addition & 1 deletion pymosa/noise_occupancy_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def scan(self):
for region in range(4):
self.fake_hit_rate_meas[plane, region] = self.hit_occ_map[m26_regions[region][0]:m26_regions[region][1], :, plane].sum() / 576. / 288. / self.scan_timeout / 1e6 * 115.2

self.hist_occ.stop.set() # stop analysis process
self.hist_occ.close() # stop analysis process

# Log status (fake hit rate, noise occupoancy, threshold setting)
self.print_log_status()
Expand Down
17 changes: 16 additions & 1 deletion pymosa/online.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,26 @@ def worker(self, raw_data_queue, shared_array_base, lock, stop):
except queue.Empty:
continue

def __del__(self):
def close(self):
''' Close process and wait till done. Likely needed to give access to pytable file handle.'''
logger.info('Stopping process %d', self.p.pid)
self._raw_data_queue.close()
self._raw_data_queue.join_thread() # Needed otherwise IOError: [Errno 232] The pipe is being closed
self.stop.set()
self.p.join()
del self.p # explicit delete required to free memory
self.p = None

def __del__(self):
if self.p and self.p.is_alive():
logger.warning('Process still running. Was close() called?')
self.close()

# def __del__(self):
# self._raw_data_queue.close()
# self._raw_data_queue.join_thread() # Needed otherwise IOError: [Errno 232] The pipe is being closed
# self.stop.set()
# self.p.join()


if __name__ == "__main__":
Expand Down

0 comments on commit a6d5546

Please sign in to comment.