Low-Energy Muon (LEM) Experiment  0.5.2
mod_cryo_scfe.cxx
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: mod_cryo_scfe.cxx
4  Created by: Andreas Suter
5 
6  Contents: Midas frontend to handle the moderator cryo of the
7  LEM experiment
8 
9 \********************************************************************/
10 
11 #include <cstdio>
12 #include <cstdlib>
13 #include <cstring>
14 #include <cmath>
15 
16 #include "midas.h"
17 #include "mfe.h"
18 
19 #include "class/multi.h"
20 #include "LakeShore336.h"
21 #include "west6100.h"
22 #include "eurotherm2416.h"
23 #include "xtc.h"
24 #include "twickenham.h"
25 #include "tcpip_rs232.h"
26 
27 #define MOD_CF1_DEMAND 9
28 #define MOD_CF1_MEASURED 0
29 #define MOD_HE_SHIELD_DEMAND 17
30 #define MOD_HE_SHIELD_MEASURED 3
31 
32 //-- Globals -------------------------------------------------------
33 
35 const char *frontend_name = "ModCryo";
37 const char *frontend_file_name = __FILE__;
38 
40 BOOL frontend_call_loop = FALSE;
41 
43 INT display_period = 1000;
44 
46 INT max_event_size = 10000;
47 
49 INT max_event_size_frag = 5*1024*1024;
50 
52 INT event_buffer_size = 10*10000;
53 
54 float *input;
55 
56 //-- Equipment list ------------------------------------------------
57 
59 DEVICE_DRIVER mod_cryo_driver[] = {
60  { "Lake336_Moderator", ls336_in, 24, tcpip_rs232, DF_INPUT },
61  { "Lake336_Moderator", ls336_out, 14, tcpip_rs232, DF_OUTPUT },
62  { "Eurotherm2416_In", eurotherm2416_in, 8, tcpip_rs232, DF_INPUT },
63  { "Eurotherm2416_Out", eurotherm2416_out, 7, tcpip_rs232, DF_OUTPUT },
64  { "W6100_In", w6100_in, 6, tcpip_rs232, DF_INPUT },
65  { "W6100_Out", w6100_out, 8, tcpip_rs232, DF_OUTPUT },
66  { "XTC", xtc, 2, tcpip_rs232, DF_INPUT },
67  { "LN2_Moddy", twickenham, 1, tcpip_rs232, DF_INPUT },
68  { "" }
69 };
70 
80 
82 EQUIPMENT equipment[] = {
83 
84  { "ModCryo", // equipment name
85  {71, 0, // event ID, trigger mask
86  "SYSTEM", // event buffer
87  EQ_SLOW, // equipment type
88  0, // event source
89  "FIXED", // format
90  TRUE, // enabled
91  RO_RUNNING |
92  RO_TRANSITIONS, // read when running and on transitions
93  30000, // read every 30 sec
94  0, // stop run after this event limit
95  0, // number of sub events
96  1, // log history every event
97  "", "", "",},
98  cd_multi_read, // readout routine
99  cd_multi, // class driver main routine
100  mod_cryo_driver, // device driver list
101  NULL, // init string
102  },
103 
104  { "" }
105 };
106 
107 
108 
109 //-- Dummy routines ------------------------------------------------
110 
111 INT poll_event(INT source, INT count, BOOL test) {return 1;};
112 INT interrupt_configure(INT cmd, INT source, POINTER_T adr) {return 1;};
113 
114 //------------------------------------------------------------------
122 void mod_cryo_checks(HNDLE hDB, HNDLE hKey, void *dummy)
123 {
124  char str[256];
125  static int cf1_fired = 0;
126  static int he_shield_fired = 0;
127 
128  // check if CF1 Measured is within tolerance to CF1 Demand
129  if (fabs(input[MOD_CF1_DEMAND]-input[MOD_CF1_MEASURED])>3.0) {
130  if (!cf1_fired) {
131  if (input[MOD_CF1_DEMAND]-input[MOD_CF1_MEASURED]>0.0)
132  sprintf(str, "Moderator CF1 Demand = %0.1f, Measured = %0.1f: Heater off??",
133  input[MOD_CF1_DEMAND], input[MOD_CF1_MEASURED]);
134  else
135  sprintf(str, "Moderator CF1 Demand = %0.1f, Measured = %0.1f: intentionally??",
136  input[MOD_CF1_DEMAND], input[MOD_CF1_MEASURED]);
137  al_trigger_alarm( "mod_cryo_checks", str, "Warning", str, AT_INTERNAL);
138  }
139  cf1_fired++;
140  } else {
141  cf1_fired = 0;
142  }
143 
144  // check if He Shield Measured is within tolerance to He Shield Demand
146  if (!he_shield_fired) {
147  if (input[MOD_HE_SHIELD_DEMAND]-input[MOD_HE_SHIELD_MEASURED]>0.0)
148  sprintf(str, "Moderator He Shield Demand = %0.1f, Measured = %0.1f: Heater off??",
149  input[MOD_HE_SHIELD_DEMAND], input[MOD_HE_SHIELD_MEASURED]);
150  else
151  sprintf(str, "Moderator He Shield Demand = %0.1f, Measured = %0.1f: intentionally??",
152  input[MOD_HE_SHIELD_DEMAND], input[MOD_HE_SHIELD_MEASURED]);
153  al_trigger_alarm( "mod_cryo_checks", str, "Warning", str, AT_INTERNAL);
154  }
155  he_shield_fired++;
156  } else {
157  he_shield_fired = 0;
158  }
159 }
160 
161 //-- Frontend Init -------------------------------------------------
167 {
168  HNDLE hDB, hKey;
169  KEY key;
170  char str[256];
171  int status;
172 
173  // de-register run-transition notifications
174  cm_deregister_transition(TR_START);
175  cm_deregister_transition(TR_STOP);
176  cm_deregister_transition(TR_PAUSE);
177  cm_deregister_transition(TR_RESUME);
178 
179  // get ODB main handle
180  cm_get_experiment_database(&hDB, NULL);
181 
182  // hotlink lemvac mc status
183  strcpy(str, "/Equipment/ModCryo/Variables/Input");
184  status = db_find_key(hDB, 0, str, &hKey);
185  if (status != DB_SUCCESS) {
186  cm_msg(MERROR, "frontend_init", "mod_cryo_scfe: Couldn't find %s", str);
187  return CM_SUCCESS;
188  }
189 
190  // get key
191  status = db_get_key(hDB, hKey, &key);
192  if (status != DB_SUCCESS) {
193  cm_msg(MERROR, "frontend_init", "mod_cryo_scfe: Couldn't get ODB key for %s", str);
194  return CM_SUCCESS;
195  }
196 
197  // allocate memory for the input variables
198  input = (float *) malloc(key.total_size);
199 
200  // hotlink that stuff
201  status = db_open_record(hDB, hKey, input, key.total_size, MODE_READ, &mod_cryo_checks, NULL);
202 
203  return CM_SUCCESS;
204 }
205 
206 //-- Frontend Exit -------------------------------------------------
212 {
213  HNDLE hDB, hKey;
214  char str[256];
215  int status;
216 
217  // get ODB main handle
218  cm_get_experiment_database(&hDB, NULL);
219 
220  // unlink detector db50 mc status
221  strcpy(str, "/Equipment/ModCryo/Variables/Input");
222  status = db_find_key(hDB, 0, str, &hKey);
223  if (status != DB_SUCCESS) {
224  cm_msg(MERROR, "frontend_exit", "mod_cryo_scfe: Couldn't find %s, status=%d", str, status);
225  return CM_SUCCESS;
226  }
227  db_close_record(hDB, hKey);
228 
229  // memory cleanup
230  free(input);
231 
232  return CM_SUCCESS;
233 }
234 
235 //-- Frontend Loop -------------------------------------------------
241 {
242  return CM_SUCCESS;
243 }
244 
245 //-- Begin of Run --------------------------------------------------
250 INT begin_of_run(INT run_number, char *error)
251 {
252  return CM_SUCCESS;
253 }
254 
255 //-- End of Run ----------------------------------------------------
260 INT end_of_run(INT run_number, char *error)
261 {
262  return CM_SUCCESS;
263 }
264 
265 //-- Pause Run -----------------------------------------------------
270 INT pause_run(INT run_number, char *error)
271 {
272  return CM_SUCCESS;
273 }
274 
275 //-- Resume Run ----------------------------------------------------
280 INT resume_run(INT run_number, char *error)
281 {
282  return CM_SUCCESS;
283 }
284 
285 //------------------------------------------------------------------
const char * frontend_name
&lt; created by ODBedit, command &quot;make&quot;
Definition: vme_fe.cxx:167
INT max_event_size
maximum event size produced by this frontend
Definition: vme_fe.cxx:179
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
Definition: vme_fe.cxx:173
INT display_period
a frontend status page is displayed with this frequency in ms
Definition: vme_fe.cxx:176
INT event_buffer_size
buffer size to hold events
Definition: vme_fe.cxx:185
INT w6100_in(INT cmd,...)
#define MOD_HE_SHIELD_MEASURED
#define MOD_HE_SHIELD_DEMAND
INT xtc(INT cmd,...)
INT frontend_exit()
Definition: vme_fe.cxx:565
EQUIPMENT equipment[]
Definition: vme_fe.cxx:343
INT begin_of_run(INT run_number, char *error)
Definition: vme_fe.cxx:597
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
INT twickenham(INT cmd,...)
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
Definition: vme_fe.cxx:182
INT frontend_init()
Definition: vme_fe.cxx:429
#define MOD_CF1_MEASURED
HNDLE hKey
BOOL equipment_common_overwrite
Definition: vme_fe.cxx:341
void mod_cryo_checks(HNDLE hDB, HNDLE hKey, void *dummy)
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
DEVICE_DRIVER mod_cryo_driver[]
device driver list
HNDLE hDB
float * input
#define MOD_CF1_DEMAND
INT pause_run(INT run_number, char *error)
Definition: vme_fe.cxx:893
INT w6100_out(INT cmd,...)
const char * frontend_file_name
The frontend file name, don&#39;t change it.
Definition: vme_fe.cxx:170