Skip to content
Snippets Groups Projects
Commit f6a60e22 authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

Merge branch 'L2SS-869-improve-querying-in-stats-writer' into 'master'

Resolve L2SS-869 "Improve querying in stats writer"

Closes L2SS-869

See merge request !426
parents 437f5d98 e7513c44
No related branches found
No related tags found
1 merge request!426Resolve L2SS-869 "Improve querying in stats writer"
......@@ -202,25 +202,14 @@ class statistics_data:
# get SST specific stuff
if self.marker == "S":
self.data_id_signal_input_index = file[group_key].attrs["data_id_signal_input_index"]
# check if the dataset is empty or not. if empty, set to None, if not get the value
if file.get(f'{group_key}/rcu_attenuator_dB').shape is None:
self.rcu_attenuator_dB = None
else:
self.rcu_attenuator_dB = numpy.array(file.get(f"{group_key}/rcu_attenuator_dB"))
if file.get(f'{group_key}/rcu_band_select').shape is None:
self.rcu_band_select = None
else:
self.rcu_band_select = numpy.array(file.get(f"{group_key}/rcu_band_select"))
if file.get(f'{group_key}/rcu_dth_on').shape is None:
self.rcu_dth_on = None
attribute_names = ["rcu_attenuator_dB", "rcu_band_select", "rcu_dth_on"]
for a in attribute_names:
if file[group_key].attrs[a].shape is None:
setattr(self, a, None)
else :
self.rcu_dth_on = numpy.array(file.get(f"{group_key}/rcu_dth_on"))
setattr(self, a, numpy.array(file[group_key].attrs[a]))
# get XST specific stuff
if self.marker == "X":
......
......@@ -87,6 +87,7 @@ class HDF5Writer(ABC):
# Set device if any, defaults to None
self.device = device
self.device_attributes = {}
@abstractmethod
def decoder(self, packet):
......@@ -169,6 +170,8 @@ class HDF5Writer(ABC):
# write the finished (and checks if its the first matrix)
if self.current_matrix is not None:
try:
# query the device attributes for updated values
self.retrieve_attribute_values()
self.write_matrix()
except Exception as e:
time = self.current_timestamp.strftime(
......@@ -187,6 +190,7 @@ class HDF5Writer(ABC):
# create a new and empty current_matrix
self.current_matrix = self.new_collector()
self.statistics_header = None
self.device_attributes = {}
def write_matrix(self):
"""Writes the finished matrix to the hdf5 file"""
......@@ -238,6 +242,10 @@ class HDF5Writer(ABC):
else:
current_group.attrs[k] = v
@abstractmethod
def retrieve_attribute_values(self):
pass
@abstractmethod
def write_values_matrix(self, current_group):
pass
......@@ -323,6 +331,19 @@ class SstHdf5Writer(HDF5Writer):
def new_collector(self):
return StationSSTCollector(self.device)
def retrieve_attribute_values(self):
attribute_names = ["rcu_attenuator_dB", "rcu_band_select", "rcu_dth_on"]
attribute_types = {"rcu_attenuator_dB": numpy.int64, "rcu_band_select" : numpy.int64, "rcu_dth_on" : bool}
# write the device attributes
for a in attribute_names:
try:
if self.current_matrix.parameters[a] is None:
self.device_attributes[a] = h5py.Empty("f")
else:
self.device_attributes[a] = self.current_matrix.parameters[a].flatten().astype(attribute_types[a])
except AttributeError:
self.device_attributes[a] = h5py.Empty("f")
def write_values_matrix(self, current_group):
# store the SST values
current_group.create_dataset(
......@@ -333,43 +354,8 @@ class SstHdf5Writer(HDF5Writer):
compression="gzip",
)
try:
current_group.create_dataset(
name="rcu_attenuator_dB",
data=self.current_matrix.parameters["rcu_attenuator_dB"].astype(numpy.int64),
compression="gzip",
)
except AttributeError:
current_group.create_dataset(
name="rcu_attenuator_dB",
data=h5py.Empty("f"),
)
try:
current_group.create_dataset(
name="rcu_band_select",
data=self.current_matrix.parameters["rcu_band_select"].astype(numpy.int64),
compression="gzip",
)
except AttributeError:
current_group.create_dataset(
name="rcu_band_select",
data=h5py.Empty("f"),
)
try:
current_group.create_dataset(
name="rcu_dth_on",
data=self.current_matrix.parameters["rcu_dth_on"].astype(numpy.bool_),
compression="gzip",
)
except AttributeError:
current_group.create_dataset(
name="rcu_dth_on",
data=h5py.Empty("f"),
)
for k,v in self.device_attributes.items():
current_group.attrs[k] = v
class BstHdf5Writer(HDF5Writer):
def __init__(
......@@ -388,6 +374,9 @@ class BstHdf5Writer(HDF5Writer):
def new_collector(self):
return BSTCollector()
def retrieve_attribute_values(self):
pass
def write_values_matrix(self, current_group):
# store the BST values
current_group.create_dataset(
......@@ -428,6 +417,9 @@ class XstHdf5Writer(HDF5Writer):
f"{time_str}{suffix}"
)
def retrieve_attribute_values(self):
pass
def write_values_matrix(self, current_group):
# requires a function call to transform the xst_blocks in to the right
# structure
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment