Event Structure

From MidasWiki
Revision as of 17:20, 29 October 2013 by Suz (talk | contribs) (Created page with "==Introduction == Only two formats are now now supported by the frontend, * MIDAS * FIXED Note that a frontend cannot write data directly into ROOT format. A conversion t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Only two formats are now now supported by the frontend,


Note that a frontend cannot write data directly into ROOT format. A conversion to ROOT may be done (e.g. by the data logger) from one of the supported formats (see equipment list for details).


The @ref FE_tbl_Format "FIXED format" is the simplest event format. The event length is fixed and is mapped to a C structure that is filled by the readout routine. Since the standard MIDAS analyzer cannot work with this format, it is only recommended for an experiment which uses its own analyzer and wants to avoid the overhead of a bank structure, or for monitoring purposes in the ODB.

For fixed events, the structure has to be defined twice: once for the compiler in the form of a C structure, and once for the ODB in form of an ASCII representation. There are several ways of doing this. The ASCII string may be supplied to the system as the @ref FE_tbl_InitString "init string" in the equipment list as follows:

Example of definition of FIXED format using Equipment field "init string"

Alternatively, the structure may be defined first in the ODB, under /Equipment/<eqp_name>/Variables, and an experim.h file generated (see experim.h. The structure is then supplied to the readout routine by the frontend program including "experim.h", as follows:

Example of structure from experim.h for a fixed event

The Equipment Definition for this fixed event might be:

{ "Info ODB",     /* equipment name */
   10, 0,         /* event ID, trigger mask */
   "",            /* no banks sent */
   EQ_PERIODIC,   /* equipment type */
   0,             /* interrupt source */
   "FIXED",       /* format */
   TRUE,          /* enabled */
         RO_EOR,  /* read when running; 
                     send to odb */
   500,           /* polling period */
   0,             /* event limit */
   0,             /* number of sub-events */
   0,             /* log history */
   "", "", "",
   info_odb,      /* readout routine */

It is a good idea to check the record size and/or create the record in the ODB when using C structures from experim.h, to make sure that the structures in the ODB and in experim.h are identical. The frontend code might look like this:

/* frontend.c */
#include experim.h
// INFO_ODB_EVENT and  INFO_ODB_EVENT_STR are defined in experim.h
HNDLE hInfo;
INT status, size;
char   str_set[256];
sprintf(str_set,"/Equipment/INFO ODB/Variables");
/* create record /Equipment/INFO ODB/Variables to make sure it exists  */
/* find the key for info odb */
 status = db_find_key(hDB, 0, str_set, &hInfo);
 if (status != DB_SUCCESS)
     printf( "Key %s not found; creating record for info odb\n",str_set);
     status = db_create_record(hDB, 0, str_set, strcomb(info_odb_event_str));
 /* check the record size */
 status = db_get_record_size(hDB, hInfo, 0, &size);
 if (sizeof(INFO_ODB_EVENT) != size)
       cm_msg(MERROR, "bnmr_init", "error; record sizes do not match");
       return DB_TYPE_MISMATCH;

A readout routine for this fixed event is as follows:

INT info_odb(char * pevent, INT off)
/* - periodic equipment updating the ODB ONLY
  - no event generation for the data stream.
 /* fill various values */
 cyinfo.helicity = gbl_ppg_hel;
 cyinfo.current_cycle = gbl_CYCLE_N;
 cyinfo.current_scan = gbl_SCAN_N;
 cyinfo.epicsdev_set_v_ = epics_params.Epics_val;
 cyinfo.epicsdev_read_v_ = epics_params.Epics_read;
 cyinfo.campdev_set = 0;   
 cyinfo.campdev_read = 0; 
 memcpy(pevent, (char *)&(cyinfo.helicity), sizeof(cyinfo));
 pevent += sizeof(cyinfo);
 logMsg ("info_odb %d size:%d\n",gbl_CYCLE_N,sizeof(cyinfo),0,0,0,0);
 return sizeof(cyinfo);

More examples of FIXED events can be found in the slow controls device drivers, for example ../examples/slowcont/frontend.c and ../drivers/class/hv.c