MIDAS
Loading...
Searching...
No Matches
feslow.cxx
Go to the documentation of this file.
1/*******************************************************************\
2
3 Name: fedummy.c
4 Created by: K.Olchanski
5
6 Contents: Front end for creating dummy data
7
8\********************************************************************/
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <unistd.h>
13#include <stdint.h>
14#include <sys/time.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <fcntl.h>
18#include <errno.h>
19#include <math.h>
20#include <ctype.h>
21#include <assert.h>
22
23#include "midas.h"
24
25#define FE_NAME "feslow"
26#define EQ_NAME "Slow"
27#define EQ_EVID 1
28
29/* make frontend functions callable from the C framework */
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/*-- Globals -------------------------------------------------------*/
35
36/* The frontend name (client name) as seen by other MIDAS clients */
38
39/* The frontend file name, don't change it */
41
42/* frontend_loop is called periodically if this variable is TRUE */
44
45/* a frontend status page is displayed with this frequency in ms */
46//INT display_period = 3000;
48
49/* maximum event size produced by this frontend */
52
53/* buffer size to hold events */
55
56/*-- Function declarations -----------------------------------------*/
57
60INT begin_of_run(INT run_number, char *error);
61INT end_of_run(INT run_number, char *error);
62INT pause_run(INT run_number, char *error);
63INT resume_run(INT run_number, char *error);
65
68
69int read_slow_event(char *pevent, int off);
70
71/*-- Equipment list ------------------------------------------------*/
72
74
75 { EQ_NAME, /* equipment name */
76 {
77 EQ_EVID, (1<<EQ_EVID), /* event ID, trigger mask */
78 "SYSTEM", /* event buffer */
79 EQ_PERIODIC, /* equipment type */
80 0, /* event source */
81 "MIDAS", /* format */
82 TRUE, /* enabled */
83 RO_RUNNING|RO_STOPPED|RO_PAUSED|RO_ODB, /* When to read */
84 1000, /* poll every so milliseconds */
85 0, /* stop run after this event limit */
86 0, /* number of sub events */
87 1, /* history period*/
88 "", "", ""
89 },
90 read_slow_event, /* readout routine */
91 },
92 { "" }
93};
94
95#ifdef __cplusplus
96}
97#endif
98
99/********************************************************************\
100 Callback routines for system transitions
101
102 These routines are called whenever a system transition like start/
103 stop of a run occurs. The routines are called on the following
104 occations:
105
106 frontend_init: When the frontend program is started. This routine
107 should initialize the hardware.
108
109 frontend_exit: When the frontend program is shut down. Can be used
110 to releas any locked resources like memory, commu-
111 nications ports etc.
112
113 begin_of_run: When a new run is started. Clear scalers, open
114 rungates, etc.
115
116 end_of_run: Called on a request to stop a run. Can send
117 end-of-run event and close run gates.
118
119 pause_run: When a run is paused. Should disable trigger events.
120
121 resume_run: When a run is resumed. Should enable trigger events.
122
123\********************************************************************/
124
126
127static int configure()
128{
129 int size, status;
130
131 //size = sizeof(int);
132 //status = db_get_value(hDB, 0, "/Equipment/" EQ_NAME "/Settings/event_size", &event_size, &size, TID_INT, TRUE);
133 //printf("Event size set to %d bytes\n", event_size);
134
135 return SUCCESS;
136}
137
138/*-- Frontend Init -------------------------------------------------*/
139
141{
142 //cm_set_watchdog_params (FALSE, 0);
143
144 configure();
145
146 return SUCCESS;
147}
148
149/*-- Frontend Exit -------------------------------------------------*/
150
152{
153 return SUCCESS;
154}
155
156/*-- Begin of Run --------------------------------------------------*/
157
159{
160 printf("Begin run %d\n", run_number);
162
163 configure();
164
165 count_slow = 0;
166
167 return SUCCESS;
168}
169
170/*-- End of Run ----------------------------------------------------*/
171
173{
174 printf("End run %d!\n", run_number);
175
176 cm_msg(MINFO, frontend_name, "read %d slow events", count_slow);
177
178 return SUCCESS;
179}
180
181/*-- Pause Run -----------------------------------------------------*/
182
184{
185 return SUCCESS;
186}
187
188/*-- Resume Run ----------------------------------------------------*/
189
191{
192 return SUCCESS;
193}
194
195/*-- Frontend Loop -------------------------------------------------*/
196
198{
199 /* if frontend_call_loop is true, this routine gets called when
200 the frontend is idle or once between every event */
201 //printf("frontend_loop!\n");
202 ss_sleep(10);
203 return SUCCESS;
204}
205
206/*------------------------------------------------------------------*/
207
208/********************************************************************\
209
210 Readout routines for different events
211
212\********************************************************************/
213
214extern "C" INT poll_event(INT source, INT count, BOOL test)
215/* Polling routine for events. Returns TRUE if event
216 is available. If test equals TRUE, don't return. The test
217 flag is used to time the polling */
218{
219 if (test) {
220 ss_sleep (count);
221 }
222 return (0);
223}
224
225/*-- Interrupt configuration ---------------------------------------*/
226
227extern "C" INT interrupt_configure(INT cmd, INT source, PTYPE adr)
228{
229 switch(cmd)
230 {
232 break;
234 break;
236 break;
238 break;
239 }
240 return SUCCESS;
241}
242
243/*-- Event readout -------------------------------------------------*/
244
245double get_time()
246{
247 struct timeval tv;
249 return tv.tv_sec + 0.000001*tv.tv_usec;
250}
251
252int read_slow_event(char *pevent, int off)
253{
254 bk_init32(pevent);
255
256 count_slow++;
257
258 if ((count_slow%2) == 0) {
259 double* pdatad;
260 bk_create(pevent, "SIN2", TID_DOUBLE, &pdatad);
261
262 time_t t = time(NULL);
263 pdatad[0] = count_slow;
264 pdatad[1] = t;
265 pdatad[2] = 100.0*sin(M_PI*t/60);
266 printf("time %d, data %f\n", (int)t, pdatad[2]);
267
268 bk_close(pevent, pdatad + 3);
269 }
270
271 if ((count_slow%3) == 0) {
272 double* pdatad;
273 bk_create(pevent, "COS3", TID_DOUBLE, &pdatad);
274
275 time_t t = time(NULL);
276 pdatad[0] = count_slow;
277 pdatad[1] = t;
278 pdatad[2] = 100.0*cos(M_PI*t/60);
279 printf("time %d, data %f\n", (int)t, pdatad[2]);
280
281 bk_close(pevent, pdatad + 3);
282 }
283
284 return bk_size(pevent);
285}
286
287// end file
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 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
#define SUCCESS
Definition mcstd.h:54
#define RO_STOPPED
Definition midas.h:427
#define TID_DOUBLE
Definition midas.h:343
#define RO_ODB
Definition midas.h:438
#define EQ_PERIODIC
Definition midas.h:414
#define MINFO
Definition midas.h:560
#define RO_PAUSED
Definition midas.h:428
#define RO_RUNNING
Definition midas.h:426
INT ss_sleep(INT millisec)
Definition system.cxx:3628
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:915
BOOL frontend_call_loop
Definition feslow.cxx:43
#define EQ_NAME
Definition feslow.cxx:26
INT max_event_size
Definition feslow.cxx:50
INT frontend_exit()
Frontend exit.
Definition feslow.cxx:151
int read_slow_event(char *pevent, int off)
Definition feslow.cxx:252
INT frontend_init()
Frontend initialization.
Definition feslow.cxx:140
INT event_buffer_size
Definition feslow.cxx:54
INT max_event_size_frag
Definition feslow.cxx:51
INT interrupt_configure(INT cmd, INT source, PTYPE adr)
Definition feslow.cxx:227
int count_slow
Definition feslow.cxx:125
INT poll_event(INT source, INT count, BOOL test)
Definition feslow.cxx:214
#define FE_NAME
Definition feslow.cxx:25
EQUIPMENT equipment[]
Definition feslow.cxx:73
HNDLE hDB
main ODB handle
Definition feslow.cxx:66
INT display_period
Definition feslow.cxx:47
char * frontend_name
Definition feslow.cxx:37
char * frontend_file_name
Definition feslow.cxx:40
#define EQ_EVID
Definition feslow.cxx:27
INT begin_of_run(INT run_number, char *error)
Begin of Run.
Definition feslow.cxx:158
INT frontend_loop()
Frontend loop.
Definition feslow.cxx:197
INT end_of_run(INT run_number, char *error)
End of Run.
Definition feslow.cxx:172
INT gbl_run_number
Definition feslow.cxx:67
double get_time()
Definition feslow.cxx:245
static int configure()
Definition feslow.cxx:127
INT run_number[2]
Definition mana.cxx:246
double count
Definition mdump.cxx:33
INT HNDLE
Definition midas.h:132
DWORD BOOL
Definition midas.h:105
int INT
Definition midas.h:129
#define PTYPE
Definition midas.h:170
#define TRUE
Definition midas.h:182
#define resume_run
#define pause_run
program test
Definition miniana.f:6
int gettimeofday(struct timeval *tp, void *tzp)
timeval tv
Definition msysmon.cxx:1095
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