MIDAS
Loading...
Searching...
No Matches
tmfe_example_frontend.cxx
Go to the documentation of this file.
1/*******************************************************************\
2
3 Name: tmfe_example_frontend.cxx
4 Created by: K.Olchanski
5
6 Contents: Example of converting examples/experiment/frontend.cxx to TMFE framework
7
8\********************************************************************/
9
10#undef NDEBUG // midas required assert() to be always enabled
11
12#include <stdio.h>
13#include <math.h> // M_PI
14
15#include "tmfe.h"
16
17/********************************************************************\
18
19 Name: frontend.c
20 Created by: Stefan Ritt
21
22 Contents: Experiment specific readout code (user part) of
23 Midas frontend. This example simulates a "trigger
24 event" and a "periodic event" which are filled with
25 random data.
26
27 The trigger event is filled with two banks (ADC0 and TDC0),
28 both with values with a gaussian distribution between
29 0 and 4096. About 100 event are produced per second.
30
31 The periodic event contains one bank (PRDC) with four
32 sine-wave values with a period of one minute. The
33 periodic event is produced once per second and can
34 be viewed in the history system.
35
36\********************************************************************/
37
38#undef NDEBUG // midas required assert() to be always enabled
39
40//#include "midas.h"
41//#include "experim.h"
42
43#if 0
44const char *frontend_name = "Sample Frontend";
45const char *frontend_file_name = __FILE__;
47INT display_period = 3000;
48INT max_event_size = 10000;
49INT max_event_size_frag = 5 * 1024 * 1024;
50INT event_buffer_size = 100 * 10000;
52
54
55 {"Trigger", /* equipment name */
56 {1, 0, /* event ID, trigger mask */
57 "SYSTEM", /* event buffer */
58 EQ_POLLED, /* equipment type */
59 0, /* event source */
60 "MIDAS", /* format */
61 TRUE, /* enabled */
62 RO_RUNNING | /* read only when running */
63 RO_ODB, /* and update ODB */
64 100, /* poll for 100ms */
65 0, /* stop run after this event limit */
66 0, /* number of sub events */
67 0, /* don't log history */
68 "", "", "",},
69 read_trigger_event, /* readout routine */
70 },
71
72 {"Periodic", /* equipment name */
73 {2, 0, /* event ID, trigger mask */
74 "SYSTEM", /* event buffer */
75 EQ_PERIODIC, /* equipment type */
76 0, /* event source */
77 "MIDAS", /* format */
78 TRUE, /* enabled */
79 RO_RUNNING | RO_TRANSITIONS | /* read when running and on transitions */
80 RO_ODB, /* and update ODB */
81 1000, /* read every sec */
82 0, /* stop run after this event limit */
83 0, /* number of sub events */
84 TRUE, /* log history */
85 "", "", "",},
86 read_periodic_event, /* readout routine */
87 },
88
89 {""}
90};
91#endif
92
93class EqTrigger :
94 public TMFeEquipment
95{
96public:
97 EqTrigger(const char* eqname, const char* eqfilename) // ctor
99 {
100 /* configure your equipment here */
101
103 fEqConfEventID = 1;
104 fEqConfBuffer = "SYSTEM";
105 fEqConfPeriodMilliSec = 0; // in milliseconds
108 //fEqConfWriteEventsToOdb = true;
109 fEqConfEnablePoll = true; // enable polled equipment
110 //fEqConfPollSleepSec = 0; // to create a "100% CPU busy" polling loop, set poll sleep time to zero
111 fEqConfPollSleepSec = 0.010; // limit event rate to 100 Hz. In a real experiment remove this line
112 }
113
114 ~EqTrigger() // dtor
115 {
116 }
117
119 {
120 printf("EqTrigger::Usage!\n");
121 }
122
123 TMFeResult HandleInit(const std::vector<std::string>& args)
124 {
125 /* put any hardware initialization here */
126
127
128 /* start poll thread here */
129
130 //EqStartPollThread();
131
132 /* return TMFeErrorMessage("my error message") if frontend should not be started */
133 return TMFeOk();
134 }
135
136 TMFeResult HandleRpc(const char* cmd, const char* args, std::string& response)
137 {
138 /* handler for JRPC into the frontend, see tmfe_example_everything.cxx */
139 return TMFeOk();
140 }
141
143 {
144 /* put here clear scalers etc. */
145 return TMFeOk();
146 }
147
149 {
150 return TMFeOk();
151 }
152
154 {
155 /* Polling routine for events. Returns TRUE if event is available */
156 return true;
157 }
158
160 {
161 char buf[1024];
162 ComposeEvent(buf, sizeof(buf));
163 BkInit(buf, sizeof(buf));
164
165 /* create structured ADC0 bank */
166 uint32_t* pdata = (uint32_t*)BkOpen(buf, "ADC0", TID_UINT32);
167
168 /* following code to "simulates" some ADC data */
169 for (int a = 0; a < 4; a++)
170 *pdata++ = rand()%1024 + rand()%1024 + rand()%1024 + rand()%1024;
171
172 BkClose(buf, pdata);
173
174 /* create variable length TDC bank */
175 pdata = (uint32_t*)BkOpen(buf, "TDC0", TID_UINT32);
176
177 /* following code to "simulates" some TDC data */
178 for (int a = 0; a < 4; a++)
179 *pdata++ = rand()%1024 + rand()%1024 + rand()%1024 + rand()%1024;
180
181 BkClose(buf, pdata);
182
183 EqSendEvent(buf);
184 }
185};
186
188 public TMFeEquipment
189{
190public:
191 EqPeriodic(const char* eqname, const char* eqfilename) // ctor
193 {
194 /* configure your equipment here */
195
197 fEqConfEventID = 2;
198 fEqConfBuffer = "SYSTEM";
199 fEqConfPeriodMilliSec = 1000; // in milliseconds
203 }
204
206 {
207 char buf[1024];
208
209 ComposeEvent(buf, sizeof(buf));
210 BkInit(buf, sizeof(buf));
211
212 /* create SCLR bank */
213 uint32_t* pdata = (uint32_t*)BkOpen(buf, "PRDC", TID_UINT32);
214
215 /* following code "simulates" some values in sine wave form */
216 for (int a = 0; a < 16; a++)
217 *pdata++ = 100*sin(M_PI*time(NULL)/60+a/2.0)+100;
218
219 BkClose(buf, pdata);
220
221 EqSendEvent(buf);
222 }
223};
224
226{
227public:
228 FeExample() // ctor
229 {
230 /* register with the framework */
231 FeSetName("Sample Frontend");
232 FeAddEquipment(new EqTrigger("Trigger", __FILE__));
233 FeAddEquipment(new EqPeriodic("Periodic", __FILE__));
234 }
235
236 TMFeResult HandleFrontendInit(const std::vector<std::string>& args)
237 {
238 /* called before equipment HandleInit(), do all hardware initialization here */
239
240 printf("frontend init!\n");
241
242 return TMFeOk();
243 };
244
245 TMFeResult HandleFrontendReady(const std::vector<std::string>& args)
246 {
247 /* called after equipment HandleInit(), anything that needs to be done
248 * before starting the main loop goes here */
249
250 printf("frontend ready!\n");
251
252 /* start periodic and rpc threads here */
253
254 //fMfe->StartPeriodicThread();
255 //fMfe->StartRpcThread();
256
257 return TMFeOk();
258 };
259
261 {
262 /* hardware shutdown goes here */
263
264 printf("frontend exit!\n");
265 };
266};
267
268int main(int argc, char* argv[])
269{
271 return fe_example.FeMain(argc, argv);
272}
273
274/* emacs
275 * Local Variables:
276 * tab-width: 8
277 * c-basic-offset: 3
278 * indent-tabs-mode: nil
279 * End:
280 */
#define FALSE
Definition cfortran.h:309
EqPeriodic(const char *eqname, const char *eqfilename)
TMFeResult HandleEndRun(int run_number)
TMFeResult HandleInit(const std::vector< std::string > &args)
TMFeResult HandleBeginRun(int run_number)
EqTrigger(const char *eqname, const char *eqfilename)
TMFeResult HandleRpc(const char *cmd, const char *args, std::string &response)
TMFeResult HandleFrontendReady(const std::vector< std::string > &args)
TMFeResult HandleFrontendInit(const std::vector< std::string > &args)
void * BkOpen(char *pevent, const char *bank_name, int bank_type) const
Definition tmfe.cxx:2201
TMFeResult BkInit(char *pevent, size_t size) const
Definition tmfe.cxx:2195
bool fEqConfWriteEventsToOdb
Definition tmfe.h:197
uint16_t fEqConfEventID
Definition tmfe.h:171
double fEqConfPollSleepSec
Definition tmfe.h:199
int fEqConfPeriodMilliSec
Definition tmfe.h:178
TMFeResult BkClose(char *pevent, void *ptr) const
Definition tmfe.cxx:2208
int fEqConfLogHistory
Definition tmfe.h:181
TMFeResult ComposeEvent(char *pevent, size_t size) const
Definition tmfe.cxx:1995
TMFeResult EqSendEvent(const char *pevent, bool write_to_odb=true)
Definition tmfe.cxx:2006
bool fEqConfReadConfigFromOdb
Definition tmfe.h:168
bool fEqConfEnablePoll
Definition tmfe.h:166
std::string fEqConfBuffer
Definition tmfe.h:173
bool fEqConfReadOnlyWhenRunning
Definition tmfe.h:196
void FeSetName(const char *program_name)
Definition tmfe.cxx:1647
TMFeResult FeAddEquipment(TMFeEquipment *eq)
Definition tmfe.cxx:1600
int FeMain(int argc, char *argv[])
Definition tmfe.cxx:2279
INT read_periodic_event(char *pevent, INT off)
Definition frontend.cxx:208
INT read_trigger_event(char *pevent, INT off)
Event readout.
Definition feccusb.cxx:529
#define EQ_POLLED
Definition midas.h:415
#define RO_ODB
Definition midas.h:438
#define EQ_PERIODIC
Definition midas.h:414
#define TID_UINT32
Definition midas.h:337
#define RO_TRANSITIONS
Definition midas.h:434
#define RO_RUNNING
Definition midas.h:426
int main()
Definition hwtest.cxx:23
INT run_number[2]
Definition mana.cxx:246
char response[10000]
Definition melog.cxx:90
const char * frontend_file_name
The frontend file name, don't change it.
Definition feudp.cxx:23
BOOL equipment_common_overwrite
Definition feudp.cxx:50
const char * frontend_name
The frontend name (client name) as seen by other MIDAS clients.
Definition feudp.cxx:22
BOOL frontend_call_loop
Definition mfed.cxx:24
INT max_event_size
Definition mfed.cxx:30
INT event_buffer_size
Definition mfed.cxx:36
INT max_event_size_frag
Definition mfed.cxx:33
INT display_period
Definition mfed.cxx:27
DWORD BOOL
Definition midas.h:105
int INT
Definition midas.h:129
#define TRUE
Definition midas.h:182
#define equipment(name, id, type, source, readon, period, readout, cd, driver)
Definition midas_macro.h:60
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
TMFeResult TMFeOk()
Definition tmfe.h:106