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

Go to the source code of this file.

Functions

INT trigger_thread (void *param)
 
INT frontend_init ()
 Frontend initialization.
 

Variables

const charfrontend_name = "Sample Frontend"
 
const charfrontend_file_name = __FILE__
 
BOOL equipment_common_overwrite = TRUE
 
EQUIPMENT equipment []
 

Function Documentation

◆ 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 57 of file mtfe.cxx.

58{
59 /* for this demo, use three readout threads */
60 for (int i=0 ; i<3 ; i++) {
61
62 /* create a ring buffer for each thread */
64
65 /* create readout thread */
67 }
68
69 return SUCCESS;
70}
#define SUCCESS
Definition mcstd.h:54
midas_thread_t ss_thread_create(INT(*thread_func)(void *), void *param)
Definition system.cxx:2310
INT i
Definition mdump.cxx:32
int create_event_rb(int i)
Definition mfe.cxx:1150
#define PTYPE
Definition midas.h:170
INT trigger_thread(void *param)
Definition mtfe.cxx:74
Here is the call graph for this function:

◆ trigger_thread()

INT trigger_thread ( void param)

Definition at line 74 of file mtfe.cxx.

75{
76 EVENT_HEADER *pevent;
77 WORD *pdata, *padc;
78 int index, i, status, exit = FALSE;
79 INT rbh;
80
81 /* index of this thread */
82 index = (int)(PTYPE)param;
83
84 /* tell framework that we are alive */
86
87 /* set name of thread as seen by OS */
88 ss_thread_set_name(std::string(equipment[0].name) + "RT" + std::to_string(index));
89
90 /* Initialize hardware here ... */
91 printf("Start readout thread %d\n", index);
92
93 /* Obtain ring buffer for inter-thread data exchange */
95
97
98 if (!readout_enabled()) {
99 // do not produce events when run is stopped
100 ss_sleep(10);
101 continue;
102 }
103
104 /* check for new event (poll) */
105 status = ss_sleep(100); // for this demo, just sleep a bit
106
107 if (status) { // if event available, read it out
108
109 // check once more in case state changed during the poll
111 break;
112
113 // obtain buffer space
114 do {
115 status = rb_get_wp(rbh, (void **) &pevent, 0);
116 if (status == DB_TIMEOUT) {
117 ss_sleep(10);
118 // check for readout thread disable, thread might be stop from main thread
119 // in case Ctrl-C is hit for example
121 exit = TRUE;
122 break;
123 }
124 }
125 } while (status != DB_SUCCESS);
126
127 if (exit)
128 break;
129
131 pdata = (WORD *)(pevent + 1);
132
133 /* init bank structure */
135
136 /* create ADC0 bank */
137 bk_create(pdata, "ADC0", TID_WORD, (void **)&padc);
138
139 /* just put in some random numbers in this demo */
140 int len = 32 + rand() % 10000;
141 for (i=0 ; i<len; i++)
142 *padc++ = len;
143
145
146 pevent->data_size = bk_size(pdata);
147
148 /* send event to ring buffer */
149 rb_increment_wp(rbh, sizeof(EVENT_HEADER) + pevent->data_size);
150 }
151 }
152
153 /* tell framework that we are finished */
155
156 printf("Stop readout thread %d\n", index);
157
158 return 0;
159}
#define FALSE
Definition cfortran.h:309
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
INT bm_compose_event_threadsafe(EVENT_HEADER *event_header, short int event_id, short int trigger_mask, DWORD data_size, DWORD *serial)
Definition midas.cxx:8292
#define DB_SUCCESS
Definition midas.h:631
#define DB_TIMEOUT
Definition midas.h:655
unsigned short int WORD
Definition mcstd.h:49
#define TID_WORD
Definition midas.h:332
INT EXPRT ss_thread_set_name(std::string name)
Definition system.cxx:2426
INT ss_sleep(INT millisec)
Definition system.cxx:3628
int rb_get_wp(int handle, void **p, int millisec)
Definition midas.cxx:17427
int rb_increment_wp(int handle, int size)
Definition midas.cxx:17502
INT index
Definition mana.cxx:271
char param[10][256]
Definition mana.cxx:250
static int rbh[MAX_N_THREADS]
Definition mfe.cxx:71
void signal_readout_thread_active(int index, int flag)
Definition mfe.cxx:1180
int get_event_rbh(int i)
Definition mfe.cxx:1160
bool readout_enabled(void)
Definition mfe.cxx:1096
bool is_readout_thread_enabled()
Definition mfe.cxx:1168
int INT
Definition midas.h:129
#define TRUE
Definition midas.h:182
#define serial_number
#define name(x)
Definition midas_macro.h:24
EQUIPMENT equipment[]
Definition mtfe.cxx:34
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
DWORD data_size
Definition midas.h:856
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ equipment

EQUIPMENT equipment[]
Initial value:
= {
{"Trigger",
{1, 0,
"SYSTEM",
0,
"MIDAS",
TRUE,
500,
0,
0,
0,
"", "", "",},
NULL,
},
{""}
}
#define EQ_USER
Definition midas.h:422
#define RO_RUNNING
Definition midas.h:426

Definition at line 34 of file mtfe.cxx.

34 {
35
36 {"Trigger", /* equipment name */
37 {1, 0, /* event ID, trigger mask */
38 "SYSTEM", /* event buffer */
39 EQ_USER, /* equipment type */
40 0, /* event source (not used) */
41 "MIDAS", /* format */
42 TRUE, /* enabled */
43 RO_RUNNING, /* read only when running */
44 500, /* poll for 500ms */
45 0, /* stop run after this event limit */
46 0, /* number of sub events */
47 0, /* don't log history */
48 "", "", "",},
49 NULL, /* readout routine */
50 },
51
52 {""}
53};

◆ equipment_common_overwrite

BOOL equipment_common_overwrite = TRUE

Definition at line 32 of file mtfe.cxx.

◆ frontend_file_name

const char* frontend_file_name = __FILE__

Definition at line 24 of file mtfe.cxx.

◆ frontend_name

const char* frontend_name = "Sample Frontend"

Definition at line 22 of file mtfe.cxx.