Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#ifndef _EVENT_H_
#define _EVENT_H_
#ifdef COMMENT
/*--------------------------------------------------------------------------*
 *                                                                          *
 *              HERA-B  Online  Event  Format  Structures                   *
 *                                                                          *
 *                                                                          *
 *    Hera-B events are are formatted online as described in the memo:      *
 *    "Protocols & Data Formats in Hera-B" available on the DAQ-Notes       *
 *    WWW page. The format consisted of one or more nested data blocks      *
 *    as illustrated below. Each block contains a header, a data field      *
 *    and a trailer. The data field of many blocks (e.g. Event and SLB      *
 *    blocks) is composed of additional block of similar format. For        *
 *    example, the data portion of an SLB block consists of one or more     *
 *    FED blocks. This is illustrated in the following example, where       *
 *    EVTH/EVTT are the event header/trailer, SLBH/SLBT are the SLB         *
 *    block header/trailer and FEDH is the SLB sub-block.                   *
 *                                                                          *
 *       +---+---+---+-...-+---+-...-+---+---+-...-+---+---+                *
 *       | E | S | F |  d  | F |  d  | S | S |     | S | E |                *
 *       | V | L | E |  a  | E |  a  | L | L |     | L | V |                *
 *       | T | B | D |  t  | D |  t  | B | B |     | B | T |                *
 *       | H | H | H |  a  | H |  a  | T | H |     | T | T |                *
 *       +---+---+---+-...-+---+-...-+---+---+-...-+---+---+                *
 *                                                                          *
 *    Block alignment:                                                      *
 *    SLB and Event level blocks are aligned on a long word boundaries.     *
 *    If an SLB block has a length that is not a multiple of 4, the         *
 *    header length field will reflect this fact, but the following block   *
 *    will not start until the next 4-byte boundary. The FED sub-blocks     *
 *    within the SLB block also have long-word alignment. The length        *
 *    field of the FED sub-block does not include any additional padding    *
 *    to expand the field length. Padding bytes are undefined, but it is    *
 *    recommended that they be filled with zeroes.                          *
 *                                                                          *
 *--------------------------------------------------------------------------*/

#endif

#ifdef __cplusplus
extern "C" {
#endif

/*********************************
 *
 *    Record IDs -
 *
 *    Note: The definition of most record IDs are specific to the
 *          individual components i.e. the record type is uniquely
 *          identified by the combination of the component ID and
 *          the record ID. The record IDs are therefore left to the
 *          disgression of the detector groups. The IDs listed here
 *          are those used by the central DAQ, and several suggested
 *
 *********************************/

#define RID_MASK_ERROR      0x8000     /* Error in Record */
#define RID_NORMAL_EVENT    0x3000     /* Normal/error event envelope  */
#define RID_ERROR_EVENT     0xb000     /* - with error */
#define RID_NORMAL_SLB0     0x2000     /* Normal standard SLB    */
#define RID_ERROR_SLB0      0xa000     /* - with error */
#define RID_SPARSE_SLB0     0x2001     /* - with sparse data  */
#define RID_NORMAL_SLBDBG   0x2800     /* Addidtional SLB record for debugging */
#define RID_ERROR_SLBDBG    0xa800     /* - with error */
#define RID_SPARSE_SLBDBG   0x2801     /* - with sparse data */
#define RID_NORMAL_FEDRAW   0x1000     /* Normal/Error raw FED data    */
#define RID_ERROR_FEDRAW    0x9000     /*       (component dependent)  */
#define RID_NORMAL_DEFAULT_SPARSE   0x100A     /* Normal/Error sparsified data */
#define RID_NORMAL_SPARSE   0x1001     /* Normal/Error sparsified data */
#define RID_ERROR_SPARSE    0x9001     /*       (component dependent)  */
#define RID_NORMAL_FEDDBG   0x1800     /* Normal/Error raw FED data    */
#define RID_ERROR_FEDDBG    0x9800     /*       (component dependent)  */
#define RID_SPARSE_FEDDBG   0x1801     /* Normal/Error sparsified data */
#define RID_NORMAL_COOKED   0x1002     /* Normal/Error cooked FED data */
#define RID_ERROR_COOKED    0x9002     /*       (component dependent)  */
/****************
* Error Masks -
* Note: The mask will be non-zero on error
*       if the data given is in import format
*       This is basically a bit test for the first bit
*********************/

#define RID_ERROR_MASK(i) (((i)&0x8000)?(i):0)
#define RID_MASK_FEDRAW(i) RID_ERROR_MASK(i)
#define RID_MASK_EVENT(i)  RID_ERROR_MASK(i)
#define RID_MASK_SLB0(i)   RID_ERROR_MASK(i)
#define RID_MASK_SPARSE(i) RID_ERROR_MASK(i)
#define RID_MASK_COOKED(i) RID_ERROR_MASK(i)
/*********************************
 *
 *    Event record format format
 *
 *********************************/

struct EVENT_HDR {
  int length;             /* event length including header and trailer            */
  unsigned short recid;   /* event block ID (0x3000 - 0x3fff)                     */
  short format;           /* format identifier                                    */
  int   sltevt;           /* second level trigger number                          */
  int   compmask;         /* component mask (defined in component.h)              */
  int   evtmask;          /* event mask (trigger code, or etc.)                   */
};

typedef struct EVENT_HDR envelope;     /* for backwards compatibility */
typedef struct EVENT_HDR EVENT_HDR;

struct EVENT_TAIL {
  int sltevt;};           /* second level trigger number                 */

typedef struct EVENT_TAIL EVENT_TAIL;

#define RUNTYPE(ptr)  (((struct EVENT_HDR *) ptr)->evtmask >> 16)
#define RUNTYPEI(ptr) (import_i(((struct EVENT_HDR *) ptr)->evtmask) >> 16)

/*********************************
 *
 *    SLB data block format
 *
 *********************************/


struct SLB_HDR {
  int   length;           /* SLB block length including header and trailer */
  unsigned short recid;   /* SLB record ID (0x2000 - 0x2fff)               */
  short fltevt;           /* FLT event number                              */
  short compid;           /* component id (defined in component.h)         */
  short slbid;            /* identified of the SLB generating this block   */
  int   nodeid;};         /* destination node                              */

typedef struct SLB_HDR slbrec;        /* for backwards compatibility       */
typedef struct SLB_HDR SLB_HDR;

struct SLB_SUBHDR {
  short length;           /* FED block length including header and trailer */
  short fedid;            /* ID of FED producing this block                */
  unsigned short recid;   /* FED record ID (0x1000 - 0x1fff)               */
  short bxid;};           /* Bx number                                     */

typedef struct SLB_SUBHDR SLB_SUBHDR;

struct SLB_TAIL {
  unsigned short recid;   /* Record ID                                     */
  short fltevt;};         /* FLT event number                              */

typedef struct SLB_TAIL SLB_TAIL;

/*********************************
 *
 *    FED data block format
 *
 *    Note that the header and trailer described here are used only
 *    on the readout links. This bloxk must be padded to a 48-bit
 *    boundary to allow it to be transferred over the sharc link. The
 *    length field doesn't include the padding bytes.
 *
 *********************************/

struct FED_HDR {
  short length;           /* FED block length including header and trailer */
  unsigned short recid;   /* FED record ID (0x1000 - 0x1fff)               */
  short fltevt;           /* FLT event number                              */
  short bxid;             /* Bx number                                     */
  short compid;           /* component id (defined in component.h)         */
  short fedid;};          /* ID of FED producing this block                */

typedef struct FED_HDR FED_HDR;

struct FED_TAIL {
  short fltevt;};         /* FLT event number                              */

typedef struct FED_TAIL FED_TAIL;

/*********************************
 *
 *    Event data provided by the event builder.
 *    CompID: 0x0000, RecID: 0x2000
 *
 *********************************/

struct EVT_DATA {
  int run_number;               /* Run number                 */
  int event_time;               /* Time event was built       */
  int event_status;             /* event status/error code    */
  int flt_status;               /* FLT trigger number         */
  int slp_node;                 /* SLP processing node        */
  int slt_status;               /* SLT trigger number/status  */
  int exp_number;               /* Experiment Number          */
  int farm_node;                /* Farm node                  */
  int   BX_long;                /* bits 0 to 31 of the BX tag (at time trigger issued)  */
  short BX_upper;               /* bits 32 to 47 of the BX tag (at time trigger issued) */
  short FCS_tcode;              /* FCS trigger code for event                           */
  short physBX;                 /* physical BX == hera bucket ID of event               */
  short FLT_BX;                 /* pipeline cell triggered on by FLT for this event     */
  short fltevt;                 /* flt event number as delivered by FCS                 */
  short fill;
  int   dbKey;                  /* key to tables used to process event      */
  int   dbVersion;              /* version of key table used for this event */
};
typedef struct EVT_DATA EVT_DATA;

struct EVT_DATA_RECORD {
  SLB_HDR  hdr;
  EVT_DATA data;
  SLB_TAIL tail;};

typedef struct EVT_DATA_RECORD EVT_DATA_RECORD;

#ifdef __cplusplus
}
#endif

#endif