esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% RING_CURRENT.MAC
#%NAME% %B%ring_current.mac%B% - various macros to read the ring current and
#other "machine" parameters
#%END%

#%IU% (mc)
#%MDESC% read some parameters from the "machine" and save them
#them in the %B%mc%B% array as follows: mc[0] - current {mA},
#mc[1] - lifetime [s], mc[2] - time left until injection [s]
def _read_mach_current(mc) '{
local ret dev

  dev = "//acs.esrf.fr:10000/sys/machstat/tango"
  ret = tango_get(dev, "Current")
  if (TANGO_ERR != "0") {
    print_tango_err()
    return (-1)
  } else
    mc[0] = ret

  ret = tango_get(dev, "Lifetime")
  if (TANGO_ERR != "0") {
    print_tango_err()
    return (-1)
  } else
    mc[1] = ret

  ret = tango_get(dev, "Countdown")
  if (TANGO_ERR != "0") {
    print_tango_err()
    return (-1)
  } else
    mc[2] = ret

  return (0)
}'

#%UU% (elapsed_time)
#%MDESC% Calculate the ring current in function of the beam lifetime.
#If %B%elapsed_time%B% = -1, calculate the current factor, rather than
#the current.
def ring_curr(elapsed_time) '{
global RING_ltime RING_curr RING_etime
local curr mc[]

  if (elapsed_time == -1)
    return(exp(-(time() - RING_etime) / RING_ltime))
  if (((time() - RING_etime) > elapsed_time) || (elapsed_time <= 0)) {
    if (_read_mach_current(mc) == 0) {
      if (mc[2] != 0) {
        curr = mc[0]
        RING_curr = mc[0]
        RING_ltime = mc[1]
        RING_etime = time()
      } else {
        if (RING_ltime != 0)
          curr = RING_curr * exp(-(time() - RING_etime) / RING_ltime)
      }
    } else {
      curr = -1
    }
  } else {
    if (RING_ltime != 0)
      curr = RING_curr * exp(-(time() - RING_etime) / RING_ltime)
  }
  return (curr)
}'

#%IU% ()
#%MDESC% Read the ring current. Return the actual value or -1 of error.
def _rc() '{
local mc[]
 if (_read_mach_current(mc) == 0)
   return(mc[0])
 else
   return(-1)
}'

#%UU% counter_mnemonic
#%MDESC% read the ring current only if there is counter %B%counter_mnemonic%B%
def rc_on '{
  cdef ("user_getcounts",";S[$1]=_rc();", "$1",0x22)
}'

#%UU% counter_mnemonic
#%MDESC% clean the ring current %B%counter_mnemonic%B% definition
def rc_off '{
  S[$1]=0
  cdef ("","","$1","delete")
}'


#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% A.Beteva, A.Filipponi%BR%
#$Revision: 1.8 $, $Date: 2021/03/15 16:44:48 $
#%END%
#%LOG%
#$Log: ring_current.mac,v $
#Revision 1.8  2021/03/15 16:44:48  guilloud
#change acs for acs.esrf.fr to avoid possible timeout
#
#Revision 1.7  2019/10/08 12:35:39  ohlsson
#new attributes Sig_current -> Current and Sig_lifetime -> Lifetime
#for the new server
#
#Revision 1.6  2019/10/07 07:45:29  ohlsson
#Prepare for EBS orion -> acs
#
#Revision 1.5  2016/12/02 10:23:52  guilloud
#changed TANGO_ERR test.
#
#Revision 1.4  2012/03/21 17:10:37  beteva
#Changd the reading of the parameters - new front end software.
#
#Revision 1.3  2004/06/08 12:51:31  beteva
#added -1 option in ring_curr()
#
#Revision 1.2  2003/04/22 16:13:33  beteva
#define RING_etime
#
#Revision 1.1  2003/04/14 12:33:57  beteva
#Initial revision
#