ebuser.c File Reference


Detailed Description

The Event builder user file

Definition in file ebuser.c.

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)
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 = 10000
INT max_event_size_frag = 5 * 1024 * 1024
INT event_buffer_size = 10 * 10000
INT lModulo = 100
EBUILDER_SETTINGS ebset
BOOL debug
EQUIPMENT equipment []


Function Documentation

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

Hook to the event builder task at PreStart transition.

Parameters:
rn run number
UserField argument from /Ebuilder/Settings
error error string to be passed back to the system.
Returns:
EB_SUCCESS

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:
rn run number
error error string to be passed back to the system.
Returns:
EB_SUCCESS

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 *)
    ...
} EBUILDER_CHANNEL;

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_size(pevent) + sizeof(EVENT_HEADER);
  pheader->data_size = bk_size(pevent);

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;
Parameters:
nfrag Number of fragment.
mismatch Midas Serial number mismatch flag.
ebch Structure to all the fragments.
pheader Destination pointer to the header.
pevent Destination pointer to the bank header.
dest_size Destination event size in bytes.
Returns:
EB_SUCCESS

Definition at line 188 of file ebuser.c.

00190 {
00191   INT i, frag_size, serial;
00192   DWORD *psrcData;
00193   DWORD  *pdata;
00194 
00195   //
00196   // Do some extra fragment consistency check
00197   if (mismatch){
00198     printf("Serial number do not match across fragments\n");
00199     for (i = 0; i < nfrag; i++) {
00200       serial = ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
00201       printf("Ser[%i]:%d ", i + 1, serial);
00202     }
00203     printf("\n");
00204     return EB_USER_ERROR;
00205   }
00206 
00207   //
00208   // Include my own bank
00209   bk_init(pevent);
00210   bk_create(pevent, "MYOW", TID_DWORD, &pdata);
00211   for (i = 0; i < nfrag; i++) {
00212     *pdata++ = ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
00213     *pdata++ = ((EVENT_HEADER *) ebch[i].pfragment)->time_stamp;
00214   }
00215   *dest_size = bk_size(pevent) + sizeof(EVENT_HEADER);
00216   pheader->data_size = bk_size(pevent);
00217 
00218 
00219   //
00220   // Destination access
00221   // dest_serial = pheader->serial_number;
00222   // printf("DSer#:%d ", dest_serial);
00223 
00224   // Stop run if condition requires
00225   // if (dest_serial == 505) return EB_USER_ERROR;
00226 
00227   // Skip event if condition requires
00228   // if (dest_serial == 505) return EB_SKIP;
00229 
00230   //
00231   // Loop over fragments.
00232   if (debug) {
00233     for (i = 0; i < nfrag; i++) {
00234       if (ebset.preqfrag[i]) { // printf if channel enable
00235         frag_size = ((EVENT_HEADER *) ebch[i].pfragment)->data_size;
00236         serial = ((EVENT_HEADER *) ebch[i].pfragment)->serial_number;
00237         printf("Frg#:%d Dsz:%d Ser:%d ", i + 1, frag_size, serial);
00238         // For Data fragment Access.
00239         psrcData = (DWORD *) (((EVENT_HEADER *) ebch[i].pfragment) + 1);
00240       }
00241     }
00242     printf("\n");
00243   }
00244   return EB_SUCCESS;
00245 }

INT ebuilder_exit (  ) 

INT ebuilder_init (  ) 

INT ebuilder_loop (  ) 

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

INT read_scaler_event ( char *  pevent,
INT  off 
)

Definition at line 339 of file frontend.c.

00340 {
00341    DWORD *pdata, a;
00342 
00343    /* init bank structure */
00344    bk_init(pevent);
00345 
00346    /* create SCLR bank */
00347    bk_create(pevent, "SCLR", TID_DWORD, &pdata);
00348 
00349    /* read scaler bank */
00350    for (a = 0; a < N_SCLR; a++)
00351       cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);
00352 
00353    bk_close(pevent, pdata);
00354 
00355    return bk_size(pevent);
00356 }


Variable Documentation

BOOL debug

Definition at line 65 of file mfe.c.

INT display_period = 3000

Definition at line 32 of file ebuser.c.

EBUILDER_SETTINGS ebset

Definition at line 29 of file mevb.c.

Referenced by eb_user(), handFlush(), main(), source_booking(), source_scan(), and tr_start().

BOOL ebuilder_call_loop = FALSE

Definition at line 29 of file ebuser.c.

EQUIPMENT equipment[]

Initial value:

 {
   {"EB",                
    {1, 1,                   
     "SYSTEM",               
     0,                      
     0,                      
     "MIDAS",                
     TRUE,                   
     },
    },

  {""}
}

Definition at line 59 of file ebuser.c.

INT event_buffer_size = 10 * 10000

Definition at line 41 of file ebuser.c.

char* frontend_file_name = __FILE__

Definition at line 26 of file ebuser.c.

char* frontend_name = "Ebuilder"

Definition at line 23 of file ebuser.c.

INT lModulo = 100

Global var for testing passed at BOR.

Globals

Definition at line 45 of file ebuser.c.

Referenced by build_log_list(), and eb_begin_of_run().

INT max_event_size = 10000

Definition at line 35 of file ebuser.c.

INT max_event_size_frag = 5 * 1024 * 1024

Definition at line 38 of file ebuser.c.


Midas DOC Version 3.0.0 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk