Low-Energy Muon (LEM) Experiment  0.5.2
hv_fug_scfe.cxx
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: hv_fug_scfe.cxx
4  Created by: Andreas Suter
5 
6  Contents: Midas frontend for the high voltage FUG devices
7 
8 \********************************************************************/
9 
10 #include <cstdio>
11 #include <cstdlib>
12 #include <cstring>
13 #include <cmath>
14 
15 #include "midas.h"
16 #include "mfe.h"
17 #include "msystem.h"
18 
19 #include "class/hv.h"
20 #include "hv_scs3000.h"
21 #include "bus/null.h"
22 
23 // -- Globals -------------------------------------------------------
24 
26 const char *frontend_name = "FUG";
28 const char *frontend_file_name = __FILE__;
29 
31 BOOL frontend_call_loop = TRUE;
32 
34 INT display_period = 1000;
35 
37 INT max_event_size = 10000;
38 
40 INT max_event_size_frag = 5*1024*1024;
41 
43 INT event_buffer_size = 10*10000;
44 
45 // -- HV Monitoring Variables -----------------------------------------
46 
47 #define LEMVAC_GAS_INLET_ON 0x80
48 #define LEMVAC_MC_STATUS_WORD_2 15
49 #define LEMVAC_TC_STATUS_WORD_2 18
50 #define LEMVAC_SC_STATUS_WORD_2 21
51 
52 #define FUG_CHS 16
53 #define FUG_READ_TIME 10
54 #define FUG_DEMAND_CHANGED_TIMEOUT 300
55 #define FUG_MC 0
56 #define FUG_TC 1
57 #define FUG_SC 2
58 
59 #define TD_FIRST_CH 0
60 #define TD_LAST_CH 3
61 #define FUG_BEAMLINE_KV61_CH 28
62 #define FUG_BEAMLINE_KV62_CH 29
63 
64 // detector rate
66 
67 // Detector HV's
69 
70 // keep handle to ODB
71 HNDLE hv_fug_hDB;
73 
74 // fug demand HV's
76 // flag array telling which channel is belonging to which chamber
78 // fug demand HV's changed timer
80 // fug demand <-> measured check timestamp
82 // fug demand HV drop counter
84 
85 // debug flag, when enabled sending additional messages to the message system
86 int hv_fug_debug = 0;
87 
88 // Monitoring stuff
90 char hv_fug_trip_rate_source[NAME_LENGTH];
94 
95 // Gas inlet stuff
96 float lemvac_in[27];
97 
98 // FUG Monitoring default. Is used in case FUG Monitoring ODB structure is not in place yet.
99 const char *hv_fug_monitoring_str =
100 "FUG Monitoring = INT : 0\n\
101 Trip Rate Source = STRING : [32] TD\n\
102 Trip Enabled = INT : 1\n\
103 Trip Level = INT : 1500000\n\
104 ";
105 
106 //-- Equipment list ------------------------------------------------
107 
109 DEVICE_DRIVER hv_driver[] = {
110  { "hv_spin_rot", hv_scs3000, 4, null, DF_PRIO_DEVICE },
111  { "hv_mc_tc", hv_scs3000, 7, null, DF_PRIO_DEVICE },
112  { "hv_sc", hv_scs3000, 5, null, DF_PRIO_DEVICE }
113 };
114 
124 
126 EQUIPMENT equipment[] = {
127 
128  { "HV", // equipment name
129  {72, 0, // event ID, trigger mask
130  "SYSTEM", // event buffer
131  EQ_SLOW, // equipment type
132  0, // event source
133  "FIXED", // format
134  TRUE, // enabled
135  RO_RUNNING |
136  RO_TRANSITIONS, // read when running and on transitions
137  30000, // read every 30 sec
138  0, // stop run after this event limit
139  0, // number of sub events
140  1, // log history every event
141  "", "", "",},
142  cd_hv_read, // readout routine
143  cd_hv, // class driver main routine
144  hv_driver, // device driver list
145  NULL, // init string
146  },
147 
148  { "" }
149 };
150 
151 
152 
153 //-- Dummy routines ------------------------------------------------
154 
155 INT poll_event(INT source, INT count, BOOL test) {return 1;};
156 INT interrupt_configure(INT cmd, INT source, POINTER_T adr) {return 1;};
157 
158 //-- prototype declaration -----------------------------------------
159 
160 void hv_fug_check_trip_level(INT, INT, void *);
161 
162 // -- HV monitoring routines ---------------------------------------
171 void hv_fug_trip_rate_source_changed(INT hDB, INT hKey, void *dummy)
172 {
173  INT status;
174  char str[128];
175  char svalue[NAME_LENGTH];
176 
177  if (strstr(hv_fug_trip_rate_source, "TD")) { // rate switched to TD
178 
179  // close MCP1 rate hotlink
180  strcpy(str, "/Equipment/Scaler/Variables/RATE/MCP1");
181  status = db_find_key(hDB, 0, str, &hKey);
182  if (status != DB_SUCCESS) {
183  cm_msg(MERROR, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Couldn't find %s", str);
184  return;
185  }
186  db_close_record(hDB, hKey);
187 
188  // establish TD rate hotlink
189  strcpy(str, "/Equipment/Scaler/Variables/RATE/TD");
190  status = db_find_key(hDB, 0, str, &hKey);
191  if (status != DB_SUCCESS) {
192  cm_msg(MERROR, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Couldn't find %s", str);
193  return;
194  }
195  status = db_open_record(hDB, hKey, &hv_fug_detector_rate, sizeof(hv_fug_detector_rate),
196  MODE_READ, &hv_fug_check_trip_level, NULL);
197  if (status != DB_SUCCESS) {
198  cm_msg(MERROR, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Couldn't establish hotlink to %s", str);
199  return;
200  }
201 
202  // message that the rates where switched to TD
203  cm_msg(MINFO, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Switched to the TD rate for the HV trip monitoring");
204 
205  } else if (strstr(hv_fug_trip_rate_source, "MCP1")) { // rate switched to MCP1
206 
207  // close TD rate hotlink
208  strcpy(str, "/Equipment/Scaler/Variables/RATE/TD");
209  status = db_find_key(hDB, 0, str, &hKey);
210  if (status != DB_SUCCESS) {
211  cm_msg(MERROR, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Couldn't find %s", str);
212  return;
213  }
214  db_close_record(hDB, hKey);
215 
216  // establish MCP1 rate hotlink
217  strcpy(str, "/Equipment/Scaler/Variables/RATE/MCP1");
218  status = db_find_key(hDB, 0, str, &hKey);
219  if (status != DB_SUCCESS) {
220  cm_msg(MERROR, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Couldn't find %s", str);
221  return;
222  }
223  status = db_open_record(hDB, hKey, &hv_fug_detector_rate, sizeof(hv_fug_detector_rate),
224  MODE_READ, &hv_fug_check_trip_level, NULL);
225  if (status != DB_SUCCESS) {
226  cm_msg(MERROR, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Couldn't establish hotlink to %s", str);
227  return;
228  }
229 
230  // message that the rates where switched to MCP1
231  cm_msg(MINFO, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Switched to the MCP1 rate for the HV trip monitoring");
232 
233  } else { // garbage hence will set hv_fug_trip_rate_source to TD
234  cm_msg(MERROR, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: %s not allowed, will switch to TD", hv_fug_trip_rate_source);
235  strcpy(str, "/Equipment/HV/Monitoring/Trip Rate Source");
236  status = db_find_key(hDB, 0, str, &hKey);
237  if (status != DB_SUCCESS) {
238  cm_msg(MERROR, "hv_fug_trip_rate_source_changed", "hv_fug_scfe: Couldn't find %s", str);
239  return;
240  }
241  strcpy(svalue, "TD");
242  db_set_data(hDB, hKey, svalue, sizeof(svalue), 1, TID_STRING);
243  }
244 }
245 
246 //------------------------------------------------------------------
257 void hv_fug_check_trip_level(INT hDB, INT hKey, void *hv)
258 {
259  char str[128];
260  INT status, size, i, run_state;
261  float value;
262  float hv_demand_value[FUG_CHS];
263  HNDLE demandKey, runStateKey;
264  KEY key;
265 
266  if (!hv_fug_tripEnabled) // trip monitoring not enabled, hence do nothing
267  return;
268 
269  if (hv_fug_detector_rate > hv_fug_tripRate) { // measured TD/MCP1 rate larger than the trip level
270  strcpy(str, "/Equipment/HV/Variables/Demand");
271  status = db_find_key(hDB, 0, str, &demandKey);
272  if (status != DB_SUCCESS) {
273  cm_msg(MERROR, "hv_fug_check_trip_level", "Couldn't find %s", str);
274  return;
275  }
276  status = db_get_key(hDB, demandKey, &key);
277  if (status != DB_SUCCESS) {
278  cm_msg(MERROR, "hv_fug_check_trip_level", "Couldn't get key info of %s", str);
279  return;
280  }
281  // check if already tripped
282  size = sizeof(hv_demand_value);
283  db_get_data(hDB, demandKey, &hv_demand_value, &size, TID_FLOAT);
284  for (i=0; i < key.num_values; i++) {
285  if (hv_demand_value[i] != 0)
286  break;
287  }
288 
289  if (i<key.num_values) { // at least one demand value != 0
290  // set all demand values to zero
291  value = 0.f;
292  for (i=0; i < key.num_values; i++)
293  db_set_data_index(hDB, demandKey, &value, sizeof(value), i, TID_FLOAT);
294 
295  if (strstr(hv_fug_trip_rate_source, "TD")) // TD
296  sprintf(str, "HV tripped due to too high rate (TD=%d/trip level=%d)",
298  else // MCP1
299  sprintf(str, "HV tripped due to too high rate (MCP1=%d/trip level=%d)",
301 
302  cm_msg(MERROR, "hv_fug_check_trip_level", str);
303 
304  al_trigger_alarm( "hv_fug_check_trip_level", str, "Warning", "High Voltage tripped. Will also close KV61, KV62!", AT_INTERNAL);
305 
306  // check if a run is active, and if yes pause it ----------------------------
307 
308  // get the run state and check if a run is active
309  strcpy(str, "/Runinfo/State");
310  status = db_find_key(hDB, 0, str, &runStateKey);
311  if (status != DB_SUCCESS) {
312  cm_msg(MERROR, "hv_fug_check_trip_level", "Couldn't find %s", str);
313  return;
314  }
315  size = sizeof(run_state);
316  db_get_data(hDB, runStateKey, &run_state, &size, TID_INT);
317  if (run_state == STATE_RUNNING) {
318  // pause the run
319  status = cm_transition(TR_PAUSE, 0, str, sizeof(str), TR_SYNC, 0);
320  if (status != CM_SUCCESS) {
321  cm_msg(MERROR, "hv_fug_check_trip_level", "%s", str);
322  }
323  }
324 
325  // close KV61, KV62
326  // get the demand array of the beamline frontend
327  strcpy(str, "/Equipment/Beamline/Variables/Demand");
328  status = db_find_key(hDB, 0, str, &demandKey);
329  if (status != DB_SUCCESS) {
330  cm_msg(MERROR, "hv_fug_check_trip_level", "Couldn't find %s", str);
331  return;
332  }
333  // close KV61
334  value = 0.0;
335  db_set_data_index(hDB, demandKey, &value, sizeof(value), FUG_BEAMLINE_KV61_CH, TID_FLOAT);
336  // close KV62
337  value = 0.0;
338  db_set_data_index(hDB, demandKey, &value, sizeof(value), FUG_BEAMLINE_KV62_CH, TID_FLOAT);
339  }
340  }
341 }
342 
343 //------------------------------------------------------------------
353 void hv_fug_scfe_monitoring(INT hDB, INT hKey, void *hv)
354 {
355  int i;
356  int trip = FALSE;
357  int status;
358  HNDLE demandKey;
359  KEY key;
360  char str[128];
361  float value;
362  float *hv_measured;
363 
364  // check if HV monitoring is enabled
366  return;
367 
368  hv_measured = (float *)hv;
369 
370  // check if TD HV is too small
371  for (i=TD_FIRST_CH; i<TD_LAST_CH; i++) {
372  if (fabs(hv_measured[i]) < 0.1f) { // i.e. smaller 100V
373  trip = TRUE;
374  break;
375  }
376  }
377 
378  if (!trip) // if TD HV are set
379  hv_fug_hvAlreadyOff = FALSE;
380 
381  // at least on TD HV < 100V and not already tripped
382  if (trip && !hv_fug_hvAlreadyOff) {
383  hv_fug_hvAlreadyOff = TRUE;
384  cm_msg(MERROR, "hv_fug_scfe_monitoring", "TD HV off!! Will switch off all HV :-(");
385  strcpy(str, "/Equipment/HV/Variables/Demand");
386  status = db_find_key(hDB, 0, str, &demandKey);
387  if (status != DB_SUCCESS) {
388  cm_msg(MERROR, "hv_fug_scfe_monitoring", "Couldn't find %s", str);
389  return;
390  }
391  status = db_get_key(hDB, demandKey, &key);
392  if (status != DB_SUCCESS) {
393  cm_msg(MERROR, "hv_fug_scfe_monitoring", "Couldn't get key info of %s", str);
394  return;
395  }
396  value = 0.f;
397  for (i=0; i < key.num_values; i++)
398  db_set_data_index(hDB, demandKey, &value, sizeof(value), i, TID_FLOAT);
399  }
400 }
401 
402 //------------------------------------------------------------------
419 void hv_fug_scfe_gas_inlet(INT hDB, INT hKey, void *dummy)
420 {
421  char str[128];
422  int status, i, ival;
423  float value;
424  HNDLE fug_hKey;
425 
426  // check moderator chamber
427  ival = (int)lemvac_in[LEMVAC_MC_STATUS_WORD_2];
428  if (ival & LEMVAC_GAS_INLET_ON) {
429  // get FUG hv demand odb key
430  strcpy(str, "/Equipment/HV/Variables/Demand");
431  status = db_find_key(hDB, 0, str, &fug_hKey);
432  if (status != DB_SUCCESS) {
433  cm_msg(MERROR, "hv_fug_scfe_gas_inlet", "Couldn't find %s", str);
434  return;
435  }
436 
437  // set all hv values of the moderator chamber (Moderator, Mod_Guard, Mod_Grid, Lense_1, Mirror) to zero
438  value = 0.0;
439  for (i=0; i<FUG_CHS; i++) {
440  if (hv_fug_chamber_flag[i] == FUG_MC)
441  db_set_data_index(hDB, fug_hKey, &value, sizeof(value), i, TID_FLOAT);
442  }
443  }
444 
445  // check trigger chamber
446  ival = (int)lemvac_in[LEMVAC_TC_STATUS_WORD_2];
447  if (ival & LEMVAC_GAS_INLET_ON) {
448  // get FUG hv demand odb key
449  strcpy(str, "/Equipment/HV/Variables/Demand");
450  status = db_find_key(hDB, 0, str, &fug_hKey);
451  if (status != DB_SUCCESS) {
452  cm_msg(MERROR, "hv_fug_scfe_gas_inlet", "Couldn't find %s", str);
453  return;
454  }
455 
456  // set all hv values of the trigger chamber (Lense_2, Lense_3) to zero
457  value = 0.0;
458  for (i=0; i<FUG_CHS; i++) {
459  if (hv_fug_chamber_flag[i] == FUG_TC)
460  db_set_data_index(hDB, fug_hKey, &value, sizeof(value), i, TID_FLOAT);
461  }
462  }
463 
464  // check sample chamber
465  ival = (int)lemvac_in[LEMVAC_SC_STATUS_WORD_2];
466  if (ival & LEMVAC_GAS_INLET_ON) {
467  // get FUG hv demand odb key
468  strcpy(str, "/Equipment/HV/Variables/Demand");
469  status = db_find_key(hDB, 0, str, &fug_hKey);
470  if (status != DB_SUCCESS) {
471  cm_msg(MERROR, "hv_fug_scfe_gas_inlet", "Couldn't find %s", str);
472  return;
473  }
474 
475  // set all hv values of the sample chamber (RA-L, RA-R, RA-T, RA-B, Sample) to zero
476  value = 0.0;
477  for (i=0; i<FUG_CHS; i++) {
478  if (hv_fug_chamber_flag[i] == FUG_SC)
479  db_set_data_index(hDB, fug_hKey, &value, sizeof(value), i, TID_FLOAT);
480  }
481  }
482 }
483 
484 //------------------------------------------------------------------
493 void hv_fug_demand_changed(INT hDB, INT hKey, void *dummy)
494 {
495  hv_fug_demand_changed_timer = ss_time();
496 }
497 
498 //-- Frontend Init -------------------------------------------------
508 {
509  HNDLE hDB, hKey;
510  KEY keyInfo;
511  INT status, i;
512  char str[128];
513 
514  // de-register run-transition notifications
515  cm_deregister_transition(TR_START);
516  cm_deregister_transition(TR_STOP);
517  cm_deregister_transition(TR_PAUSE);
518  cm_deregister_transition(TR_RESUME);
519 
520  // fill the FUG chamber flag array
521  hv_fug_chamber_flag[0] = FUG_TC; // Right rod of the spin rotator
522  hv_fug_chamber_flag[1] = FUG_TC; // Left rod of the spin rotator
523  hv_fug_chamber_flag[2] = FUG_TC; // Left plate of the spin rotator
524  hv_fug_chamber_flag[3] = FUG_TC; // Right plate of the spin rotator
525  hv_fug_chamber_flag[4] = FUG_MC; // Moderator
526  hv_fug_chamber_flag[5] = FUG_MC; // Moderator guard
527  hv_fug_chamber_flag[6] = FUG_MC; // Moderator grid
528  hv_fug_chamber_flag[7] = FUG_MC; // Lense 1
529  hv_fug_chamber_flag[8] = FUG_MC; // Mirror
530  hv_fug_chamber_flag[9] = FUG_TC; // Lense 2
531  hv_fug_chamber_flag[10] = FUG_TC; // Lense 3
532  hv_fug_chamber_flag[11] = FUG_SC; // RA-L
533  hv_fug_chamber_flag[12] = FUG_SC; // RA-R
534  hv_fug_chamber_flag[13] = FUG_SC; // RA-T
535  hv_fug_chamber_flag[14] = FUG_SC; // RA-B
536  hv_fug_chamber_flag[15] = FUG_SC; // Sample
537 
538 
539  // init global variables
541  hv_fug_hvAlreadyOff = FALSE;
542  hv_detectors_measured = NULL;
543  hv_fug_demand_changed_timer = ss_time();
544 
545  // get ODB main handle
546  cm_get_experiment_database(&hDB, NULL);
547 
548  // keep global handle
549  hv_fug_hDB = hDB;
550 
551  // hotlink monitoring
552  strcpy(str, "/Equipment/HV/Monitoring/FUG Monitoring");
553  status = db_find_key(hDB, 0, str, &hKey);
554  if (status != DB_SUCCESS) {
555  cm_msg(MINFO, "frontend_init", "hv_fug_scfe: Couldn't find %s. Will try to generate it.", str);
556  cm_yield(0);
557  status = db_create_record(hDB, 0, "/Equipment/HV/Monitoring", hv_fug_monitoring_str);
558  if (status != DB_SUCCESS) {
559  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: **ERROR** Couldn't find %s", str);
560  cm_yield(0);
561  return CM_SUCCESS;
562  }
563  return CM_SUCCESS;
564  }
565  status = db_open_record(hDB, hKey, &hv_fug_monitoring_enabled, sizeof(hv_fug_monitoring_enabled),
566  MODE_READ, NULL, NULL);
567  if (status != DB_SUCCESS) {
568  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't establish hotlink to %s", str);
569  return CM_SUCCESS;
570  }
571 
572 /* //as35
573  // hotlink trip rate source: TD or MCP1
574  strcpy(str, "/Equipment/HV/Monitoring/Trip Rate Source");
575  status = db_find_key(hDB, 0, str, &hKey);
576  if (status != DB_SUCCESS) {
577  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't find %s", str);
578  return CM_SUCCESS;
579  }
580  status = db_open_record(hDB, hKey, &hv_fug_trip_rate_source, sizeof(hv_fug_trip_rate_source),
581  MODE_READ, &hv_fug_trip_rate_source_changed, NULL);
582  if (status != DB_SUCCESS) {
583  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't establish hotlink to %s", str);
584  return CM_SUCCESS;
585  }
586 
587  // hotlink trip enable flag
588  strcpy(str, "/Equipment/HV/Monitoring/Trip Enabled");
589  status = db_find_key(hDB, 0, str, &hKey);
590  if (status != DB_SUCCESS) {
591  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't find %s", str);
592  return CM_SUCCESS;
593  }
594  status = db_open_record(hDB, hKey, &hv_fug_tripEnabled, sizeof(hv_fug_tripEnabled),
595  MODE_READ, NULL, NULL);
596  if (status != DB_SUCCESS) {
597  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't establish hotlink to %s", str);
598  return CM_SUCCESS;
599  }
600 
601  // hotlink trip rate
602  strcpy(str, "/Equipment/HV/Monitoring/Trip Level");
603  status = db_find_key(hDB, 0, str, &hKey);
604  if (status != DB_SUCCESS) {
605  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't find %s", str);
606  return CM_SUCCESS;
607  }
608  status = db_open_record(hDB, hKey, &hv_fug_tripRate, sizeof(hv_fug_tripRate),
609  MODE_READ, NULL, NULL);
610  if (status != DB_SUCCESS) {
611  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't establish hotlink to %s", str);
612  return CM_SUCCESS;
613  }
614 
615  if (strstr(hv_fug_trip_rate_source, "TD")) { // hotlink TD rate
616  cm_msg(MINFO, "frontend_init", "hv_fug_scfe: will used TD rate for HV rate monitoring");
617  strcpy(str, "/Equipment/Scaler/Variables/RATE/TD");
618  } else { // hotlink MCP1 rate
619  cm_msg(MINFO, "frontend_init", "hv_fug_scfe: will used MCP1 rate for HV rate monitoring");
620  strcpy(str, "/Equipment/Scaler/Variables/RATE/MCP1");
621  }
622  status = db_find_key(hDB, 0, str, &hKey);
623  if (status != DB_SUCCESS) {
624  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't find %s", str);
625  return CM_SUCCESS;
626  }
627  status = db_open_record(hDB, hKey, &hv_fug_detector_rate, sizeof(hv_fug_detector_rate),
628  MODE_READ, &hv_fug_check_trip_level, NULL);
629  if (status != DB_SUCCESS) {
630  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't establish hotlink to %s", str);
631  return CM_SUCCESS;
632  }
633 
634  // hotlink Detector HV measured
635  strcpy(str, "/Equipment/HV Detectors/Variables/Measured");
636  status = db_find_key(hDB, 0, str, &hKey);
637  if (status != DB_SUCCESS) {
638  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't find %s", str);
639  return CM_SUCCESS;
640  }
641  status = db_get_key(hDB, hKey, &keyInfo);
642  if (status != DB_SUCCESS) {
643  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't get key info of %s", str);
644  return CM_SUCCESS;
645  }
646 
647  hv_detectors_measured = (float *)calloc(keyInfo.num_values, sizeof(float));
648 
649  status = db_open_record(hDB, hKey, hv_detectors_measured,
650  keyInfo.num_values*sizeof(float),
651  MODE_READ, &hv_fug_scfe_monitoring, hv_detectors_measured);
652  if (status != DB_SUCCESS) {
653  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't establish hotlink to %s", str);
654  return CM_SUCCESS;
655  }
656 */ //as35
657 
658  // keep measured key for cyclic reading in frontend loop
659  strcpy(str, "/Equipment/HV/Variables/Measured");
660  status = db_find_key(hDB, 0, str, &hKey);
661  if (status != DB_SUCCESS) {
662  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't find %s", str);
663  return CM_SUCCESS;
664  }
666 
667 /* //as35
668  // hotlink lemvac input variables needed to check the gas inlet state
669  strcpy(str, "/Equipment/LEMVAC/Variables/Input");
670  status = db_find_key(hDB, 0, str, &hKey);
671  if (status != DB_SUCCESS) {
672  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't find %s", str);
673  return CM_SUCCESS;
674  }
675 
676  status = db_open_record(hDB, hKey, &lemvac_in, sizeof(lemvac_in), MODE_READ,
677  &hv_fug_scfe_gas_inlet, NULL);
678 */ //as35
679 
680  // hotlink FUG HV demand
681  strcpy(str, "/Equipment/HV/Variables/Demand");
682  status = db_find_key(hDB, 0, str, &hKey);
683  if (status != DB_SUCCESS) {
684  cm_msg(MERROR, "frontend_init", "hv_fug_scfe: Couldn't find %s", str);
685  return CM_SUCCESS;
686  }
687 
688  status = db_open_record(hDB, hKey, &hv_fug_demand, sizeof(hv_fug_demand), MODE_READ,
689  &hv_fug_demand_changed, NULL);
690 
691  // init FUG HV demand <-> measured drop counter
692  for (i=0; i<FUG_CHS; i++)
693  hv_fug_drop_counter[i] = 0;
694 
695  // init FUG HV demand <-> measured read timer
696  hv_fug_check_timestamp = ss_time();
697 
698  return CM_SUCCESS;
699 }
700 
701 //-- Frontend Exit -------------------------------------------------
707 {
708  char str[128];
709  int status;
710  HNDLE hDB, hKey;
711 
712  // get ODB main handle
713  cm_get_experiment_database(&hDB, NULL);
714 
715  // unlink fug monitoring
716  strcpy(str, "/Equipment/HV/Monitoring/FUG Monitoring");
717  status = db_find_key(hDB, 0, str, &hKey);
718  if (status != DB_SUCCESS) {
719  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
720  return CM_SUCCESS;
721  }
722  db_close_record(hDB, hKey);
723 
724 /* //as35
725  // unlink trip rate source
726  strcpy(str, "/Equipment/HV/Monitoring/Trip Rate Source");
727  status = db_find_key(hDB, 0, str, &hKey);
728  if (status != DB_SUCCESS) {
729  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
730  return CM_SUCCESS;
731  }
732  db_close_record(hDB, hKey);
733 
734  // unlink trip enabled
735  strcpy(str, "/Equipment/HV/Monitoring/Trip Enabled");
736  status = db_find_key(hDB, 0, str, &hKey);
737  if (status != DB_SUCCESS) {
738  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
739  return CM_SUCCESS;
740  }
741  db_close_record(hDB, hKey);
742 
743  // unlink trip level
744  strcpy(str, "/Equipment/HV/Monitoring/Trip Level");
745  status = db_find_key(hDB, 0, str, &hKey);
746  if (status != DB_SUCCESS) {
747  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
748  return CM_SUCCESS;
749  }
750  db_close_record(hDB, hKey);
751 
752  // unlink TD/MCP1 rates
753  if (strstr(hv_fug_trip_rate_source, "TD")) { // unlink TD rate
754  strcpy(str, "/Equipment/Scaler/Variables/RATE/TD");
755  status = db_find_key(hDB, 0, str, &hKey);
756  if (status != DB_SUCCESS) {
757  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
758  return CM_SUCCESS;
759  }
760  db_close_record(hDB, hKey);
761  } else { // unlink MCP1 rate
762  strcpy(str, "/Equipment/Scaler/Variables/RATE/MCP1");
763  status = db_find_key(hDB, 0, str, &hKey);
764  if (status != DB_SUCCESS) {
765  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
766  return CM_SUCCESS;
767  }
768  db_close_record(hDB, hKey);
769  }
770 
771  // unlink detector hv measured
772  strcpy(str, "/Equipment/HV Detectors/Variables/Measured");
773  status = db_find_key(hDB, 0, str, &hKey);
774  if (status != DB_SUCCESS) {
775  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
776  return CM_SUCCESS;
777  }
778  db_close_record(hDB, hKey);
779 */ //as35
780 
781  // free memory
783  free(hv_detectors_measured);
784 
785 /* //as35
786  // unlink lemvac input
787  strcpy(str, "/Equipment/LEMVAC/Variables/Input");
788  status = db_find_key(hDB, 0, str, &hKey);
789  if (status != DB_SUCCESS) {
790  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
791  return CM_SUCCESS;
792  }
793  db_close_record(hDB, hKey);
794 */ //as35
795 
796  // unlink FUG HV demand values
797  strcpy(str, "/Equipment/HV/Variables/Demand");
798  status = db_find_key(hDB, 0, str, &hKey);
799  if (status != DB_SUCCESS) {
800  cm_msg(MERROR, "frontend_exit", "hv_fug_scfe: Couldn't find %s, status=%d", str, status);
801  return CM_SUCCESS;
802  }
803  db_close_record(hDB, hKey);
804 
805  return CM_SUCCESS;
806 }
807 
808 //-- Frontend Loop -------------------------------------------------
814 {
815  HNDLE hKey;
816  DWORD now;
817  int size, i;
818  float measured[FUG_CHS];
819  char str[256];
820  char name[NAME_LENGTH];
821 
822  // check if FUG HV demand values just recently changed. If so, do nothing
823  now = ss_time();
825  return CM_SUCCESS;
826  } else {
827  if (hv_fug_debug)
828  cm_msg(MINFO, "frontend_loop", "hv_fug_scfe: time to do something ...");
829  }
830 
831  // check if FUG HV demand - FUG HV measured is within the tolerance
832  // time to read hv measured?
833  now = ss_time();
835  if (hv_fug_debug)
836  cm_msg(MINFO, "frontend_loop", "hv_fug_scfe: will read hv measured");
837  // reset timer
839  // read hv measured values from ODB
840  size = sizeof(measured);
841  db_get_record(hv_fug_hDB, hv_fug_measured_hKey, &measured[0], &size, 0);
842  // check if measured one is deviating too strongly from the demand
843  for (i=0; i<FUG_CHS; i++) {
844  if ((hv_fug_demand[i] != 0.0) && (fabs(hv_fug_demand[i]-measured[i])>0.2)) {
845  hv_fug_drop_counter[i]++;
846  if (hv_fug_debug)
847  cm_msg(MINFO, "frontend_loop", "hv_fug_scfe: ch = %d, drop counter = %d", i, hv_fug_drop_counter[i]);
848  // check of limit is reached
849  if (hv_fug_drop_counter[i]>5) {
850  // get name from ODB
851  strcpy(str, "/Equipment/HV/Settings/Names");
852  db_find_key(hv_fug_hDB, 0, str, &hKey);
853  size = sizeof(name);
854  db_get_data_index(hv_fug_hDB, hKey, name, &size, i, TID_STRING);
855  sprintf(str, "HV FUG %s: measured = %f, demand = %f, check!!",
856  name, measured[i], hv_fug_demand[i]);
857  al_trigger_alarm( "hv_fug_scfe", str, "Warning", str, AT_INTERNAL);
858  }
859  } else { // reset drop counter since readback is OK
860  hv_fug_drop_counter[i] = 0;
861  }
862  }
863  }
864 
865  return CM_SUCCESS;
866 }
867 
868 //-- Begin of Run --------------------------------------------------
873 INT begin_of_run(INT run_number, char *error)
874 {
875  return CM_SUCCESS;
876 }
877 
878 //-- End of Run ----------------------------------------------------
883 INT end_of_run(INT run_number, char *error)
884 {
885  return CM_SUCCESS;
886 }
887 
888 //-- Pause Run -----------------------------------------------------
893 INT pause_run(INT run_number, char *error)
894 {
895  return CM_SUCCESS;
896 }
897 
898 //-- Resume Run ----------------------------------------------------
903 INT resume_run(INT run_number, char *error)
904 {
905  return CM_SUCCESS;
906 }
907 
908 //------------------------------------------------------------------
int hv_fug_debug
Definition: hv_fug_scfe.cxx:86
const char * frontend_name
&lt; created by ODBedit, command &quot;make&quot;
Definition: vme_fe.cxx:167
#define FUG_BEAMLINE_KV61_CH
Definition: hv_fug_scfe.cxx:61
float hv_detectors_measured[HV_DETECTOR_CHANNELS]
INT max_event_size
maximum event size produced by this frontend
Definition: vme_fe.cxx:179
#define FUG_CHS
Definition: hv_fug_scfe.cxx:52
#define LEMVAC_GAS_INLET_ON
Definition: hv_fug_scfe.cxx:47
INT hv_fug_tripEnabled
hotlink variable holding the trip enabled flag
Definition: hv_fug_scfe.cxx:91
#define TD_LAST_CH
Definition: hv_fug_scfe.cxx:60
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
Definition: vme_fe.cxx:173
float hv_fug_demand[FUG_CHS]
Definition: hv_fug_scfe.cxx:75
INT display_period
a frontend status page is displayed with this frequency in ms
Definition: vme_fe.cxx:176
#define LEMVAC_TC_STATUS_WORD_2
Definition: hv_fug_scfe.cxx:49
INT event_buffer_size
buffer size to hold events
Definition: vme_fe.cxx:185
INT hv_fug_tripRate
hotlink variable holding the TD trip rate
Definition: hv_fug_scfe.cxx:92
#define LEMVAC_SC_STATUS_WORD_2
Definition: hv_fug_scfe.cxx:50
char hv_fug_trip_rate_source[NAME_LENGTH]
hotlink variable holding the name of the detector which is to monitor the rate
Definition: hv_fug_scfe.cxx:90
#define FUG_DEMAND_CHANGED_TIMEOUT
Definition: hv_fug_scfe.cxx:54
int hv_fug_chamber_flag[FUG_CHS]
Definition: hv_fug_scfe.cxx:77
void hv_fug_scfe_gas_inlet(INT hDB, INT hKey, void *dummy)
int hv_fug_drop_counter[FUG_CHS]
Definition: hv_fug_scfe.cxx:83
DWORD hv_fug_demand_changed_timer
Definition: hv_fug_scfe.cxx:79
#define LEMVAC_MC_STATUS_WORD_2
Definition: hv_fug_scfe.cxx:48
#define FUG_READ_TIME
Definition: hv_fug_scfe.cxx:53
INT frontend_exit()
Definition: vme_fe.cxx:565
EQUIPMENT equipment[]
Definition: vme_fe.cxx:343
INT hv_fug_detector_rate
hotlink variable holding the TD or MCP1 rate
Definition: hv_fug_scfe.cxx:65
INT begin_of_run(INT run_number, char *error)
Definition: vme_fe.cxx:597
DEVICE_DRIVER hv_driver[]
device driver list
#define FUG_TC
Definition: hv_fug_scfe.cxx:56
const char * hv_fug_monitoring_str
Definition: hv_fug_scfe.cxx:99
#define FUG_SC
Definition: hv_fug_scfe.cxx:57
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
Definition: vme_fe.cxx:2105
INT frontend_loop()
Definition: vme_fe.cxx:957
INT resume_run(INT run_number, char *error)
Definition: vme_fe.cxx:900
HNDLE hv_fug_measured_hKey
Definition: hv_fug_scfe.cxx:72
void hv_fug_check_trip_level(INT, INT, void *)
#define TD_FIRST_CH
Definition: hv_fug_scfe.cxx:59
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
Definition: vme_fe.cxx:182
float lemvac_in[27]
holds the status info of lemvac input variables
INT frontend_init()
Definition: vme_fe.cxx:429
void hv_fug_scfe_monitoring(INT hDB, INT hKey, void *hv)
HNDLE hKey
BOOL equipment_common_overwrite
Definition: vme_fe.cxx:341
INT hv_fug_monitoring_enabled
hotlink variable holding the monitoring enabled flag
Definition: hv_fug_scfe.cxx:89
#define FUG_BEAMLINE_KV62_CH
Definition: hv_fug_scfe.cxx:62
INT end_of_run(INT run_number, char *error)
Definition: vme_fe.cxx:865
INT poll_event(INT source, INT count, BOOL test)
Definition: vme_fe.cxx:2088
#define FUG_MC
Definition: hv_fug_scfe.cxx:55
HNDLE hDB
HNDLE hv_fug_hDB
Definition: hv_fug_scfe.cxx:71
INT hv_fug_hvAlreadyOff
HV already switched off.
Definition: hv_fug_scfe.cxx:93
INT pause_run(INT run_number, char *error)
Definition: vme_fe.cxx:893
DWORD hv_fug_check_timestamp
Definition: hv_fug_scfe.cxx:81
void hv_fug_trip_rate_source_changed(INT hDB, INT hKey, void *dummy)
const char * frontend_file_name
The frontend file name, don&#39;t change it.
Definition: vme_fe.cxx:170
void hv_fug_demand_changed(INT hDB, INT hKey, void *dummy)