Low-Energy Muon (LEM) Experiment  0.5.2
scs2001m_scfe.cxx
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: scs2001m_scfe.cxx
4  Created by: Andreas Suter
5 
6  Contents: Midas Slowcontrol Frontend to readout the scs2001
7  (ADC/DAC/Thermo Coupler/Relais/24V power)
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 "scs2001m.h"
21 #include "bus/null.h"
22 
23 //-- Globals -------------------------------------------------------
24 
26 const char *frontend_name = "SCS2001M_SC";
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 // -- Globals for Hotlinks -----------------------------------------
46 #define SCS2001M_OUPUT_CH 12
47 #define SCS2001M_RELAY_FIRST 8
48 
49 #define SCS2001M_MC_INTERLOCK_RESET 8
50 #define SCS2001M_TC_INTERLOCK_RESET 9
51 #define SCS2001M_SC_INTERLOCK_RESET 10
52 
55 
56 //-- Equipment list ------------------------------------------------
57 
58 DEVICE_DRIVER scs2001m_driver[] = {
59  { "SCS2001m", scs2001m_in, 44, null, DF_INPUT },
60  { "SCS2001m", scs2001m_out, 12, null, DF_OUTPUT },
61  { "" }
62 };
63 
73 
75 EQUIPMENT equipment[] = {
76 
77  { "SCS2001M", // equipment name
78  {97, 0, // event ID, trigger mask
79  "SYSTEM", // event buffer
80  EQ_SLOW, // equipment type
81  0, // event source
82  "FIXED", // format
83  TRUE, // enabled
84  RO_RUNNING |
85  RO_TRANSITIONS, // read when running and on transitions
86  30000, // read every 30 sec
87  0, // stop run after this event limit
88  0, // number of sub events
89  1, // log history every event
90  "", "", "",},
91  cd_multi_read, // readout routine
92  cd_multi, // class driver main routine
93  scs2001m_driver, // device driver list
94  NULL, // init string
95  },
96 
97  { "" }
98 };
99 
100 
101 
102 //-- Dummy routines ------------------------------------------------
103 
104 INT poll_event(INT source, INT count, BOOL test) {return 1;};
105 INT interrupt_configure(INT cmd, INT source, POINTER_T adr) {return 1;};
106 
107 //-- Dispatcher routines -------------------------------------------
108 void scs2001m_output_changed(INT hDB, INT hKey, void *data)
109 {
110  scs2001m_start = ss_time();
111 }
112 
113 //-- Frontend Init -------------------------------------------------
118 {
119  HNDLE hDB, hKey;
120  char str[128];
121  int status;
122 
123  // de-register run-transition notifications
124  cm_deregister_transition(TR_START);
125  cm_deregister_transition(TR_STOP);
126  cm_deregister_transition(TR_PAUSE);
127  cm_deregister_transition(TR_RESUME);
128 
129  // get ODB main handle
130  cm_get_experiment_database(&hDB, NULL);
131 
132  // hotlink SCS2001M ouput record
133  strcpy(str, "/Equipment/SCS2001M/Variables/Output");
134  status = db_find_key(hDB, 0, str, &hKey);
135  if (status != DB_SUCCESS) {
136  cm_msg(MERROR, "frontend_init", "scs2001m_scfe: Couldn't find %s", str);
137  return CM_SUCCESS;
138  }
139  status = db_open_record(hDB, hKey, (void*)&scs2001m_output, SCS2001M_OUPUT_CH*sizeof(float),
140  MODE_READ, &scs2001m_output_changed, NULL);
141  if (status != DB_SUCCESS) {
142  cm_msg(MERROR, "frontend_init", "scs2001m_scfe: Couldn't establish hotlink to %s", str);
143  return CM_SUCCESS;
144  }
145  scs2001m_start = 0;
146 
147  return CM_SUCCESS;
148 }
149 
150 //-- Frontend Exit -------------------------------------------------
155 {
156  char str[128];
157  int status;
158  HNDLE hDB, hKey;
159 
160  // get ODB main handle
161  cm_get_experiment_database(&hDB, NULL);
162 
163  // unlink scs2001m output
164  strcpy(str, "/Equipment/SCS2001M/Variables/Output");
165  status = db_find_key(hDB, 0, str, &hKey);
166  if (status != DB_SUCCESS) {
167  cm_msg(MERROR, "frontend_exit", "scs2001m_scfe: Couldn't find %s, status=%d", str, status);
168  return CM_SUCCESS;
169  }
170  db_close_record(hDB, hKey);
171 
172  return CM_SUCCESS;
173 }
174 
175 //-- Frontend Loop -------------------------------------------------
180 {
181  char str[128];
182  int status, i;
183  HNDLE hDB, hKey;
184  float fval;
185 
186  // reset relay if necessary
187  if (scs2001m_start != 0) {
188  if (ss_time() - scs2001m_start > 2) {
189  scs2001m_start = 0; // reset times
190 
191  // get ODB main handle
192  cm_get_experiment_database(&hDB, NULL);
193 
194  strcpy(str, "/Equipment/SCS2001M/Variables/Output");
195  status = db_find_key(hDB, 0, str, &hKey);
196  if (status != DB_SUCCESS) {
197  cm_msg(MERROR, "frontend_loop", "scs2001m_scfe: Couldn't find %s, status=%d", str, status);
198  return CM_SUCCESS;
199  }
200 
201  for (i=SCS2001M_RELAY_FIRST; i<SCS2001M_OUPUT_CH; i++) {
202  if (scs2001m_output[i] != 0.0) {
203  fval = 0.0;
204  db_set_data_index(hDB, hKey, &fval, sizeof(float), i, TID_FLOAT);
205  switch (i) {
207  strcpy(str, "scs2001m_scfe: attempt to remotely reset MC HV interlock.");
208  break;
210  strcpy(str, "scs2001m_scfe: attempt to remotely reset TC HV interlock.");
211  break;
213  strcpy(str, "scs2001m_scfe: attempt to remotely reset SC HV interlock.");
214  break;
215  default:
216  strcpy(str, "scs2001m_scfe: ??");
217  break;
218  }
219  cm_msg(MINFO, "scs2001m_scfe", str);
220  }
221  }
222  }
223  }
224 
225  return CM_SUCCESS;
226 }
227 
228 //-- Begin of Run --------------------------------------------------
233 INT begin_of_run(INT run_number, char *error)
234 {
235  return CM_SUCCESS;
236 }
237 
238 //-- End of Run ----------------------------------------------------
243 INT end_of_run(INT run_number, char *error)
244 {
245  return CM_SUCCESS;
246 }
247 
248 //-- Pause Run -----------------------------------------------------
253 INT pause_run(INT run_number, char *error)
254 {
255  return CM_SUCCESS;
256 }
257 
258 //-- Resume Run ----------------------------------------------------
263 INT resume_run(INT run_number, char *error)
264 {
265  return CM_SUCCESS;
266 }
267 
268 //------------------------------------------------------------------
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
float scs2001m_output[SCS2001M_OUPUT_CH]
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
#define SCS2001M_SC_INTERLOCK_RESET
DWORD scs2001m_start
#define SCS2001M_TC_INTERLOCK_RESET
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
void scs2001m_output_changed(INT hDB, INT hKey, void *data)
#define SCS2001M_OUPUT_CH
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 max_event_size_frag
maximum event size for fragmented events (EQ_FRAGMENTED)
Definition: vme_fe.cxx:182
#define SCS2001M_RELAY_FIRST
INT frontend_init()
Definition: vme_fe.cxx:429
#define SCS2001M_MC_INTERLOCK_RESET
HNDLE hKey
BOOL equipment_common_overwrite
Definition: vme_fe.cxx:341
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
HNDLE hDB
INT pause_run(INT run_number, char *error)
Definition: vme_fe.cxx:893
const char * frontend_file_name
The frontend file name, don&#39;t change it.
Definition: vme_fe.cxx:170
DEVICE_DRIVER scs2001m_driver[]