Skip to content
mihai-stfc edited this page Aug 26, 2021 · 32 revisions

PV Import Service

The purpose of the service is to enable efficient monitoring of Helium consumption by populating the HLM Database with new object measurements using the PV data provided by the Helium Recovery PLC. This repository contains both the HLM PV Import Service and its Service Manager.

The service uses caproto for Channel Access ("EPICS") to read and store the data of specified PVs, whose values are then added as measurements for objects to the HLM Database.

The service primarily consists of:

  1. User Config (Object/PV configuration) - reads and validates the object measurement/PV values configuration file
  2. CA Wrapper (Channel Access) - fetches and prepares PV data via PV monitors, handles data, updates, stale value checks etc.
  3. PV Import (Main Loop) - manages updating the DB with measurements containing the PV values using the Object/PV user config and PV values provided by the monitors; initializes tasks, handles update intervals, insertion of non-PLC PVs (e.g. Mercury Cryostat) and more.

A general idea of how the service works:

Service Diagram

On service start, the EPICS CA Address from settings will be set, and a UserConfig object will be created. After validating the provided configuration, it will fetch the entries (object IDs, measurement PVs, logging periods) and store them as attributes.

The PV measurements list from the UserConfig, and the configurations for external PVs, are then used to create the PV Monitors object. The monitors object will prepare the caproto threading client Context. Monitors will be set-up for each PV name, and a dictionary containing the latest PV values will be regularly updated by the callback functions that were added to each subscription, alongside the time of each update (for checking stale PVs).

Lastly, a PV Import object will be created with references to the UserConfig and PV Monitors object. This is the main loop, which will be responsible for preparing the addition of new measurements: initializing tasks, handling update intervals, running stale PV checks, handling missing PV data, etc. If a measurement and its PV data meet the criteria, they will be inserted into the database.

The supporting modules are:

  • DB Functions - HLM databases utility functions (add measurement, add relation, check for object modules etc.)
  • Utilities - Miscellaneous utility functions (e.g. convert ints to string, dehex/decompress PV values)
  • Logger - Contains the loggers and their configurations for the service
  • Settings - Service settings, paths, table/key names and other constants, all in one place
  • External PVs - Contains configurations of PVs that are not part of the Helium Recovery PLC, such as the Mercury Cryostat PVs

How PVs are added to the database as measurements

In pv_config.json, each entry has up to 5 PV names assigned to an object ID, and the update interval:

{
    "records": [
        {
            "object_id": 158,
            "logging_period": 60,
            "measurements": {
                "1": "PURIFIER:LEVEL",
                "2": "PURIFIER:TT102:TEMP",
                "3": "PURIFIER:TT104:TEMP",
                "4": null,
                "5": null
            }
        },
        {
            "object_id": 92,
            "logging_period": 60,
            "measurements": {
                "1": "MCP1:BANK4:DLS_HE_STORAGE",
                "2": null,
                "3": null,
                "4": null,
                "5": null
            }
        },
        {
            "object_id": 185,
            "logging_period": 60,
            "measurements": {
                "1": null,
                "2": null,
                "3": null,
                "4": null,
                "5": "MCP:LIQUID_HE_INVENTORY"
            }
        }
    ]
}

The number of PVs and their position (measurement no.) can vary depending on the object's class in the HLM database.

Note: In the HLM database, each object has a type, each type has a class, and each class has a function (e.g. HeliumVessel default and NitrogenVessel default are types of class Vessel, which is of function storage). The service & manager mostly only care about the class, as that is what defines what each measurement no. (from 1 to 5) means.

For example, Object ID 92 is MCP1 DLS Main Helium of Type ID 6.

gam_object_example



Object Type with ID 6 is Pressure sensor default, and it belongs to Class ID 6.

gam_objecttype_example



Class with ID 6 is Pressure sensor. The important part here is the measurement types (OC_MEASURETYPE1, OC_MEASURETYPE2, ..., OC_MEASURETYPE5). For the class Pressure sensor, only one measurement no. is filled: OC_MEASURETYPE1 = Pressure (mbar). This means that objects of this class should only be assigned one PV, in measurement 1, whose value is the pressure in millibars of the object.

gam_objectclass_example

Note: If PVs are being assigned to measurements with no type (NULL), they will still be added to the database but the HZB Helium Management app may not take it into consideration or display it properly.



The service will read the values of all PVs from the pv_config.json, set a monitor on them and update the pv_data dictionary on each PV value change. When it is time for an object to be updated (logging period, in minutes), a new measurement record will be created for the object.

gam_measurement_example_1 gam_measurement_example_2

Each measurement record has the ID of the object is it for, the dates when the measurement was taken and received by the server (for HLM PV Import, this is the same), a comment which displays the object name, type and class for easier readability, and the PV values in their respective measurement no./position.



Object Modules

While most objects can receive measurements "directly", objects of classes Vessel, Cryostat and Gas counter require a Module object which receives the measurements for them and provides each measurement type via its class. This is required by the HZB HM app. Vessels and Cryostats need Software Level Devices, while Gas counters need Gas Counter Modules.

The HLM Service Manager takes care of this by creating the module object and the relation between the module and the object itself.

For example, next to object with ID 109 (INES & TOSCA Gas Counter) is ID 110 (SLD "INES & TOSCA Gas Counter").

Note: This example is partially outdated, as Gas Counters are now using Gas Counter Modules instead of SLDs.

gam_db_sld_example



Then, in the object relations table, relation with ID 34423 has the object itself (109) and the SLD object (110) being assigned to it.

gam_objectrelation_example



Each time the service the service begins to update an object, it will first check the relations table for an SLD. If the object does have an SLD, the SLD object will receive the measurement in the object's stead. If the object does not have an SLD, it will receive the measurement directly.



Note

The PV Import service does not require the service manager - it can be set-up manually by directly editing the files and WinReg, adding the objects and run via terminal commands. The service's only dependencies are its settings.ini, pv_config.json and the He DB user & pass as service parameters in the Windows Registry.


Service Manager

Although the PV Import service can be managed manually (see above), the HLM Service Manager offers a GUI that makes it easier to set-up, configure, validate and run the service. It can also be used to create new objects when adding configurations, and handle any SLD requirements.

Features include:

  • Viewing the service details and current status
  • Running, stopping and restarting the service
  • Viewing the live service log output
  • Adding, editing & deleting PV configuration entries
  • Creating new objects and handle Software Level Device requirements
  • Displaying details of existing objects when managing the PV configuration
  • Running PV connection checks
  • Easily set up the HLM Database connection
  • Configuring the general settings of the PV Import service, such as EPICS Channel Access address list, PV settings etc.

Note: The manager should be run with administrator rights to ensure all features are available.

Main Window

The main window is divided into three sections, from top to bottom:

  1. Service Status, control & details
  2. Object/PV Configuration table
  3. Service Log output

The service status panel is updated with the current status and details of the service every few seconds. The user can start, stop or restart the service. The database connection status for the manager is also displayed, and the connection can be refreshed.

The PV configuration table displays the contents of pv_config.json as a table. The buttons on the left of the table allows one to add or edit a configuration for an object, or delete existing entries. Utility buttons allow the user to expand/shrink the table, apply filters to the table and refresh the contents (they should be automatically refreshed, unless the file is changed manually while the manager is running). The Add/Edit buttons will open the Configuration Entry dialog.

The service log panel displays the real time contents of the HLM PV Import, together with some utility widgets.

hlm_manager_main_window




Configuration Entry

Through the Object PV Configuration Entry dialog, the user can add, edit or delete a PV configuration entry, as well as create new objects to the database. If the newly created object is a vessel, cryostat or gas counter, a Software Level Device will be created as well as the relation between the two.

In the object name field, an existing object can be selected, or the name of a new object can be entered. If the object exists, the type, comment and object details panel (name, id, class, function, SLD name & ID) will be autocompleted from the database. If the name of a new object is entered, the type & comment (optional) fields will be enabled for editing.

The value of the measurements update interval spinbox represents the minutes between each new measurement that will be added to the object; the default time between updates is 60 minutes.

In Measurements and PVs, the names of up to 5 PVs can be entered. Depending on the class of the selected object, each measurement can have different meanings in the HLM database, which will be displayed next to each field.

The Check Measurement PVs will start a connection test for all entered PV names, displaying the results for each PV. An automatic check will start upon clicking "Save"; this can be enabled or disabled in manager general settings.

If the selected object already has a PV configuration in pv_config.json, a message will inform the user of that, and a "Load" button will appear, which upon clicking will fill the fields with the PV names from the config entry. An option to enable/disable existing config auto-load is available in manager general settings.

If any field is invalid, an error message will inform the user and highlight the respective field(s).

hlm_manager_config_entry




Settings

Service Directory Path

When first starting the manager, a dialog will ask for the service directory path. Once provided, the manager will look for the service settings and PV config, and if not found, create them from the templates. The directory path can be changed at any time from Settings -> Service Directory.

DB Connection

The database connection can be configured through Settings -> DB Connection. The host, database name, user & password can be changed. The host and database will be saved in the service settings.ini, while the host & password will be saved as parameters of the service in the Windows Registry. In order for the manager to connect to the database, the set service directory must be correct and contain settings.ini.

Channel Access

The EPICS CA address list and other PV settings can be configured through Settings -> Channel Access. The address list and PV settings are saved in the service settings.ini.

General Settings

The manager can be configured through Settings -> General Settings. Settings include PV auto-check on config Save, auto-load existing config entries, default update interval value, etc.

Manager Data

The manager data directory can be opened through View -> Manager Data Dir. It contains the logs and settings of the manager. They can differ depending on the user, as the directory is stored in AppData.