AlcapDAQ  1
Macros | Functions | Variables
ebuser.cpp File Reference
#include <stdio.h>
#include "midas.h"
#include "mevb.h"
#include "ybos.h"
#include "mucap_compress.h"

Go to the source code of this file.

Macros

#define NUMCRATES   5
 

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)
 
INT eb_user (INT nfrag, BOOL mismatch, EBUILDER_CHANNEL *ebch, EVENT_HEADER *pheader, void *pevent, INT *dest_size)
 

Variables

char * frontend_name = "Ebuilder"
 
char * frontend_file_name = __FILE__
 
BOOL ebuilder_call_loop = FALSE
 
INT display_period = 3000
 
INT max_event_size = MAX_EVENT_SIZE
 
INT max_event_size_frag = MAX_EVENT_SIZE
 
INT event_buffer_size = EVENT_BUFFER_SIZE
 
INT lModulo = 100
 Global var for testing. More...
 
EQUIPMENT equipment []
 

Macro Definition Documentation

#define NUMCRATES   5

Definition at line 63 of file ebuser.cpp.

Referenced by eb_begin_of_run().

Function Documentation

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
eb_begin_of_run()

Hook to the event builder task at PreStart transition. {verbatim} {verbatim}

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

Definition at line 145 of file ebuser.cpp.

Referenced by tr_prestart(), and tr_start().

146 {
147 #if 0
148  extern EBUILDER_SETTINGS ebset;
150  extern HNDLE hDB;
151 
152  int n;
153  int mask = 0;
154 
155  char keyName[256];
156  BOOL enabled;
157  int size;
158 
159  /*
160  * Determine which crates are enabled and set up the mask
161  * accordingly.
162  */
163  for(n = 1; n <= NUMCRATES; n++) {
164  sprintf(keyName, "/Equipment/Crate %d/Settings/Enabled", n);
165  size = sizeof(enabled);
166  db_get_value(hDB, 0, keyName, &enabled, &size, TID_BOOL, FALSE);
167  if(size == sizeof(enabled) && enabled) {
168  ebch[n-1].trigger_mask = (1 << (n-1));
169  mask |= ebch[n-1].trigger_mask;
170  } else {
171  ebch[n-1].trigger_mask = 0;
172  }
173  }
174 
175  cm_msg(MINFO, "eb_begin_of_run", "Setting event mask to 0x%x", mask);
176  ebset.trigger_mask = mask;
177 #endif
178 
179  // Initialize online compression
181 
182  return EB_SUCCESS;
183 }
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
eb_end_of_run()

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

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

Definition at line 193 of file ebuser.cpp.

Referenced by close_buffers(), and main().

194 {
195  return EB_SUCCESS;
196 }
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.

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 *)
...

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 or xxx_BKTYPE for Ybos data 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!

// Event is empty, fill it with BANK_HEADER
// If you need to add your own bank at this stage
bk_init(pevent);
bk_create(pevent, bank_name, TID_xxxx, &pdata);
pdata++ = ...;
dest_size = bk_close(pevent, pdata);
pheader->data_size = *dest_size + sizeof(EVENT_HEADER);

For YBOS format, use the following example.

ybk_init(pevent);
ybk_create(pevent, "EBBK", I4_BKTYPE, &pdata);
pdata++ = 0x12345678;
pdata++ = 0x87654321;
dest_size = ybk_close(pevent, pdata);
dest_size *= 4;
pheader->data_size = *dest_size + sizeof(YBOS_BANK_HEADER);
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 259 of file ebuser.cpp.

References compress_event(), EB_SUCCESS, EB_USER_ERROR, i, EBUILDER_CHANNEL::pfragment, and printf().

Referenced by source_scan().

261 {
262  if (mismatch){
263  printf("Serial number do not match across fragments\n");
264  for (int i = 0; i < nfrag; i++) {
265  int serial = ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
266  printf("Ser[%i]:%d ", i + 1, serial);
267  }
268  printf("\n");
269  return EB_USER_ERROR;
270  }
271 
272  // Initialize output event
273  bk_init32(pevent);
274 
275  // Loop over the event fragments, performing compression into the output event
276  for(int i = 0; i < nfrag; i++) {
277  void *fragment = ebch[i].pfragment;
278 
279  if(fragment != NULL) {
280  compress_event(((EVENT_HEADER *) fragment) + 1, pevent);
281  pheader->serial_number =
282  ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
283  }
284  }
285 
286  // Set the size of the output event properly
287  pheader->data_size = *dest_size = bk_size(pevent);
288 
289  // printf("Returning size %d\n", pheader->data_size);
290 
291  return EB_SUCCESS;
292 
293 }
INT ebuilder_exit ( void  )

Definition at line 126 of file ebuser.cpp.

References EB_SUCCESS.

Referenced by main().

127 {
128  return EB_SUCCESS;
129 }
INT ebuilder_init ( void  )

Definition at line 120 of file ebuser.cpp.

References EB_SUCCESS.

Referenced by main().

121 {
122  return EB_SUCCESS;
123 }
INT ebuilder_loop ( void  )

Definition at line 132 of file ebuser.cpp.

References EB_SUCCESS.

133 {
134  return EB_SUCCESS;
135 }
INT ebuser ( INT  ,
BOOL  mismatch,
EBUILDER_CHANNEL ,
EVENT_HEADER *  ,
void *  ,
INT *   
)
INT read_scaler_event ( char *  pevent,
INT  off 
)

Variable Documentation

INT display_period = 3000

Definition at line 77 of file ebuser.cpp.

BOOL ebuilder_call_loop = FALSE

Definition at line 74 of file ebuser.cpp.

EQUIPMENT equipment[]
Initial value:
= {
{"EB",
{1, 0,
"SYSTEM",
0,
0,
"MIDAS",
TRUE,
},
},
{""}
}

Definition at line 102 of file ebuser.cpp.

INT event_buffer_size = EVENT_BUFFER_SIZE

Definition at line 86 of file ebuser.cpp.

char* frontend_file_name = __FILE__

Definition at line 71 of file ebuser.cpp.

char* frontend_name = "Ebuilder"

Definition at line 68 of file ebuser.cpp.

INT lModulo = 100

Global var for testing.

Globals

Definition at line 90 of file ebuser.cpp.

INT max_event_size = MAX_EVENT_SIZE

Definition at line 80 of file ebuser.cpp.

INT max_event_size_frag = MAX_EVENT_SIZE

Definition at line 83 of file ebuser.cpp.