Low-Energy Muon (LEM) Experiment  0.5.1
sample_scfe.c
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: sample_scfe.c
4  Created by: Andreas Suter
5 
6  Contents: Midas Slowcontrol Frontend to readout all devices related
7  to the sample region (except high voltages)
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 "lem_generic.h"
19 #include "LakeShore340.h"
20 #include "bronkhorst.h"
21 #include "thcd_100.h"
22 #include "tcpip_rs232.h"
23 #include "null.h"
24 
25 //-- Globals -------------------------------------------------------
26 
28 char *frontend_name = "Sample_SC";
30 char *frontend_file_name = __FILE__;
31 
33 BOOL frontend_call_loop = FALSE;
34 
36 INT display_period = 1000;
37 
39 INT max_event_size = 10000;
40 
42 INT max_event_size_frag = 5*1024*1024;
43 
45 INT event_buffer_size = 10*10000;
46 
48 char sample_cryo[NAME_LENGTH];
49 
50 //-- Equipment list ------------------------------------------------
54 DEVICE_DRIVER sample_driver[] = {
55  { "Lake340_Sample", ls340_in, 15, tcpip_rs232, DF_INPUT },
56  { "Lake340_Sample", ls340_out, 8, tcpip_rs232, DF_OUTPUT },
57  { "BH_Flow_1", bh_flow_in, 2, tcpip_rs232, DF_INPUT },
58  { "BH_Flow_1", bh_flow_out, 2, tcpip_rs232, DF_OUTPUT },
59  { "BH_Flow_2", bh_flow_in, 2, tcpip_rs232, DF_INPUT },
60  { "BH_Flow_2", bh_flow_out, 2, tcpip_rs232, DF_OUTPUT },
61  { "THCD_100_1", thcd_100_in, 1, tcpip_rs232, DF_INPUT },
62  { "THCD_100_1", thcd_100_out, 1, tcpip_rs232, DF_OUTPUT },
63  { "THCD_100_2", thcd_100_in, 1, tcpip_rs232, DF_INPUT },
64  { "THCD_100_2", thcd_100_out, 1, tcpip_rs232, DF_OUTPUT },
65  { "" }
66 };
67 
69 EQUIPMENT equipment[] = {
70 
71  { "SampleCryo", // equipment name
72  {70, 0, // event ID, trigger mask
73  "SYSTEM", // event buffer
74  EQ_SLOW, // equipment type
75  0, // event source
76  "FIXED", // format
77  TRUE, // enabled
78  RO_RUNNING |
79  RO_TRANSITIONS, // read when running and on transitions
80  30000, // read every 30 sec
81  0, // stop run after this event limit
82  0, // number of sub events
83  1, // log history every event
84  "", "", "",},
85  cd_multi_read, // readout routine
86  cd_multi, // class driver main routine
87  sample_driver, // device driver list
88  NULL, // init string
89  },
90 
91  { "" }
92 };
93 
94 
95 
96 //-- Dummy routines ------------------------------------------------
97 
98 INT poll_event(INT source[], INT count, BOOL test) {return 1;};
99 INT interrupt_configure(INT cmd, INT source[], PTYPE adr) {return 1;};
100 
101 //-- Global hotlink dispatcher routines ----------------------------
111 void sample_cryo_changed(INT hDB, INT dummy2, void *info)
112 {
113  int status;
114  char cryo_path[256];
115  HNDLE hKey;
116 
117  // get experiment handle
118  cm_get_experiment_database(&hDB, NULL);
119 
120  // get main handle
121  sprintf(cryo_path, "/Equipment/SampleCryo/Settings/Devices/Lake340_Sample_0/DD/ODB Names/LakeShore 340 Name");
122 
123  status = db_find_key(hDB, 0, cryo_path, &hKey);
124  if (status != DB_SUCCESS) {
125  cm_msg(MINFO, "sample_cryo_changed",
126  "sample_scfe, sample_cryo_changed: couldn't find sample cryo ODB entry.");
127  return;
128  }
129 
130  // write new name to DD structure
131  db_set_data(hDB, hKey, (void *)&sample_cryo, sizeof(sample_cryo), 1, TID_STRING);
132 }
133 
134 //-- Frontend Init -------------------------------------------------
140 {
141  HNDLE hDB, hKey;
142  int size, status;
143 
144  // de-register run-transition notifications
145  cm_deregister_transition(TR_START);
146  cm_deregister_transition(TR_STOP);
147  cm_deregister_transition(TR_PAUSE);
148  cm_deregister_transition(TR_RESUME);
149 
150  // get experiment handle
151  cm_get_experiment_database(&hDB, NULL);
152 
153  // find ODB entry
154  status = db_find_key(hDB, 0, "/Info/Sample Cryo", &hKey);
155  if (status != DB_SUCCESS) {
156  cm_msg(MINFO, "frontend_init", "sample_scfe, frontend_init: couldn't find sample cryo ODB entry");
157  return CM_SUCCESS;
158  }
159 
160  // hotlink sample cryo name
161  size = sizeof(sample_cryo);
162  db_open_record(hDB, hKey, (void *)&sample_cryo, size, MODE_READ, &sample_cryo_changed, NULL);
163 
164  return CM_SUCCESS;
165 }
166 
167 //-- Frontend Exit -------------------------------------------------
173 {
174  return CM_SUCCESS;
175 }
176 
177 //-- Frontend Loop -------------------------------------------------
183 {
184  return CM_SUCCESS;
185 }
186 
187 //-- Begin of Run --------------------------------------------------
192 INT begin_of_run(INT run_number, char *error)
193 {
194  return CM_SUCCESS;
195 }
196 
197 //-- End of Run ----------------------------------------------------
202 INT end_of_run(INT run_number, char *error)
203 {
204  return CM_SUCCESS;
205 }
206 
207 //-- Pause Run -----------------------------------------------------
212 INT pause_run(INT run_number, char *error)
213 {
214  return CM_SUCCESS;
215 }
216 
217 //-- Resume Run ----------------------------------------------------
222 INT resume_run(INT run_number, char *error)
223 {
224  return CM_SUCCESS;
225 }
226 
227 //------------------------------------------------------------------
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
Definition: vme_fe.c:2119
INFO info
Definition: vme_fe.c:206
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
INT ls340_in(INT cmd,...)
INT end_of_run(INT run_number, char *error)
Definition: vme_fe.c:858
INT frontend_init()
Definition: vme_fe.c:416
HNDLE hKey
Definition: write_summary.c:97
INT frontend_loop()
Definition: vme_fe.c:949
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 bh_flow_out(INT cmd,...)
Definition: bronkhorst.c:1141
void sample_cryo_changed(INT hDB, INT dummy2, void *info)
Definition: sample_scfe.c:111
char sample_cryo[NAME_LENGTH]
sample cryo name
Definition: sample_scfe.c:48
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 bh_flow_in(INT cmd,...)
Definition: bronkhorst.c:1088
INT begin_of_run(INT run_number, char *error)
Definition: vme_fe.c:589
DEVICE_DRIVER sample_driver[]
Definition: sample_scfe.c:54
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
INT ls340_out(INT cmd,...)