MIDAS
Loading...
Searching...
No Matches
fejrpc.cxx File Reference
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <math.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include "midas.h"
#include "mrpc.h"
#include "mfe.h"
Include dependency graph for fejrpc.cxx:

Go to the source code of this file.

Macros

#define FE_NAME   "fejrpc"
 
#define EQ_NAME   "RpcExample"
 
#define EQ_EVID   1
 

Functions

INT frontend_init ()
 Frontend initialization.
 
INT frontend_exit ()
 Frontend exit.
 
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.
 
INT frontend_loop ()
 Frontend loop.
 
int read_slow_event (char *pevent, int off)
 
static int configure ()
 
INT rpc_callback (INT index, void *prpc_param[])
 
INT poll_event (INT source, INT count, BOOL test)
 
INT interrupt_configure (INT cmd, INT source, PTYPE adr)
 
double get_time ()
 

Variables

const charfrontend_name = FE_NAME
 
const charfrontend_file_name = __FILE__
 
BOOL frontend_call_loop = TRUE
 
INT display_period = 0
 
INT max_event_size = 2000
 
INT max_event_size_frag = 0
 
INT event_buffer_size = 10*2000
 
INT gbl_run_number
 
EQUIPMENT equipment []
 
int count_slow = 0
 

Macro Definition Documentation

◆ EQ_EVID

#define EQ_EVID   1

Definition at line 30 of file fejrpc.cxx.

◆ EQ_NAME

#define EQ_NAME   "RpcExample"

Definition at line 29 of file fejrpc.cxx.

◆ FE_NAME

#define FE_NAME   "fejrpc"

Definition at line 28 of file fejrpc.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 188 of file fejrpc.cxx.

189{
190 cm_msg(MINFO, "begin_of_run", "Begin run %d", run_number);
191
193
194 configure();
195
196 count_slow = 0;
197
198 return SUCCESS;
199}
int count_slow
Definition fejrpc.cxx:120
INT gbl_run_number
Definition fejrpc.cxx:66
static int configure()
Definition fejrpc.cxx:122
#define SUCCESS
Definition mcstd.h:54
#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 run_number[2]
Definition mana.cxx:246
Here is the call graph for this function:

◆ configure()

static int configure ( )
static

Definition at line 122 of file fejrpc.cxx.

123{
124 int size, status;
125 int example_int = 0;
126
127 size = sizeof(int);
128 status = db_get_value(hDB, 0, "/Equipment/" EQ_NAME "/Settings/example_int", &example_int, &size, TID_INT, TRUE);
129 printf("Example_int: %d\n", example_int);
130
131 return SUCCESS;
132}
#define EQ_NAME
Definition fejrpc.cxx:29
#define TID_INT
Definition midas.h:338
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
Definition odb.cxx:5415
HNDLE hDB
main ODB handle
Definition mana.cxx:207
#define TRUE
Definition midas.h:182
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
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 203 of file fejrpc.cxx.

204{
205 cm_msg(MINFO, "end_of_run", "End run %d", run_number);
206
207 cm_msg(MINFO, frontend_name, "read %d slow events", count_slow);
208
209 return SUCCESS;
210}
const char * frontend_name
Definition fejrpc.cxx:36
Here is the call graph for this function:

◆ 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 180 of file fejrpc.cxx.

181{
182 cm_msg(MINFO, "frontend_exit", "Frontend exit");
183 return SUCCESS;
184}
Here is the call graph for this function:

◆ 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 162 of file fejrpc.cxx.

163{
164 int status;
165
166 cm_msg(MINFO, "frontend_init", "Frontend init");
167
168 //cm_set_watchdog_params (FALSE, 0);
169
171 assert(status == SUCCESS);
172
173 configure();
174
175 return SUCCESS;
176}
INT rpc_callback(INT index, void *prpc_param[])
Definition fejrpc.cxx:136
INT cm_register_function(INT id, INT(*func)(INT, void **))
Definition midas.cxx:5790
#define RPC_JRPC
Definition mrpc.h:130
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 230 of file fejrpc.cxx.

231{
232 /* if frontend_call_loop is true, this routine gets called when
233 the frontend is idle or once between every event */
234 //printf("frontend_loop!\n");
235 ss_sleep(10);
236 return SUCCESS;
237}
INT ss_sleep(INT millisec)
Definition system.cxx:3628
Here is the call graph for this function:

◆ get_time()

double get_time ( )

Definition at line 278 of file fejrpc.cxx.

279{
280 struct timeval tv;
282 return tv.tv_sec + 0.000001*tv.tv_usec;
283}
int gettimeofday(struct timeval *tp, void *tzp)
timeval tv
Definition msysmon.cxx:1095
Here is the call graph for this function:

◆ interrupt_configure()

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

Definition at line 260 of file fejrpc.cxx.

261{
262 switch(cmd)
263 {
265 break;
267 break;
269 break;
271 break;
272 }
273 return SUCCESS;
274}
#define CMD_INTERRUPT_ATTACH
Definition midas.h:822
#define CMD_INTERRUPT_DISABLE
Definition midas.h:821
#define CMD_INTERRUPT_ENABLE
Definition midas.h:820
#define CMD_INTERRUPT_DETACH
Definition midas.h:823

◆ 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 214 of file fejrpc.cxx.

215{
216 cm_msg(MINFO, "pause_run", "Pause run %d", run_number);
217 return SUCCESS;
218}
Here is the call graph for this function:

◆ poll_event()

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

Definition at line 247 of file fejrpc.cxx.

251{
252 if (test) {
253 ss_sleep (count);
254 }
255 return (0);
256}
double count
Definition mdump.cxx:33
program test
Definition miniana.f:6
Here is the call graph for this function:

◆ read_slow_event()

int read_slow_event ( char pevent,
int  off 
)

Definition at line 285 of file fejrpc.cxx.

286{
287 bk_init32(pevent);
288
289 count_slow++;
290
291 double* pdatad;
292 bk_create(pevent, "SLOW", TID_DOUBLE, (void**)&pdatad);
293
294 time_t t = time(NULL);
295 pdatad[0] = count_slow;
296 pdatad[1] = t;
297 pdatad[2] = 100.0*sin(M_PI*t/60);
298 //pdatad[0] = 0.0/0.0; // nan
299 //pdatad[1] = 1.0/0.0; // inf
300 //pdatad[2] = -1.0/0.0; // -inf
301 printf("time %d, data %f\n", (int)t, pdatad[2]);
302
303 bk_close(pevent, pdatad + 3);
304
305 return bk_size(pevent);
306}
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
void bk_init32(void *event)
Definition midas.cxx:16469
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_DOUBLE
Definition midas.h:343
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 222 of file fejrpc.cxx.

223{
224 cm_msg(MINFO, "resume_run", "Resume run %d", run_number);
225 return SUCCESS;
226}
Here is the call graph for this function:

◆ rpc_callback()

INT rpc_callback ( INT  index,
void prpc_param[] 
)

Definition at line 136 of file fejrpc.cxx.

137{
138 const char* cmd = CSTRING(0);
139 const char* args = CSTRING(1);
140 char* return_buf = CSTRING(2);
141 int return_max_length = CINT(3);
142
143 cm_msg(MINFO, "rpc_callback", "--------> rpc_callback: index %d, max_length %d, cmd [%s], args [%s]", index, return_max_length, cmd, args);
144
145 int example_int = strtol(args, NULL, 0);
146 int size = sizeof(int);
147 int status = db_set_value(hDB, 0, "/Equipment/" EQ_NAME "/Settings/example_int", &example_int, size, 1, TID_INT);
148 if (status != DB_SUCCESS)
149 printf("db_set_value() status %d\n", status);
150
151 char tmp[256];
152 time_t now = time(NULL);
153 sprintf(tmp, "current time is %d %s", (int)now, ctime(&now));
154
156
157 return RPC_SUCCESS;
158}
#define DB_SUCCESS
Definition midas.h:631
#define RPC_SUCCESS
Definition midas.h:698
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 index
Definition mana.cxx:271
#define CINT(_i)
Definition midas.h:1622
#define CSTRING(_i)
Definition midas.h:1646
#define ctime
Definition msystem.h:264
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ count_slow

int count_slow = 0

Definition at line 120 of file fejrpc.cxx.

◆ display_period

INT display_period = 0

Definition at line 46 of file fejrpc.cxx.

◆ equipment

EQUIPMENT equipment[]
Initial value:
= {
{ EQ_NAME,
{
EQ_EVID, (1<<EQ_EVID),
"SYSTEM",
0,
"MIDAS",
TRUE,
1000,
0,
0,
1,
"", "", ""
},
},
{ "" }
}
int read_slow_event(char *pevent, int off)
Definition fejrpc.cxx:285
#define EQ_EVID
Definition fejrpc.cxx:30
#define RO_STOPPED
Definition midas.h:427
#define RO_ODB
Definition midas.h:438
#define EQ_PERIODIC
Definition midas.h:414
#define RO_PAUSED
Definition midas.h:428
#define RO_RUNNING
Definition midas.h:426

Definition at line 72 of file fejrpc.cxx.

72 {
73
74 { EQ_NAME, /* equipment name */
75 {
76 EQ_EVID, (1<<EQ_EVID), /* event ID, trigger mask */
77 "SYSTEM", /* event buffer */
78 EQ_PERIODIC, /* equipment type */
79 0, /* event source */
80 "MIDAS", /* format */
81 TRUE, /* enabled */
82 RO_RUNNING|RO_STOPPED|RO_PAUSED|RO_ODB, /* When to read */
83 1000, /* poll every so milliseconds */
84 0, /* stop run after this event limit */
85 0, /* number of sub events */
86 1, /* history period*/
87 "", "", ""
88 },
89 read_slow_event, /* readout routine */
90 },
91 { "" }
92};

◆ event_buffer_size

INT event_buffer_size = 10*2000

Definition at line 53 of file fejrpc.cxx.

◆ frontend_call_loop

BOOL frontend_call_loop = TRUE

Definition at line 42 of file fejrpc.cxx.

◆ frontend_file_name

const char* frontend_file_name = __FILE__

Definition at line 39 of file fejrpc.cxx.

◆ frontend_name

const char* frontend_name = FE_NAME

Definition at line 36 of file fejrpc.cxx.

◆ gbl_run_number

INT gbl_run_number

Definition at line 66 of file fejrpc.cxx.

◆ max_event_size

INT max_event_size = 2000

Definition at line 49 of file fejrpc.cxx.

◆ max_event_size_frag

INT max_event_size_frag = 0

Definition at line 50 of file fejrpc.cxx.