Commit e0a9e657 authored by Elisabetta Giani's avatar Elisabetta Giani
Browse files

AT5-259: Removed file loading in ConfigureScan()

parent 5e8e381f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -630,7 +630,7 @@ class CspMaster(with_metaclass(DeviceMeta, SKAMaster)):
        for fqdn in self._capability_fqdn:
            try:
                self._capability_proxy[fqdn] = tango.DeviceProxy(fqdn)
            except tango.Except as tango_err:
            except tango.DevFailed as tango_err:
                self.logger.warn(tango_err.args[0].desc)
            
                
+14 −67
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ from enum import IntEnum, unique
import threading
import time
import json

# PROTECTED REGION END# //CspSubarray.standardlibray_import

# tango imports
@@ -1891,43 +1892,14 @@ class CspSubarray(with_metaclass(DeviceMeta,SKASubarray)):
            time.sleep(0.2)
        # PROTECTED REGION END #    //  CspSubarray.Scan    
        
    def __validate_scan_configuration(self, json_config):
        """
        here is done a preliminary validation of the configuraito:
        - look for the sub-element entries
        - add eventual information to the sub-element blocks (for example for PSS add the
        addresses of the PSS pipelines or the IDs of the SearchBeams)
        - set the observing mode for each sub-element sub-array/PSTBeam
    
        if "cbf" in json_config:
            self._sc_subarray_obs_mode[self.CbfSubarray] = ObsMode.CORRELATION
            scan_configutation[self.CbfSubarray] = json_config["cbf"]
        if "pss" in json_config:
            scan_configutation[self.PssSubarray] = json_config["pss"]
        if "pst" in json_config:
            scan_configuration[self.PssSubarray] = json_config["pst"]
        return scan_configuration_dict
    
        Customize the function for each instance
    def _validate_scan_configuration(self, argin):
        """
        if "cbf" in json_config:
            if self._sc_subarray_state[self.CbfSubarray] != tango.DevState.ON:
                pass
                # throw exception
            self._sc_subarray_obs_mode[self.CbfSubarray] = ObsMode.CORRELATION
            self._sc_scan_configuration[self.CbfSubarray] = json_config["cbf"]
            self._sc_subarray_assigned_fqdn.append(self.CbfSubarray)
        if "pss" in json_config:
            if self._sc_subarray_state[self.PssSubarray] != tango.DevState.ON:
                pass
                # throw exception
            #self._sc_subarray_obs_mode[self.PssSubarray] = ??
            self._sc_subarray_assigned_fqdn.append(self.PssSubarray)
            self._sc_scan_configuration[self.PssSubarray] = json_config["pss"]
            if "searchbeams" not in self._sc_scan_configuration[self.PssSubarray]:
                self._sc_scan_configuration[self.PssSubarray]["searchbeams"] = self._assigned_search_beams
        if "pst" in json_config:
        This method is overwritten in each CspSubarray instance.
        
        :param argin: the JSON string with scan configuration
        :return: None
        :raise: tango.DevFailed exception
        """
        pass
        
    @AdminModeCheck('ConfigureScan')
@@ -1967,44 +1939,19 @@ class CspSubarray(with_metaclass(DeviceMeta,SKASubarray)):
        """
        # PROTECTED REGION ID(CspSubarray.ConfigureScan) ENABLED START #

        # checks on Stae, adminMode and obsState values are performed inside the 
        # checks on State, adminMode and obsState values are performed inside the 
        # python decorators
       
        # the dictionary with the scan configuration
        argin_dict = {}
        try:
            # for test purpose we load the json configuration from an
            # external file.
            if "load" in argin:
                # skip the 'load' chars and remove spaces from the filename
                fn = (argin[4:]).strip()
		# !!!Note!! set the path to the data file
                filename = os.path.join(commons_pkg_path, fn)
                with open(filename) as json_file:
                    # load the file into a dictionary
                    argin_dict = json.load(json_file)
                    # dump the dictionary into the input string to forward
                    # to CbfSubarray
                    argin = json.dumps(argin_dict)
            else:
                argin_dict = json.loads(argin)
        except FileNotFoundError as file_err:
            self.logger.error(file_err)
            tango.Except.throw_exception("Command failed",
                                         str(file_err),
                                         "ConfigureScan execution",
                                         tango.ErrSeverity.ERR)
        except json.JSONDecodeError as e:  # argument not a valid JSON object
            # this is a fatal error
            msg = ("Scan configuration object is not a valid JSON object."
                   "Aborting configuration:{}".format(str(e)))
            self._validate_scan_configuration(argin)
        except tango.DevFailed as tango_err:
            msg = tango_err.args[0].desc
            self.logger.error(msg)
            tango.Except.throw_exception("Command failed",
                                         msg,
                                         "ConfigureScan execution",
                                         tango.ErrSeverity.ERR)
        self._validate_scan_configuration(argin)
        
        # Forward the ConfigureScan command to CbfSubarray.
        for device in self._sc_subarray_assigned_fqdn:
            error_device = 0
+2 −2
Original line number Diff line number Diff line
@@ -37,14 +37,14 @@
      <type xsi:type="pogoDsl:StringType"/>
      <status abstract="false" inherited="true" concrete="true"/>
    </deviceProperties>
    <commands name="ObsState" description="Set the observation state" execMethod="obs_state" displayLevel="OPERATOR" polledPeriod="0">
    <commands name="ObsState" description="Set the observation state" execMethod="obs_state" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false">
      <argin description="">
        <type xsi:type="pogoDsl:VoidType"/>
      </argin>
      <argout description="Observation state">
        <type xsi:type="pogoDsl:ConstStringType"/>
      </argout>
      <status abstract="true" inherited="true" concrete="true" concreteHere="true"/>
      <status abstract="true" inherited="true" concrete="true" concreteHere="false"/>
    </commands>
    <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0">
      <argin description="none">