import sys
from epics import PV
from time import sleep
from threading import Semaphore, BoundedSemaphore, Timer
import os
import argparse

class TimedSemaphore(object):
  '''
  Reimplements a semaphore so that it has a timeout property.
  '''
  def __init__(self, tickets, timeout):
    '''
    Constructor for this class. 
    @params
      tickets Number of times semaphore can be aqcuired at any
              given moment.
      timeout Number of seconds semaphore will wait if acquired is 
              blocked. 
    '''
    self.timeout = timeout
    self.semaphore = BoundedSemaphore(tickets)

  def acquire(self):
    '''
    Reimplementation of acquire so that it will timeout after
    self.timeout seconds. 
    '''
    timer_stopped = [True]

    def stop_timer():
      timer_stopped[0] = True

    timer = Timer(self.timeout, stop_timer)
    timer_stopped = [False]
    timer.start()
    while not self.semaphore.acquire(blocking=False):
      if timer_stopped[0]: #if the timer stopped, we can almost be certain that whatever was supposed to release this sempaphore won't do it ever
        self.semaphore.release() #the semaphore should thus be released for this current job to use
        self.semaphore.acquire() #and acquired by this job
        break
    timer.cancel()

  def release(self):
    '''
    Same as semaphore's default release method.
    '''
    self.semaphore.release()

class InterlockAlarms(object):
  '''
  A class to hold PVs for the summary alarm, protection system alarm, bypass button, and bypass status
  for an interlock group. 
  '''
  def __init__(self, alias=None, status_pv_name=None, psbypass_pv_name=None, psbypstat_pv_name=None, ps_pv_name=None,
    status_pv_name_ext=None, psbypass_pv_name_ext=None, psbypstat_pv_name_ext=None, ps_pv_name_ext=None):
    '''
    Constructor for InterlockAlarms class. 
    @params
      alias Common prefix for all pvs.
      status_pv_name Summary alarm pv name. If not None, ignores alias and extension.
      psbypass_pv_name Protection system bypass pv name. If not None, ignores alias and extension.
      psbypstat_pv_name Protection system bypass status pv name. If not None, ignores alias and extension.
      ps_pv_name Protection system alarm pv name. If not None, ignores alias and extension.
      status_pv_name_ext Extension to append to alias to get the summary alarm pv name. Ignored if status_pv_name
                         is not None.
      psbypass_pv_name_ext Extension to append to alias to get the protection system bypass pv name. Ignored if 
                           psbypass_pv_name_ext is not None.
      psbypstat_pv_name_ext Extension to append to alias to get the protection system bypass status pv name. 
                            Ignored if psbypstat_pv_name is not None.
      ps_pv_name_ext Extension to append to alias to get the protection system alarm pv name. Ignored if 
                     ps_pv_name is not None.
    '''
    
    if status_pv_name == None and status_pv_name_ext == None:
      self.status_pv = None
    elif status_pv_name != None:
      self.status_pv = PV(status_pv_name)
    elif status_pv_name_ext != None:
      self.status_pv = PV(alias + status_pv_name_ext)

    if psbypass_pv_name == None and psbypass_pv_name_ext == None:
      self.psbypass_pv = None
    elif status_pv_name != None:
      self.psbypass_pv = PV(psbypass_pv_name)
    elif status_pv_name_ext != None:
      self.psbypass_pv = PV(alias + psbypass_pv_name_ext)

    if psbypstat_pv_name == None and psbypstat_pv_name_ext == None:
      self.psbypstat_pv = None
    elif psbypstat_pv_name != None:
      self.psbypstat_pv = PV(psbypstat_pv_name)
    elif psbypstat_pv_name_ext != None:
      self.psbypstat_pv = PV(alias + psbypstat_pv_name_ext)

    if ps_pv_name == None and ps_pv_name_ext == None:
      self.ps_pv = None
    elif ps_pv_name != None:
      self.ps_pv = PV(ps_pv_name)
    elif ps_pv_name_ext != None:
      self.ps_pv = PV(alias + ps_pv_name_ext)


    #this section checks to make sure the PVs are connected
    if self.status_pv != None and not self.status_pv.wait_for_connection(timeout=2):
      print(self.status_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.psbypass_pv != None and not self.psbypass_pv.wait_for_connection(timeout=2):
      print(self.psbypass_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.psbypstat_pv != None and not self.psbypstat_pv.wait_for_connection(timeout=2):
      print(self.psbypstat_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.ps_pv != None and not self.ps_pv.wait_for_connection(timeout=2):
      print(self.ps_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")

class InterlockSensor(object):
  '''
  A class that holds all related PVs for an interlock sensor, including the sensor, high limit, low limit, alarm,
  bypass, bypass status, and reset pvs. 
  '''
  def __init__(self, alias=None, sensor_pv_name=None, high_limit_pv_name=None, low_limit_pv_name=None, status_pv_name=None, 
    bypass_pv_name=None, bypstat_pv_name=None, reset_pv_name=None, sensor_pv_name_ext=None, high_limit_pv_name_ext=None, 
    low_limit_pv_name_ext=None, status_pv_name_ext=None, bypass_pv_name_ext=None, bypstat_pv_name_ext=None, reset_pv_name_ext=None):
    '''
    Constructor for InterlockSensor class
    @params
      alias Common prefix for all pvs. 
      sensor_pv_name Sensor reading pv name. If not None, ignores alias and extension. 
      high_limit_pv_name High limit pv name. If not None, ignores alias and extension.
      low_limit_pv_name Low limit pv name. If not None, ignores alias and extension. 
      status_pv_name Alarm pv name. If not None, ignores alias and extension. 
      bypass_pv_name Bypass pv name. If not None, ignores alias and extension.
      bypstat_pv_name Bypass status pv name. If not None, ignores alias and extension. 
      reset_pv_name Reset button pv name. If not None, ignores alias and extension. 
      sensor_pv_name_ext Extension to append to alias to get sensor pv anme. Ignored if 
                         sensor_pv_name is not None. 
      high_limit_pv_name_ext Extension to append to alias to get high limit pv name. Ignored if
                             high_limit_pv_name is not None.
      low_limit_pv_name_ext Extension to append to alias to get low limit pv name. Ignored if 
                            low_limit_pv_name is not None.
      status_pv_name_ext Extension to append to alias to get alarm pv name. Ignored if 
                         status_pv_name is not None.
      bypass_pv_name_ext Extension to append to alias to get bypass pv name. Ignored if 
                         bypass_pv_name is not None.
      bypstat_pv_name_ext Extension to append to alias to get bypass status pv name. Ignored if
                          bypstat_pv_name is not None.
      reset_pv_name_ext Extension to append to alias to get reset pv name. Ignroed if reset_pv_name
                        is not None. 
    '''
    if sensor_pv_name == None and sensor_pv_name_ext == None:
      self.sensor_pv = None
    elif sensor_pv_name != None:
      self.sensor_pv = PV(sensor_pv_name)
    elif sensor_pv_name_ext != None:
      self.sensor_pv = PV(alias + sensor_pv_name_ext)

    if high_limit_pv_name == None and high_limit_pv_name_ext == None:
      self.high_limit_pv = None
    elif high_limit_pv_name != None:
      self.high_limit_pv = PV(high_limit_pv_name)
    elif high_limit_pv_name_ext != None:
      self.high_limit_pv = PV(alias + high_limit_pv_name_ext)

    if low_limit_pv_name == None and low_limit_pv_name_ext == None:
      self.low_limit_pv = None
    elif low_limit_pv_name != None:
      self.low_limit_pv = PV(low_limit_pv_name)
    elif low_limit_pv_name_ext != None:
      self.low_limit_pv = PV(alias + low_limit_pv_name_ext)

    if status_pv_name == None and status_pv_name_ext == None:
      self.status_pv = None
    elif status_pv_name != None:
      self.sensor_pv = PV(status_pv_name)
    elif status_pv_name_ext != None:
      self.status_pv = PV(alias + status_pv_name_ext)

    if bypass_pv_name == None and bypass_pv_name_ext == None:
      self.bypass_pv = None
    elif bypass_pv_name != None:
      self.bypass_pv = PV(bypass_pv_name)
    elif bypass_pv_name_ext != None:
      self.bypass_pv = PV(alias + bypass_pv_name_ext)

    if bypstat_pv_name == None and bypstat_pv_name_ext == None:
      self.bypstat_pv = None
    elif bypstat_pv_name != None:
      self.bypstat_pv = PV(bypstat_pv_name)
    elif bypstat_pv_name_ext != None:
      self.bypstat_pv = PV(alias + bypstat_pv_name_ext)

    if reset_pv_name == None and reset_pv_name_ext == None:
      self.reset_pv = None
    elif reset_pv_name != None:
      self.reset_pv = PV(reset_pv_name)
    elif reset_pv_name_ext != None:
      self.reset_pv = PV(alias + reset_pv_name_ext)

    #this portion checks to make sure all the PVs are connected
    if self.sensor_pv != None and not self.sensor_pv.wait_for_connection(timeout=2):
      print(self.sensor_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.high_limit_pv != None and not self.high_limit_pv.wait_for_connection(timeout=2):
      print(self.high_limit_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.low_limit_pv != None and not self.low_limit_pv.wait_for_connection(timeout=2):
      print(self.low_limit_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.status_pv != None and not self.status_pv.wait_for_connection(timeout=2):
      print(self.status_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.bypass_pv != None and not self.bypass_pv.wait_for_connection(timeout=2):
      print(self.bypass_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.bypstat_pv != None and not self.bypstat_pv.wait_for_connection(timeout=2):
      print(self.bypstat_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")
    if self.reset_pv != None and not self.reset_pv.wait_for_connection(timeout=2):
      print(self.reset_pv.pvname + " is failed to connect, timed out, or is a typo.")
      print("Not recommended to proceed.")

class Logger(object):
  '''
  A class that allows output to be written to bouth stdout and
  a file. To use, simply do
    sys.stdout = Logger("filename")
  Any time this script writes to stdout, now it will also write to the file. 
  '''
  def __init__(self, filename):
    '''
    Constructor for Logger class.
    @params
      filename Filename to write to. 
    '''
    self.filename = filename
    self.terminal = sys.stdout
    self.log_file = open(filename, "w+")

  def write(self, message):
    '''
    Reimplementation of write method to write to both stdout and 
    a file. 
    @params
      message The string to write to both stdout and file. 
    '''
    self.terminal.write(message)
    if "\033" in message: #if message is colored, uncolor it
      self.log_file.write(message[5:len(message)-5])
    else:
      self.log_file.write(message)

  def flush(self):
    '''
    A dummy method. It's just here because it needs to be reimplemented.
    '''
    pass

  def close(self):
    '''
    Closes both the log file and stdout. 
    '''
    self.terminal.close()
    self.log_file.close()

class Checkout(object):
  '''
  A class to encapsulate all the methods and logic for the checkout script. 
  '''
  def __init__(self, interlock_groups):
    '''
    Constructor for Checkout class. Interlock groups is dictionary of
    InterlockAlarms to a list of related InterlockSensors. 

    @params
      interlock_groups A dictionary of interlock groups. 
      ex. interlock_groups = {
            InterlockAlarms(...): [InterlockSensor(...), InterlockSensor(...), ...],
            InterlockAlarms(...): [InterlockSensor(...), InterlockSensor(...), ...],
            InterlockAlarms(...): [InterlockSensor(...), InterlockSensor(...), ...],
            ...
          }
    '''
    self.interlock_groups = interlock_groups
    #valid alarm severities
    self.ANY_MODE = -1
    self.ALARM_NONE = 0
    self.ALARM_MINOR = 1
    self.ALARM_MAJOR = 2
    self.ALARM_INVALID = 3
    self.ALARM_DISCONNECTED = 4

    #valid bypass status modes
    self.NOBYPASS_MODE = 0
    self.BYPASS_MODE = 1

    self.PUT_WAIT = True #not safe to put to False

    #5 seconds seems to be safe
    self.PUT_TIMEOUT = 5 
    self.GET_TIMEOUT = 5
    self.SEMAPHORE_TIMEOUT = 5

    #should be used right after toggling a bypass switch, so as to wait for bypstat to update
    self.bypstat_pv_semaphore = TimedSemaphore(1, self.SEMAPHORE_TIMEOUT)
    #should be used right after doing anything that might change the protection system alarm
    self.ps_pv_semaphore = TimedSemaphore(1, self.SEMAPHORE_TIMEOUT)
    #unused in this script
    self.limit_pv_semaphore = TimedSemaphore(1, self.SEMAPHORE_TIMEOUT)
    #should be used right after doing anything that may change the status of a sensor's alarm
    self.sensor_status_pv_semaphore = TimedSemaphore(1, self.SEMAPHORE_TIMEOUT)
    #should be used right after doing anything that may change the status of a summary alarm 
    self.interlock_group_status_pv_semaphore = TimedSemaphore(1, self.SEMAPHORE_TIMEOUT)
    #should be used right after doing anything that may change the status of the summary protection system alarm
    self.interlock_group_ps_pv_semaphore = TimedSemaphore(1, self.SEMAPHORE_TIMEOUT)

  def get_int(self, prompt_text):
    '''
    Prompts user for an integer. Used for getting user to pick an option.
    @params
      prompt_text What to prompt the user when asking for integer. 
    @return
      The integer.
    '''
    num = None
    while True:
      num = raw_input(prompt_text)
      try:
        num = int(num)
        break
      except:
        print("Please enter an integer.")
    return num

  def prompt_continue(self):
    '''
    Prompts user to hit enter to continue if self.continuous_tests == False. 
    '''
    if not self.continuous_tests:
      raw_input("Press ENTER to continue w/ next test...")
    
  def change_text_color(self, text, color):
    '''
    Returns the colored version of the text passed in if this test log
    is to be printed in color, otherwise the text should
    not be colored and the text should be returned unchanged.

    Note, these colors show up well on a black background terminal.

    Note, "RED" is always assumed to be an error message. Don't use "RED" for any other reason.

    @params
      text The text.
      color The color.
    @return
      The colored version of the text.
    '''
    if not self.print_color:
      return text

    color = color.upper().strip()
    assert color == "GREEN" or color == "BLUE" or color == "RED" or color == "BLUE" or color == "YELLOW", \
      "Passed in argument to change_text_color, color={} is invalid. color should be \"GREEN\" \"BLUE\", \"RED\", \"GREY\", or \"YELLOW\".".format(color)
    
    if color == "GREEN":
      return "\033[92m {}\033[00m".format(text)
    elif color == "BLUE":
      return "\033[96m {}\033[00m".format(text)
    elif color == "RED":
      return "\033[91m {}\033[00m".format(text)
    elif color == "GREY":
      return "\033[97m {}\033[00m".format(text)
    elif color == "YELLOW":
      return "\033[93m {}\033[00m".format(text)

  def raise_error(self, error_msg):
    '''
    Called when a test fails. Will simply print the error message if 
    running passive tests and continue with rest of execution. If 
    not running passive tests, an exception will be raised instead and
    exectuion will stop. 
    @params
      error_msg The error message.
    '''
    error_msg = self.change_text_color(error_msg, "RED")
    if self.passive_tests:
      print(error_msg)
    else: 
      self.log.write(error_msg)
      self.log.close()
      raise(Exception(error_msg))

  def main_menu(self):
    '''
    Main menu of checkout script.
    @return
      User option as integer.
    '''
    print("0. Initialize all interlock groups.")
    print("1. Initialize a single interlock group.")
    print("2. Initialize a single sensor.")
    print("3. Checkout all interlock groups. ")
    print("4. Checkout a single interlock group.")
    print("5. Checkout single temperature sensor.")
    print("6. Exit.")
    option = self.get_int("Select an option (0-6): ")
    print("Option {} chosen.".format(option))
    return option

  def print_test(self, test_text, color, verbose_level):
    '''
    Prints a description of the test to run. If the verbose_level
    entered is greater than the threshold specificity level, nothing
    will be printed. 
    @params
      test_text Description of test.
      color Color test is to be printed in
      verbose_level Level of specificity of test. [0-3]
    '''
    if verbose_level > self.verbose_level:
      return

    tabs = ""
    for _ in range(verbose_level + 1):
      tabs += "\t"
    if color == "RED": #red is always reserved for an error message
      self.raise_error(tabs + test_text)
      return
    print(self.change_text_color(tabs + test_text, color))

  def severity_to_string(self, severity):
    '''
    Converts a severity level to its string form.
    @params
      severity Severity of alarm.
    @return
      The string version fo the severity. 
    '''
    if severity == self.ALARM_NONE:
      return "OK"
    elif severity == self.ALARM_MINOR:
      return "MINOR"
    elif severity == self.ALARM_MAJOR:
      return "FAULT"
    elif severity == self.ALARM_INVALID:
      return "INVALID"
    elif severity == self.ALARM_DISCONNECTED:
      return "DISCONNECTED"
    elif severity == self.ANY_MODE:
      return "ANY SEVERITY"
    else:
      raise(Exception("In severity_to_string, {} is not a recognized severity.".format(severity)))

  def bypstat_to_string(self, bypstat):
    '''
    Converts the bypass status to its string form.
    @params
      bypstat The bypass status.
    @return 

    '''
    if bypstat == self.NOBYPASS_MODE:
      return "NO BYPASS"
    elif bypstat == self.BYPASS_MODE:
      return "BYPASS"
    elif bypstat == self.ANY_MODE:
      return "ANY MODE"
    else:
      raise(Exception("In bypstat_to_string, {} is not a recognized mode.".format(bypstat)))

  def test_pv_severity(self, pv, expected_severity, semaphore):
    '''
    Tests to make sure that the severity of the pv passed in has the expected severity. NOTE, this
    function is assumed to be called after an event that may have changed the pv's severity. 

    If the pv doesn't change to exepcted_severity within the timeout specified by semaphore, then
    an error message is printed. 
    @params
      pv A pyepics PV object
      expected_severity Expected severity of the pv. (see constructor for valid severities)
      semaphore The semaphore used to wait for the pv to change to expected_severity.
    @return
      Returns True if the pv has the expected severity, False otherwise. 
    '''
    self.print_test("Ensuring status of {} is {}...".format(pv.pvname, self.severity_to_string(expected_severity)), "YELLOW", 1)
    semaphore.acquire()
    pv.clear_callbacks() #just in case the semaphore timed out, we don't want our call back to run
    passed = True
    if expected_severity == self.ANY_MODE:
      passed = True
      self.print_test("success", "GREEN", 1)
    elif pv.severity != expected_severity:
      passed = False
      self.print_test("{} has severity {}, but severity {} expected.".format(pv.pvname, self.severity_to_string(pv.severity), self.severity_to_string(expected_severity)), "RED", 1)
    else:
      passed = True
      self.print_test("success", "GREEN", 1)
    semaphore.release()
    return passed

  def test_bypstat(self, bypstat_pv, expected_mode, semaphore):
    '''
    Used to test if a bypass status is in an expected mode. NOTE, this function is 
    assumed to be called immediately after an event that would change the bypass status.
    Usually, only toggling the bypass pv should cause this change. 

    If the bypass status does not change to the expected mode within the timeout specified
    by semaphore, an error message will be printed. 
    @params
      bypstat_pv The bypass status PV object.
      expected_mode The expected mode that this bypass status should be in. (see constructor for valid modes)
      semaphore Semaphore used to wait for the bypass status to change to expected mode.
    @return
      Returns True if the bypstat pv is in the expected mode. False otherwise. 
    '''
    self.print_test("Ensuring mode of {} is {}...".format(bypstat_pv.pvname, self.bypstat_to_string(expected_mode)), "YELLOW", 1)
    semaphore.acquire()
    bypstat_pv.clear_callbacks() #just in case the semaphore timed out, we don't want our call back to run, so get rid of it
    passed = True
    bypstat_mode = bypstat_pv.get(timeout=self.GET_TIMEOUT)
    if expected_mode == self.ANY_MODE:
      passed = True
      self.print_test("success", "GREEN", 1)
    elif bypstat_mode != expected_mode:
      passed = False
      self.print_test("{} is in mode {}, but mode {} expected.".format(bypstat_pv.pvname, 
        self.bypstat_to_string(bypstat_mode), self.bypstat_to_string(expected_mode)), "RED", 1)
    else:
      passed = True
      self.print_test("success", "GREEN", 1)
    semaphore.release()
    return passed

  def add_pv_update_handler(self, pv, semaphore):
    '''
    Adds an update handler to a pv. The handler is called when the pv's value changes and
    releases the associated semaphore so that the function waiting for the pv to change 
    can now acquire the semaphore and move on with the checkout.
    @params
      pv The PV object to add an update handler to.
      semaphore The associated semaphore which is used to wait for the pv to change values.
    '''
    if pv == None:
      return

    def update_handler(**kw):
      semaphore.release()
      pv.clear_callbacks()
    pv.add_callback(update_handler)

  def add_delayed_pv(self, delayed_pv, semaphore, expected_val):
    '''
    This function should be called BEFORE an event that might change the value of the
    pv denoted by delayed_pv. This function acquires the associated semaphore, and
    calls self.add_pv_update_handler to add a handler that will eventually release the semaphore.

    NOTE, this this function only works on bypass status and alarm status pvs, which is the 
    only ones that this script needs to work for.  

    @params
      delayed_pv The PV object to be waited on.
      semaphore The associated semaphore which is used to wait for the pv to change values.
      expected_val The expected value for the pv to be in
    '''
    if delayed_pv == None:
      return 

    if "BYP" in delayed_pv.pvname: # then we know its a bypass status
      if expected_val == self.ANY_MODE or delayed_pv.get(timeout=self.GET_TIMEOUT) == expected_val:
        return 
    else: # then we know its an alarm
      if expected_val == self.ANY_MODE or delayed_pv.severity == expected_val: 
        return 
    semaphore.acquire()
    self.add_pv_update_handler(delayed_pv, semaphore)
    
  def add_delayed_pvs(self, delayed_pvs):
    '''
    Function to add multiple delayed pvs. Calls self.add_delayed_pv multiple
    times to do so.

    NOTE, this this function only works on bypass status and alarm status pvs, which is the 
    only ones that this script needs to work for.

    @params
      delayed_pvs A tuple with three items:
        (delayed_pv, semaphore, expected_val), where
          delayed_pv The PV object to be waited on.
          semaphore The associated semaphore which is used to wait for the pv to change values.
          expected_val The expected value for the pv to be in

    '''
    for delayed_pv, semaphore, expected_val in delayed_pvs:
      self.add_delayed_pv(delayed_pv, semaphore, expected_val)

  def wait_delayed_pvs(self, delayed_pvs):
    '''
    Waits for the delayed pvs that were added via self.add_delayed_pvs.

    @params
      delayed_pvs A tuple with three items:
        (delayed_pv, semaphore, expected_val), where
          delayed_pv The PV object to be waited on.
          semaphore The associated semaphore which is used to wait for the pv to change values.
          expected_val The expected value for the pv to be in
    '''
    passed = True
    for pv, semaphore, expected_val in delayed_pvs:
      if pv == None:
        continue
      if "BYP" in pv.pvname: # then we know its a bypass status
        passed = self.test_bypstat(pv, expected_val, semaphore) and passed
      else: # then we know its an alarm
        passed = self.test_pv_severity(pv, expected_val, semaphore) and passed

    return passed

  def toggle_bypass_mode(self, bypass_pv, mode, delayed_pvs):
    '''
    Toggles the bypass pv to be in the mode passed in. 
    @params
      bypass_pv The bypass PV object
      mode The mode that you want to switch this bypass pv to (either self.NOBYPASS_MODE or self.BYPASS_MODE)
      delayed_pvs A list of tuples, each with three items:
        (delayed_pv, semaphore, expected_val), where
          delayed_pv The PV object to be waited on. NOTE, in this function, you should always include a tuple with
                     the associated bypstat pv, and have it be first. This is so that upon switching the bypass mode,
                     you wait for the bypstat pv to change first before moving onto anything else.
          semaphore The associated semaphore which is used to wait for the pv to change values.
          expected_val The expected value for the pv to be in
    @return 
      Returns True if toggling the bypass pv didn't encounter any errors. False otherwise.
    '''
    #sometimes an interlock sensor/summary alarm won't have a bypass, in which case this function should just return True
    if bypass_pv == None: 
      return True

    self.print_test("Turning on mode {} for {}...".format(self.bypstat_to_string(mode), bypass_pv.pvname), "YELLOW", 1)
    self.add_delayed_pvs(delayed_pvs)
    

    if mode == self.BYPASS_MODE:
      bypass_pv.put(self.BYPASS_MODE, wait=self.PUT_WAIT, timeout=self.PUT_TIMEOUT, use_complete=True)
    elif mode == self.NOBYPASS_MODE:
      bypass_pv.put(self.NOBYPASS_MODE, wait=self.PUT_WAIT, timeout=self.PUT_TIMEOUT, use_complete=True)
    
    if bypass_pv.put_complete:
      self.print_test("success", "GREEN", 1)
      passed = True
    else:
      self.print_test("put failed", "RED", 1)
      passed = False

    passed = self.wait_delayed_pvs(delayed_pvs) and passed
    return passed 
   
  def press_reset(self, reset_pv, delayed_pvs):
    '''
    reset_pv The reset PV object
    delayed_pvs A list of tuples, each with three items:
      (delayed_pv, semaphore, expected_val), where
        delayed_pv The PV object to be waited on.
        semaphore The associated semaphore which is used to wait for the pv to change values.
        expected_val The expected value for the pv to be in
    @return
      Returns True if pressing the reset button didn't encounter any errors. False otherwise.
    '''
    if reset_pv == None:
      print("no reset")
      return True
    self.print_test("Pressing RESET for {}...".format(reset_pv.pvname), "YELLOW", 1)
    passed = True
    self.add_delayed_pvs(delayed_pvs)
    reset_pv.put(1, wait=self.PUT_WAIT, timeout=self.PUT_TIMEOUT, use_complete=True)
    if reset_pv.put_complete:
      passed = True
      self.print_test("success", "GREEN", 1)
    else:
      passed = False
      self.print_test("put failed", "RED", 1)
    passed = self.wait_delayed_pvs(delayed_pvs) and passed
    return passed

  def list_all_interlock_groups(self):
    '''
    Lists all the interlock groups. 
    '''
    print("Listing all interlock groups...")
    for i, interlock_group in enumerate(self.interlock_groups.items()):
      print("{}. {}".format(i, interlock_group[0].status_pv.pvname))

  def list_interlock_sensors(self, interlock_alarms):
    '''
    Lists all sensors associated with the passed in interlock_alarms.
    @params
      interlock_alarms An InterlockAlarms object.
    '''
    print("All sensors for {}.".format(interlock_alarms.status_pv.pvname))
    for i, interlock_sensor in enumerate(self.interlock_groups[interlock_alarms]):
      print("\t{}. {}".format(i, interlock_sensor.sensor_pv.pvname))

  def list_all_sensors(self):
    '''
    Lists all sensors for every interlock group.
    '''
    for interlock_alarms, interlock_sensors in interlock_groups.items():
      self.list_interlock_sensors(interlock_alarms)

  def set_limit_pv(self, limit_pv, val, delayed_pvs=[]):
    '''
    Sets a high/low alarm limit pv to be the the value passed in.
    @params
      limit_pv A high or low limit PV object. 
      val The value to set the limit pv to.
      delayed_pvs A list of tuples, each with three items:
        (delayed_pv, semaphore, expected_val), where
          delayed_pv The PV object to be waited on.
          semaphore The associated semaphore which is used to wait for the pv to change values.
          expected_val The expected value for the pv to be in
    '''
    self.print_test("Setting {} to {}...".format(limit_pv.pvname, val), "YELLOW", 1)
    passed = True
    self.add_delayed_pvs(delayed_pvs)
    #self.add_delayed_pv(limit_pv, self.limit_pv_semaphore, val)
    if limit_pv.put(val, wait=self.PUT_WAIT, timeout=self.PUT_TIMEOUT) == None:
      self.raise_error("Attempt to put value of {} in {} failed.".format(val, limit_pv.pvname))
      passed = False
    else:
      passed = True
      self.print_test("success", "GREEN", 1) #TODO, change where success prints for other funcitons
    
    passed = self.wait_delayed_pvs(delayed_pvs) and passed

    return passed

  def init_interlock_alarms(self, interlock_alarms):
    '''
    This function intializes an InterlockAlarms object, which really means just turning off the bypass switch
    for the protection system alarm if there is one. Called before testing an interlock group.
    @params
      interlock_alarms An InterlockAlarms object
    @return
      Returns True if nothing went wrong with the intialization step. False otherwise.
    '''
    self.print_test("Initializing {} interlock group for tests...".format(interlock_alarms.status_pv.pvname), "BLUE", 0)
    passed = True

    #activate NO BYPASS mode for PS alarm
    passed = self.toggle_bypass_mode(interlock_alarms.psbypass_pv, self.NOBYPASS_MODE, [
        #bypstat should be in NO BYPASS mode
        (interlock_alarms.psbypstat_pv, self.bypstat_pv_semaphore, self.NOBYPASS_MODE)
      ]) and passed
    if passed:
      self.print_test("all subtests passed", "GREEN", 0)
    else:
      self.print_test("at least one subtest failed", "RED", 0)
    self.prompt_continue()

  def init_interlock_sensor(self, interlock_sensor): 
    '''
    Sets the HIGH and LOW limits for a single sensor and turns off the bypass switch for that sensor.
    @params
      interlock_sensor An InterlockSensor object.
    @return
      True if nothing went wrong. False otherwise.
    '''
    self.print_test("Initializing {} sensor for tests...".format(interlock_sensor.sensor_pv.pvname), "BLUE", 0)
    passed = True
    # set HIGH and LOW limits
    test_high_limit = interlock_sensor.sensor_pv.get(timeout=self.GET_TIMEOUT) + self.test_limit_diff
    test_low_limit = interlock_sensor.sensor_pv.get(timeout=self.GET_TIMEOUT) - self.test_limit_diff
    passed = self.set_limit_pv(interlock_sensor.high_limit_pv, test_high_limit) and passed
    self.prompt_continue()
    passed = self.set_limit_pv(interlock_sensor.low_limit_pv, test_low_limit) and passed
    self.prompt_continue()

    #activate NO BYPASS mode
    passed = self.toggle_bypass_mode(interlock_sensor.bypass_pv, self.NOBYPASS_MODE, [
        #bypstat should be in NO BYPASS mode
        (interlock_sensor.bypstat_pv, self.bypstat_pv_semaphore, self.NOBYPASS_MODE)
        #alarm should be in ANY mode because it could've been faulted
        #(interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ANY_MODE)
      ]) and passed
    self.prompt_continue()
    
  
    passed = self.press_reset(interlock_sensor.reset_pv, [
        #alarm should be OK
        #(interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ALARM_NONE)
      ]) and passed
    if passed:
      self.print_test("all subtests passed", "GREEN", 0)
    else: 
      self.print_test("at least one subtest failed", "RED", 0)
    self.prompt_continue()

  def init_all_interlock_groups(self):
    '''
    Calls self.init_interlock_group on all interlock_alarms in self.interlock_groups.
    '''
    for interlock_alarms in self.interlock_groups:
      self.init_interlock_group(interlock_alarms)
      sleep(2)

  def init_interlock_group(self, interlock_alarms):
    '''
    Calls self.init_interlock_sensor on all sensors that connect to the summary alarms
    in the passed in interlock_alarms.
    @params
      interlock_alarms An InterlockAlarms object. 
    '''
    for interlock_sensor in self.interlock_groups[interlock_alarms]:
      self.init_interlock_sensor(interlock_sensor)
    self.init_interlock_alarms(interlock_alarms)

  def get_interlock_group(self):
    '''
    Prompts the user to pick an interlock group.
    @return
      The interlock group as an InterlockAlarms object. Each interlock group has a unique InterlockAlarms object,
      so thats why the InterlockAlarms object is returned. 
    '''
    self.list_all_interlock_groups()
    while True:
      option = self.get_int("Select an interlock group (0-{}): ".format(len(self.interlock_groups) - 1))
      if option < 0 or option >= len(self.interlock_groups):
        print("Invalid option.")
      else:
        print("Option {} chosen.".format(option))
        return self.interlock_groups.items()[option][0]

  def get_interlock_sensor(self, interlock_alarms):
    '''
    Prompts the user for an interlock sensor connected to the interlock alarms passed in. 
    @params
      interlock_alarms An InterlockAlarms object
    @return
      An InterlockSensor object. 
    '''
    while True:
      self.list_interlock_sensors(interlock_alarms)
      option = self.get_int("Select a sensor(0-{}): ".format(len(self.interlock_groups[interlock_alarms]) - 1))
      if option < 0 or option >= len(self.interlock_groups[interlock_alarms]):
        print("Invalid option")
      else:
        print("Option {} chosen.".format(option))
        return self.interlock_groups[interlock_alarms][option]

  def run(self, print_color=True, passive_tests=True, continuous_tests=True, test_limit_diff=10, test_limit_change=0.25, verbose_level=True, filename=None):
    '''
    Runs the checkout with the passed in parameters.
    @params
      print_color Whether or not to print the checkout output in color.
      passive_tests If True, will continue with checkout even if a test fails. If False and a test fails, program will exit.
      continuous_tests If True, will prompt user to hit enter after a test is done. Should be paired with verbose=True
      test_limit_diff Will set the initial high and low limits for testing to be curr_temp + test_limit_diff and curr_temp - test_limit_diff respectively. Default is test_limit_diff=10
      test_limit_change When breaking a high or low limit for testing, will set them to be curr_temp - test_limit_change or curr_temp + test_limit_change respectively. Default is test_limit_change=0.25
      verbose_level If True, script will also print out subtests. If False, won't. 
      filename If filename is present, script will also output to a log file specified by filename.
    '''
    self.print_color = print_color
    self.passive_tests = passive_tests
    self.continuous_tests = continuous_tests
    self.test_limit_diff = test_limit_diff
    self.test_limit_change = test_limit_change
    self.verbose_level = verbose_level
    if filename != None:
      sys.stdout = Logger(filename)

    print("assertive={}".format(not self.passive_tests))
    print("non_continuous={}".format(not self.continuous_tests))
    print("delta={}".format(self.test_limit_diff))
    print("small_delta={}".format(self.test_limit_change))
    print("verbose={}".format(bool(self.verbose_level)))
    print("filename={}".format(filename))



    print("\n\
      This checkout script runs a battery of tests on interlock group\n\
      to ensure that all alarms are in working condition. See options\n\
      below.\n\
      ")
    while True:
      option = self.main_menu()
      if option == 0: #init all interlock groups
        self.init_all_interlock_groups()
      elif option == 1: #initialize single interlock group
        interlock_alarms = self.get_interlock_group()
        self.init_interlock_group(interlock_alarms)
      elif option == 2: #initialize single sensor
        print("Select the interlock group in which this sensor is located.")
        interlock_alarms = self.get_interlock_group()
        print("Select the interlock sensor from this interlock group.")
        interlock_sensor = self.get_interlock_sensor(interlock_alarms)
        self.init_interlock_sensor(interlock_sensor)
      elif option == 3: # checkout all interlock gorups
        self.checkout_all_interlock_groups()
      elif option == 4: # checkout single interlock group
        interlock_alarms = self.get_interlock_group()
        self.checkout_interlock_group(interlock_alarms)
      elif option == 5: # checkout single sensor
        print("Select the interlock group in which this sensor is located.")
        interlock_alarms = self.get_interlock_group()
        print("Select the interlock sensor from this interlock group.")
        interlock_sensor = self.get_interlock_sensor(interlock_alarms)
        self.checkout_interlock_sensor(interlock_alarms, interlock_sensor, "HIGH") #TOD add
        self.checkout_interlock_sensor(interlock_alarms, interlock_sensor, "LOW")
      elif option == 6:
        break
      else:
        print("Invalid option")

      print("") #line break

    if filename != None:
      sys.stdout.close()


  def checkout_interlock_sensor(self, interlock_alarms, interlock_sensor, limit_type):
    '''
    Checks out a single interlock sensor.
    @params
      interlock_alarms An InterlockAlarms object. Needed to check the summary and protection system alarms. 
      interlock_sensor An InterlockSensor object connected to the passed in InterlockAlarms. 
      limit_type Type of limit to be checked. Either "HIGH" or "LOW" may be passed in.
    '''
    self.print_test("Testing {} limit for {}...".format(limit_type, interlock_sensor.sensor_pv.pvname), "BLUE", 0)
    #this function assumes all alarms and interlock sensors have been set. 
    limit_type = limit_type.upper().strip()
    assert limit_type == "HIGH" or limit_type == "LOW", \
      "Passed in argument to test_limit, limit_type{} is invalid, limit_type should be \"HIGH\" or \"LOW\".".format(limit_type)
    limit_pv = None
    if limit_type == "HIGH":
      limit_pv = interlock_sensor.high_limit_pv
    elif limit_type == "LOW":
      limit_pv = interlock_sensor.low_limit_pv

    passed = True
    #activate NO BYPASS mode
    passed = self.toggle_bypass_mode(interlock_sensor.bypass_pv, self.NOBYPASS_MODE, [
        (interlock_sensor.bypstat_pv, self.bypstat_pv_semaphore, self.NOBYPASS_MODE)
      ]) and passed
    self.prompt_continue()
 
    #break limit and make sure all relevant alarms go to fault
    curr_val = interlock_sensor.sensor_pv.get(timeout=self.GET_TIMEOUT)
    old_limit = limit_pv.get(timeout=self.GET_TIMEOUT)
    new_limit = None

    if limit_type == "HIGH":
      new_limit = curr_val - self.test_limit_change
    elif limit_type == "LOW":
      new_limit = curr_val + self.test_limit_change

    passed = self.set_limit_pv(limit_pv, new_limit, [
        # this sensor's own alarm should be FAULT
        (interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ALARM_MAJOR),
        # interlock group summary alarm should be FAULT
        (interlock_alarms.status_pv, self.interlock_group_status_pv_semaphore, self.ALARM_MAJOR),
        # interlock group PS alarm mode should be FAULT
        (interlock_alarms.ps_pv, self.interlock_group_ps_pv_semaphore, self.ALARM_MAJOR)
      ]) and passed 
    self.prompt_continue()

    # activate BYPASS mode for PS alarm
    passed = self.toggle_bypass_mode(interlock_alarms.psbypass_pv, self.BYPASS_MODE, [
        # ensure BYPASS mode activated
        (interlock_alarms.psbypstat_pv, self.bypstat_pv_semaphore, self.BYPASS_MODE),
        # ensure PS alarm is OK
        (interlock_alarms.ps_pv, self.interlock_group_ps_pv_semaphore, self.ALARM_NONE)
      ]) and passed
    self.prompt_continue()

    # activate NO BYPASS mode for PS alarm
    passed = self.toggle_bypass_mode(interlock_alarms.psbypass_pv, self.NOBYPASS_MODE, [
        # ensure BYPASS mode activated
        (interlock_alarms.psbypstat_pv, self.bypstat_pv_semaphore, self.NOBYPASS_MODE),
        # ensure PS alarm is FAULT
        (interlock_alarms.ps_pv, self.interlock_group_ps_pv_semaphore, self.ALARM_MAJOR)
      ]) and passed
    self.prompt_continue()

    # reset limit to old value
    passed = self.set_limit_pv(limit_pv, old_limit, [
        #FAULT mode should be latched for this limit's status alarm
        (interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ALARM_MAJOR)
        #TODO, test interlock alarms and ps alarms too? 
      ]) and passed
    self.prompt_continue()

    # go past limit again for rest of tests
    passed = self.set_limit_pv(limit_pv, new_limit, [
        #this sensor's alarm should still be in FAULT mode
        (interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ALARM_MAJOR),
      ]) and passed
    self.prompt_continue()
    #activate BYPASS mode for sensor
    passed = self.toggle_bypass_mode(interlock_sensor.bypass_pv, self.BYPASS_MODE, [
        #bypass status should be in BYPASS MODE
        (interlock_sensor.bypstat_pv, self.bypstat_pv_semaphore, self.BYPASS_MODE),
        # this sensor's alarm should now be OK
        (interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ALARM_NONE),
        # interlock group summary alarm should be OK
        (interlock_alarms.status_pv, self.interlock_group_status_pv_semaphore, self.ALARM_NONE),
        # interlock group PS alarm mode should be OK
        (interlock_alarms.ps_pv, self.interlock_group_ps_pv_semaphore, self.ALARM_NONE)
      ]) and passed
    self.prompt_continue()


    

    #activate NO BYPASS mode for sensor
    passed = self.toggle_bypass_mode(interlock_sensor.bypass_pv, self.NOBYPASS_MODE, [
        #bypass status should be in NO BYPASS MODE
        (interlock_sensor.bypstat_pv, self.bypstat_pv_semaphore, self.NOBYPASS_MODE),
        # this sensor's alarm should now be FAULT
        (interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ALARM_MAJOR),
        # interlock group summary alarm should be FAULT
        (interlock_alarms.status_pv, self.interlock_group_status_pv_semaphore, self.ALARM_MAJOR),
        # interlock group PS alarm mode should be FAULT
        (interlock_alarms.ps_pv, self.interlock_group_ps_pv_semaphore, self.ALARM_MAJOR)
      ]) and passed
    self.prompt_continue()
    
    #reset limit
    passed = self.set_limit_pv(limit_pv, old_limit, [
        #FAULT mode should be latched for this limit's status alarm
        (interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ALARM_MAJOR)

      ]) and passed
    
    # press reset
    passed = self.press_reset(interlock_sensor.reset_pv, [
        #alarm for this sensor should be OK
        (interlock_sensor.status_pv, self.sensor_status_pv_semaphore, self.ALARM_NONE),
        #alarm interlock status is OK
        (interlock_alarms.status_pv, self.interlock_group_status_pv_semaphore, self.ALARM_NONE),
        #alarm for interlock PS is OK
        (interlock_alarms.ps_pv, self.interlock_group_ps_pv_semaphore, self.ALARM_NONE)
      ]) and passed

    if passed:
      self.print_test("all subtests passed", "GREEN", 0)
    else:
      self.print_test("at least one subtest failed", "RED", 0)

  def checkout_interlock_group(self, interlock_alarms):
    '''
    Checks out each sensor in an interlock group. 
    @params
      interlock_alarms An InterlockAlarms object denoting the interlock group. 
    '''
    for interlock_sensor in self.interlock_groups[interlock_alarms]:
      for limit_type in ["HIGH", "LOW"]:
        self.checkout_interlock_sensor(interlock_alarms, interlock_sensor, limit_type)

  def checkout_all_interlock_groups(self):
    '''
    Checks out all interlock groups. Basically calls self.checkout_interlock_group multiple
    times for all the InterlockAlarms in self.interlock_groups.
    '''
    for interlock_alarms in self.interlock_groups:
      self.checkout_interlock_group(interlock_alarms)

if __name__ == "__main__":
  print("Starting...")


  parser = argparse.ArgumentParser()
  parser.add_argument("-v", "--verbose", action="store_true", help="Controls verbose level. If flag present, displays subtests as well.")
  parser.add_argument("-f", "--filename", type=str, help="Writes all output to file specified.")
  parser.add_argument("-nc", "--non_continuous", action="store_true", help="If flag present, will ask user to hit ENTER after a test finishes.")
  parser.add_argument("-a", "--assertive", action="store_true", help="If flag present, program will exit as soon as a test fails.")
  parser.add_argument("-d", "--delta", type=float, default=10.0, help="Will set the initial high and low limits for testing to be curr_temp + delta and curr_temp - delta respectively. Default is delta=10")
  parser.add_argument("-sd", "--small_delta", type=float, default=0.25, help="Will set high and low limits when trying to set off an alarm to be curr_temp - small_delta and curr_temp + small_delta resepctively. Default is small_delta=0.25")
  args = parser.parse_args()

  # test_interlock_groups = {
  #   InterlockAlarms("COLL:BPN22:414:", status_pv_name_ext="ALARM", psbypass_pv_name_ext="MPSBYP", ps_pv_name_ext="MPSALARM"): [
  #     InterlockSensor("COLL:BPN22:414:1:TEMP", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", status_pv_name_ext="ALARM", reset_pv_name_ext="RESET"),
  #     InterlockSensor("COLL:BPN22:414:2:TEMP", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", status_pv_name_ext="ALARM", reset_pv_name_ext="RESET"),
  #     InterlockSensor("COLL:BPN22:414:3:TEMP", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", status_pv_name_ext="ALARM", reset_pv_name_ext="RESET"),
  #     InterlockSensor("COLL:BPN22:414:4:TEMP", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", status_pv_name_ext="ALARM", reset_pv_name_ext="RESET")
  #   ]
  # }

  gunb_mps_interlock_groups = {
    InterlockAlarms(status_pv_name="GUN:GUNB:100:EPS_BDYTEMPSUM" , psbypass_pv_name= "GUN:GUNB:100:MPS_BDYTEMPSUMBYP" , ps_pv_name= "GUN:GUNB:100:MPS_BDYTEMP_PERMIT" ) : [
      InterlockSensor(alias="GUN:GUNB:100:NOSE", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CATHENDCAPCEN", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CATHENDCAPOUT", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANCEN", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANOUT", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:VACWALLS", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:VACWALLN", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANFLANGE", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:BUCKCOIL", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:INLT", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANENDCAPRET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CATHENDCAPRET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:NOSERET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CAVITYWALLRET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "GUN:GUNB:100:EPS_WGTEMPSUM", psbypass_pv_name= "GUN:GUNB:100:MPS_WGTEMPSUMBYP", ps_pv_name= "GUN:GUNB:100:MPS_WGTEMP_PERMIT") : [
      #waveguid a3 tunnel rtds
      InterlockSensor(alias="GUN:GUNB:100:WGA3CPLREND", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3ELBOW", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3MID", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3VRUN", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:A3CPLRRFWNDW", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E7", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:FLANGE", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:S6", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E8", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:S7", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E9", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:B4", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:W", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      
      #waveguid a3 gallery rtds
      InterlockSensor(alias="GUN:GUNB:100:WGA3:B1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:S2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:B2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:CIRC", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:CIRC", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:B3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:S3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E6", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      
      #waveguid a4 tunnel rtds
      InterlockSensor(alias="GUN:GUNB:100:WGA4CPLREND", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4ELBOW", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4MID", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4VRUN", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:A4CPLRRFWNDW", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E7", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:FLANGE", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:S6", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E8", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:S7", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E9", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:B4", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E10", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      
      #waveguide a4 gallery rtds
      InterlockSensor(alias="GUN:GUNB:100:WGA4:B1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:S2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:B2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:CIRC", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:B3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:S3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E6", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
      
    ],
    
    InterlockAlarms(status_pv_name= "GUN:GUNB:100:EPS_FLOWSUM", psbypass_pv_name= "GUN:GUNB:100:MPS_FLOWSUMBYP", ps_pv_name= "GUN:GUNB:100:MPS_FLOW_PERMIT") : [
      InterlockSensor(alias="GUN:GUNB:100:ANENDCAPFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANFLANGEFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CATENDCAPFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:NOSEFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CAVWALLFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CPLRFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    
    InterlockAlarms(status_pv_name= "SOLN:GUNB:212:FLOWALARM", psbypass_pv_name= "SOLN:GUNB:212:MPS_FLOWBYP", ps_pv_name= "SOLN:GUNB:212:MPS_FLOW_PERMIT") : [
      InterlockSensor(alias="SOLN:GUNB:212:FLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    
    #note, soln:gunb:212:eps_tempsum and 823 are exactly the same
    InterlockAlarms(status_pv_name= "SOLN:GUNB:212:EPS_TEMPSUM", psbypass_pv_name= "SOLN:GUNB:212:MPS_TEMPSUMBYP", ps_pv_name= "SOLN:GUNB:212:MPS_TEMP_PERMIT") : [
      InterlockSensor(alias="SOLN:GUNB:212:BDY", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:212:RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:212:INLT", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:823:BDY", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:823:RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "SOLN:GUNB:823:EPS_TEMPSUM", psbypass_pv_name= "SOLN:GUNB:823:MPS_TEMPSUMBYP", ps_pv_name= "SOLN:GUNB:823:MPS_TEMP_PERMIT") : [
      InterlockSensor(alias="SOLN:GUNB:212:BDY", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:212:RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:212:INLT", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:823:BDY", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:823:RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "ACCL:GUNB:455:EPS_TEMPSUM", psbypass_pv_name= "ACCL:GUNB:455:MPS_TEMPSUMBYP", ps_pv_name= "ACCL:GUNB:455:MPS_TEMP_PERMIT") : [
      InterlockSensor(alias="ACCL:GUNB:455:INLT", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:CELL1RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:CELL1RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:CELL2RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:ENDCAP1S", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:ENDCAP2S", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:ENDCAP1N", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:ENDCAP2N", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:CPLR1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:CPLR2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:CPLR3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="ACCL:GUNB:455:CPLR4", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "ACCL:GUNB:455:FLOWALARM", psbypass_pv_name= "ACCL:GUNB:455:MPS_FLOWBYP", ps_pv_name= "ACCL:GUNB:455:MPS_FLOW_PERMIT") : [
      InterlockSensor(alias="ACCL:GUNB:455:FLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ]
  }
  gunb_gun_interlock_groups = {
    InterlockAlarms(status_pv_name= "GUN:GUNB:100:EPS_BDYTEMPSUM", psbypass_pv_name= "GUN:GUNB:100:EPS_BDYTEMPSUMBYP", psbypstat_pv_name= "GUN:GUNB:100:EPS_BDYTEMPSUMBYPSTAT", ps_pv_name= "GUN:GUNB:100:EPS_PERMIT") : [
      InterlockSensor(alias="GUN:GUNB:100:NOSE", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CATHENDCAPCEN", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CATHENDCAPOUT", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANCEN", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANOUT", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:VACWALLS", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:VACWALLN", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANFLANGE", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:BUCKCOIL", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:INLT", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANENDCAPRET", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CATHENDCAPRET", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:NOSERET", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CAVITYWALLRET", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "GUN:GUNB:100:EPS_WGTEMPSUM", psbypass_pv_name= "GUN:GUNB:100:EPS_WGTEMPSUMBYP", psbypstat_pv_name= "GUN:GUNB:100:EPS_WGTEMPSUMBYPSTAT", ps_pv_name= "GUN:GUNB:100:EPS_PERMIT") : [
      #waveguid a3 tunnel rtds
      InterlockSensor(alias="GUN:GUNB:100:WGA3CPLREND", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3ELBOW", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3MID", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3VRUN", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:A3CPLRRFWNDW", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E7", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:FLANGE", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:S6", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E8", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:S7", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E9", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:B4", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:W", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      
      #waveguid a3 gallery rtds
      InterlockSensor(alias="GUN:GUNB:100:WGA3:B1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:S2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:B2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:CIRC", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:CIRC", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:B3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:S3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA3:E6", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      
      #waveguid a4 tunnel rtds
      InterlockSensor(alias="GUN:GUNB:100:WGA4CPLREND", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4ELBOW", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4MID", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4VRUN", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:A4CPLRRFWNDW", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E7", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:FLANGE", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:S6", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E8", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:S7", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E9", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:B4", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E10", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      
      #waveguide a4 gallery rtds
      InterlockSensor(alias="GUN:GUNB:100:WGA4:B1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E1", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:S2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:B2", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:CIRC", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:B3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:S3", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:WGA4:E6", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "GUN:GUNB:100:EPS_FLOWSUM", psbypass_pv_name= "GUN:GUNB:100:EPS_FLOWSUMBYP", psbypstat_pv_name= "GUN:GUNB:100:EPS_FLOWSUMBYPSTAT", ps_pv_name= "GUN:GUNB:100:EPS_PERMIT") : [
      InterlockSensor(alias="GUN:GUNB:100:ANENDCAPFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:ANFLANGEFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CATENDCAPFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:NOSEFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CAVWALLFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="GUN:GUNB:100:CPLRFLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="ALARM", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "SOLN:GUNB:212:EPS_TEMPSUM", psbypass_pv_name= "SOLN:GUNB:212:EPS_TEMPSUMBYP", psbypstat_pv_name= "SOLN:GUNB:212:EPS_TEMPSUMBYPSTAT", ps_pv_name= "GUN:GUNB:100:EPS_PERMIT") : [
      InterlockSensor(alias="SOLN:GUNB:212:BDY", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:212:RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:212:INLT", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:823:BDY", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:823:RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "SOLN:GUNB:823:EPS_TEMPSUM", psbypass_pv_name= "SOLN:GUNB:823:EPS_TEMPSUMBYP", psbypstat_pv_name= "SOLN:GUNB:823:EPS_TEMPSUMBYPSTAT", ps_pv_name= "GUN:GUNB:100:EPS_PERMIT") : [
      InterlockSensor(alias="SOLN:GUNB:212:BDY", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:212:RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:212:INLT", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:823:BDY", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET"),
      InterlockSensor(alias="SOLN:GUNB:823:RET", sensor_pv_name_ext="TEMP", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ],
    InterlockAlarms(status_pv_name= "SOLN:GUNB:212:FLOWALARM", psbypass_pv_name= None, psbypstat_pv_name= None, ps_pv_name= "GUN:GUNB:100:EPS_PERMIT") : [
      InterlockSensor(alias="SOLN:GUNB:212:FLOW", sensor_pv_name_ext="", high_limit_pv_name_ext="HLIMDES", low_limit_pv_name_ext="LLIMDES", status_pv_name_ext="", bypass_pv_name_ext="BYP", bypstat_pv_name_ext="BYPSTAT", reset_pv_name_ext="RESET")
    ]
  }


  Checkout(gunb_mps_interlock_groups).run(continuous_tests=not args.non_continuous, verbose_level=int(args.verbose), 
    passive_tests=not args.assertive, test_limit_diff=args.delta, test_limit_change=args.small_delta, filename=args.filename)








