MIDAS
Loading...
Searching...
No Matches
frontend.cxx File Reference
#include <stdio.h>
#include <math.h>
#include "midas.h"
#include "class/generic.h"
#include "device/epics_ca.h"
#include "mfe.h"
Include dependency graph for frontend.cxx:

Go to the source code of this file.

Functions

INT poll_event (INT source, INT count, BOOL test)
 
INT interrupt_configure (INT cmd, INT source, PTYPE adr)
 
INT frontend_init ()
 Frontend initialization.
 
INT frontend_exit ()
 Frontend exit.
 
INT frontend_loop ()
 Frontend loop.
 
INT begin_of_run (INT run_number, char *error)
 Begin of Run.
 
INT end_of_run (INT run_number, char *error)
 End of Run.
 
INT pause_run (INT run_number, char *error)
 Pause Run.
 
INT resume_run (INT run_number, char *error)
 Resume Run.
 

Variables

const charfrontend_name = "feEpics"
 
const charfrontend_file_name = __FILE__
 
BOOL frontend_call_loop = TRUE
 
INT display_period = 2000
 
INT max_event_size_frag = 5 * 1024 * 1024
 
INT max_event_size = 10000
 
INT event_buffer_size = 10 * 10000
 
BOOL equipment_common_overwrite = FALSE
 
DEVICE_DRIVER epics_driver []
 
EQUIPMENT equipment []
 

Function Documentation

◆ begin_of_run()

INT begin_of_run ( INT  run_number,
char error 
)

Begin of Run.

Called every run start transition. Set equipment status in ODB, start acquisition on the modules.

Parameters
[in]run_numberNumber of the run being started
[out]errorCan be used to write a message string to midas.log

Definition at line 216 of file frontend.cxx.

217{
218 return CM_SUCCESS;
219}
#define CM_SUCCESS
Definition midas.h:582

◆ end_of_run()

INT end_of_run ( INT  run_number,
char error 
)

End of Run.

Called every stop run transition. Set equipment status in ODB, stop acquisition on the modules.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log

Definition at line 223 of file frontend.cxx.

224{
225 return CM_SUCCESS;
226}

◆ frontend_exit()

INT frontend_exit ( void  )

Frontend exit.

Runs at frontend shutdown. Disconnect hardware and set equipment status in ODB

Returns
Midas status code

Definition at line 153 of file frontend.cxx.

154{
155 return CM_SUCCESS;
156}

◆ frontend_init()

INT frontend_init ( void  )

Frontend initialization.

Runs once at application startup. We initialize the hardware and optical interfaces and set the equipment status in ODB. We also lock the frontend to once physical cpu core.

Returns
Midas status code

Definition at line 118 of file frontend.cxx.

119{
120 /* enable/disable certain command in device driver */
121
122 // default number of channels is set in the epics_driver struct
123 // at the top of this file. If ODB has more channels, we do not want
124 // them truncated. Set number of channels to what we see in ODB. K.O.
125
126 int status;
127 HNDLE hkey;
128 std::string odb_path;
129 odb_path += "/Equipment/";
130 odb_path += equipment[0].name;
131 odb_path += "/Variables/Measured";
132
133 status = db_find_key(hDB, 0, odb_path.c_str(), &hkey);
134 if (hkey) {
135 KEY key;
137 if (status == DB_SUCCESS) {
139
140 //printf("key [%s] size %d default %d\n", key.name, key.num_values, default_values);
141
144 }
145 }
146 }
147
148 return CM_SUCCESS;
149}
EQUIPMENT equipment[]
Definition frontend.cxx:81
DEVICE_DRIVER epics_driver[]
Definition frontend.cxx:76
#define DB_SUCCESS
Definition midas.h:631
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6019
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
HNDLE hDB
main ODB handle
Definition mana.cxx:207
KEY key
Definition mdump.cxx:34
INT HNDLE
Definition midas.h:132
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Definition midas.h:1026
INT num_values
Definition midas.h:1028
char name[NAME_LENGTH]
Definition midas.h:1173
Here is the call graph for this function:

◆ frontend_loop()

INT frontend_loop ( void  )

Frontend loop.

If frontend_call_loop is true, this routine gets called when the frontend is idle or once between every event.

Returns
Midas status code

Definition at line 163 of file frontend.cxx.

164{
165 int status, size;
166 static HNDLE hDB, hWatch=0, hRespond;
167 static DWORD watchdog_time=0;
168 static float dog=0.f;
169
170 /* slow down frontend not to eat all CPU cycles */
171 /* ss_sleep(50); */
172 status = cm_yield(50); /* 15Feb05 */
173
174 //if (status != SS_TIMEOUT)
175 // cm_msg(MERROR, "frontend_loop", "cm_yield status %d", status);
176
177 if (status == RPC_SHUTDOWN || status == SS_ABORT) {
178 return status;
179 }
180
181 if (ss_time() - watchdog_time > 10)
182 {
183 //const float wraparound = 100;
185 if (!hWatch)
186 {
188 status = db_find_key(hDB, 0, "/equipment/Beamline/variables/demand", &hWatch);
189 status = db_find_key(hDB, 0, "/equipment/Beamline/variables/measured", &hRespond);
190 if (status != DB_SUCCESS) {
191 cm_msg(MERROR, "frontend_loop", "key not found");
192 return FE_ERR_HW;
193 }
194 }
195 if (hWatch) {
196 /* Check if Epics alive */
197 float cat=0.f;
198 size = sizeof(float);
200 if (fabs(dog - cat) > 10) {
201 cm_msg(MINFO,"feEpics","Epics R/W access watchdog failure, wrote %f, read %f!", dog, cat);
202 }
203
204 db_set_data_index(hDB, hWatch, &dog, sizeof(float), 19, TID_FLOAT);
205 }
206 dog += 1;
207 // watchdog mismatch check above does not know how to check for wraparound. K.O.
208 //if (dog > wraparound)
209 // dog = 0;
210 }
211 return CM_SUCCESS;
212}
INT cm_yield(INT millisec)
Definition midas.cxx:5642
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
#define SS_ABORT
Definition midas.h:677
#define RPC_SHUTDOWN
Definition midas.h:707
#define FE_ERR_HW
Definition midas.h:719
unsigned int DWORD
Definition mcstd.h:51
#define MINFO
Definition midas.h:560
#define MERROR
Definition midas.h:559
#define TID_FLOAT
Definition midas.h:341
DWORD ss_time()
Definition system.cxx:3462
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
Definition odb.cxx:6893
INT db_set_data_index(HNDLE hDB, HNDLE hKey, const void *data, INT data_size, INT idx, DWORD type)
Definition odb.cxx:7648
Here is the call graph for this function:

◆ interrupt_configure()

INT interrupt_configure ( INT  cmd,
INT  source,
PTYPE  adr 
)

Definition at line 111 of file frontend.cxx.

112{
113 return 1;
114};

◆ pause_run()

INT pause_run ( INT  run_number,
char error 
)

Pause Run.

Called every pause run transition.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log
Returns
Midas status code

Definition at line 230 of file frontend.cxx.

231{
232 return CM_SUCCESS;
233}

◆ poll_event()

INT poll_event ( INT  source,
INT  count,
BOOL  test 
)

Definition at line 107 of file frontend.cxx.

108{
109 return 1;
110};

◆ resume_run()

INT resume_run ( INT  run_number,
char error 
)

Resume Run.

Called every resume run transition.

Parameters
[in]run_numberNumber of the run being ended
[out]errorCan be used to write a message string to midas.log
Returns
Midas status code

Definition at line 237 of file frontend.cxx.

238{
239 return CM_SUCCESS;
240}

Variable Documentation

◆ display_period

INT display_period = 2000

Definition at line 31 of file frontend.cxx.

◆ epics_driver

DEVICE_DRIVER epics_driver[]
Initial value:
= {
{"Beamline", epics_ca, 20, NULL},
{""}
}

Definition at line 76 of file frontend.cxx.

76 {
77 {"Beamline", epics_ca, 20, NULL}, /* disable CMD_SET_LABEL */
78 {""}
79};

◆ equipment

EQUIPMENT equipment[]
Initial value:
= {
{"Beamline",
{ 3, 0,
"SYSTEM",
0,
"FIXED",
TRUE,
60000,
0,
0,
1,
"", "", "" },
NULL,
},
{""}
}
#define RO_TRANSITIONS
Definition midas.h:434
#define RO_RUNNING
Definition midas.h:426
#define EQ_SLOW
Definition midas.h:418
#define TRUE
Definition midas.h:182

Definition at line 81 of file frontend.cxx.

81 {
82
83 {"Beamline", /* equipment name */
84 { 3, 0, /* event ID, trigger mask */
85 "SYSTEM", /* event buffer */
86 EQ_SLOW, /* equipment type */
87 0, /* event source */
88 "FIXED", /* format */
89 TRUE, /* enabled */
90 RO_RUNNING | RO_TRANSITIONS, /* read when running and on transitions */
91 60000, /* read every 60 sec */
92 0, /* stop run after this event limit */
93 0, /* number of sub events */
94 1, /* log history every event */
95 "", "", "" },
96 cd_gen_read, /* readout routine */
97 cd_gen, /* class driver main routine */
98 epics_driver, /* device driver list */
99 NULL, /* init string */
100 },
101
102 {""}
103};

◆ equipment_common_overwrite

BOOL equipment_common_overwrite = FALSE

Definition at line 42 of file frontend.cxx.

◆ event_buffer_size

INT event_buffer_size = 10 * 10000

Definition at line 40 of file frontend.cxx.

◆ frontend_call_loop

BOOL frontend_call_loop = TRUE

Definition at line 28 of file frontend.cxx.

◆ frontend_file_name

const char* frontend_file_name = __FILE__

Definition at line 25 of file frontend.cxx.

◆ frontend_name

const char* frontend_name = "feEpics"

Definition at line 23 of file frontend.cxx.

◆ max_event_size

INT max_event_size = 10000

Definition at line 37 of file frontend.cxx.

◆ max_event_size_frag

INT max_event_size_frag = 5 * 1024 * 1024

Definition at line 34 of file frontend.cxx.