ybos.h

Go to the documentation of this file.
00001 /********************************************************************\
00002 
00003   Name:         ybos.h
00004   Created by:   Pierre Amaudruz, Stefan Ritt
00005 
00006   Contents:     Declarations for ybos data format
00007 
00008   $Id: ybos.h 3016 2006-01-05 01:03:05Z amaudruz $
00009 
00010 \********************************************************************/
00011 
00012 /**dox***************************************************************/
00013 /** @file ybos.h
00014 The YBOS include file
00015 */
00016 
00017 /** @defgroup ybosincludecode The ybos.h & ybos.c
00018  */
00019 /** @defgroup ybosdefineh YBOS Define 
00020  */
00021 /** @defgroup ybosmacroh YBOS Macros 
00022  */
00023 /** @defgroup yboserrorh YBOS error code 
00024  */
00025 
00026 /**dox***************************************************************/
00027 /** @addtogroup ybosincludecode
00028  *  
00029  *  @{  */
00030 
00031 /**dox***************************************************************/
00032 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00033 
00034 #ifdef OS_WINNT
00035 #include <io.h>
00036 #include <time.h>
00037 #endif
00038 #include <fcntl.h>
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 #include <string.h>
00042 #include <sys/stat.h>
00043 #include <sys/types.h>
00044 
00045 #ifndef EXPRT
00046 #define EXPRT
00047 #endif
00048 
00049 /**dox***************************************************************/
00050 #endif                          /* DOXYGEN_SHOULD_SKIP_THIS */
00051 
00052 /**dox***************************************************************/
00053 /** @addtogroup ybosdefineh
00054  *  
00055  *  @{  */
00056 
00057 /********************************************************************/
00058 /**
00059 General parameters
00060 */
00061 #ifdef YBOS_VERSION_3_3
00062 #define YBOS_PHYREC_SIZE        8190  /**< I*4 */
00063 #else
00064 #define YBOS_PHYREC_SIZE        8192  /**< I*4 */
00065 #endif
00066 #define YBOS_HEADER_LENGTH      4
00067 #define YBOS_BUFFER_SIZE        3*(YBOS_PHYREC_SIZE<<2) + MAX_EVENT_SIZE + 128  /**< in BYTES */
00068 
00069 #define YB_BANKLIST_MAX        32     /**< maximum number of banks to be found 
00070                                          by the ybk_list() or bk_list() */
00071 #define YB_STRING_BANKLIST_MAX          YB_BANKLIST_MAX * 4
00072                                        /**< to be used for xbk_list() */
00073 
00074 /**dox***************************************************************/
00075 /** @} */ /* end of ybosdefineh */
00076 
00077 /**dox***************************************************************/
00078 /** @addtogroup yboserrorh
00079  *  
00080  *  @{  */
00081 #define YB_SUCCESS               1     /**< Ok */
00082 #define YB_EVENT_NOT_SWAPPED     2     /**< Not swapped */
00083 #define YB_DONE                  2     /**< Operation complete */
00084 #define YB_WRONG_BANK_TYPE    -100     /**< Wrong bank type (see @ref YBOS_Bank_Types) */
00085 #define YB_BANK_NOT_FOUND     -101     /**< Bank not found */
00086 #define YB_SWAP_ERROR         -102     /**< Error swapping */
00087 #define YB_NOMORE_SLOT        -103     /**< No more space for fragment */
00088 #define YB_UNKNOWN_FORMAT     -104     /**< Unknown format (see @ref YBOS_format) */
00089 
00090 /**dox***************************************************************/
00091 /** @} */ /* end of yboserrorh */
00092 
00093 /**dox***************************************************************/
00094 /** @addtogroup ybosdefineh
00095  *  
00096  *  @{  */
00097 
00098 /**
00099 record header content */
00100 #define H_BLOCK_SIZE   0     /**< YBOS */
00101 #define H_BLOCK_NUM    1     /**< YBOS */
00102 #define H_HEAD_LEN     2     /**< YBOS */
00103 #define H_START        3     /**< YBOS */
00104 
00105 /**
00106 Display parameters */
00107 #define D_RECORD       1     /**< YBOS */
00108 #define D_HEADER       2     /**< YBOS */
00109 #define D_EVTLEN       3     /**< YBOS */
00110 
00111 /**
00112 File fragmentation */
00113 #define YB_COMPLETE       1     /**< YBOS */
00114 #define YB_INCOMPLETE     2     /**< YBOS */
00115 #define YB_NO_RECOVER    -1     /**< YBOS */
00116 #define YB_NO_RUN         0     /**< YBOS */
00117 #define YB_ADD_RUN        1     /**< YBOS */
00118 
00119 /**
00120 Display mode options */
00121 #define DSP_RAW    1         /**< Display raw data */
00122 #define DSP_RAW_SINGLE    2  /**< Display raw data (no single mode) */
00123 #define DSP_BANK   3         /**< Display data in bank format */
00124 #define DSP_BANK_SINGLE   4  /**< Display only requested data in bank format */
00125 
00126 /**
00127 Display format */
00128 #define DSP_UNK    0  /**< Display format unknown */
00129 #define DSP_DEC    1  /**< Display data in decimal format*/
00130 #define DSP_HEX    2  /**< Display data in headecimal format */
00131 #define DSP_ASC    3  /**< Display data in ASCII format */
00132 
00133 /**dox***************************************************************/
00134 /** @} */ /* end of ybosdefineh */
00135 
00136 /**dox***************************************************************/
00137 /** @addtogroup ybosmacroh
00138  *  
00139  *  @{  */
00140 
00141 /*---- Macros for YBOS ------------------------*/
00142 /**
00143 word swap (I4=I21I22 -> I4=I22I21*/
00144 #define SWAP_D2WORD(_d2w) {\
00145   WORD _tmp2;                                    \
00146   _tmp2                 = *((WORD *)(_d2w));     \
00147   *((WORD *)(_d2w))     = *(((WORD *)(_d2w))+1); \
00148   *(((WORD *)(_d2w))+1) = _tmp2;                 \
00149 }
00150 
00151 /* the s for the following macros */
00152 #ifdef CHAOS_EVID_FMT
00153 extern chaos;
00154 #endif
00155 
00156 /********************************************************************/
00157 /**
00158 As soon as the Midas header is striped out from the event, the YBOS
00159 remaining  data has lost the event synchonization unless included by the
00160 user. It is therefore necessary to have a YBOS bank duplicating
00161 this information usually done in the FE by creating a
00162 "EVID" bank filled with the Midas info and other user information.
00163 
00164 Unfortunately the format of this EVID is flexible and I couldn't
00165 force user to use a default structure. For this reason, I'm
00166 introducing a preprocessor flag for selecting such format.
00167 
00168 Omitting the declaration of the pre-processor flag the EVID_TRINAT is taken by
00169 default see @ref AppendixD.
00170 
00171 Special macros are avaialbe to retrieve this information
00172 based on the EVID content and the type of EVID structure.
00173 
00174 The Macro parameter should point to the first data of the EVID bank.
00175 \code
00176   // check if EVID is present if so display its content 
00177   if ((status = ybk_find (pybos, "EVID", &bklen, &bktyp, (void *)&pybk)) == YB_SUCCESS)
00178   {
00179     pdata = (DWORD *)((YBOS_BANK_HEADER *)pybk + 1);
00180     pevent->event_id      = YBOS_EVID_EVENT_ID(pdata);
00181     pevent->trigger_mask  = YBOS_EVID_TRIGGER_MASK(pdata);
00182     pevent->serial_number = YBOS_EVID_SERIAL(pdata);
00183     pevent->time_stamp    = YBOS_EVID_TIME(pdata);
00184     pevent->data_size     = pybk->length;
00185   }
00186 \endcode
00187 
00188 The current type of EVID bank are:
00189 - [EVID_TRINAT] Specific for Trinat experiment.
00190 \code
00191   ybk_create((DWORD *)pevent, "EVID", I4_BKTYPE, (DWORD *)(&pbkdat));
00192   *((WORD *)pbkdat) = EVENT_ID(pevent);     ((WORD *)pbkdat)++;
00193   *((WORD *)pbkdat) = TRIGGER_MASK(pevent); ((WORD *)pbkdat)++;
00194   *(pbkdat)++ = SERIAL_NUMBER(pevent);
00195   *(pbkdat)++ = TIME_STAMP(pevent);
00196   *(pbkdat)++ = gbl_run_number;                // run number 
00197 \endcode
00198 - [EVID_TWIST] Specific to Twist Experiment (Triumf).
00199 \code
00200   ybk_create((DWORD *)pevent, "EVID", I4_BKTYPE, &pbkdat);
00201   *((WORD *)pbkdat) = EVENT_ID(pevent);     ((WORD *)pbkdat)++;
00202   *((WORD *)pbkdat) = TRIGGER_MASK(pevent); ((WORD *)pbkdat)++;
00203   *(pbkdat)++ = SERIAL_NUMBER(pevent);
00204   *(pbkdat)++ = TIME_STAMP(pevent);
00205   *(pbkdat)++ = gbl_run_number;                // run number 
00206   *(pbkdat)++ = *((DWORD *)frontend_name);     // frontend name 
00207   ybk_close((DWORD *)pevent, pbkdat);
00208 \endcode
00209 */
00210 #if (!defined (EVID_TRINAT) && !defined (EVID_CHAOS) && !defined (EVID_TWIST))
00211 #define EVID_TRINAT
00212 #endif
00213 
00214 #if defined(EVID_TRINAT)
00215 #define YBOS_EVID_EVENT_ID(e)      *((WORD *)(e)+1)
00216 #define YBOS_EVID_TRIGGER_MASK(e)  *((WORD *)(e)+0)
00217 #define YBOS_EVID_SERIAL(e)        *((DWORD *)(e)+1)
00218 #define YBOS_EVID_TIME(e)          *((DWORD *)(e)+2)
00219 #define YBOS_EVID_RUN_NUMBER(e)    *((DWORD *)(e)+3)
00220 #define YBOS_EVID_EVENT_NB(e)      *((DWORD *)(e)+1)
00221 #elif defined(EVID_CHAOS)
00222 #define YBOS_EVID_EVENT_ID(e)      *((WORD *)(e)+3)
00223 #define YBOS_EVID_TRIGGER_MASK(e)  *((WORD *)(e)+2)
00224 #define YBOS_EVID_SERIAL(e)        *((DWORD *)(e)+2)
00225 #define YBOS_EVID_TIME(e)          *((DWORD *)(e)+3)
00226 #define YBOS_EVID_RUN_NUMBER(e)    *((DWORD *)(e)+4)
00227 #define YBOS_EVID_EVENT_NB(e)      *((DWORD *)(e)+0)
00228 #elif defined(EVID_TWIST)
00229 #define YBOS_EVID_EVENT_ID(e)      *((WORD *)(e)+1)
00230 #define YBOS_EVID_TRIGGER_MASK(e)  *((WORD *)(e)+0)
00231 #define YBOS_EVID_SERIAL(e)        *((DWORD *)(e)+1)
00232 #define YBOS_EVID_TIME(e)          *((DWORD *)(e)+2)
00233 #define YBOS_EVID_RUN_NUMBER(e)    *((DWORD *)(e)+3)
00234 #define YBOS_EVID_EVENT_NB(e)      *((DWORD *)(e)+1)
00235 /* frontend name ignored */
00236 #endif
00237 
00238 /********************************************************************/
00239 /**
00240 pevt Evt# id/msk serial run# */
00241 #define YBOS_EVID_BANK(__a, __b, __c,   __d,   __e) {\
00242       DWORD * pbuf;\
00243       ybk_create(__a, "EVID", I4_BKTYPE, &pbuf);\
00244       *(pbuf)++ = (DWORD)__b;\
00245       *(pbuf)++ = (DWORD)__c;\
00246       *(pbuf)++ = (DWORD)__d;\
00247       *(pbuf)++ = (DWORD)ss_millitime();\
00248       *(pbuf)++ = (DWORD)__e;\
00249       ybk_close(__a, pbuf);\
00250         }
00251 
00252 /********************************************************************/
00253 /**
00254 pevt Evt# id/msk serial run# */
00255 #define MIDAS_EVID_BANK(__a, __b, __c,   __d,   __e) {\
00256       DWORD * pbuf;\
00257       bk_create(__a, "EVID", TID_DWORD, &pbuf);\
00258       *(pbuf)++ = (DWORD)__b;\
00259       *(pbuf)++ = (DWORD)__c;\
00260       *(pbuf)++ = (DWORD)__d;\
00261       *(pbuf)++ = (DWORD)ss_millitime();\
00262       *(pbuf)++ = (DWORD)__e;\
00263       bk_close(__a, pbuf);\
00264         }
00265 
00266 /**dox***************************************************************/
00267 /** @} */ /* end of ybosmacroh */
00268 
00269 /**dox***************************************************************/
00270 /** @addtogroup ybosdefineh
00271  *  
00272  *  @{  */
00273 
00274 /*---- data structures for YBOS file format ------------------------*/
00275 /**
00276 YBOS Bank types */
00277 #define I2_BKTYPE       1  /**< Signed Integer 2 bytes */
00278 #define A1_BKTYPE       2  /**< ASCII 1 byte */
00279 #define I4_BKTYPE       3  /**< Signed Interger 4bytes */
00280 #define F4_BKTYPE       4  /**< Float 4 bytes */
00281 #define D8_BKTYPE       5  /**< Double 8 bytes */
00282 #define I1_BKTYPE       8  /**< Signed Integer 1 byte */
00283 #define MAX_BKTYPE      I1_BKTYPE+1 /**< delimiter */
00284 
00285 /**dox***************************************************************/
00286 /** @} */ /* end of ybosdefineh */
00287 
00288 /**dox***************************************************************/
00289 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00290 
00291 /**
00292 YBOS logger channel ALL in 4BYTES! */
00293 typedef struct {
00294    DWORD *ptop;        /**< pointer to top of YBOS buffer */
00295    DWORD *pbuf;        /**< current data pointer for writing to buffer */
00296    DWORD *pwrt;        /**< current data pointer for writing to device */
00297    DWORD *pbot;        /**< bottom of the physical record */
00298    DWORD *pend;        /**< end of the buffer */
00299    DWORD reco;         /**< offset to first logical record 4BYTES */
00300    DWORD recn;         /**< current YBOS physical record number */
00301 } YBOS_INFO;
00302 
00303 /**
00304 YBOS Physical record header */
00305 typedef struct {
00306    DWORD rec_size;          /**< LPR Length of Physical Record (exclusive) */
00307    DWORD header_length;     /**< LPH Length of Physical Header (inclusive) */
00308    DWORD rec_num;           /**< NPR Physical Record Number (start 0) */
00309    DWORD offset;            /**< LRD Offset to 1st Logical Record 
00310                                    (=LPH for 1st Logical record) */
00311 } YBOS_PHYSREC_HEADER;
00312 
00313 /**
00314 Bank header */
00315 typedef struct {
00316    DWORD name;              /**< bank name 4ASCII */
00317    DWORD number;            /**< bank number (=1) */
00318    DWORD index;             /**< index within bank (=0) */
00319    DWORD length;            /**< bank length (I*4, exclusive ) */
00320    DWORD type;              /**< bank type refer to above */
00321 } YBOS_BANK_HEADER;
00322 
00323 /**
00324 YBOS FILE parameters */
00325 #define MAX_FILE_PATH    128
00326 #define MAX_FRAG_SIZE   2000    /* max event size for fragmented file (bytes) */
00327 #define MAX_YM_FILE        8    /* max concurrent file handling */
00328 #define NLINE              8    /* number of elements for display routine */
00329 
00330 /**
00331 YBOS control file header (private structure) */
00332 typedef struct {
00333    INT file_ID;
00334    INT size;
00335    INT fragment_size;
00336    INT total_fragment;
00337    INT current_fragment;
00338    INT current_read_byte;
00339    INT run_number;
00340    INT spare;
00341 } YM_CFILE;
00342 
00343 /**
00344 YBOS path file header (private structure) */
00345 typedef struct {
00346    char path[MAX_FILE_PATH];
00347 } YM_PFILE;
00348 
00349 /**
00350 YBOS file replay handler (for multiple file entries) */
00351 typedef struct {
00352    INT fHandle;
00353    INT file_ID;
00354    INT current_fragment;
00355    INT current_read_byte;
00356    char path[MAX_FILE_PATH];
00357 } R_YM_FILE;
00358 
00359 /*---- function declarations ---------------------------------------*/
00360 
00361 /* make functions callable from a C++ program */
00362 #ifdef __cplusplus
00363 extern "C" {
00364 #endif
00365 
00366    INT EXPRT yb_file_recompose(void *pevt, INT fmt, char *svpath, INT file_mode);
00367    INT EXPRT feodb_file_dump(EQUIPMENT * eqp, char *eqpname, char *pevent,
00368                              INT run_number, char *path);
00369 
00370    void EXPRT yb_any_bank_display(void *pmbh, void *pbk, INT fmt,
00371                                   INT dsp_mode, INT dsp_fmt);
00372    void EXPRT yb_any_event_display(void *pevt, INT data_fmt, INT dsp_mode, INT dsp_fmt, char * bn);
00373    INT EXPRT yb_any_all_info_display(INT what);
00374    INT EXPRT yb_any_physrec_display(INT data_fmt);
00375 
00376    INT EXPRT yb_any_physrec_skip(INT data_fmt, INT bl);
00377    INT EXPRT yb_any_physrec_get(INT data_fmt, void **prec, DWORD * psize);
00378    INT EXPRT yb_any_file_rclose(INT data_fmt);
00379    INT EXPRT yb_any_file_ropen(char *infile, INT data_fmt);
00380    INT EXPRT yb_any_file_wopen(INT type, INT data_fmt, char *filename, INT * hDev);
00381    INT EXPRT yb_any_file_wclose(INT handle, INT type, INT data_fmt);
00382    INT EXPRT yb_any_log_write(INT handle, INT data_fmt, INT type,
00383                               void *prec, DWORD nbytes);
00384    INT EXPRT yb_any_event_swap(INT data_fmt, void *pevent);
00385    INT EXPRT yb_any_event_get(INT data_fmt, void **pevent, DWORD * psize);
00386 
00387 /* Bank manipulation */
00388    void EXPRT ybk_init(DWORD * pevent);
00389    void EXPRT ybk_create(DWORD * pevent, char *bkname, DWORD btype, void *pbkdat);
00390    INT EXPRT ybk_close(DWORD * pevent, void *pbkdat);
00391    INT EXPRT ybk_size(DWORD * pevent);
00392    INT EXPRT ybk_list(DWORD * pevent, char *bklist);
00393    INT EXPRT ybk_locate(DWORD * pevent, char *bkname, void *pdata);
00394    INT EXPRT ybk_find(DWORD * pevent, char *bkname, DWORD * bklength,
00395                       DWORD * bktype, void **pbkdata);
00396    void EXPRT ybk_create_chaos(DWORD * pevent, char *bname, DWORD btype, void *pbkdat);
00397    INT EXPRT ybk_iterate(DWORD * pevent, YBOS_BANK_HEADER ** pybkh, void **pdata);
00398    INT EXPRT ybk_close_chaos(DWORD * pevent, DWORD btype, void *pbkdat);
00399 
00400 #ifdef INCLUDE_LOGGING
00401    INT EXPRT ybos_log_open(LOG_CHN * log_chn, INT run_number);
00402    INT EXPRT ybos_write(LOG_CHN * log_chn, EVENT_HEADER * pevent, INT evt_size);
00403    INT EXPRT ybos_log_close(LOG_CHN * log_chn, INT run_number);
00404 #endif
00405 
00406    INT EXPRT ybos_event_get(DWORD ** plrl, DWORD * size);
00407    INT EXPRT ybos_get_tid_size(INT tid);
00408 
00409 #ifdef __cplusplus
00410 }
00411 #endif
00412 
00413 /*------------ END --------------------------------------------------------------*/
00414 /**dox***************************************************************/
00415 #endif                          /* DOXYGEN_SHOULD_SKIP_THIS */
00416 
00417 /**dox***************************************************************/
00418 /** @} */ /* end of ybosincludecode */

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