MIDAS
Loading...
Searching...
No Matches
ebuser.cxx File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "midas.h"
#include "mevb.h"
Include dependency graph for ebuser.cxx:

Go to the source code of this file.

Functions

INT ebuilder_init ()
 
INT ebuilder_exit ()
 
INT eb_begin_of_run (INT, char *, char *)
 
INT eb_end_of_run (INT, char *)
 
INT ebuilder_loop ()
 
INT ebuser (INT, BOOL mismatch, EBUILDER_CHANNEL *, EVENT_HEADER *, void *, INT *)
 
INT read_scaler_event (char *pevent, INT off)
 Scaler event readout.
 
INT eb_user (INT nfrag, BOOL mismatch, EBUILDER_CHANNEL *ebch, EVENT_HEADER *pheader, void *pevent, INT *dest_size)
 

Variables

INT tid_size []
 
const charfrontend_name = "Ebuilder"
 
const charfrontend_file_name = __FILE__
 
BOOL ebuilder_call_loop = FALSE
 
INT display_period = 3000
 
INT max_event_size = 500000
 
INT max_event_size_frag = 5 * 1024 * 1024
 
INT event_buffer_size = 20 * 50000
 
INT lModulo = 100
 Global var for testing passed at BOR.
 
EBUILDER_SETTINGS ebset
 
BOOL debug
 
EQUIPMENT equipment []
 

Function Documentation

◆ eb_begin_of_run()

INT eb_begin_of_run ( INT  rn,
char UserField,
char error 
)

Hook to the event builder task at PreStart transition.

Parameters
rnrun number
UserFieldargument from /Ebuilder/Settings
errorerror string to be passed back to the system.
Returns
EB_SUCCESS

Definition at line 106 of file ebuser.cxx.

107{
108 printf("In eb_begin_of_run for run:%d User_field:%s \n", rn, UserField);
110 return EB_SUCCESS;
111}
INT lModulo
Global var for testing passed at BOR.
Definition ebuser.cxx:48
#define EB_SUCCESS
Definition mevb.h:57
INT rn
Definition mstat.cxx:30
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the caller graph for this function:

◆ eb_end_of_run()

INT eb_end_of_run ( INT  rn,
char error 
)

Hook to the event builder task at completion of event collection after receiving the Stop transition.

Parameters
rnrun number
errorerror string to be passed back to the system.
Returns
EB_SUCCESS

Definition at line 121 of file ebuser.cxx.

122{
123 printf("In eb_end_of_run\n");
124 return EB_SUCCESS;
125}
Here is the caller graph for this function:

◆ eb_user()

INT eb_user ( INT  nfrag,
BOOL  mismatch,
EBUILDER_CHANNEL ebch,
EVENT_HEADER pheader,
void pevent,
INT dest_size 
)

Hook to the event builder task after the reception of all fragments of the same serial number. The destination event has already the final EVENT_HEADER setup with the data size set to 0. It is than possible to add private data at this point using the proper bank calls. Therefore any new banks created within eb_user will be appearing before the collected banks from the fragments. When using the eb_user with the ODB flag "user build=y" (equipments/EB/settings) the automatic event builder is skipped. This allow the user to extract selectively from the different fragments the appropriate banks and compose the final destination event. In order to do so, the function "bk_copy(pevent, ebch[i].pfragment, bankname)" will copy a particular bank from a given fragment.

Note: It exists two Midas event format to address bank size less than 32KB and larger bank size <4GB. This distinction is done by the call bk_init(pevent) for the small bank size and bk_init32(pevent) for large bank size. Within an experiment, this declaration has to be consistant. Therefore the bk_init in the eb_user should follow as well the type of the frontends.

The ebch[] array structure points to nfragment channel structure with the following content:

typedef struct {
char name[32]; // Fragment name (Buffer name).
DWORD serial; // Serial fragment number.
char *pfragment; // Pointer to fragment (EVENT_HEADER *)
...
unsigned int DWORD
Definition mcstd.h:51
#define name(x)
Definition midas_macro.h:24
INT serial
Definition minife.c:20

The correct code for including your own MIDAS bank is shown below where TID_xxx is one of the valid Bank type starting with TID_ for midas format bank_name is a 4 character descriptor. pdata has to be declared accordingly with the bank type. Refers to the ebuser.c source code for further description.

It is not possible to mix within the same destination event different event format! No bk_swap performed when user build is requested.

// Event is empty, fill it with BANK_HEADER
// If you need to add your own bank at this stage
// Need to match the decalration in the Frontends.
bk_init(pevent);
// bk_init32(pevent);
*pdata++ = ...;
*dest_size = bk_close(pevent, pdata);
pheader->data_size = *dest_size + sizeof(EVENT_HEADER);
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
void bk_init(void *event)
Definition midas.cxx:16406
void bk_create(void *event, const char *name, WORD type, void **pdata)
Definition midas.cxx:16561
char bank_name[4]
Definition mdump.cxx:26
Parameters
nfragNumber of fragment.
mismatchMidas Serial number mismatch flag.
ebchStructure to all the fragments.
pheaderDestination pointer to the header.
peventDestination pointer to the bank header.
dest_sizeDestination event size in bytes.
Returns
EB_SUCCESS

Definition at line 192 of file ebuser.cxx.

194{
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}
EBUILDER_SETTINGS ebset
Definition mevb.cxx:34
BOOL debug
Definition mana.cxx:254
INT bk_copy(char *pevent, char *psrce, const char *bkname)
Definition midas.cxx:16604
#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_USER_ERROR
Definition mevb.h:60
int INT
Definition midas.h:129
DWORD status
Definition odbhist.cxx:39
BOOL * preqfrag
Definition mevb.h:32
DWORD data_size
Definition midas.h:856
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ebuilder_exit()

INT ebuilder_exit ( void  )

Definition at line 87 of file ebuser.cxx.

88{
89 return EB_SUCCESS;
90}
Here is the caller graph for this function:

◆ ebuilder_init()

INT ebuilder_init ( void  )

Definition at line 79 of file ebuser.cxx.

80{
83 return EB_SUCCESS;
84}
Here is the caller graph for this function:

◆ ebuilder_loop()

INT ebuilder_loop ( void  )

Definition at line 93 of file ebuser.cxx.

94{
95 return EB_SUCCESS;
96}

◆ ebuser()

INT ebuser ( INT  ,
BOOL  mismatch,
EBUILDER_CHANNEL ,
EVENT_HEADER ,
void ,
INT  
)

◆ read_scaler_event()

INT read_scaler_event ( char pevent,
INT  off 
)

Scaler event readout.

Scaler event readout routine. Not used in this example.

Parameters
[in]peventPointer to event buffer
[in]offCaller info (unused here), see mfe.c
Returns
Size of the event

Definition at line 295 of file ebfe.cxx.

296{
297 DWORD *pdata, a;
298
299 /* init bank structure */
300 bk_init(pevent);
301
302 /* create SCLR bank */
303 bk_create(pevent, Sclx, TID_DWORD, (void**)&pdata);
304
305 /* read scaler bank */
306 for (a = 0; a < N_SCLR; a++)
307 cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);
308
309 bk_close(pevent, pdata);
310
311 return bk_size(pevent);
312}
#define SLOT_SCLR
Definition ebfe.cxx:63
char Sclx[5]
Definition ebfe.cxx:51
#define N_SCLR
Definition ebfe.cxx:56
#define CRATE
Definition ebfe.cxx:59
INT bk_size(const void *event)
Definition midas.cxx:16495
EXTERNAL void EXPRT cam24i(const int c, const int n, const int a, const int f, DWORD *d)

Variable Documentation

◆ debug

BOOL debug
extern

Definition at line 254 of file mana.cxx.

◆ display_period

INT display_period = 3000

Definition at line 35 of file ebuser.cxx.

◆ ebset

EBUILDER_SETTINGS ebset
extern

Definition at line 34 of file mevb.cxx.

◆ ebuilder_call_loop

BOOL ebuilder_call_loop = FALSE

Definition at line 32 of file ebuser.cxx.

◆ equipment

EQUIPMENT equipment[]
Initial value:
= {
{"EB",
{1, 0,
"SYSTEM",
0,
0,
"MIDAS",
TRUE,
},
},
{""}
}
#define TRUE
Definition midas.h:182

Definition at line 62 of file ebuser.cxx.

62 {
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};

◆ event_buffer_size

INT event_buffer_size = 20 * 50000

Definition at line 44 of file ebuser.cxx.

◆ frontend_file_name

const char* frontend_file_name = __FILE__

Definition at line 29 of file ebuser.cxx.

◆ frontend_name

const char* frontend_name = "Ebuilder"

Definition at line 26 of file ebuser.cxx.

◆ lModulo

INT lModulo = 100

Global var for testing passed at BOR.

Globals

Definition at line 48 of file ebuser.cxx.

◆ max_event_size

INT max_event_size = 500000

Definition at line 38 of file ebuser.cxx.

◆ max_event_size_frag

INT max_event_size_frag = 5 * 1024 * 1024

Definition at line 41 of file ebuser.cxx.

◆ tid_size

INT tid_size[]
extern

Definition at line 55 of file mhdump.cxx.

55 {
56 0, /* tid == 0 not defined */
57 1, /* TID_BYTE unsigned byte 0 255 */
58 1, /* TID_SBYTE signed byte -128 127 */
59 1, /* TID_CHAR single character 0 255 */
60 2, /* TID_WORD two bytes 0 65535 */
61 2, /* TID_SHORT signed word -32768 32767 */
62 4, /* TID_DWORD four bytes 0 2^32-1 */
63 4, /* TID_INT signed dword -2^31 2^31-1 */
64 4, /* TID_BOOL four bytes bool 0 1 */
65 4, /* TID_FLOAT 4 Byte float format */
66 8, /* TID_DOUBLE 8 Byte float format */
67 1, /* TID_BITFIELD 8 Bits Bitfield 00000000 11111111 */
68 0, /* TID_STRING zero terminated string */
69 0, /* TID_ARRAY variable length array of unkown type */
70 0, /* TID_STRUCT C structure */
71 0, /* TID_KEY key in online database */
72 0, /* TID_LINK link in online database */
73 8, /* TID_INT64 8 bytes int -2^63 2^63-1 */
74 8 /* TID_UINT64 8 bytes unsigned int 0 2^64-1 */
75};