.. Magnet Information documentation master file, created by
   sphinx-quickstart on Tue Aug  1 10:23:57 2023.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

mgnt_info
=========

Synopsis
--------

**mgnt_info.py** [-h] [-d DEVICE_NAME] [-e ELEMENT_NAME] [-f FACILITY] [-s STRING] [-c COOLING_TYPE] [-n ENAME] [-o FIELD [FIELD ...]] [-r] [-w FILE_NAME]

Description
-----------

``mgnt_info`` provides a command-line tool for interacting with the magnet information retrieval functions. 
Magnet retrieval works in two modes: single-magnet retrieval and multi-magnet retrieval. 

Single-magnet retrieval will output the following data for one magnet: 

.. list-table:: Fields returned in single-magnet mode
   :widths: 50 50
   :header-rows: 1

   * - Field name
     - Description
   * - ELEMENT
     - MAD name
   * - BARCODE
     - Barcode
   * - AREA
     - Area
   * - EPICS_CHANNEL_ACCESS_NAME
     - Control system name
   * - ENGINEERING_NAME
     - Engineering name
   * - LINACZ_M
     - Linac Z location (m)
   * - DEVICE
     - Magnet/device type
   * - OPS_STATUS
     - Operation status
   * - PSC_TYPE
     - Power supply type
   * - PSC_DEVICE
     - Power supply device name
   * - PSC_LOCN
     - Power supply rack location
   * - ACSW_NODE
     - Full ACSW nodename, including plug
   * - TS_NODE
     - Terminal server nodename
   * - MCOR_CRATE_NUM
     - MCOR crate number
   * - MCOR_CRATE_CHAN
     - MCOR crate channel
   * - BULK_PS
     - Bulk power supply device name
   * - IOC
     - IOC controlling this magnet
   * - SW_PS_STRING
     - String main specified in software but not hardware
   * - ACSW_NAME
     - ACSW device name
   * - ACSW_HOST
     - ACSW nodename
   * - ACSW_PLUG
     - ACSW plug
   * - HW_AREA
     - Hardware area
   * - HW_DISPLAY
     - Hardware display filename
   * - LIMIT_DISPLAY
     - Limit display filename
   * - UNIT_DISPLAY
     - Unit display filename
   * - COOLING_TYPE
     - Magnet cooling type (air, helium, water, or none)
   * - SAFETY_PPS
     - Safety system bitmask
   * - DEGAUSS_FUNC
     - Whether degauss is enabled
   * - DEGAUSS_RAMP_RATE
     - Degauss ramp rate (A/s)
   * - DEGAUSS_SETL
     - Degauss settle time (s)
   * - DEGAUSS_WF
     - Current setpoint waveform for degauss (A)
   * - DISPLAY_SUBAREA
     - Group under which magnet is located on mgnt_<DISPLAY_AREA>_all
   * - DISPLAY_AREA
     - This magnet is on the display mgnt_<DISPLAY_AREA>_all.
   * - PS_STRING
     - String main, if applicable
   * - PS_CONFIG
     - Magnet configuration (string or individual)
   * - IMIN_VAL
     - Minimum current
   * - IMAX_VAL
     - Maximum current
   * - BMIN_VAL
     - Minimum B-field
   * - BMAX_VAL
     - Maximum B-field
   * - STDZ_FUNC
     - Whether stdz is enabled
   * - STDZCYCLENUM_VAL
     - Number of stdz cycles
   * - STDZIMIN_VAL
     - Minimum stdz current (A)
   * - STDZIMAX_VAL
     - Maximum stdz current (A)
   * - STDZIFINAL_VAL
     - Final stdz current (A)
   * - TRIMRAMPRATE_VAL
     - Trim ramp rate (A/s)
   * - TRIMSETL_VAL
     - Trim settle time (s)
   * - COEFF_0_VAL
     - Constant coefficient of IVB polynomial
   * - COEFF_1_VAL
     - Linear coefficient of IVB polynomial
   * - COEFF_2_VAL
     - Quadratic coefficient of IVB polynomial
   * - COEFF_3_VAL
     - Cubic coefficient of IVB polynomial
   * - COEFF_4_VAL
     - 4th-degree coefficient of IVB polynomial
   * - COEFF_5_VAL
     - 5th-degree coefficient of IVB polynomial
   * - COEFF_6_VAL
     - 6th-degree coefficient of IVB polynomial
   * - COEFF_7_VAL
     - 7th-degree coefficient of IVB polynomial
   * - COEFF_8_VAL
     - 8th-degree coefficient of IVB polynomial
   * - COEFF_9_VAL
     - 9th-degree coefficient of IVB polynomial
   * - COEFF_10_VAL
     - 10th-degree coefficient of IVB polynomial
   * - COEFF_11_VAL
     - 11th-degree coefficient of IVB polynomial
   * - COEFF_12_VAL
     - 12th-degree coefficient of IVB polynomial

Multi-magnet retrieval will output the following data for multiple magnets:

.. list-table:: Fields returned in multi-magnet mode
   :widths: 50 50
   :header-rows: 1

   * - Field name
     - Description
   * - ELEMENT
     - MAD name
   * - EPICS_CHANNEL_ACCESS_NAME
     - Control system name

To get more info about a magnet found using multi-magnet retrieval, use the single-magnet functionality by running ``mgnt_info`` with the device or element name specified.

``mgnt_info`` supports various options to filter the magnet data based on device name, element name, facility, cooling type, and engineering name. 
The retrieved data is printed to the console, and it can be optionally saved as a JSON file. See supported arguments.

Options
-------

.. program:: mgnt_info

.. option:: -d, --device-name
   
   Retrieves magnet info by device name.

.. option:: -e, --element-name
   
   Retrieves magnet info by element name.

.. option:: -f, --facility FACILITY
   
   Retrieves magnet info by individual facility, expects <AD_ACCEL> or <FACET2>.

.. option:: -s, --string
   
   Retrieves magnet info based on if the magnet is part of a string, expects <INDIVIDUAL> or <STRING>.

.. option:: -c, --cooling-type
   
   Retrieves magnet info based on cooling method, expects <AIR> or <HELIUM> or <WATER> or <NONE>.

.. option:: -n, --engineering-name ENAME
   
   Retrieves magnet info by engineering name.

.. option:: -o, --output-fields FIELD [FIELD ...]
   
   Select what fields to output, expects a valid field, see above list of outputted data for a list of valid fields.
   Prefixes and lowercase letters are supported.

   Example usage::

    $ mgnt_info.py -e Q30501 -o stdz
    +------------------+---------+
    | STDZ_FUNC        | ENABLED |
    +------------------+---------+
    | STDZCYCLENUM_VAL | 3       |
    +------------------+---------+
    | STDZIMIN_VAL     | 0       |
    +------------------+---------+
    | STDZIMAX_VAL     | 100     |
    +------------------+---------+
    | STDZIFINAL_VAL   | 0       |
    +------------------+---------+

.. option:: -r, --raw
   
   Outputs the data in raw format.

.. option:: -w, --write-json FILE_NAME
   
   Outputs data to a json file.

.. option:: -f, --file FILE

   Specify the input file to process.

Examples
--------

Single-magnet retrieval::

   $ mgnt_info.py -d BEND:CLTS:280 -r
   [{'ELEMENT': 'BLRCUS', 'BARCODE': '4584', 'AREA': 'CLTS', 'EPICS_CHANNEL_ACCESS_NAME': 'BEND:CLTS:280', 'ENGINEERING_NAME': '0.625SD38.98', 'LINACZ_M': '3076.79', 'DEVICE': 'SEPT', 'OPS_STATUS': 'Commissioned, Online', 'PSC_TYPE': 'EPSC', 'PSC_DEVICE': 'PSC:CLTS:MG08', 'PSC_LOCN': ' ', 'ACSW_NODE': ' ', 'TS_NODE': ' ', 'MCOR_CRATE_NUM': '0', 'MCOR_CRATE_CHAN': '0', 'BULK_PS': ' ', 'IOC': 'SIOC:SYS0:MG08', 'SW_PS_STRING': ' ', 'ACSW_NAME': ' ', 'ACSW_HOST': ' ', 'ACSW_PLUG': '0', 'HW_AREA': 'CLTS', 'HW_DISPLAY': 'mgnt_epsc', 'LIMIT_DISPLAY': 'mgnt_limits_aux', 'UNIT_DISPLAY': 'mgnt_unit2', 'COOLING_TYPE': 'WATER', 'SAFETY_PPS': '0', 'DEGAUSS_FUNC': 'DISABLED', 'DEGAUSS_RAMP_RATE': '0', 'DEGAUSS_SETL': '0', 'DEGAUSS_WF': ' ', 'DISPLAY_SUBAREA': 'CLTS', 'DISPLAY_AREA': 'bsyCu', 'PS_STRING': ' ', 'PS_CONFIG': 'INDIVIDUAL', 'IMIN_VAL': '0', 'IMAX_VAL': '130', 'BMIN_VAL': '0.1061', 'BMAX_VAL': '15.606', 'STDZ_FUNC': 'ENABLED', 'STDZCYCLENUM_VAL': '3', 'STDZIMIN_VAL': '0', 'STDZIMAX_VAL': '130', 'STDZIFINAL_VAL': '0', 'TRIMRAMPRATE_VAL': '10', 'TRIMSETL_VAL': '10', 'COEFF_0_VAL': '-0.9133', 'COEFF_1_VAL': '8.61424', 'COEFF_2_VAL': '-0.0432501', 'COEFF_3_VAL': '0.0024633', 'COEFF_4_VAL': '-2.00019e-05', 'COEFF_5_VAL': '-1.25678e-06', 'COEFF_6_VAL': '0', 'COEFF_7_VAL': '0', 'COEFF_8_VAL': '0', 'COEFF_9_VAL': '0', 'COEFF_10_VAL': '0', 'COEFF_11_VAL': '0', 'COEFF_12_VAL': '0'}]

Multi-magnet retrieval::

   $ mgnt_info.py -n 0.625SD38.98
   +-----------+-----------------------------+
   | ELEMENT   | EPICS_CHANNEL_ACCESS_NAME   |
   +===========+=============================+
   | BLXSPH    | BEND:SPH:170                |
   +-----------+-----------------------------+
   | BLXSPS    | BEND:SPS:470                |
   +-----------+-----------------------------+
   | BLRCUS    | BEND:CLTS:280               |
   +-----------+-----------------------------+
   3 results

Note, mgnt_info temporarily only works on lcls-dev3.

.. toctree::
   :maxdepth: 2
   :caption: Contents:



=================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
