MIDAS
Loading...
Searching...
No Matches
crfe.cxx File Reference
#include <stdio.h>
#include <assert.h>
#include "midas.h"
#include "mfe.h"
Include dependency graph for crfe.cxx:

Go to the source code of this file.

Macros

#define N_READBACK   4
 

Functions

INT read_cr_event (char *pevent, INT off)
 
void cr_settings_changed (HNDLE, HNDLE, int, void *)
 
INT poll_event (INT source, INT count, BOOL test)
 
INT interrupt_configure (INT cmd, INT source, POINTER_T 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 = "CR Frontend"
 
const charfrontend_file_name = __FILE__
 
BOOL frontend_call_loop = FALSE
 
INT display_period = 1000
 
INT max_event_size = 10000
 
INT max_event_size_frag = 5 * 1024 * 1024
 
INT event_buffer_size = 10 * 10000
 
BOOL equipment_common_overwrite = TRUE
 
const charcr_settings_str []
 
EQUIPMENT equipment []
 

Macro Definition Documentation

◆ N_READBACK

#define N_READBACK   4

Definition at line 165 of file crfe.cxx.

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 167 of file crfe.cxx.

168{
169 /*
170 * This example code starts a run transition, then waits on some
171 * external conditions by polling an array in the ODB. It expects
172 * that other programs set the readback array in the ODB to the
173 * current run number
174 */
175
176 HNDLE hDB, hKey;
179
180 // set requested run number in ODB
181 db_set_value(hDB, 0, "/Equipment/Clock Reset/Run transitions/Requested run number", &run_number, sizeof(INT), 1, TID_INT);
182
183 // retrieve readback array form ODB
184 int size = sizeof(readback);
185 memset(readback, 0, size);
186 db_find_key(hDB, 0, "/Equipment/Clock Reset/Run transitions/FEB readback", &hKey);
187 if (!hKey) {
188 // create readback array if not existing
189 db_create_key(hDB, 0, "/Equipment/Clock Reset/Run transitions/FEB readback", TID_INT);
190 db_find_key(hDB, 0, "/Equipment/Clock Reset/Run transitions/FEB readback", &hKey);
192 }
193
194 // set equipment status for status web page
195 set_equipment_status("Clock Reset", "Waiting for readback", "yellowLight");
196
197 // wait until readback succeeds
198 int start_time = ss_time();
199 do {
201 for (i=0 ; i<N_READBACK ; i++) {
202 if (readback[i] != run_number)
203 break;
204 }
205 if (i == N_READBACK)
206 break;
207
208 // don't waste 100% CPU time
209 ss_sleep(10);
210
211 } while (ss_time() < start_time + 5); // wait maximal 5 seconds
212
213 if (i < N_READBACK) {
214 strcpy(error, "Timeout receiving FEB feedback");
215 return FE_ERR_HW;
216 }
217
218 // set equipment status for status web page
219 set_equipment_status("Clock Reset", "Ok", "greenLight");
220
221 return CM_SUCCESS;
222}
#define N_READBACK
Definition crfe.cxx:165
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
Definition midas.cxx:3011
#define CM_SUCCESS
Definition midas.h:582
#define FE_ERR_HW
Definition midas.h:719
#define TID_INT
Definition midas.h:338
DWORD ss_time()
Definition system.cxx:3462
INT ss_sleep(INT millisec)
Definition system.cxx:3628
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
Definition odb.cxx:6539
INT db_create_key(HNDLE hDB, HNDLE hKey, const char *key_name, DWORD type)
Definition odb.cxx:3308
INT db_set_data(HNDLE hDB, HNDLE hKey, const void *data, INT buf_size, INT num_values, DWORD type)
Definition odb.cxx:7215
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
Definition odb.cxx:5261
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
Definition odb.cxx:4079
HNDLE hKey
INT run_number[2]
Definition mana.cxx:246
HNDLE hDB
main ODB handle
Definition mana.cxx:207
INT i
Definition mdump.cxx:32
int set_equipment_status(const char *name, const char *equipment_status, const char *status_class)
Definition mfe.cxx:884
INT HNDLE
Definition midas.h:132
int INT
Definition midas.h:129
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:

◆ cr_settings_changed()

void cr_settings_changed ( HNDLE  hDB,
HNDLE  hKey,
int  ,
void  
)

Definition at line 297 of file crfe.cxx.

298{
299 KEY key;
300
302
303 if (std::string(key.name) == "Active") {
304 BOOL value;
305 int size = sizeof(value);
306 db_get_data(hDB, hKey, &value, &size, TID_BOOL);
307 cm_msg(MINFO, "cr_settings_changed", "Set active to %d", value);
308 // TODO: propagate to hardware
309 }
310
311 if (std::string(key.name) == "Delay") {
312 INT value;
313 int size = sizeof(value);
314 db_get_data(hDB, hKey, &value, &size, TID_INT);
315 cm_msg(MINFO, "cr_settings_changed", "Set delay to %d", value);
316 // TODO: propagate to hardware
317 }
318
319 if (std::string(key.name) == "Reset Trigger") {
320 BOOL value;
321 int size = sizeof(value);
322 db_get_data(hDB, hKey, &value, &size, TID_BOOL);
323 if (value) {
324 cm_msg(MINFO, "cr_settings_changed", "Execute reset");
325 // TODO: propagate to hardware
326 value = FALSE; // reset flag in ODB
327 db_set_data(hDB, hKey, &value, sizeof(value), 1, TID_BOOL);
328 }
329 }
330
331 if (std::string(key.name) == "Sync Trigger") {
332 BOOL value;
333 int size = sizeof(value);
334 db_get_data(hDB, hKey, &value, &size, TID_BOOL);
335 if (value) {
336 cm_msg(MINFO, "cr_settings_changed", "Execute sync");
337 // TODO: propagate to hardware
338 value = FALSE; // reset flag in ODB
339 db_set_data(hDB, hKey, &value, sizeof(value), 1, TID_BOOL);
340 }
341 }
342}
#define FALSE
Definition cfortran.h:309
#define TID_BOOL
Definition midas.h:340
#define MINFO
Definition midas.h:560
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
Definition odb.cxx:6019
KEY key
Definition mdump.cxx:34
DWORD BOOL
Definition midas.h:105
double value[100]
Definition odbhist.cxx:42
Definition midas.h:1026
char name[NAME_LENGTH]
Definition midas.h:1029
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 226 of file crfe.cxx.

227{
228 return CM_SUCCESS;
229}

◆ 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 151 of file crfe.cxx.

152{
153 return CM_SUCCESS;
154}

◆ 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 129 of file crfe.cxx.

130{
131 HNDLE hKey;
132
133 // create Settings structure in ODB
134 db_create_record(hDB, 0, "Equipment/Clock Reset/Settings", strcomb1(cr_settings_str).c_str());
135 db_find_key(hDB, 0, "/Equipment/Clock Reset", &hKey);
136 assert(hKey);
137
139
140 /*
141 * Set our transition sequence. The default is 500. Setting it
142 * to 600 means we are called AFTER most other clients.
143 */
145
146 return CM_SUCCESS;
147}
void cr_settings_changed(HNDLE, HNDLE, int, void *)
Definition crfe.cxx:297
const char * cr_settings_str[]
Definition crfe.cxx:80
INT cm_set_transition_sequence(INT transition, INT sequence_number)
Definition midas.cxx:3723
#define TR_START
Definition midas.h:405
std::string strcomb1(const char **list)
Definition odb.cxx:598
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
Definition odb.cxx:13813
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
Definition odb.cxx:12800
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 158 of file crfe.cxx.

159{
160 return CM_SUCCESS;
161}

◆ interrupt_configure()

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

Definition at line 122 of file crfe.cxx.

123{
124 return 1;
125};

◆ 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 233 of file crfe.cxx.

234{
235 return CM_SUCCESS;
236}

◆ poll_event()

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

Definition at line 117 of file crfe.cxx.

118{
119 return 1;
120};

◆ read_cr_event()

INT read_cr_event ( char pevent,
INT  off 
)

Definition at line 278 of file crfe.cxx.

279{
280 bk_init(pevent);
281
282 float *pdata;
283 bk_create(pevent, "CRT1", TID_FLOAT, (void **)&pdata);
284
285 *pdata++ = (float) rand() / RAND_MAX;
286 *pdata++ = (float) rand() / RAND_MAX;
287 *pdata++ = (float) rand() / RAND_MAX;
288 *pdata++ = (float) rand() / RAND_MAX;
289
290 bk_close(pevent, pdata);
291
292 return bk_size(pevent);
293}
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
void bk_init(void *event)
Definition midas.cxx:16406
void bk_create(void *event, const char *name, WORD type, void **pdata)
Definition midas.cxx:16561
INT bk_size(const void *event)
Definition midas.cxx:16495
#define TID_FLOAT
Definition midas.h:341
Here is the call graph for this function:

◆ 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 240 of file crfe.cxx.

241{
242 return CM_SUCCESS;
243}

Variable Documentation

◆ cr_settings_str

const char* cr_settings_str[]
Initial value:
= {
"Active = BOOL : 1",
"Delay = INT : 0",
"Reset Trigger = BOOL : 0",
"Sync Trigger = BOOL : 0",
"Names CRT1 = STRING[4] :",
"[32] Temp0",
"[32] Temp1",
"[32] Temp2",
"[32] Temp3",
}

Definition at line 80 of file crfe.cxx.

80 {
81"Active = BOOL : 1",
82"Delay = INT : 0",
83"Reset Trigger = BOOL : 0",
84"Sync Trigger = BOOL : 0",
85"Names CRT1 = STRING[4] :",
86"[32] Temp0",
87"[32] Temp1",
88"[32] Temp2",
89"[32] Temp3",
90NULL
91};

◆ display_period

INT display_period = 1000

Definition at line 59 of file crfe.cxx.

◆ equipment

EQUIPMENT equipment[]
Initial value:
= {
{"Clock Reset",
{10, 0,
"SYSTEM",
0,
"MIDAS",
TRUE,
10000,
0,
0,
1,
"", "", ""} ,
},
{""}
}
INT read_cr_event(char *pevent, INT off)
Definition crfe.cxx:278
#define RO_ODB
Definition midas.h:438
#define EQ_PERIODIC
Definition midas.h:414
#define RO_ALWAYS
Definition midas.h:436
#define TRUE
Definition midas.h:182

Definition at line 93 of file crfe.cxx.

93 {
94
95 {"Clock Reset", /* equipment name */
96 {10, 0, /* event ID, trigger mask */
97 "SYSTEM", /* event buffer */
98 EQ_PERIODIC, /* equipment type */
99 0, /* event source */
100 "MIDAS", /* format */
101 TRUE, /* enabled */
102 RO_ALWAYS | RO_ODB, /* read always and update ODB */
103 10000, /* read every 10 sec */
104 0, /* stop run after this event limit */
105 0, /* number of sub events */
106 1, /* log history every event */
107 "", "", ""} ,
108 read_cr_event, /* readout routine */
109 },
110
111 {""}
112};

◆ equipment_common_overwrite

BOOL equipment_common_overwrite = TRUE

Definition at line 77 of file crfe.cxx.

◆ event_buffer_size

INT event_buffer_size = 10 * 10000

Definition at line 68 of file crfe.cxx.

◆ frontend_call_loop

BOOL frontend_call_loop = FALSE

Definition at line 56 of file crfe.cxx.

◆ frontend_file_name

const char* frontend_file_name = __FILE__

Definition at line 53 of file crfe.cxx.

◆ frontend_name

const char* frontend_name = "CR Frontend"

Definition at line 51 of file crfe.cxx.

◆ max_event_size

INT max_event_size = 10000

Definition at line 62 of file crfe.cxx.

◆ max_event_size_frag

INT max_event_size_frag = 5 * 1024 * 1024

Definition at line 65 of file crfe.cxx.