Low-Energy Muon (LEM) Experiment  0.5.1
mod_cryo_scfe.c
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: mod_cryo_scfe.c
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 <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <math.h>
15 
16 #include "midas.h"
17 #include "class/multi.h"
18 #include "LakeShore336.h"
19 #include "west6100.h"
20 #include "eurotherm2416.h"
21 #include "xtc.h"
22 #include "twickenham.h"
23 #include "tcpip_rs232.h"
24 
25 #define MOD_CF1_DEMAND 9
26 #define MOD_CF1_MEASURED 0
27 #define MOD_HE_SHIELD_DEMAND 17
28 #define MOD_HE_SHIELD_MEASURED 3
29 
30 //-- Globals -------------------------------------------------------
31 
33 char *frontend_name = "ModCryo";
35 char *frontend_file_name = __FILE__;
36 
38 BOOL frontend_call_loop = FALSE;
39 
41 INT display_period = 1000;
42 
44 INT max_event_size = 10000;
45 
47 INT max_event_size_frag = 5*1024*1024;
48 
50 INT event_buffer_size = 10*10000;
51 
52 float *input;
53 
54 //-- Equipment list ------------------------------------------------
55 
57 DEVICE_DRIVER mod_cryo_driver[] = {
58  { "Lake336_Moderator", ls336_in, 24, tcpip_rs232, DF_INPUT },
59  { "Lake336_Moderator", ls336_out, 14, tcpip_rs232, DF_OUTPUT },
60  { "Eurotherm2416_In", eurotherm2416_in, 8, tcpip_rs232, DF_INPUT },
61  { "Eurotherm2416_Out", eurotherm2416_out, 7, tcpip_rs232, DF_OUTPUT },
62  { "W6100_In", w6100_in, 6, tcpip_rs232, DF_INPUT },
63  { "W6100_Out", w6100_out, 8, tcpip_rs232, DF_OUTPUT },
64  { "XTC", xtc, 2, tcpip_rs232, DF_INPUT },
65  { "LN2_Moddy", twickenham, 1, tcpip_rs232, DF_INPUT },
66  { "" }
67 };
68 
70 EQUIPMENT equipment[] = {
71 
72  { "ModCryo", // equipment name
73  {71, 0, // event ID, trigger mask
74  "SYSTEM", // event buffer
75  EQ_SLOW, // equipment type
76  0, // event source
77  "FIXED", // format
78  TRUE, // enabled
79  RO_RUNNING |
80  RO_TRANSITIONS, // read when running and on transitions
81  30000, // read every 30 sec
82  0, // stop run after this event limit
83  0, // number of sub events
84  1, // log history every event
85  "", "", "",},
86  cd_multi_read, // readout routine
87  cd_multi, // class driver main routine
88  mod_cryo_driver, // device driver list
89  NULL, // init string
90  },
91 
92  { "" }
93 };
94 
95 
96 
97 //-- Dummy routines ------------------------------------------------
98 
99 INT poll_event(INT source[], INT count, BOOL test) {return 1;};
100 INT interrupt_configure(INT cmd, INT source[], PTYPE adr) {return 1;};
101 
102 //------------------------------------------------------------------
110 void mod_cryo_checks(HNDLE hDB, HNDLE hKey, void *dummy)
111 {
112  char str[256];
113  static int cf1_fired = 0;
114  static int he_shield_fired = 0;
115 
116  // check if CF1 Measured is within tolerance to CF1 Demand
117  if (fabs(input[MOD_CF1_DEMAND]-input[MOD_CF1_MEASURED])>3.0) {
118  if (!cf1_fired) {
119  if (input[MOD_CF1_DEMAND]-input[MOD_CF1_MEASURED]>0.0)
120  sprintf(str, "Moderator CF1 Demand = %0.1f, Measured = %0.1f: Heater off??",
121  input[MOD_CF1_DEMAND], input[MOD_CF1_MEASURED]);
122  else
123  sprintf(str, "Moderator CF1 Demand = %0.1f, Measured = %0.1f: intentionally??",
124  input[MOD_CF1_DEMAND], input[MOD_CF1_MEASURED]);
125  al_trigger_alarm( "mod_cryo_checks", str, "Warning", str, AT_INTERNAL);
126  }
127  cf1_fired++;
128  } else {
129  cf1_fired = 0;
130  }
131 
132  // check if He Shield Measured is within tolerance to He Shield Demand
134  if (!he_shield_fired) {
135  if (input[MOD_HE_SHIELD_DEMAND]-input[MOD_HE_SHIELD_MEASURED]>0.0)
136  sprintf(str, "Moderator He Shield Demand = %0.1f, Measured = %0.1f: Heater off??",
137  input[MOD_HE_SHIELD_DEMAND], input[MOD_HE_SHIELD_MEASURED]);
138  else
139  sprintf(str, "Moderator He Shield Demand = %0.1f, Measured = %0.1f: intentionally??",
140  input[MOD_HE_SHIELD_DEMAND], input[MOD_HE_SHIELD_MEASURED]);
141  al_trigger_alarm( "mod_cryo_checks", str, "Warning", str, AT_INTERNAL);
142  }
143  he_shield_fired++;
144  } else {
145  he_shield_fired = 0;
146  }
147 }
148 
149 //-- Frontend Init -------------------------------------------------
155 {
156  HNDLE hDB, hKey;
157  KEY key;
158  char str[256];
159  int status;
160 
161  // de-register run-transition notifications
162  cm_deregister_transition(TR_START);
163  cm_deregister_transition(TR_STOP);
164  cm_deregister_transition(TR_PAUSE);
165  cm_deregister_transition(TR_RESUME);
166 
167  // get ODB main handle
168  cm_get_experiment_database(&hDB, NULL);
169 
170  // hotlink lemvac mc status
171  strcpy(str, "/Equipment/ModCryo/Variables/Input");
172  status = db_find_key(hDB, 0, str, &hKey);
173  if (status != DB_SUCCESS) {
174  cm_msg(MERROR, "frontend_init", "mod_cryo_scfe: Couldn't find %s", str);
175  return CM_SUCCESS;
176  }
177 
178  // get key
179  status = db_get_key(hDB, hKey, &key);
180  if (status != DB_SUCCESS) {
181  cm_msg(MERROR, "frontend_init", "mod_cryo_scfe: Couldn't get ODB key for %s", str);
182  return CM_SUCCESS;
183  }
184 
185  // allocate memory for the input variables
186  input = (float *) malloc(key.total_size);
187 
188  // hotlink that stuff
189  status = db_open_record(hDB, hKey, input, key.total_size, MODE_READ, &mod_cryo_checks, NULL);
190 
191  return CM_SUCCESS;
192 }
193 
194 //-- Frontend Exit -------------------------------------------------
200 {
201  HNDLE hDB, hKey;
202  char str[256];
203  int status;
204 
205  // get ODB main handle
206  cm_get_experiment_database(&hDB, NULL);
207 
208  // unlink detector db50 mc status
209  strcpy(str, "/Equipment/ModCryo/Variables/Input");
210  status = db_find_key(hDB, 0, str, &hKey);
211  if (status != DB_SUCCESS) {
212  cm_msg(MERROR, "frontend_exit", "mod_cryo_scfe: Couldn't find %s, status=%d", str, status);
213  return CM_SUCCESS;
214  }
215  db_close_record(hDB, hKey);
216 
217  // memory cleanup
218  free(input);
219 
220  return CM_SUCCESS;
221 }
222 
223 //-- Frontend Loop -------------------------------------------------
229 {
230  return CM_SUCCESS;
231 }
232 
233 //-- Begin of Run --------------------------------------------------
238 INT begin_of_run(INT run_number, char *error)
239 {
240  return CM_SUCCESS;
241 }
242 
243 //-- End of Run ----------------------------------------------------
248 INT end_of_run(INT run_number, char *error)
249 {
250  return CM_SUCCESS;
251 }
252 
253 //-- Pause Run -----------------------------------------------------
258 INT pause_run(INT run_number, char *error)
259 {
260  return CM_SUCCESS;
261 }
262 
263 //-- Resume Run ----------------------------------------------------
268 INT resume_run(INT run_number, char *error)
269 {
270  return CM_SUCCESS;
271 }
272 
273 //------------------------------------------------------------------
#define MOD_CF1_DEMAND
Definition: mod_cryo_scfe.c:25
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
Definition: vme_fe.c:2119
char * frontend_name
experiment specific ODB structures
Definition: vme_fe.c:159
EQUIPMENT equipment[]
Definition: vme_fe.c:326
INT max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
Definition: vme_fe.c:174
float * input
Definition: mod_cryo_scfe.c:52
#define MOD_HE_SHIELD_DEMAND
Definition: mod_cryo_scfe.c:27
#define MOD_CF1_MEASURED
Definition: mod_cryo_scfe.c:26
INT end_of_run(INT run_number, char *error)
Definition: vme_fe.c:858
INT w6100_in(INT cmd,...)
Definition: west6100.c:1058
void mod_cryo_checks(HNDLE hDB, HNDLE hKey, void *dummy)
INT frontend_init()
Definition: vme_fe.c:416
HNDLE hKey
Definition: write_summary.c:97
INT xtc(INT cmd,...)
Definition: xtc.c:342
INT frontend_loop()
Definition: vme_fe.c:949
DEVICE_DRIVER mod_cryo_driver[]
device driver list
Definition: mod_cryo_scfe.c:57
BOOL frontend_call_loop
frontend_loop is called periodically if this variable is TRUE
Definition: vme_fe.c:165
HNDLE hDB
Definition: write_summary.c:97
INT max_event_size
maximum event size produced by this frontend
Definition: vme_fe.c:171
INT pause_run(INT run_number, char *error)
Definition: vme_fe.c:886
INT frontend_exit()
Definition: vme_fe.c:557
INT twickenham(INT cmd,...)
Definition: twickenham.c:275
INT event_buffer_size
buffer size to hold events
Definition: vme_fe.c:177
char * frontend_file_name
The frontend file name, don&#39;t change it.
Definition: vme_fe.c:162
INT poll_event(INT source, INT count, BOOL test)
Definition: vme_fe.c:2102
INT begin_of_run(INT run_number, char *error)
Definition: vme_fe.c:589
#define MOD_HE_SHIELD_MEASURED
Definition: mod_cryo_scfe.c:28
INT w6100_out(INT cmd,...)
Definition: west6100.c:1108
INT display_period
a frontend status page is displayed with this frequency in ms
Definition: vme_fe.c:168
INT resume_run(INT run_number, char *error)
Definition: vme_fe.c:893