program l2refAlarm

double   l2refPhase;
assign   l2refPhase      to    "LLRF:IN20:RH:REF_1_S_PA";
monitor  l2refPhase;
evflag   ev_l2refPhase;
sync     l2refPhase      ev_l2refPhase;

double   l2refPhase_hihi;
assign   l2refPhase_hihi  to   "LLRF:IN20:RH:REF_1_S_PA.HIHI";
double   l2refPhase_high;
assign   l2refPhase_high  to   "LLRF:IN20:RH:REF_1_S_PA.HIGH";
double   l2refPhase_low;
assign   l2refPhase_low   to   "LLRF:IN20:RH:REF_1_S_PA.LOW";
double   l2refPhase_lolo;
assign   l2refPhase_lolo  to   "LLRF:IN20:RH:REF_1_S_PA.LOLO";

%% #define ALARM_MARGINE    1.

ss l2refAlarm
{
    state l2refMon {
        when(efTestAndClear(ev_l2refPhase)) {} state l2refCalc
    }

    state l2refCalc {
        when(1) {
            l2refPhase_hihi = l2refPhase + (ALARM_MARGINE * 2.);  pvPut(l2refPhase_hihi);
            l2refPhase_high = l2refPhase +  ALARM_MARGINE;        pvPut(l2refPhase_high);
            l2refPhase_low  = l2refPhase -  ALARM_MARGINE;        pvPut(l2refPhase_low);
            l2refPhase_lolo = l2refPhase - (ALARM_MARGINE * 2.);  pvPut(l2refPhase_lolo);
        } state l2refMon
    }
}
