#include #include #include #include #include #include #include #include #include #include #include static long bkptEval(epicsFloat64 a, epicsFloat64 b, epicsFloat64 *bkpt_a, epicsFloat64 *bkpt_b, size_t bkpt_size); #define SXRSS_UNDEF 0 #define SXRSS_SASE 1 #define SXRSS_SEEDED 2 #define SXRSS_HARMONIC 3 #define SXRSS_SLIT 4 /* * Inputs ( 0 = FALSE, 1 = TRUE ) * * a Guardian OK for Seeded mode * b Position OK for SASE mode * c Position OK for Seeded mode * d Position OK for Harmonic mode * e Energy OK for Seeded mode * f Energy OK for Harmonic mode * g Chicane power supply ON * h Grating/Mirror 1 OUT * i Grating/Mirror 1 IN * j Slit OUT * k Slit IN * l Mirror 2 OUT * m Mirror 2 IN * n Mirror 3 OUT * o Mirror 3 IN * p Guardian ON for seeded mode * * Outputs * * a SXRSS Mode * 0 = Undefined * 1 = SASE * 2 = Seeded * 3 = Harmonic * 4 = SLIT * * Logic * * MPS requirements and mode definitions can be found here: * https://slacspace.slac.stanford.edu/sites/lclscore/und/sxrss/Shared_Documents/Controls/MPS/Documents/SXRSS-MPS.docx */ long subSxrssMode(struct aSubRecord *psub) { int guard_ok = *(epicsUInt16 *)psub->a; int guard_on = *(epicsUInt16 *)psub->p; int sa_x = *(epicsUInt16 *)psub->b; int ss_x = *(epicsUInt16 *)psub->c; int hm_x = *(epicsUInt16 *)psub->d; int ss_e = *(epicsUInt16 *)psub->e; int hm_e = *(epicsUInt16 *)psub->f; int chic = *(epicsUInt16 *)psub->g; int gm1_out = *(epicsUInt16 *)psub->h; int gm1_in = *(epicsUInt16 *)psub->i; int slit_out = *(epicsUInt16 *)psub->j; int slit_in = *(epicsUInt16 *)psub->k; int m2_out = *(epicsUInt16 *)psub->l; /* currently unused: * int m2_in = *(epicsUInt16 *)psub->m; */ int m3_out = *(epicsUInt16 *)psub->n; int m3_in = *(epicsUInt16 *)psub->o; epicsUInt16 mode = SXRSS_UNDEF; int optics_out = (gm1_out) && (m2_out) && (m3_out); /* Grating and mirrors retracted */ int all_out = (optics_out) && (slit_out); /* Grating, mirrors, and slit retracted */ int ss_ins = (gm1_in) && ((m3_out) || (m3_in)); /* Insertable devices okay for seeded */ int ss_slit = ((slit_in) && optics_out ); /* Insertable devices okay for seeded */ if( psub == NULL) return 0; if ( (all_out) && (sa_x) ) mode = SXRSS_SASE; else if ( (ss_e) && (chic) && (ss_x) && (guard_ok) && (ss_ins) && (guard_on) ) mode = SXRSS_SEEDED; else if ( (hm_e) && (hm_x) && (optics_out) && !(slit_in) && !(slit_out) && (chic) ) mode = SXRSS_HARMONIC; else if ( (ss_e) && (chic) && (ss_x) && (ss_slit) ) mode = SXRSS_SLIT; *((epicsUInt16 *)psub->vala) = mode; return 0; } /* Return codes for subroutine functions. * (Note that MPS interlock ok/fault values * do not follow same conventions) */ #define SUB_OK 0 #define SUB_ERROR -1 long subCalcPhotonEnergy(struct aSubRecord *psub) { epicsFloat64 ebeam_energy_des = *(epicsFloat64 *)psub->a; epicsFloat64 ebeam_energy_act = *(epicsFloat64 *)psub->b; epicsFloat64 tmp; if( psub == NULL) return SUB_OK; tmp = 8265.9/13.64/13.64/1000; /* Photon energy in keV */ *(epicsFloat64 *)psub->vala = tmp*ebeam_energy_des*ebeam_energy_des; *(epicsFloat64 *)psub->valb = tmp*ebeam_energy_act*ebeam_energy_act; return SUB_OK; } /* On Wed, 9 Mar 2016, Zhang, Dehong wrote: Hi Jacek, Shawn, Sonya and Jim, The output from Diling's It becomes this, formula is this: with a divide-by-2: Energy Max mJ Energy Max mJ 12.0 11.96 12.0 5.98 11.8 11.44 11.8 5.72 11.6 10.93 11.6 5.47 11.4 10.44 11.4 5.22 11.2 9.95 11.2 4.98 11.0 9.48 11.0 4.74 10.8 9.02 10.8 4.51 10.6 8.57 10.6 4.29 10.4 8.14 10.4 4.07 10.2 7.71 10.2 3.86 10.0 7.30 10.0 3.65 9.8 6.90 9.8 3.45 9.6 6.51 9.6 3.26 9.4 6.14 9.4 3.07 9.2 5.77 9.2 2.89 9.0 5.42 9.0 2.71 8.8 5.08 8.8 2.54 8.6 4.75 8.6 2.38 8.4 4.44 8.4 2.22 8.2 4.13 8.2 2.07 8.0 3.84 8.0 1.92 7.8 3.56 7.8 1.78 7.6 3.29 7.6 1.65 7.4 3.04 7.4 1.52 7.2 2.79 7.2 1.40 7.0 2.56 7.0 1.28 6.8 2.34 6.8 1.17 6.6 2.13 6.6 1.07 6.4 1.94 6.4 0.97 6.2 1.75 6.2 0.88 6.0 1.58 6.0 0.79 5.8 1.42 5.8 0.71 5.6 1.27 5.6 0.64 5.4 1.14 5.4 0.57 5.2 1.01 5.2 0.51 5.0 0.90 5.0 0.45 4.8 0.80 4.8 0.40 4.6 0.71 4.6 0.36 4.4 0.64 4.4 0.32 4.2 0.57 4.2 0.29 4.0 0.52 4.0 0.26 * * Inputs * * a BYD BDES * b GDET pulse energy * * Outputs * * a 0 if FAULT, 1 if OK * * Logic * * MPS requirements can be found... */ /* MPS interlock summary values */ #define OK 1 #define FAULT 0 long subFeeXtalInit(struct aSubRecord *psub) { size_t tmp1, tmp2, N_LEVELS; /* Breakpoint table: photon energies and corresponding allowed pulse energies */ epicsFloat64 bkpt_photon_energy[] = { 4.0, 4.2, 4.4, 4.6, 4.8, 5.0, 5.2, 5.4, 5.6, 5.8, 6.0, 6.2, 6.4, 6.6, 6.8, 7.0, 7.2, 7.4, 7.6, 7.8, 8.0, 8.2, 8.4, 8.6, 8.8, 9.0, 9.2, 9.4, 9.6, 9.8, 10.0, 10.2, 10.4, 10.6, 10.8, 11.0, 11.2, 11.4, 11.6, 11.8, 12.0 }; epicsFloat64 bkpt_pulse_energy[] = { 0.26, 0.29, 0.32, 0.36, 0.40, 0.45, 0.51, 0.57, 0.64, 0.71, 0.79, 0.88, 0.97, 1.07, 1.17, 1.28, 1.40, 1.52, 1.65, 1.78, 1.92, 2.07, 2.22, 2.38, 2.54, 2.71, 2.89, 3.07, 3.26, 3.45, 3.65, 3.86, 4.07, 4.29, 4.51, 4.74, 4.98, 5.22, 5.47, 5.72, 5.98 }; tmp1 = sizeof(bkpt_photon_energy)/sizeof(epicsFloat64); tmp2 = sizeof(bkpt_pulse_energy)/sizeof(epicsFloat64); if ( tmp1 != tmp2 ) { printf("subFeeXtalInit: ERROR: breakpoint table dimension mismatch: photon energy is %i, pulse energy is %i\n", (int)tmp1, (int)tmp2); return SUB_ERROR; } N_LEVELS = tmp1; if ( psub->nod != psub->noe ) { printf("subFeeXtalInit: ERROR: %s record FTD % does not match FTE %i\n", psub->name, psub->nod, psub->noe); return SUB_ERROR; } if ( N_LEVELS != psub->nod ) { printf("subFeeXtalInit: ERROR: %s subroutine breakpoint sizes %i do not match record array sizes (FTD and FTE) %i\n", psub->name, (int)N_LEVELS, psub->ftd); return SUB_ERROR; } /* Copy static breakpoint values to PV fields */ memcpy( psub->d, bkpt_photon_energy, sizeof( bkpt_photon_energy ) ); memcpy( psub->e, bkpt_pulse_energy , sizeof( bkpt_pulse_energy ) ); return SUB_OK; } /* # VALA is pulse energy summary result: 1 = OK, 0 = Fault # Used by XTAL:FEE1:441:PULSEENERGY, which feeds LN input field(FTVA, "SHORT") # VALB is pulse energy safe result for 'DES' value, for diagnostics # Value used in XTAL:FEE1:441:PULSEENERGY_DES field(FTVB, "SHORT") # VALC is pulse energy safe result for 'ACT' value, for diagnostics # Value used in XTAL:FEE1:441:PULSEENERGY_ACT field(FTVC, "SHORT") # VALD is beam energy summary result: 1 = OK, 0 = Fault # Used by XTAL:FEE1:441:ENERGY_STATE, which feeds LN input field(FTVD, "SHORT") # VALE is beam energy result for 'DES' value, for diagnostics # Value used in XTAL:FEE1:441:ENERGY_DES field(FTVE, "SHORT") # VALF is beam energy result for 'ACT' value, for diagnostics # Value used in XTAL:FEE1:441:ENERGY_ACT */ long subFeeXtal(struct aSubRecord *psub) { epicsFloat64 e_des = *(epicsFloat64 *)psub->a; /* Desired photon beam energy */ epicsFloat64 e_act = *(epicsFloat64 *)psub->b; /* Actual photon beam energy */ epicsFloat64 pe = *(epicsFloat64 *)psub->c; /* Pulse energy */ epicsFloat64 *bkpt_e = (epicsFloat64 *)psub->d; /* Breakpoint beam energy values */ epicsFloat64 *bkpt_pe = (epicsFloat64 *)psub->e; /* Breakpoint pulse energy values */ unsigned long n = 41; //Fix this = *(unsigned long *)psub->nod; /* Number of rows in breakpoint table */ long rval_des, rval_act; int energy_ok, pulse_energy_ok; if( psub == NULL) goto bail;; /* Initialize to no errors */ *((epicsUInt16 *)psub->vala) = *((epicsUInt16 *)psub->valb) = *((epicsUInt16 *)psub->valc) = 1; *((epicsUInt16 *)psub->vald) = *((epicsUInt16 *)psub->vale) = *((epicsUInt16 *)psub->valf) = 1; energy_ok = pulse_energy_ok = 1; /* Copy pulse energy reading here for PV diagnostics */ *((epicsUInt16 *)psub->valg) = pe; if ( e_des < bkpt_e[0] ) { *((epicsUInt16 *)psub->vale) = 0; /* Fault */ energy_ok = 0; } if ( e_act < bkpt_e[0] ) { *((epicsUInt16 *)psub->valf) = 0; /* Fault */ energy_ok = 0; } if ( energy_ok == 0 ) { *((epicsUInt16 *)psub->vald) = 0; /* Fault */ } rval_des = bkptEval( e_des, pe, bkpt_e, bkpt_pe, n ); rval_act = bkptEval( e_act, pe, bkpt_e, bkpt_pe, n ); *((epicsUInt16 *)psub->valb) = rval_des; *((epicsUInt16 *)psub->valc) = rval_act; if ( rval_des != OK ) { *((epicsUInt16 *)psub->valb) = 0; /* Fault */ pulse_energy_ok = 0; } if ( rval_act != OK ) { *((epicsUInt16 *)psub->valc) = 0; /* Fault */ pulse_energy_ok = 0; } if ( pulse_energy_ok == 0 ) { *((epicsUInt16 *)psub->vala) = 0; /* Fault */ } bail: return OK; } static long bkptEval(epicsFloat64 a, epicsFloat64 b, epicsFloat64 *bkpt_a, epicsFloat64 *bkpt_b, size_t bkpt_size) { int i; if ( a < bkpt_a[0] ) return FAULT; for ( i = 0 ; i < bkpt_size; i++ ) { if ( i < bkpt_size - 1 ) { if ( (a >= bkpt_a[i]) && (a < bkpt_a[i+1]) ) { if ( b >= bkpt_b[i] ) { return FAULT; } } } else { if ( (a >= bkpt_a[i]) ) { if ( b >= bkpt_b[i] ) { return FAULT; } } } } return OK; } epicsRegisterFunction(subSxrssMode); epicsRegisterFunction(subCalcPhotonEnergy); epicsRegisterFunction(subFeeXtalInit); epicsRegisterFunction(subFeeXtal);