MIDAS
Loading...
Searching...
No Matches
ebuser.cxx
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: ebuser.c
4 Created by: Pierre-Andre Amaudruz
5
6 Contents: User section for the Event builder
7
8 $Id$
9
10\********************************************************************/
15#include <stdio.h>
16#include <string.h>
17#include <stdlib.h> // atoi()
18#include "midas.h"
19#include "mevb.h"
20
21/* data type sizes */
22extern INT tid_size[];
23/*-- Globals -------------------------------------------------------*/
24
25/* The frontend name (client name) as seen by other MIDAS clients */
26const char *frontend_name = "Ebuilder";
27
28/* The frontend file name, don't change it */
29const char *frontend_file_name = __FILE__;
30
31/* frontend_loop is called periodically if this variable is TRUE */
33
34/* A frontend status page is displayed with this frequency in ms */
36
37/* maximum event size produced by this frontend */
39
40/* maximum event size for fragmented events (EQ_FRAGMENTED) */
41INT max_event_size_frag = 5 * 1024 * 1024;
42
43/* buffer size to hold events */
45
48INT lModulo = 100;
49
50/*-- Function declarations -----------------------------------------*/
53INT eb_begin_of_run(INT, char *, char *);
54INT eb_end_of_run(INT, char *);
56INT ebuser(INT, BOOL mismatch, EBUILDER_CHANNEL *, EVENT_HEADER *, void *, INT *);
57INT read_scaler_event(char *pevent, INT off);
59extern BOOL debug;
60
61/*-- Equipment list ------------------------------------------------*/
63 {"EB", /* equipment name */
64 {1, 0, /* event ID, trigger mask */
65 "SYSTEM", /* event buffer */
66 0, /* equipment type */
67 0, /* event source */
68 "MIDAS", /* format */
69 TRUE, /* enabled */
70 },
71 },
72
73 {""}
74};
75
76
77/********************************************************************/
78/********************************************************************/
80{
81 setbuf(stdout, NULL);
82 setbuf(stderr, NULL);
83 return EB_SUCCESS;
84}
85
86/********************************************************************/
88{
89 return EB_SUCCESS;
90}
91
92/********************************************************************/
94{
95 return EB_SUCCESS;
96}
97
98/********************************************************************/
106INT eb_begin_of_run(INT rn, char *UserField, char *error)
107{
108 printf("In eb_begin_of_run for run:%d User_field:%s \n", rn, UserField);
109 lModulo = atoi(UserField);
110 return EB_SUCCESS;
111}
112
113/********************************************************************/
121INT eb_end_of_run(INT rn, char *error)
122{
123 printf("In eb_end_of_run\n");
124 return EB_SUCCESS;
125}
126
127/********************************************************************/
193 , EVENT_HEADER * pheader, void *pevent, INT * dest_size)
194{
195 INT i, frag_size, serial, status;
196 DWORD *pdata;
197
198
199 //
200 // Do some extra fragment consistency check
201 if (mismatch){
202 printf("Serial number do not match across fragments\n");
203 for (i = 0; i < nfrag; i++) {
204 serial = ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
205 printf("Ser[%i]:%d ", i + 1, serial);
206 }
207 printf("\n");
208 return EB_USER_ERROR;
209 }
210
211 //
212 // Include my own bank
213 bk_init(pevent);
214 bk_create(pevent, "MYOW", TID_DWORD, (void**)&pdata);
215 for (i = 0; i < nfrag; i++) {
216 if (ebset.preqfrag[i]) { // if channel enable
217 *pdata++ = ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
218 *pdata++ = ((EVENT_HEADER *) ebch[i].pfragment)->time_stamp;
219 }
220 }
221 *dest_size = bk_close(pevent, pdata);
222 pheader->data_size = *dest_size + sizeof(EVENT_HEADER);
223
224 // Copy the bank TC01 if found from fragment0 to the destination
225 status = bk_copy((char*)pevent, ebch[0].pfragment, "TC01");
226 if (status == EB_BANK_NOT_FOUND) {
227 printf("bank TC01 not found\n");
228 }
229
230 // Destination access
231 // dest_serial = pheader->serial_number;
232 // printf("DSer#:%d ", dest_serial);
233
234 // Stop run if condition requires
235 // if (dest_serial == 505) return EB_USER_ERROR;
236
237 // Skip event if condition requires
238 // if (dest_serial == 505) return EB_SKIP;
239
240 //
241 // Loop over fragments.
242 if (debug) {
243 for (i = 0; i < nfrag; i++) {
244 if (1) {
245 if (ebset.preqfrag[i]) { // printf if channel enable
246 frag_size = ((EVENT_HEADER *) ebch[i].pfragment)->data_size;
247 serial = ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
248 printf("Frg#:%d Dsz:%d Ser:%d ", i, frag_size, serial);
249 // For Data fragment Access.
250 // psrcData = (DWORD *) (((EVENT_HEADER *) ebch[i].pfragment) + 1);
251 }
252 }
253 }
254 printf("\n");
255 }
256 return EB_SUCCESS;
257}
#define FALSE
Definition cfortran.h:309
const char * frontend_file_name
Definition ebuser.cxx:29
INT max_event_size
Definition ebuser.cxx:38
INT eb_user(INT nfrag, BOOL mismatch, EBUILDER_CHANNEL *ebch, EVENT_HEADER *pheader, void *pevent, INT *dest_size)
Definition ebuser.cxx:192
INT event_buffer_size
Definition ebuser.cxx:44
INT ebuser(INT, BOOL mismatch, EBUILDER_CHANNEL *, EVENT_HEADER *, void *, INT *)
INT max_event_size_frag
Definition ebuser.cxx:41
BOOL ebuilder_call_loop
Definition ebuser.cxx:32
INT ebuilder_loop()
Definition ebuser.cxx:93
EBUILDER_SETTINGS ebset
Definition mevb.cxx:34
BOOL debug
Definition mana.cxx:254
INT lModulo
Global var for testing passed at BOR.
Definition ebuser.cxx:48
INT tid_size[]
Definition mhdump.cxx:55
INT eb_end_of_run(INT, char *)
Definition ebuser.cxx:121
EQUIPMENT equipment[]
Definition ebuser.cxx:62
INT eb_begin_of_run(INT, char *, char *)
Definition ebuser.cxx:106
const char * frontend_name
Definition ebuser.cxx:26
INT display_period
Definition ebuser.cxx:35
INT ebuilder_exit()
Definition ebuser.cxx:87
INT ebuilder_init()
Definition ebuser.cxx:79
INT read_scaler_event(char *pevent, INT off)
Scaler event readout.
Definition ebfe.cxx:295
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
void bk_init(void *event)
Definition midas.cxx:16406
INT bk_copy(char *pevent, char *psrce, const char *bkname)
Definition midas.cxx:16604
void bk_create(void *event, const char *name, WORD type, void **pdata)
Definition midas.cxx:16561
unsigned int DWORD
Definition mcstd.h:51
#define TID_DWORD
Definition midas.h:336
INT i
Definition mdump.cxx:32
EBUILDER_CHANNEL ebch[MAX_CHANNELS]
Definition mevb.cxx:35
#define EB_BANK_NOT_FOUND
Definition mevb.h:63
#define EB_SUCCESS
Definition mevb.h:57
#define EB_USER_ERROR
Definition mevb.h:60
DWORD BOOL
Definition midas.h:105
int INT
Definition midas.h:129
#define TRUE
Definition midas.h:182
INT serial
Definition minife.c:20
INT rn
Definition mstat.cxx:30
DWORD status
Definition odbhist.cxx:39
BOOL * preqfrag
Definition mevb.h:32
DWORD data_size
Definition midas.h:856