midas.h

Go to the documentation of this file.
00001 /********************************************************************\
00002 
00003   Name:         MIDAS.H
00004   Created by:   Stefan Ritt
00005 
00006   Contents:     Type definitions and function declarations needed
00007                 for MIDAS applications
00008 
00009 
00010   $Id: midas.h 3197 2006-07-31 19:01:21Z ritt $
00011 
00012 \********************************************************************/
00013 
00014 #ifndef _MIDAS_H_
00015 #define _MIDAS_H_
00016 
00017 /*------------------------------------------------------------------*/
00018 
00019 /* MIDAS library version number. This value is returned by 
00020    cm_get_version and will be incremented whenever changes are done
00021    to the MIDAS library. First digit is major release, second
00022    digit is minor release, third digit is patch level */
00023 
00024 /**dox***************************************************************/
00025 /** @file midas.h
00026 The main include file
00027 */
00028 
00029 /** @defgroup midasincludecode The midas.h & midas.c
00030  */
00031 /** @defgroup mdefineh Midas Define 
00032  */
00033 /** @defgroup mmacroh Midas Macros
00034  */
00035 /** @defgroup mdeferrorh Midas Error definition
00036  */
00037 /** @defgroup msectionh Midas Structure Declaration
00038  */
00039 
00040 /**dox***************************************************************/
00041 /** @addtogroup midasincludecode
00042  *  
00043  *  @{  */
00044 
00045 #define MIDAS_VERSION "1.9.5"
00046 #define DATABASE_VERSION 2      /* has to be changed whenever binary ODB format changes */
00047 
00048 /**dox***************************************************************/
00049 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00050 
00051 /*------------------------------------------------------------------*/
00052 
00053 /* find out on which operating system we are running */
00054 
00055 #if defined( VAX ) || defined( __VMS )
00056 #define OS_VMS
00057 #endif
00058 
00059 #if defined( _MSC_VER )
00060 #define OS_WINNT
00061 #endif
00062 
00063 #if defined( __MSDOS__ )
00064 #define OS_MSDOS
00065 #endif
00066 
00067 #if defined ( vxw )
00068 #define OS_VXWORKS
00069 #undef OS_UNIX
00070 #endif
00071 
00072 #if !defined(OS_LINUX)
00073 #if defined ( __linux__ )
00074 #define OS_LINUX
00075 #endif
00076 #endif
00077 
00078 #if defined(OS_LINUX) || defined(OS_OSF1) || defined(OS_ULTRIX) || defined(OS_FREEBSD) || defined(OS_SOLARIS) || defined(OS_IRIX) || defined(OS_DARWIN)
00079 #define OS_UNIX
00080 #endif
00081 
00082 #if !defined(OS_IRIX) && !defined(OS_VMS) && !defined(OS_MSDOS) && !defined(OS_UNIX) && !defined(OS_VXWORKS) && !defined(OS_WINNT)
00083 #error MIDAS cannot be used on this operating system
00084 #endif
00085 
00086 /*------------------------------------------------------------------*/
00087 
00088 #ifdef USE_ROOT
00089 #include <TObjArray.h>
00090 #include <TFolder.h>
00091 #include <TCutG.h>
00092 #endif
00093 
00094 /* Define basic data types */
00095 
00096 #ifndef MIDAS_TYPE_DEFINED
00097 #define MIDAS_TYPE_DEFINED
00098 
00099 typedef unsigned char BYTE;
00100 typedef unsigned short int WORD;
00101 #ifndef OS_WINNT // Windows defines already DWORD
00102 typedef unsigned int DWORD;
00103 #endif
00104 
00105 #ifndef OS_WINNT
00106 #ifndef OS_VXWORKS
00107 typedef DWORD BOOL;
00108 #endif
00109 #endif
00110 
00111 #endif                          /* MIDAS_TYPE_DEFINED */
00112 
00113 /*
00114   Definitions depending on integer types:
00115 
00116   Note that the alpha chip uses 32 bit integers by default.
00117   Therefore always use 'INT' instead 'int'.
00118 */
00119 #if defined(OS_MSDOS)
00120 typedef long int INT;
00121 #elif defined( OS_WINNT )
00122 
00123 /* INT predefined in windows.h */
00124 #ifndef _INC_WINDOWS
00125 #include <windows.h>
00126 #endif
00127 
00128 #else
00129 typedef int INT;
00130 #endif
00131 
00132 typedef INT HNDLE;
00133 
00134 /* Include vxWorks for BOOL definition */
00135 #ifdef OS_VXWORKS
00136 #ifndef __INCvxWorksh
00137 #include <vxWorks.h>
00138 #endif
00139 #endif
00140 
00141 /*
00142    Conversion from pointer to interger and back.
00143 
00144    On 64-bit systems, pointers are long ints
00145    On 32-bit systems, pointers are int
00146 
00147    Never use direct casting, since the code might then
00148    not be portable between 32-bit and 64-bit systems
00149 
00150 */
00151 #if defined(__alpha) || defined(_LP64)
00152 #define POINTER_T     long int
00153 #else
00154 #define POINTER_T     int
00155 #endif
00156 
00157 /* need system-dependant thread type */
00158 #if defined(OS_WINNT)
00159 typedef HANDLE midas_thread_t;
00160 #elif defined(OS_UNIX)
00161 #include <pthread.h>
00162 typedef pthread_t midas_thread_t;
00163 #else
00164 typedef INT midas_thread_t;
00165 #endif
00166 
00167 #define TRUE  1
00168 #define FALSE 0
00169 
00170 /* directory separator */
00171 #if defined(OS_MSDOS) || defined(OS_WINNT)
00172 #define DIR_SEPARATOR     '\\'
00173 #define DIR_SEPARATOR_STR "\\"
00174 #elif defined(OS_VMS)
00175 #define DIR_SEPARATOR     ']'
00176 #define DIR_SEPARATOR_STR "]"
00177 #else
00178 #define DIR_SEPARATOR     '/'
00179 #define DIR_SEPARATOR_STR "/"
00180 #endif
00181 
00182 /* inline functions */
00183 #if defined( _MSC_VER )
00184 #define INLINE __inline
00185 #elif defined(__GNUC__)
00186 #define INLINE __inline__
00187 #else
00188 #define INLINE
00189 #endif
00190 
00191 /* large file (>2GB) support */
00192 #ifndef _LARGEFILE64_SOURCE
00193 #define O_LARGEFILE 0
00194 #endif
00195 
00196 /**dox***************************************************************/
00197 #endif                          /* DOXYGEN_SHOULD_SKIP_THIS */
00198 
00199 /*------------------------------------------------------------------*/
00200 
00201 /* Definition of implementation specific constants */
00202 
00203 /* all buffer sizes must be multiples of 4 ! */
00204 
00205 #ifdef OS_WINNT
00206 #define TAPE_BUFFER_SIZE       0x100000      /**< buffer size for taping data */
00207 #else
00208 #define TAPE_BUFFER_SIZE       0x8000        /**< buffer size for taping data */
00209 #endif
00210 #define NET_TCP_SIZE           0xFFFF        /**< maximum TCP transfer        */
00211 #define OPT_TCP_SIZE           8192          /**< optimal TCP buffer size     */
00212 #define NET_UDP_SIZE           8192          /**< maximum UDP transfer        */
00213 
00214 #define EVENT_BUFFER_SIZE      0x100000      /**< buffer used for events      */
00215 #define EVENT_BUFFER_NAME      "SYSTEM"      /**< buffer name for commands    */
00216 #define MAX_EVENT_SIZE         0x80000       /**< maximum event size 512k     */
00217 #define DEFAULT_EVENT_BUFFER_SIZE 0x200000;  /**< 2M                          */
00218 #define DEFAULT_ODB_SIZE       0x100000      /**< online database 1M          */
00219 
00220 #define NAME_LENGTH            32            /**< length of names, mult.of 8! */
00221 #define HOST_NAME_LENGTH       256           /**< length of TCP/IP names      */
00222 #define MAX_CLIENTS            64            /**< client processes per buf/db */
00223 #define MAX_EVENT_REQUESTS     10            /**< event requests per client   */
00224 #define MAX_OPEN_RECORDS       256           /**< number of open DB records   */
00225 #define MAX_ODB_PATH           256           /**< length of path in ODB       */
00226 #define MAX_EXPERIMENT         32            /**< number of different exp.    */
00227 #define BANKLIST_MAX           64            /**< max # of banks in event     */
00228 #define STRING_BANKLIST_MAX    BANKLIST_MAX * 4   /**< for bk_list()          */
00229 
00230 
00231 #define MIDAS_TCP_PORT 1175     /* port under which server is listening */
00232 
00233 /**
00234 Timeouts [ms] */
00235 #define DEFAULT_RPC_TIMEOUT    10000
00236 #define WATCHDOG_INTERVAL      1000
00237 
00238 #define DEFAULT_WATCHDOG_TIMEOUT 10000    /**< Watchdog */
00239 
00240 /*------------------------------------------------------------------*/
00241 
00242 /* Enumeration definitions */
00243 
00244 /**dox***************************************************************/
00245 /** @addtogroup mdefineh
00246  *  
00247  *  @{  */
00248 
00249 /**
00250 System states */
00251 #define STATE_STOPPED 1      /**< MIDAS run stopped                  */
00252 #define STATE_PAUSED  2      /**< MIDAS run paused                   */
00253 #define STATE_RUNNING 3      /**< MIDAS run running                  */
00254 
00255 /**
00256 Data format */
00257 #define FORMAT_MIDAS  1       /**< MIDAS banks                        */
00258 #define FORMAT_YBOS   2       /**< YBOS  banks                        */
00259 #define FORMAT_ASCII  3       /**< ASCII format                       */
00260 #define FORMAT_FIXED  4       /**< Fixed length binary records        */
00261 #define FORMAT_DUMP   5       /**< Dump (detailed ASCII) format       */
00262 #define FORMAT_HBOOK  6       /**< CERN hbook (rz) format             */
00263 #define FORMAT_ROOT   7       /**< CERN ROOT format                   */
00264 
00265 /**
00266 Event Sampling type */
00267 #define GET_ALL   (1<<0)      /**< get all events (consume)           */
00268 #define GET_SOME  (1<<1)      /**< get as much as possible (sampling) */
00269 #define GET_FARM  (1<<2)      /**< distribute events over several
00270                                  clients (farming)                  */
00271 
00272 /**
00273 Data types Definition                         min      max    */
00274 #define TID_BYTE      1       /**< unsigned byte         0       255    */
00275 #define TID_SBYTE     2       /**< signed byte         -128      127    */
00276 #define TID_CHAR      3       /**< single character      0       255    */
00277 #define TID_WORD      4       /**< two bytes             0      65535   */
00278 #define TID_SHORT     5       /**< signed word        -32768    32767   */
00279 #define TID_DWORD     6       /**< four bytes            0      2^32-1  */
00280 #define TID_INT       7       /**< signed dword        -2^31    2^31-1  */
00281 #define TID_BOOL      8       /**< four bytes bool       0        1     */
00282 #define TID_FLOAT     9       /**< 4 Byte float format                  */
00283 #define TID_DOUBLE   10       /**< 8 Byte float format                  */
00284 #define TID_BITFIELD 11       /**< 32 Bits Bitfield      0  111... (32) */
00285 #define TID_STRING   12       /**< zero terminated string               */
00286 #define TID_ARRAY    13       /**< array with unknown contents          */
00287 #define TID_STRUCT   14       /**< structure with fixed length          */
00288 #define TID_KEY      15       /**< key in online database               */
00289 #define TID_LINK     16       /**< link in online database              */
00290 #define TID_LAST     17       /**< end of TID list indicator            */
00291 
00292 /**
00293 Synchronous / Asynchronous flags */
00294 #define SYNC          0
00295 #define ASYNC         1
00296 
00297 /**
00298 Access modes */
00299 #define MODE_READ      (1<<0)
00300 #define MODE_WRITE     (1<<1)
00301 #define MODE_DELETE    (1<<2)
00302 #define MODE_EXCLUSIVE (1<<3)
00303 #define MODE_ALLOC     (1<<7)
00304 
00305 /**
00306 RPC options */
00307 #define RPC_OTIMEOUT       1
00308 #define RPC_OTRANSPORT     2
00309 #define RPC_OCONVERT_FLAG  3
00310 #define RPC_OHW_TYPE       4
00311 #define RPC_OSERVER_TYPE   5
00312 #define RPC_OSERVER_NAME   6
00313 #define RPC_CONVERT_FLAGS  7
00314 #define RPC_ODB_HANDLE     8
00315 #define RPC_CLIENT_HANDLE  9
00316 #define RPC_SEND_SOCK      10
00317 #define RPC_WATCHDOG_TIMEOUT 11
00318 #define RPC_NODELAY        12
00319 
00320 #define RPC_TCP            0
00321 #define RPC_FTCP           1
00322 
00323 /**
00324 Watchdog flags */
00325 #define WF_WATCH_ME   (1<<0)    /* see cm_set_watchdog_flags   */
00326 #define WF_CALL_WD    (1<<1)
00327 
00328 /**
00329 Transitions values */
00330 #define TR_START      (1<<0)  /**< Start transition  */
00331 #define TR_STOP       (1<<1)  /**< Stop transition  */
00332 #define TR_PAUSE      (1<<2)  /**< Pause transition */
00333 #define TR_RESUME     (1<<3)  /**< Resume transition  */
00334 #define TR_DEFERRED   (1<<12)
00335 
00336 /** 
00337 Equipment types */
00338 #define EQ_PERIODIC   (1<<0)   /**< Periodic Event */
00339 #define EQ_POLLED     (1<<1)   /**< Polling Event */
00340 #define EQ_INTERRUPT  (1<<2)   /**< Interrupt Event */
00341 #define EQ_SLOW       (1<<3)   /**< Slow Control Event */
00342 #define EQ_MANUAL_TRIG (1<<4)  /**< Manual triggered Event */
00343 #define EQ_FRAGMENTED (1<<5)   /**< Fragmented Event */
00344 #define EQ_EB         (1<<6)   /**< Event run through the event builder */
00345 
00346 
00347 /** 
00348 Read - On flags */
00349 #define RO_RUNNING    (1<<0)   /**< While running */
00350 #define RO_STOPPED    (1<<1)   /**< Before stopping the run */
00351 #define RO_PAUSED     (1<<2)   /**< ??? */
00352 #define RO_BOR        (1<<3)   /**< At the Begin of run */
00353 #define RO_EOR        (1<<4)   /**< At the End of run */
00354 #define RO_PAUSE      (1<<5)   /**< Before pausing the run */
00355 #define RO_RESUME     (1<<6)   /**< Before resuming the run */
00356 
00357 #define RO_TRANSITIONS (RO_BOR|RO_EOR|RO_PAUSE|RO_RESUME)      /**< At all transitions */
00358 #define RO_ALWAYS      (0xFF)      /**<  Always (independent of the run status) */
00359 
00360 #define RO_ODB        (1<<8)   /**< Submit data to ODB only */
00361 
00362 /**dox***************************************************************/
00363           /** @} *//* end of mdefineh */
00364 
00365 /**
00366 special characters */
00367 #define CH_BS             8
00368 #define CH_TAB            9
00369 #define CH_CR            13
00370 
00371 #define CH_EXT 0x100
00372 
00373 #define CH_HOME   (CH_EXT+0)
00374 #define CH_INSERT (CH_EXT+1)
00375 #define CH_DELETE (CH_EXT+2)
00376 #define CH_END    (CH_EXT+3)
00377 #define CH_PUP    (CH_EXT+4)
00378 #define CH_PDOWN  (CH_EXT+5)
00379 #define CH_UP     (CH_EXT+6)
00380 #define CH_DOWN   (CH_EXT+7)
00381 #define CH_RIGHT  (CH_EXT+8)
00382 #define CH_LEFT   (CH_EXT+9)
00383 
00384 /* event sources in equipment */
00385 /**
00386 Code the LAM crate and LAM station into a bitwise register.
00387 @param c Crate number
00388 @param s Slot number
00389 */
00390 #define LAM_SOURCE(c, s)         (c<<24 | ((s) & 0xFFFFFF))
00391 
00392 /** 
00393 Code the Station number bitwise for the LAM source.
00394 @param s Slot number
00395 */
00396 #define LAM_STATION(s)           (1<<(s-1))
00397 
00398 /** 
00399 Convert the coded LAM crate to Crate number.
00400 @param c coded crate
00401 */
00402 #define LAM_SOURCE_CRATE(c)      (c>>24)
00403 
00404 /** 
00405 Convert the coded LAM station to Station number.
00406 @param s Slot number
00407 */
00408 #define LAM_SOURCE_STATION(s)    ((s) & 0xFFFFFF)
00409 
00410 /**
00411 CNAF commands */
00412 #define CNAF        0x1         /* normal read/write                */
00413 #define CNAF_nQ     0x2         /* Repeat read until noQ            */
00414 
00415 #define CNAF_INHIBIT_SET         0x100
00416 #define CNAF_INHIBIT_CLEAR       0x101
00417 #define CNAF_CRATE_CLEAR         0x102
00418 #define CNAF_CRATE_ZINIT         0x103
00419 #define CNAF_TEST                0x110
00420 
00421 /**dox***************************************************************/
00422 /** @addtogroup mmacroh
00423  *  
00424  *  @{
00425  */
00426 
00427 /**
00428 MAX */
00429 #ifndef MAX
00430 #define MAX(a,b)            (((a) > (b)) ? (a) : (b))
00431 #endif
00432 
00433 /**
00434 MIN */
00435 #ifndef MIN
00436 #define MIN(a,b)            (((a) < (b)) ? (a) : (b))
00437 #endif
00438 
00439 /*------------------------------------------------------------------*/
00440 
00441 /**
00442 Align macro for data alignment on 8-byte boundary */
00443 #define ALIGN8(x)  (((x)+7) & ~7)
00444 
00445 /**
00446 Align macro for variable data alignment */
00447 #define VALIGN(adr,align)  (((POINTER_T) (adr)+align-1) & ~(align-1))
00448 
00449 /**dox***************************************************************/
00450           /** @} *//* end of mmacroh */
00451 
00452 /**dox***************************************************************/
00453 /** @addtogroup mdefineh
00454  *  
00455  *  @{  */
00456 /*
00457 * Bit flags */
00458 #define EVENTID_ALL        -1   /* any event id                   */
00459 #define TRIGGER_ALL        -1   /* any type of trigger            */
00460 
00461 /**
00462 System message types */
00463 #define MT_ERROR           (1<<0)     /**< - */
00464 #define MT_INFO            (1<<1)     /**< - */
00465 #define MT_DEBUG           (1<<2)     /**< - */
00466 #define MT_USER            (1<<3)     /**< - */
00467 #define MT_LOG             (1<<4)     /**< - */
00468 #define MT_TALK            (1<<5)     /**< - */
00469 #define MT_CALL            (1<<6)     /**< - */
00470 #define MT_ALL              0xFF      /**< - */
00471 
00472 #define MERROR             MT_ERROR, __FILE__, __LINE__ /**< - */
00473 #define MINFO              MT_INFO,  __FILE__, __LINE__ /**< - */
00474 #define MDEBUG             MT_DEBUG, __FILE__, __LINE__ /**< - */
00475 #define MUSER              MT_USER,  __FILE__, __LINE__ /**< produced by interactive user */
00476 #define MLOG               MT_LOG,   __FILE__, __LINE__ /**< info message which is only logged */
00477 #define MTALK              MT_TALK,  __FILE__, __LINE__ /**< info message for speech system */
00478 #define MCALL              MT_CALL,  __FILE__, __LINE__ /**< info message for telephone call */
00479 
00480 /**dox***************************************************************/
00481           /** @} *//* end of mdefineh */
00482 
00483 
00484 /**dox***************************************************************/
00485 /** @addtogroup mdeferrorh
00486  *  
00487  *  @{
00488  */
00489 
00490 /**dox***************************************************************/
00491 /**
00492  @defgroup err21 Status and error codes
00493  @{ */
00494 #define SUCCESS                       1 /**< Success */
00495 #define CM_SUCCESS                    1 /**< Same  */
00496 #define CM_SET_ERROR                102 /**< set  */
00497 #define CM_NO_CLIENT                103 /**< nobody */
00498 #define CM_DB_ERROR                 104 /**< db access error */
00499 #define CM_UNDEF_EXP                105 /**< - */
00500 #define CM_VERSION_MISMATCH         106 /**< - */
00501 #define CM_SHUTDOWN                 107 /**< - */
00502 #define CM_WRONG_PASSWORD           108 /**< - */
00503 #define CM_UNDEF_ENVIRON            109 /**< - */
00504 #define CM_DEFERRED_TRANSITION      110 /**< - */
00505 #define CM_TRANSITION_IN_PROGRESS   111 /**< - */
00506 #define CM_TIMEOUT                  112 /**< - */
00507 #define CM_INVALID_TRANSITION       113 /**< - */
00508 #define CM_TOO_MANY_REQUESTS        114 /**< - */
00509 /**dox***************************************************************/
00510           /** @} *//* end of err21 */
00511 
00512 /**dox***************************************************************/
00513 /**
00514  @defgroup err22 Buffer Manager error codes
00515  @{ */
00516 #define BM_SUCCESS                    1   /**< - */
00517 #define BM_CREATED                  202   /**< - */
00518 #define BM_NO_MEMORY                203   /**< - */
00519 #define BM_INVALID_NAME             204   /**< - */
00520 #define BM_INVALID_HANDLE           205   /**< - */
00521 #define BM_NO_SLOT                  206   /**< - */
00522 #define BM_NO_MUTEX                 207   /**< - */
00523 #define BM_NOT_FOUND                208   /**< - */
00524 #define BM_ASYNC_RETURN             209   /**< - */
00525 #define BM_TRUNCATED                210   /**< - */
00526 #define BM_MULTIPLE_HOSTS           211   /**< - */
00527 #define BM_MEMSIZE_MISMATCH         212   /**< - */
00528 #define BM_CONFLICT                 213   /**< - */
00529 #define BM_EXIT                     214   /**< - */
00530 #define BM_INVALID_PARAM            215   /**< - */
00531 #define BM_MORE_EVENTS              216   /**< - */
00532 #define BM_INVALID_MIXING           217   /**< - */
00533 #define BM_NO_SHM                   218   /**< - */
00534 /**dox***************************************************************/
00535           /** @} *//* end of group 22 */
00536 
00537 /**dox***************************************************************/
00538 /**  @defgroup err23 Online Database error codes 
00539 @{ */
00540 #define DB_SUCCESS                    1   /**< - */
00541 #define DB_CREATED                  302   /**< - */
00542 #define DB_NO_MEMORY                303   /**< - */
00543 #define DB_INVALID_NAME             304   /**< - */
00544 #define DB_INVALID_HANDLE           305   /**< - */
00545 #define DB_NO_SLOT                  306   /**< - */
00546 #define DB_NO_MUTEX                 307   /**< - */
00547 #define DB_MEMSIZE_MISMATCH         308   /**< - */
00548 #define DB_INVALID_PARAM            309   /**< - */
00549 #define DB_FULL                     310   /**< - */
00550 #define DB_KEY_EXIST                311   /**< - */
00551 #define DB_NO_KEY                   312   /**< - */
00552 #define DB_KEY_CREATED              313   /**< - */
00553 #define DB_TRUNCATED                314   /**< - */
00554 #define DB_TYPE_MISMATCH            315   /**< - */
00555 #define DB_NO_MORE_SUBKEYS          316   /**< - */
00556 #define DB_FILE_ERROR               317   /**< - */
00557 #define DB_NO_ACCESS                318   /**< - */
00558 #define DB_STRUCT_SIZE_MISMATCH     319   /**< - */
00559 #define DB_OPEN_RECORD              320   /**< - */
00560 #define DB_OUT_OF_RANGE             321   /**< - */
00561 #define DB_INVALID_LINK             322   /**< - */
00562 #define DB_CORRUPTED                323   /**< - */
00563 #define DB_STRUCT_MISMATCH          324   /**< - */
00564 #define DB_TIMEOUT                  325   /**< - */
00565 #define DB_VERSION_MISMATCH         326   /**< - */
00566 /**dox***************************************************************/
00567           /** @} *//* end of group 23 */
00568 
00569 /**dox***************************************************************/
00570 /**  @defgroup err24 System Services error code
00571 @{ */
00572 #define SS_SUCCESS                    1   /**< - */
00573 #define SS_CREATED                  402   /**< - */
00574 #define SS_NO_MEMORY                403   /**< - */
00575 #define SS_INVALID_NAME             404   /**< - */
00576 #define SS_INVALID_HANDLE           405   /**< - */
00577 #define SS_INVALID_ADDRESS          406   /**< - */
00578 #define SS_FILE_ERROR               407   /**< - */
00579 #define SS_NO_MUTEX                 408   /**< - */
00580 #define SS_NO_PROCESS               409   /**< - */
00581 #define SS_NO_THREAD                410   /**< - */
00582 #define SS_SOCKET_ERROR             411   /**< - */
00583 #define SS_TIMEOUT                  412   /**< - */
00584 #define SS_SERVER_RECV              413   /**< - */
00585 #define SS_CLIENT_RECV              414   /**< - */
00586 #define SS_ABORT                    415   /**< - */
00587 #define SS_EXIT                     416   /**< - */
00588 #define SS_NO_TAPE                  417   /**< - */
00589 #define SS_DEV_BUSY                 418   /**< - */
00590 #define SS_IO_ERROR                 419   /**< - */
00591 #define SS_TAPE_ERROR               420   /**< - */
00592 #define SS_NO_DRIVER                421   /**< - */
00593 #define SS_END_OF_TAPE              422   /**< - */
00594 #define SS_END_OF_FILE              423   /**< - */
00595 #define SS_FILE_EXISTS              424   /**< - */
00596 #define SS_NO_SPACE                 425   /**< - */
00597 #define SS_INVALID_FORMAT           426   /**< - */
00598 #define SS_NO_ROOT                  427   /**< - */
00599 /**dox***************************************************************/
00600           /** @} *//* end of group 24 */
00601 
00602 /**dox***************************************************************/
00603 /**  @defgroup err25 Remote Procedure Calls error codes
00604 @{ */
00605 #define RPC_SUCCESS                   1   /**< - */
00606 #define RPC_ABORT              SS_ABORT   /**< - */
00607 #define RPC_NO_CONNECTION           502   /**< - */
00608 #define RPC_NET_ERROR               503   /**< - */
00609 #define RPC_TIMEOUT                 504   /**< - */
00610 #define RPC_EXCEED_BUFFER           505   /**< - */
00611 #define RPC_NOT_REGISTERED          506   /**< - */
00612 #define RPC_CONNCLOSED              507   /**< - */
00613 #define RPC_INVALID_ID              508   /**< - */
00614 #define RPC_SHUTDOWN                509   /**< - */
00615 #define RPC_NO_MEMORY               510   /**< - */
00616 #define RPC_DOUBLE_DEFINED          511   /**< - */
00617 /**dox***************************************************************/
00618           /** @} *//* end of group 25 */
00619 
00620 /**dox***************************************************************/
00621 /**  @defgroup err26 Other errors
00622 @{ */
00623 #define FE_SUCCESS                    1   /**< - */
00624 #define FE_ERR_ODB                  602   /**< - */
00625 #define FE_ERR_HW                   603   /**< - */
00626 #define FE_ERR_DISABLED             604   /**< - */
00627 #define FE_ERR_DRIVER               605   /**< - */
00628 
00629 /** 
00630 History error code */
00631 #define HS_SUCCESS                    1   /**< - */
00632 #define HS_FILE_ERROR               702   /**< - */
00633 #define HS_NO_MEMORY                703   /**< - */
00634 #define HS_TRUNCATED                704   /**< - */
00635 #define HS_WRONG_INDEX              705   /**< - */
00636 #define HS_UNDEFINED_EVENT          706   /**< - */
00637 #define HS_UNDEFINED_VAR            707   /**< - */
00638 
00639 /** 
00640 FTP error code */
00641 #define FTP_SUCCESS                   1   /**< - */
00642 #define FTP_NET_ERROR               802   /**< - */
00643 #define FTP_FILE_ERROR              803   /**< - */
00644 #define FTP_RESPONSE_ERROR          804   /**< - */
00645 #define FTP_INVALID_ARG             805   /**< - */
00646 
00647 /** 
00648 ELog error code */
00649 #define EL_SUCCESS                    1   /**< - */
00650 #define EL_FILE_ERROR               902   /**< - */
00651 #define EL_NO_MESSAGE               903   /**< - */
00652 #define EL_TRUNCATED                904   /**< - */
00653 #define EL_FIRST_MSG                905   /**< - */
00654 #define EL_LAST_MSG                 906   /**< - */
00655 
00656 /** 
00657 Alarm error code */
00658 #define AL_SUCCESS                    1   /**< - */
00659 #define AL_INVALID_NAME            1002   /**< - */
00660 #define AL_ERROR_ODB               1003   /**< - */
00661 #define AL_RESET                   1004   /**< - */
00662 
00663 /** 
00664 Slow control commands error code */
00665 #define CMD_INIT                    (1<<0)
00666 #define CMD_EXIT                    (1<<1)
00667 #define CMD_IDLE                    (1<<2)
00668 #define CMD_SET                     (1<<3)
00669 #define CMD_SET_ALL                 (1<<4)
00670 #define CMD_GET                     (1<<5)
00671 #define CMD_GET_ALL                 (1<<6)
00672 #define CMD_GET_CURRENT             (1<<7)
00673 #define CMD_GET_CURRENT_ALL         (1<<8)
00674 #define CMD_SET_CURRENT_LIMIT       (1<<9)
00675 #define CMD_SET_CURRENT_LIMIT_ALL  (1<<10)
00676 #define CMD_GET_DEMAND             (1<<11)
00677 #define CMD_GET_DEFAULT_NAME       (1<<12)
00678 #define CMD_GET_DEFAULT_THRESHOLD  (1<<13)
00679 #define CMD_SET_LABEL              (1<<14)
00680 #define CMD_ENABLE_COMMAND         (1<<15)
00681 #define CMD_DISABLE_COMMAND        (1<<16)
00682 
00683 /** 
00684 Bus driver commands */
00685 #define CMD_WRITE                   100
00686 #define CMD_READ                    101
00687 #define CMD_PUTS                    102
00688 #define CMD_GETS                    103
00689 #define CMD_DEBUG                   104
00690 #define CMD_NAME                    105
00691 
00692 /** 
00693 Commands for interrupt events error code */
00694 #define CMD_INTERRUPT_ENABLE        100
00695 #define CMD_INTERRUPT_DISABLE       101
00696 #define CMD_INTERRUPT_ATTACH        102
00697 #define CMD_INTERRUPT_DETACH        103
00698 
00699 /**
00700 macros for bus driver access */
00701 #define BD_GETS(s,z,p,t)   info->bd(CMD_GETS, info->bd_info, s, z, p, t)
00702 #define BD_READS(s,z,p,t)  info->bd(CMD_READ, info->bd_info, s, z, p, t)
00703 #define BD_PUTS(s)         info->bd(CMD_PUTS, info->bd_info, s)
00704 #define BD_WRITES(s)       info->bd(CMD_WRITE, info->bd_info, s)
00705 
00706 /**dox***************************************************************/
00707           /** @} *//* end of 26 */
00708 
00709 /**dox***************************************************************/
00710           /** @} *//* end of mdeferrorh */
00711 
00712 
00713 #define ANA_CONTINUE                  1
00714 #define ANA_SKIP                      0
00715 
00716 
00717 /*---- Buffer manager structures -----------------------------------*/
00718 
00719 /**dox***************************************************************/
00720 /** @addtogroup msectionh
00721  *  
00722  *  @{  */
00723 
00724 /**dox***************************************************************/
00725 /** @defgroup mbufferh Buffer Section
00726  *  @{  */
00727 /**
00728 Event header */
00729 typedef struct {
00730    short int event_id;           /**< event ID starting from one      */
00731    short int trigger_mask;       /**< hardware trigger mask           */
00732    DWORD serial_number;          /**< serial number starting from one */
00733    DWORD time_stamp;             /**< time of production of event     */
00734    DWORD data_size;              /**< size of event in bytes w/o header */
00735 } EVENT_HEADER;
00736 
00737 /**
00738 TRIGGER_MASK
00739 Extract or set the trigger mask field pointed by the argument.
00740 @param e pointer to the midas event (pevent)
00741 */
00742 #define TRIGGER_MASK(e)    ((((EVENT_HEADER *) e)-1)->trigger_mask)
00743 
00744 /**
00745 EVENT_ID
00746 Extract or set the event ID field pointed by the argument..
00747 @param e pointer to the midas event (pevent)
00748 */
00749 #define EVENT_ID(e)        ((((EVENT_HEADER *) e)-1)->event_id)
00750 
00751 /**
00752 SERIAL_NUMBER
00753 Extract or set/reset the serial number field pointed by the argument.
00754 @param e pointer to the midas event (pevent)
00755 */
00756 #define SERIAL_NUMBER(e)   ((((EVENT_HEADER *) e)-1)->serial_number)
00757 
00758 /**
00759 TIME_STAMP
00760 Extract or set/reset the time stamp field pointed by the argument.
00761 @param e pointer to the midas event (pevent)
00762 */
00763 #define TIME_STAMP(e)      ((((EVENT_HEADER *) e)-1)->time_stamp)
00764 #define EVENT_SOURCE(e,o)  (* (INT*) (e+o))
00765 
00766 /**
00767 system event IDs */
00768 #define EVENTID_BOR      ((short int) 0x8000)  /**< Begin-of-run      */
00769 #define EVENTID_EOR      ((short int) 0x8001)  /**< End-of-run        */
00770 #define EVENTID_MESSAGE  ((short int) 0x8002)  /**< Message events    */
00771 
00772 /**
00773 fragmented events */
00774 #define EVENTID_FRAG1    ((unsigned short) 0xC000)      /* first fragment */
00775 #define EVENTID_FRAG     ((unsigned short) 0xD000)      /* added to real event-id */
00776 
00777 /**
00778 magic number used in trigger_mask for BOR event */
00779 #define MIDAS_MAGIC      0x494d            /**< 'MI' */
00780 
00781 
00782 /**
00783 Buffer structure */
00784 typedef struct {
00785    INT id;                       /**< request id                      */
00786    BOOL valid;                   /**< indicating a valid entry        */
00787    short int event_id;           /**< event ID                        */
00788    short int trigger_mask;       /**< trigger mask                    */
00789    INT sampling_type;            /**< GET_ALL, GET_SOME, GET_FARM     */
00790                                  /**< dispatch function */
00791    void (*dispatch) (HNDLE, HNDLE, EVENT_HEADER *, void *);
00792 } EVENT_REQUEST;
00793 
00794 typedef struct {
00795    char name[NAME_LENGTH];            /**< name of client             */
00796    INT pid;                           /**< process ID                 */
00797    INT tid;                           /**< thread ID                  */
00798    INT thandle;                       /**< thread handle              */
00799    INT port;                          /**< UDP port for wake up       */
00800    INT read_pointer;                  /**< read pointer to buffer     */
00801    INT max_request_index;             /**< index of last request      */
00802    INT num_received_events;           /**< no of received events      */
00803    INT num_sent_events;               /**< no of sent events          */
00804    INT num_waiting_events;            /**< no of waiting events       */
00805    float data_rate;                   /**< data rate in kB/sec        */
00806    BOOL read_wait;                    /**< wait for read - flag       */
00807    INT write_wait;                    /**< wait for write # bytes     */
00808    BOOL wake_up;                      /**< client got a wake-up msg   */
00809    BOOL all_flag;                     /**< at least one GET_ALL request */
00810    DWORD last_activity;               /**< time of last activity      */
00811    DWORD watchdog_timeout;            /**< timeout in ms              */
00812 
00813    EVENT_REQUEST event_request[MAX_EVENT_REQUESTS];
00814 
00815 } BUFFER_CLIENT;
00816 
00817 typedef struct {
00818    char name[NAME_LENGTH];            /**< name of buffer             */
00819    INT num_clients;                   /**< no of active clients       */
00820    INT max_client_index;              /**< index of last client       */
00821    INT size;                          /**< size of data area in bytes */
00822    INT read_pointer;                  /**< read pointer               */
00823    INT write_pointer;                 /**< write pointer              */
00824    INT num_in_events;                 /**< no of received events      */
00825    INT num_out_events;                /**< no of distributed events   */
00826 
00827    BUFFER_CLIENT client[MAX_CLIENTS]; /**< entries for clients        */
00828 
00829 } BUFFER_HEADER;
00830 
00831 /* Per-process buffer access structure (descriptor) */
00832 
00833 typedef struct {
00834    BOOL attached;                   /**< TRUE if buffer is attached   */
00835    INT client_index;                /**< index to CLIENT str. in buf. */
00836    BUFFER_HEADER *buffer_header;    /**< pointer to buffer header     */
00837    void *buffer_data;               /**< pointer to buffer data       */
00838    char *read_cache;                /**< cache for burst read         */
00839    INT read_cache_size;             /**< cache size in bytes          */
00840    INT read_cache_rp;               /**< cache read pointer           */
00841    INT read_cache_wp;               /**< cache write pointer          */
00842    char *write_cache;               /**< cache for burst read         */
00843    INT write_cache_size;            /**< cache size in bytes          */
00844    INT write_cache_rp;              /**< cache read pointer           */
00845    INT write_cache_wp;              /**< cache write pointer          */
00846    HNDLE mutex;                     /**< mutex/semaphore handle       */
00847    INT shm_handle;                  /**< handle to shared memory      */
00848    INT index;                       /**< connection index / tid       */
00849    BOOL callback;                   /**< callback defined for this buffer */
00850 
00851 } BUFFER;
00852 
00853 typedef struct {
00854    DWORD type;                        /**< TID_xxx type                      */
00855    INT num_values;                    /**< number of values                  */
00856    char name[NAME_LENGTH];            /**< name of variable                  */
00857    INT data;                          /**< Address of variable (offset)      */
00858    INT total_size;                    /**< Total size of data block          */
00859    INT item_size;                     /**< Size of single data item          */
00860    WORD access_mode;                  /**< Access mode                       */
00861    WORD notify_count;                 /**< Notify counter                    */
00862    INT next_key;                      /**< Address of next key               */
00863    INT parent_keylist;                /**< keylist to which this key belongs */
00864    INT last_written;                  /**< Time of last write action  */
00865 } KEY;
00866 
00867 typedef struct {
00868    INT parent;                        /**< Address of parent key      */
00869    INT num_keys;                      /**< number of keys             */
00870    INT first_key;                     /**< Address of first key       */
00871 } KEYLIST;
00872 
00873 /**dox***************************************************************/
00874           /** @} *//* end of mbufferh */
00875 
00876 /*---- Equipment ---------------------------------------------------*/
00877 
00878 /**dox***************************************************************/
00879 /** @defgroup mequipment Equipment related
00880  *  @{  */
00881 
00882 #define DF_INPUT       (1<<0)         /**< channel is input           */
00883 #define DF_OUTPUT      (1<<1)         /**< channel is output          */
00884 #define DF_PRIO_DEVICE (1<<2)         /**< get demand values from device instead of ODB */
00885 #define DF_READ_ONLY   (1<<3)         /**< never write demand values to device */
00886 
00887 typedef struct {
00888    char name[NAME_LENGTH];            /**< Driver name                       */
00889     INT(*bd) (INT cmd, ...);          /**< Device driver entry point         */
00890    void *bd_info;                     /**< Private info for bus driver       */
00891 } BUS_DRIVER;
00892 
00893 typedef struct {
00894    char name[NAME_LENGTH];            /**< Driver name                       */
00895     INT(*dd) (INT cmd, ...);          /**< Device driver entry point         */
00896    INT channels;                      /**< Number of channels                */
00897     INT(*bd) (INT cmd, ...);          /**< Bus driver entry point            */
00898    DWORD flags;                       /**< Combination of DF_xx              */
00899    void *dd_info;                     /**< Private info for device driver    */
00900 } DEVICE_DRIVER;
00901 
00902 typedef struct {
00903    WORD event_id;                     /**< Event ID associated with equipm.  */
00904    WORD trigger_mask;                 /**< Trigger mask                      */
00905    char buffer[NAME_LENGTH];          /**< Event buffer to send events into  */
00906    INT eq_type;                       /**< One of EQ_xxx                     */
00907    INT source;                        /**< Event source (LAM/IRQ)            */
00908    char format[8];                    /**< Data format to produce            */
00909    BOOL enabled;                      /**< Enable flag                       */
00910    INT read_on;                       /**< Combination of Read-On flags RO_xxx */
00911    INT period;                        /**< Readout interval/Polling time in ms */
00912    double event_limit;                /**< Stop run when limit is reached    */
00913    DWORD num_subevents;               /**< Number of events in super event */
00914    INT history;                       /**< Log history                       */
00915    char frontend_host[NAME_LENGTH];   /**< Host on which FE is running       */
00916    char frontend_name[NAME_LENGTH];   /**< Frontend name                     */
00917    char frontend_file_name[256];      /**< Source file used for user FE      */
00918 } EQUIPMENT_INFO;
00919 
00920 typedef struct {
00921    double events_sent;
00922    double events_per_sec;
00923    double kbytes_per_sec;
00924 } EQUIPMENT_STATS;
00925 
00926 typedef struct eqpmnt *PEQUIPMENT;
00927 
00928 typedef struct eqpmnt {
00929    char name[NAME_LENGTH];              /**< Equipment name                            */
00930    EQUIPMENT_INFO info;                 /**< From above                                */
00931     INT(*readout) (char *, INT);        /**< Pointer to user readout routine           */
00932     INT(*cd) (INT cmd, PEQUIPMENT);     /**< Class driver routine                      */
00933    DEVICE_DRIVER *driver;               /**< Device driver list                        */
00934    void *event_descrip;                 /**< Init string for fixed events or bank list */
00935    void *cd_info;                       /**< private data for class driver             */
00936    INT status;                          /**< One of FE_xxx                             */
00937    DWORD last_called;                   /**< Last time event was read                  */
00938    DWORD last_idle;                     /**< Last time idle func was called            */
00939    DWORD poll_count;                    /**< Needed to poll 'period'                   */
00940    INT format;                          /**< FORMAT_xxx                                */
00941    HNDLE buffer_handle;                 /**< MIDAS buffer handle                       */
00942    HNDLE hkey_variables;                /**< Key to variables subtree in ODB           */
00943    DWORD serial_number;                 /**< event serial number                       */
00944    DWORD subevent_number;               /**< subevent number                           */
00945    DWORD odb_out;                       /**< # updates FE -> ODB                       */
00946    DWORD odb_in;                        /**< # updated ODB -> FE                       */
00947    DWORD bytes_sent;                    /**< number of bytes sent                      */
00948    DWORD events_sent;                   /**< number of events sent                     */
00949    EQUIPMENT_STATS stats;
00950 } EQUIPMENT;
00951 /**dox***************************************************************/
00952           /** @} *//* end of mequipmenth */
00953 
00954 /*---- Banks -------------------------------------------------------*/
00955 
00956 /**dox***************************************************************/
00957 /** @defgroup mbank Bank related
00958  *  @{  */
00959 
00960 #define BANK_FORMAT_VERSION     1      /**< - */
00961 #define BANK_FORMAT_32BIT   (1<<4)     /**< - */
00962 
00963 typedef struct {
00964    DWORD data_size;                    /**< Size in bytes */
00965    DWORD flags;                        /**< internal flag */
00966 } BANK_HEADER;
00967 
00968 typedef struct {
00969    char name[4];                       /**< - */
00970    WORD type;                          /**< - */
00971    WORD data_size;                     /**< - */
00972 } BANK;
00973 
00974 typedef struct {
00975    char name[4];                       /**< - */
00976    DWORD type;                         /**< - */
00977    DWORD data_size;                    /**< - */
00978 } BANK32;
00979 
00980 typedef struct {
00981    char name[NAME_LENGTH];             /**< - */
00982    DWORD type;                         /**< - */
00983    DWORD n_data;                       /**< - */
00984 } TAG;
00985 
00986 typedef struct {
00987    char name[9];                       /**< - */
00988    WORD type;                          /**< - */
00989    DWORD size;                         /**< - */
00990    char **init_str;                    /**< - */
00991    BOOL output_flag;                   /**< - */
00992    void *addr;                         /**< - */
00993    DWORD n_data;                       /**< - */
00994    HNDLE def_key;                      /**< - */
00995 } BANK_LIST;
00996 /**dox***************************************************************/
00997           /** @} *//* end of mbank */
00998 
00999 /*---- Analyzer request --------------------------------------------*/
01000 /**dox***************************************************************/
01001 /** @defgroup manalyzer Analyzer related
01002  *  @{  */
01003 
01004 typedef struct {
01005    char name[NAME_LENGTH];            /**< Module name                       */
01006    char author[NAME_LENGTH];          /**< Author                            */
01007     INT(*analyzer) (EVENT_HEADER *, void *);
01008                                            /**< Pointer to user analyzer routine  */
01009     INT(*bor) (INT run_number);       /**< Pointer to begin-of-run routine   */
01010     INT(*eor) (INT run_number);       /**< Pointer to end-of-run routine     */
01011     INT(*init) ();                    /**< Pointer to init routine           */
01012     INT(*exit) ();                    /**< Pointer to exit routine           */
01013    void *parameters;                  /**< Pointer to parameter structure    */
01014    INT param_size;                    /**< Size of parameter structure       */
01015    char **init_str;                   /**< Parameter init string             */
01016    BOOL enabled;                      /**< Enabled flag                      */
01017    void *histo_folder;
01018 } ANA_MODULE;
01019 
01020 typedef struct {
01021    INT event_id;                      /**< Event ID associated with equipm.  */
01022    INT trigger_mask;                  /**< Trigger mask                      */
01023    INT sampling_type;                 /**< GET_ALL/GET_SOME                  */
01024    char buffer[NAME_LENGTH];          /**< Event buffer to send events into  */
01025    BOOL enabled;                      /**< Enable flag                       */
01026    char client_name[NAME_LENGTH];     /**< Analyzer name                     */
01027    char host[NAME_LENGTH];            /**< Host on which analyzer is running */
01028 } AR_INFO;
01029 
01030 typedef struct {
01031    double events_received;
01032    double events_per_sec;
01033    double events_written;
01034 } AR_STATS;
01035 
01036 typedef struct {
01037    char event_name[NAME_LENGTH];      /**< Event name                        */
01038    AR_INFO ar_info;                   /**< From above                        */
01039     INT(*analyzer) (EVENT_HEADER *, void *);/**< Pointer to user analyzer routine  */
01040    ANA_MODULE **ana_module;           /**< List of analyzer modules          */
01041    BANK_LIST *bank_list;              /**< List of banks for event           */
01042    INT rwnt_buffer_size;              /**< Size in events of RW N-tuple buf  */
01043    BOOL use_tests;                    /**< Use tests for this event          */
01044    char **init_string;
01045    INT status;                        /**< One of FE_xxx                     */
01046    HNDLE buffer_handle;               /**< MIDAS buffer handle               */
01047    HNDLE request_id;                  /**< Event request handle              */
01048    HNDLE hkey_variables;              /**< Key to variables subtree in ODB   */
01049    HNDLE hkey_common;                 /**< Key to common subtree             */
01050    void *addr;                        /**< Buffer for CWNT filling           */
01051    struct {
01052       DWORD run;
01053       DWORD serial;
01054       DWORD time;
01055    } number;                          /**< Buffer for event number for CWNT  */
01056    DWORD events_received;             /**< number of events sent             */
01057    DWORD events_written;              /**< number of events written          */
01058    AR_STATS ar_stats;
01059 
01060 } ANALYZE_REQUEST;
01061 
01062 /*---- Tests -------------------------------------------------------*/
01063 
01064 typedef struct {
01065    char name[80];
01066    BOOL registered;
01067    DWORD count;
01068    DWORD previous_count;
01069    BOOL value;
01070 } ANA_TEST;
01071 
01072 #define SET_TEST(t, v) { if (!t.registered) test_register(&t); t.value = (v); }
01073 #define TEST(t) (t.value)
01074 
01075 #ifdef DEFINE_TESTS
01076 #define DEF_TEST(t) ANA_TEST t = { #t, 0, 0, FALSE };
01077 #else
01078 #define DEF_TEST(t) extern ANA_TEST t;
01079 #endif
01080 /**dox***************************************************************/
01081           /** @} *//* end of manalyzer */
01082 
01083 /*---- History structures ------------------------------------------*/
01084 
01085 /**dox***************************************************************/
01086 /** @defgroup mhistoryh History related
01087  *  @{  */
01088 
01089 #define RT_DATA (*((DWORD *) "HSDA"))
01090 #define RT_DEF  (*((DWORD *) "HSDF"))
01091 
01092 typedef struct {
01093    DWORD record_type;           /* RT_DATA or RT_DEF */
01094    DWORD event_id;
01095    DWORD time;
01096    DWORD def_offset;            /* place of definition */
01097    DWORD data_size;             /* data following this header in bytes */
01098 } HIST_RECORD;
01099 
01100 typedef struct {
01101    DWORD event_id;
01102    char event_name[NAME_LENGTH];
01103    DWORD def_offset;
01104 } DEF_RECORD;
01105 
01106 typedef struct {
01107    DWORD event_id;
01108    DWORD time;
01109    DWORD offset;
01110 } INDEX_RECORD;
01111 
01112 typedef struct {
01113    DWORD event_id;
01114    char event_name[NAME_LENGTH];
01115    DWORD n_tag;
01116    TAG *tag;
01117    DWORD hist_fh;
01118    DWORD index_fh;
01119    DWORD def_fh;
01120    DWORD base_time;
01121    DWORD def_offset;
01122 } HISTORY;
01123 /**dox***************************************************************/
01124           /** @} *//* end of mhistoryh */
01125 
01126 /*---- ODB runinfo -------------------------------------------------*/
01127 
01128 /**dox***************************************************************/
01129 /** @defgroup modbh ODB runinfo related
01130  *  @{  */
01131 /** Contains the main parameters regarding the run status.
01132     The containt reflects the current system ONLY if Midas clients
01133     are connected. Otherwise the status is erroneous.
01134 */
01135 typedef struct {
01136    INT state;                         /**< Current run condition  */
01137    INT online_mode;                   /**< Mode of operation online/offline */
01138    INT run_number;                    /**< Current processing run number      */
01139    INT transition_in_progress;        /**< Intermediate state during transition */
01140    INT requested_transition;          /**< Deferred transition request */
01141    char start_time[32];               /**< ASCII of the last start time */
01142    DWORD start_time_binary;           /**< Bin of the last start time */
01143    char stop_time[32];                /**< ASCII of the last stop time */
01144    DWORD stop_time_binary;            /**< ASCII of the last stop time */
01145 } RUNINFO;
01146 
01147 #define RUNINFO_STR(_name) char *_name[] = {\
01148 "[.]",\
01149 "State = INT : 1",\
01150 "Online Mode = INT : 1",\
01151 "Run number = INT : 0",\
01152 "Transition in progress = INT : 0",\
01153 "Requested transition = INT : 0",\
01154 "Start time = STRING : [32] Tue Sep 09 15:04:42 1997",\
01155 "Start time binary = DWORD : 0",\
01156 "Stop time = STRING : [32] Tue Sep 09 15:04:42 1997",\
01157 "Stop time binary = DWORD : 0",\
01158 "",\
01159 NULL }
01160 /**dox***************************************************************/
01161           /** @} *//* end of modbh */
01162 
01163 /*---- Alarm system ------------------------------------------------*/
01164 /**dox***************************************************************/
01165 /** @defgroup malarmh Alarm related
01166  * Alarm structure. 
01167  *  @{  */
01168 
01169 /********************************************************************/
01170 /**
01171 Program information structure */
01172 typedef struct {
01173    BOOL required;
01174    INT watchdog_timeout;
01175    DWORD check_interval;
01176    char start_command[256];
01177    BOOL auto_start;
01178    BOOL auto_stop;
01179    BOOL auto_restart;
01180    char alarm_class[32];
01181    DWORD first_failed;
01182 } PROGRAM_INFO;
01183 
01184 #define AT_INTERNAL   1 /**< - */
01185 #define AT_PROGRAM    2 /**< - */
01186 #define AT_EVALUATED  3 /**< - */
01187 #define AT_PERIODIC   4 /**< - */
01188 #define AT_LAST       4 /**< - */
01189 
01190 #define PROGRAM_INFO_STR(_name) char *_name[] = {\
01191 "[.]",\
01192 "Required = BOOL : n",\
01193 "Watchdog timeout = INT : 10000",\
01194 "Check interval = DWORD : 180000",\
01195 "Start command = STRING : [256] ",\
01196 "Auto start = BOOL : n",\
01197 "Auto stop = BOOL : n",\
01198 "Auto restart = BOOL : n",\
01199 "Alarm class = STRING : [32] ",\
01200 "First failed = DWORD : 0",\
01201 "",\
01202 NULL }
01203 
01204 /**
01205 Alarm class structure */
01206 typedef struct {
01207    BOOL write_system_message;
01208    BOOL write_elog_message;
01209    INT system_message_interval;
01210    DWORD system_message_last;
01211    char execute_command[256];
01212    INT execute_interval;
01213    DWORD execute_last;
01214    BOOL stop_run;
01215    char display_bgcolor[32];
01216    char display_fgcolor[32];
01217 } ALARM_CLASS;
01218 
01219 #define ALARM_CLASS_STR(_name) char *_name[] = {\
01220 "[.]",\
01221 "Write system message = BOOL : y",\
01222 "Write Elog message = BOOL : n",\
01223 "System message interval = INT : 60",\
01224 "System message last = DWORD : 0",\
01225 "Execute command = STRING : [256] ",\
01226 "Execute interval = INT : 0",\
01227 "Execute last = DWORD : 0",\
01228 "Stop run = BOOL : n",\
01229 "Display BGColor = STRING : [32] red",\
01230 "Display FGColor = STRING : [32] black",\
01231 "",\
01232 NULL }
01233 
01234 /**
01235 Alarm structure */
01236 typedef struct {
01237    BOOL active;
01238    INT triggered;
01239    INT type;
01240    INT check_interval;
01241    DWORD checked_last;
01242    char time_triggered_first[32];
01243    char time_triggered_last[32];
01244    char condition[256];
01245    char alarm_class[32];
01246    char alarm_message[80];
01247 } ALARM;
01248 
01249 #define ALARM_ODB_STR(_name) char *_name[] = {\
01250 "[.]",\
01251 "Active = BOOL : n",\
01252 "Triggered = INT : 0",\
01253 "Type = INT : 3",\
01254 "Check interval = INT : 60",\
01255 "Checked last = DWORD : 0",\
01256 "Time triggered first = STRING : [32] ",\
01257 "Time triggered last = STRING : [32] ",\
01258 "Condition = STRING : [256] /Runinfo/Run number > 100",\
01259 "Alarm Class = STRING : [32] Alarm",\
01260 "Alarm Message = STRING : [80] Run number became too large",\
01261 "",\
01262 NULL }
01263 
01264 #define ALARM_PERIODIC_STR(_name) char *_name[] = {\
01265 "[.]",\
01266 "Active = BOOL : n",\
01267 "Triggered = INT : 0",\
01268 "Type = INT : 4",\
01269 "Check interval = INT : 28800",\
01270 "Checked last = DWORD : 0",\
01271 "Time triggered first = STRING : [32] ",\
01272 "Time triggered last = STRING : [32] ",\
01273 "Condition = STRING : [256] ",\
01274 "Alarm Class = STRING : [32] Warning",\
01275 "Alarm Message = STRING : [80] Please do your shift checks",\
01276 "",\
01277 NULL }
01278 
01279 /**dox***************************************************************/
01280           /** @} *//* end of malarmh */
01281 
01282 /**dox***************************************************************/
01283 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01284 
01285 /*---- malloc/free routines for debugging --------------------------*/
01286 
01287 #ifdef _MEM_DBG
01288 #define M_MALLOC(x)   dbg_malloc((x), __FILE__, __LINE__)
01289 #define M_CALLOC(x,y) dbg_calloc((x), (y), __FILE__, __LINE__)
01290 #define M_FREE(x)     dbg_free  ((x), __FILE__, __LINE__)
01291 #else
01292 #define M_MALLOC(x) malloc(x)
01293 #define M_CALLOC(x,y) calloc(x,y)
01294 #define M_FREE(x) free(x)
01295 #endif
01296 
01297 void *dbg_malloc(unsigned int size, char *file, int line);
01298 void *dbg_calloc(unsigned int size, unsigned int count, char *file, int line);
01299 void dbg_free(void *adr, char *file, int line);
01300 
01301 /*---- CERN libray -------------------------------------------------*/
01302 
01303 #ifdef extname
01304 #define PAWC_NAME pawc_
01305 #else
01306 #define PAWC_NAME PAWC
01307 #endif
01308 
01309 #define PAWC_DEFINE(size) \
01310 INT PAWC_NAME[size/4];    \
01311 INT pawc_size = size
01312 
01313 /* bug in ROOT include files */
01314 #undef GetCurrentTime
01315 
01316 /*---- RPC ---------------------------------------------------------*/
01317 
01318 /**
01319 flags */
01320 #define RPC_IN       (1 << 0)
01321 #define RPC_OUT      (1 << 1)
01322 #define RPC_POINTER  (1 << 2)
01323 #define RPC_FIXARRAY (1 << 3)
01324 #define RPC_VARARRAY (1 << 4)
01325 #define RPC_OUTGOING (1 << 5)
01326 
01327 /**
01328 Server types */
01329 #define ST_NONE            0
01330 #define ST_SINGLE          1
01331 #define ST_MTHREAD         2
01332 #define ST_MPROCESS        3
01333 #define ST_SUBPROCESS      4
01334 #define ST_REMOTE          5
01335 
01336 /**
01337 function list */
01338 typedef struct {
01339    WORD tid;
01340    WORD flags;
01341    INT n;
01342 } RPC_PARAM;
01343 
01344 typedef struct {
01345    INT id;
01346    char *name;
01347    RPC_PARAM param[20];
01348     INT(*dispatch) (INT, void **);
01349 } RPC_LIST;
01350 
01351 /**
01352 IDs allow for users */
01353 #define RPC_MIN_ID    1
01354 #define RPC_MAX_ID 9999
01355 
01356 /**
01357 Data conversion flags */
01358 #define CF_ENDIAN          (1<<0)
01359 #define CF_IEEE2VAX        (1<<1)
01360 #define CF_VAX2IEEE        (1<<2)
01361 #define CF_ASCII           (1<<3)
01362 
01363 #define CBYTE(_i)        (* ((BYTE *)       prpc_param[_i]))
01364 #define CPBYTE(_i)       (  ((BYTE *)       prpc_param[_i]))
01365 
01366 #define CSHORT(_i)       (* ((short *)      prpc_param[_i]))
01367 #define CPSHORT(_i)      (  ((short *)      prpc_param[_i]))
01368 
01369 #define CINT(_i)         (* ((INT *)        prpc_param[_i]))
01370 #define CPINT(_i)        (  ((INT *)        prpc_param[_i]))
01371 
01372 #define CWORD(_i)        (* ((WORD *)       prpc_param[_i]))
01373 #define CPWORD(_i)       (  ((WORD *)       prpc_param[_i]))
01374 
01375 #define CLONG(_i)        (* ((long *)       prpc_param[_i]))
01376 #define CPLONG(_i)       (  ((long *)       prpc_param[_i]))
01377 
01378 #define CDWORD(_i)       (* ((DWORD *)      prpc_param[_i]))
01379 #define CPDWORD(_i)      (  ((DWORD *)      prpc_param[_i]))
01380 
01381 #define CHNDLE(_i)       (* ((HNDLE *)      prpc_param[_i]))
01382 #define CPHNDLE(_i)      (  ((HNDLE *)      prpc_param[_i]))
01383 
01384 #define CBOOL(_i)        (* ((BOOL *)       prpc_param[_i]))
01385 #define CPBOOL(_i)       (  ((BOOL *)       prpc_param[_i]))
01386 
01387 #define CFLOAT(_i)       (* ((float *)      prpc_param[_i]))
01388 #define CPFLOAT(_i)      (  ((float *)      prpc_param[_i]))
01389 
01390 #define CDOUBLE(_i)      (* ((double *)     prpc_param[_i]))
01391 #define CPDOUBLE(_i)     (  ((double *)     prpc_param[_i]))
01392 
01393 #define CSTRING(_i)      (  ((char *)       prpc_param[_i]))
01394 #define CARRAY(_i)       (  ((void *)       prpc_param[_i]))
01395 
01396 #define CBYTE(_i)        (* ((BYTE *)       prpc_param[_i]))
01397 #define CPBYTE(_i)       (  ((BYTE *)       prpc_param[_i]))
01398 
01399 #define CSHORT(_i)       (* ((short *)      prpc_param[_i]))
01400 #define CPSHORT(_i)      (  ((short *)      prpc_param[_i]))
01401 
01402 #define CINT(_i)         (* ((INT *)        prpc_param[_i]))
01403 #define CPINT(_i)        (  ((INT *)        prpc_param[_i]))
01404 
01405 #define CWORD(_i)        (* ((WORD *)       prpc_param[_i]))
01406 #define CPWORD(_i)       (  ((WORD *)       prpc_param[_i]))
01407 
01408 #define CLONG(_i)        (* ((long *)       prpc_param[_i]))
01409 #define CPLONG(_i)       (  ((long *)       prpc_param[_i]))
01410 
01411 #define CDWORD(_i)       (* ((DWORD *)      prpc_param[_i]))
01412 #define CPDWORD(_i)      (  ((DWORD *)      prpc_param[_i]))
01413 
01414 #define CHNDLE(_i)       (* ((HNDLE *)      prpc_param[_i]))
01415 #define CPHNDLE(_i)      (  ((HNDLE *)      prpc_param[_i]))
01416 
01417 #define CBOOL(_i)        (* ((BOOL *)       prpc_param[_i]))
01418 #define CPBOOL(_i)       (  ((BOOL *)       prpc_param[_i]))
01419 
01420 #define CFLOAT(_i)       (* ((float *)      prpc_param[_i]))
01421 #define CPFLOAT(_i)      (  ((float *)      prpc_param[_i]))
01422 
01423 #define CDOUBLE(_i)      (* ((double *)     prpc_param[_i]))
01424 #define CPDOUBLE(_i)     (  ((double *)     prpc_param[_i]))
01425 
01426 #define CSTRING(_i)      (  ((char *)       prpc_param[_i]))
01427 #define CARRAY(_i)       (  ((void *)       prpc_param[_i]))
01428 
01429 
01430 
01431 #define cBYTE            (* ((BYTE *)       prpc_param[--n_param]))
01432 #define cPBYTE           (  ((BYTE *)       prpc_param[--n_param]))
01433 
01434 #define cSHORT           (* ((short *)      prpc_param[--n_param]))
01435 #define cPSHORT          (  ((short *)      prpc_param[--n_param]))
01436 
01437 #define cINT             (* ((INT *)        prpc_param[--n_param]))
01438 #define cPINT            (  ((INT *)        prpc_param[--n_param]))
01439 
01440 #define cWORD            (* ((WORD *)       prpc_param[--n_param]))
01441 #define cPWORD           (  ((WORD *)       prpc_param[--n_param]))
01442 
01443 #define cLONG            (* ((long *)       prpc_param[--n_param]))
01444 #define cPLONG           (  ((long *)       prpc_param[--n_param]))
01445 
01446 #define cDWORD           (* ((DWORD *)      prpc_param[--n_param]))
01447 #define cPDWORD          (  ((DWORD *)      prpc_param[--n_param]))
01448 
01449 #define cHNDLE           (* ((HNDLE *)      prpc_param[--n_param]))
01450 #define cPHNDLE          (  ((HNDLE *)      prpc_param[--n_param]))
01451 
01452 #define cBOOL            (* ((BOOL *)       prpc_param[--n_param]))
01453 #define cPBOOL           (  ((BOOL *)       prpc_param[--n_param]))
01454 
01455 #define cFLOAT           (* ((float *)      prpc_param[--n_param]))
01456 #define cPFLOAT          (  ((float *)      prpc_param[--n_param]))
01457 
01458 #define cDOUBLE          (* ((double *)     prpc_param[--n_param]))
01459 #define cPDOUBLE         (  ((double *)     prpc_param[--n_param]))
01460 
01461 #define cSTRING          (  ((char *)       prpc_param[--n_param]))
01462 #define cARRAY           (  ((void *)       prpc_param[--n_param]))
01463 
01464 /*---- Function declarations ---------------------------------------*/
01465 
01466 /* make functions callable from a C++ program */
01467 #ifdef __cplusplus
01468 extern "C" {
01469 #endif
01470 
01471 /* make functions under WinNT dll exportable */
01472 #if defined(OS_WINNT) && defined(MIDAS_DLL)
01473 #define EXPRT __declspec(dllexport)
01474 #else
01475 #define EXPRT
01476 #endif
01477 
01478    /*---- common routines ----*/
01479    INT EXPRT cm_get_error(INT code, char *string);
01480    char EXPRT *cm_get_version(void);
01481    INT EXPRT cm_get_environment(char *host_name, int host_name_size,
01482                                 char *exp_name, int exp_name_size);
01483    INT EXPRT cm_list_experiments(char *host_name,
01484                                  char exp_name[MAX_EXPERIMENT][NAME_LENGTH]);
01485    INT EXPRT cm_select_experiment(char *host_name, char *exp_name);
01486    INT EXPRT cm_connect_experiment(char *host_name, char *exp_name,
01487                                    char *client_name, void (*func) (char *));
01488    INT EXPRT cm_connect_experiment1(char *host_name, char *exp_name,
01489                                     char *client_name,
01490                                     void (*func) (char *), INT odb_size,
01491                                     DWORD watchdog_timeout);
01492    INT EXPRT cm_disconnect_experiment(void);
01493    INT EXPRT cm_register_transition(INT transition, INT(*func) (INT, char *),
01494                                     int sequence_number);
01495    INT EXPRT cm_deregister_transition(INT transition);
01496    INT EXPRT cm_set_transition_sequence(INT transition, INT sequence_number);
01497    INT EXPRT cm_query_transition(int *transition, int *run_number, int *trans_time);
01498    INT EXPRT cm_register_deferred_transition(INT transition, BOOL(*func) (INT, BOOL));
01499    INT EXPRT cm_check_deferred_transition(void);
01500    INT EXPRT cm_transition(INT transition, INT run_number, char *error,
01501                            INT strsize, INT async_flag, INT debug_flag);
01502    INT EXPRT cm_register_server(void);
01503    INT EXPRT cm_register_function(INT id, INT(*func) (INT, void **));
01504    INT EXPRT cm_connect_client(char *client_name, HNDLE * hConn);
01505    INT EXPRT cm_disconnect_client(HNDLE hConn, BOOL bShutdown);
01506    INT EXPRT cm_set_experiment_database(HNDLE hDB, HNDLE hKeyClient);
01507    INT EXPRT cm_get_experiment_database(HNDLE * hDB, HNDLE * hKeyClient);
01508    INT EXPRT cm_set_experiment_mutex(INT mutex_alarm, INT mutex_elog);
01509    INT EXPRT cm_get_experiment_mutex(INT * mutex_alarm, INT * mutex_elog);
01510    INT EXPRT cm_set_client_info(HNDLE hDB, HNDLE * hKeyClient,
01511                                 char *host_name, char *client_name,
01512                                 INT computer_id, char *password, DWORD watchdog_timeout);
01513    INT EXPRT cm_get_client_info(char *client_name);
01514    INT EXPRT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout);
01515    INT EXPRT cm_get_watchdog_params(BOOL * call_watchdog, DWORD * timeout);
01516    INT EXPRT cm_get_watchdog_info(HNDLE hDB, char *client_name,
01517                                   DWORD * timeout, DWORD * last);
01518    INT EXPRT cm_enable_watchdog(BOOL flag);
01519    void EXPRT cm_watchdog(int);
01520    INT EXPRT cm_shutdown(char *name, BOOL bUnique);
01521    INT EXPRT cm_exist(char *name, BOOL bUnique);
01522    INT EXPRT cm_cleanup(char *client_name, BOOL ignore_timeout);
01523    INT EXPRT cm_yield(INT millisec);
01524    INT EXPRT cm_execute(char *command, char *result, INT buf_size);
01525    INT EXPRT cm_synchronize(DWORD * sec);
01526    INT EXPRT cm_asctime(char *str, INT buf_size);
01527    INT EXPRT cm_time(DWORD * time);
01528    BOOL EXPRT cm_is_ctrlc_pressed();
01529    void EXPRT cm_ack_ctrlc_pressed();
01530 
01531    INT EXPRT cm_set_msg_print(INT system_mask, INT user_mask, int (*func) (const char *));
01532    INT EXPRT cm_msg(INT message_type, char *filename, INT line,
01533                     const char *routine, const char *format, ...);
01534    INT EXPRT cm_msg1(INT message_type, char *filename, INT line,
01535                      const char *facility, const char *routine, const char *format, ...);
01536    INT EXPRT cm_msg_register(void (*func)
01537                               (HNDLE, HNDLE, EVENT_HEADER *, void *));
01538    INT EXPRT cm_msg_retrieve(INT n_message, char *message, INT * buf_size);
01539 
01540    BOOL EXPRT equal_ustring(char *str1, char *str2);
01541 
01542    /*---- buffer manager ----*/
01543    INT EXPRT bm_open_buffer(char *buffer_name, INT buffer_size, INT * buffer_handle);
01544    INT EXPRT bm_close_buffer(INT buffer_handle);
01545    INT EXPRT bm_close_all_buffers(void);
01546    INT EXPRT bm_init_buffer_counters(INT buffer_handle);
01547    INT EXPRT bm_get_buffer_info(INT buffer_handle, BUFFER_HEADER * buffer_header);
01548    INT EXPRT bm_get_buffer_level(INT buffer_handle, INT * n_bytes);
01549    INT EXPRT bm_set_cache_size(INT buffer_handle, INT read_size, INT write_size);
01550    INT EXPRT bm_compose_event(EVENT_HEADER * event_header,
01551                               short int event_id, short int trigger_mask,
01552                               DWORD size, DWORD serial);
01553    INT EXPRT bm_request_event(INT buffer_handle, short int event_id,
01554                               short int trigger_mask, INT sampling_type,
01555                               INT * request_id, void (*func) (HNDLE, HNDLE,
01556                                                               EVENT_HEADER *, void *));
01557    INT EXPRT bm_add_event_request(INT buffer_handle, short int event_id,
01558                                   short int trigger_mask,
01559                                   INT sampling_type, void (*func) (HNDLE,
01560                                                                    HNDLE,
01561                                                                    EVENT_HEADER
01562                                                                    *,
01563                                                                    void *),
01564                                   INT request_id);
01565    INT EXPRT bm_delete_request(INT request_id);
01566    INT EXPRT bm_send_event(INT buffer_handle, void *event, INT buf_size, INT async_flag);
01567    INT EXPRT bm_receive_event(INT buffer_handle, void *destination,
01568                               INT * buf_size, INT async_flag);
01569    INT EXPRT bm_skip_event(INT buffer_handle);
01570    INT EXPRT bm_flush_cache(INT buffer_handle, INT async_flag);
01571    INT EXPRT bm_poll_event(INT flag);
01572    INT EXPRT bm_empty_buffers(void);
01573 
01574    /*---- online database functions -----*/
01575    INT EXPRT db_open_database(char *database_name, INT database_size,
01576                               HNDLE * hdb, char *client_name);
01577    INT EXPRT db_close_database(HNDLE database_handle);
01578    INT EXPRT db_close_all_databases(void);
01579    INT EXPRT db_protect_database(HNDLE database_handle);
01580 
01581    INT EXPRT db_create_key(HNDLE hdb, HNDLE key_handle, char *key_name, DWORD type);
01582    INT EXPRT db_create_link(HNDLE hdb, HNDLE key_handle, char *link_name,
01583                             char *destination);
01584    INT EXPRT db_set_value(HNDLE hdb, HNDLE hKeyRoot, char *key_name,
01585                           void *data, INT size, INT num_values, DWORD type);
01586    INT EXPRT db_get_value(HNDLE hdb, HNDLE hKeyRoot, char *key_name,
01587                           void *data, INT * size, DWORD type, BOOL create);
01588    INT EXPRT db_find_key(HNDLE hdb, HNDLE hkey, char *name, HNDLE * hsubkey);
01589    INT EXPRT db_find_link(HNDLE hDB, HNDLE hKey, char *key_name, HNDLE * subhKey);
01590    INT EXPRT db_find_key1(HNDLE hdb, HNDLE hkey, char *name, HNDLE * hsubkey);
01591    INT EXPRT db_find_link1(HNDLE hDB, HNDLE hKey, char *key_name, HNDLE * subhKey);
01592    INT EXPRT db_scan_tree(HNDLE hDB, HNDLE hKey, int level,
01593                           INT(*callback) (HNDLE, HNDLE, KEY *, INT, void *), void *info);
01594    INT EXPRT db_scan_tree_link(HNDLE hDB, HNDLE hKey, int level,
01595                                void (*callback) (HNDLE, HNDLE, KEY *, INT,
01596                                                  void *), void *info);
01597    INT EXPRT db_get_path(HNDLE hDB, HNDLE hKey, char *path, INT buf_size);
01598    INT EXPRT db_delete_key(HNDLE database_handle, HNDLE key_handle, BOOL follow_links);
01599    INT EXPRT db_enum_key(HNDLE hdb, HNDLE key_handle, INT index, HNDLE * subkey_handle);
01600    INT EXPRT db_enum_link(HNDLE hdb, HNDLE key_handle, INT index, HNDLE * subkey_handle);
01601    INT EXPRT db_get_next_link(HNDLE hdb, HNDLE key_handle, HNDLE * subkey_handle);
01602    INT EXPRT db_get_key(HNDLE hdb, HNDLE key_handle, KEY * key);
01603    INT EXPRT db_get_key_info(HNDLE hDB, HNDLE hKey, char *name,
01604                              INT name_size, INT * type, INT * num_values,
01605                              INT * item_size);
01606    INT EXPRT db_get_key_time(HNDLE hdb, HNDLE key_handle, DWORD * delta);
01607    INT EXPRT db_rename_key(HNDLE hDB, HNDLE hKey, char *name);
01608    INT EXPRT db_reorder_key(HNDLE hDB, HNDLE hKey, INT index);
01609    INT EXPRT db_get_data(HNDLE hdb, HNDLE key_handle, void *data,
01610                          INT * buf_size, DWORD type);
01611    INT EXPRT db_get_data1(HNDLE hDB, HNDLE hKey, void *data,
01612                           INT * buf_size, DWORD type, INT * num_values);
01613    INT EXPRT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data,
01614                                INT * buf_size, INT index, DWORD type);
01615    INT EXPRT db_set_data(HNDLE hdb, HNDLE hKey, void *data, INT buf_size,
01616                          INT num_values, DWORD type);
01617    INT EXPRT db_set_data_index(HNDLE hDB, HNDLE hKey, void *data, INT size,
01618                                INT index, DWORD type);
01619    INT EXPRT db_set_data_index2(HNDLE hDB, HNDLE hKey, void *data,
01620                                 INT size, INT index, DWORD type, BOOL bNotify);
01621    INT EXPRT db_set_num_values(HNDLE hDB, HNDLE hKey, INT num_values);
01622    INT EXPRT db_merge_data(HNDLE hDB, HNDLE hKeyRoot, char *name,
01623                            void *data, INT data_size, INT num_values, INT type);
01624    INT EXPRT db_set_mode(HNDLE hdb, HNDLE key_handle, WORD mode, BOOL recurse);
01625    INT EXPRT db_create_record(HNDLE hdb, HNDLE hkey, char *name, char *init_str);
01626    INT EXPRT db_check_record(HNDLE hDB, HNDLE hKey, char *key_name,
01627                              char *rec_str, BOOL correct);
01628    INT EXPRT db_open_record(HNDLE hdb, HNDLE hkey, void *ptr, INT rec_size,
01629                             WORD access, void (*dispatcher) (INT, INT,
01630                                                              void *), void *info);
01631    INT EXPRT db_close_record(HNDLE hdb, HNDLE hkey);
01632    INT EXPRT db_get_record(HNDLE hdb, HNDLE hKey, void *data, INT * buf_size, INT align);
01633    INT EXPRT db_get_record_size(HNDLE hdb, HNDLE hKey, INT align, INT * buf_size);
01634    INT EXPRT db_set_record(HNDLE hdb, HNDLE hKey, void *data, INT buf_size, INT align);
01635    INT EXPRT db_send_changed_records(void);
01636    INT EXPRT db_get_open_records(HNDLE hDB, HNDLE hKey, char *str,
01637                                  INT buf_size, BOOL fix);
01638 
01639    INT EXPRT db_add_open_record(HNDLE hDB, HNDLE hKey, WORD access_mode);
01640    INT EXPRT db_remove_open_record(HNDLE hDB, HNDLE hKey, BOOL lock);
01641 
01642    INT EXPRT db_load(HNDLE hdb, HNDLE key_handle, char *filename, BOOL bRemote);
01643    INT EXPRT db_save(HNDLE hdb, HNDLE key_handle, char *filename, BOOL bRemote);
01644    INT EXPRT db_copy(HNDLE hDB, HNDLE hKey, char *buffer, INT * buffer_size, char *path);
01645    INT EXPRT db_paste(HNDLE hDB, HNDLE hKeyRoot, char *buffer);
01646    INT EXPRT db_paste_xml(HNDLE hDB, HNDLE hKeyRoot, char *buffer);
01647    INT EXPRT db_save_struct(HNDLE hDB, HNDLE hKey, char *file_name,
01648                             char *struct_name, BOOL append);
01649    INT EXPRT db_save_string(HNDLE hDB, HNDLE hKey, char *file_name,
01650                             char *string_name, BOOL append);
01651    INT EXPRT db_save_xml(HNDLE hDB, HNDLE hKey, char *file_name);
01652    INT EXPRT db_copy_xml(HNDLE hDB, HNDLE hKey, char *buffer, INT * buffer_size);
01653 
01654    INT EXPRT db_sprintf(char *string, void *data, INT data_size, INT index, DWORD type);
01655    INT EXPRT db_sprintfh(char *string, void *data, INT data_size, INT index, DWORD type);
01656    INT EXPRT db_sscanf(char *string, void *data, INT * data_size, INT index, DWORD type);
01657    char EXPRT *strcomb(char **list);
01658 
01659    /*---- Bank routines ----*/
01660    void EXPRT bk_init(void *pbh);
01661    void EXPRT bk_init32(void *event);
01662    BOOL EXPRT bk_is32(void *event);
01663    INT EXPRT bk_size(void *pbh);
01664    void EXPRT bk_create(void *pbh, const char *name, WORD type, void *pdata);
01665    INT EXPRT bk_delete(void *event, const char *name);
01666    INT EXPRT bk_close(void *pbh, void *pdata);
01667    INT EXPRT bk_list(void *pbh, char *bklist);
01668    INT EXPRT bk_locate(void *pbh, const char *name, void *pdata);
01669    INT EXPRT bk_iterate(void *pbh, BANK ** pbk, void *pdata);
01670    INT EXPRT bk_iterate32(void *pbh, BANK32 ** pbk, void *pdata);
01671    INT EXPRT bk_swap(void *event, BOOL force);
01672    INT EXPRT bk_find(BANK_HEADER * pbkh, const char *name, DWORD * bklen,
01673                      DWORD * bktype, void **pdata);
01674 
01675    /*---- RPC routines ----*/
01676    INT EXPRT rpc_register_functions(RPC_LIST * new_list, INT(*func) (INT, void **));
01677    INT EXPRT rpc_register_function(INT id, INT(*func) (INT, void **));
01678    INT EXPRT rpc_get_option(HNDLE hConn, INT item);
01679    INT EXPRT rpc_set_option(HNDLE hConn, INT item, INT value);
01680    INT EXPRT rpc_set_name(char *name);
01681    INT EXPRT rpc_get_name(char *name);
01682    INT EXPRT rpc_is_remote(void);
01683    INT EXPRT rpc_set_debug(void (*func) (char *), INT mode);
01684    void EXPRT rpc_debug_printf(char *format, ...);
01685 
01686    INT EXPRT rpc_register_server(INT server_type, char *name, INT * port,
01687                                  INT(*func) (INT, void **));
01688    INT EXPRT rpc_register_client(char *name, RPC_LIST * list);
01689    INT EXPRT rpc_server_thread(void *pointer);
01690    INT EXPRT rpc_server_shutdown(void);
01691    INT EXPRT rpc_client_call(HNDLE hConn, const INT routine_id, ...);
01692    INT EXPRT rpc_call(const INT routine_id, ...);
01693    INT EXPRT rpc_tid_size(INT id);
01694    char EXPRT *rpc_tid_name(INT id);
01695    INT EXPRT rpc_server_connect(char *host_name, char *exp_name);
01696    INT EXPRT rpc_client_connect(char *host_name, INT midas_port,
01697                                 char *client_name, HNDLE * hConnection);
01698    INT EXPRT rpc_client_disconnect(HNDLE hConn, BOOL bShutdown);
01699 
01700    INT EXPRT rpc_send_event(INT buffer_handle, void *source, INT buf_size,
01701                             INT async_flag);
01702    INT EXPRT rpc_flush_event(void);
01703 
01704    void EXPRT rpc_get_convert_flags(INT * convert_flags);
01705    void EXPRT rpc_convert_single(void *data, INT tid, INT flags, INT convert_flags);
01706    void EXPRT rpc_convert_data(void *data, INT tid, INT flags, INT size,
01707                                INT convert_flags);
01708 
01709    /*---- system services ----*/
01710    DWORD EXPRT ss_millitime(void);
01711    DWORD EXPRT ss_time(void);
01712    DWORD EXPRT ss_settime(DWORD seconds);
01713    char EXPRT *ss_asctime(void);
01714    INT EXPRT ss_sleep(INT millisec);
01715    BOOL EXPRT ss_kbhit(void);
01716 
01717    double EXPRT ss_nan(void);
01718    int ss_isnan(double x);
01719 
01720    void EXPRT ss_clear_screen(void);
01721    void EXPRT ss_printf(INT x, INT y, const char *format, ...);
01722    void ss_set_screen_size(int x, int y);
01723 
01724    char EXPRT *ss_getpass(char *prompt);
01725    INT EXPRT ss_getchar(BOOL reset);
01726    char EXPRT *ss_crypt(char *key, char *salt);
01727    char EXPRT *ss_gets(char *string, int size);
01728 
01729    void EXPRT *ss_ctrlc_handler(void (*func) (int));
01730 
01731    /*---- direct io routines ----*/
01732    INT EXPRT ss_directio_give_port(INT start, INT end);
01733    INT EXPRT ss_directio_lock_port(INT start, INT end);
01734 
01735    /*---- tape routines ----*/
01736    INT EXPRT ss_tape_open(char *path, INT oflag, INT * channel);
01737    INT EXPRT ss_tape_close(INT channel);
01738    INT EXPRT ss_tape_status(char *path);
01739    INT EXPRT ss_tape_read(INT channel, void *pdata, INT * count);
01740    INT EXPRT ss_tape_write(INT channel, void *pdata, INT count);
01741    INT EXPRT ss_tape_write_eof(INT channel);
01742    INT EXPRT ss_tape_fskip(INT channel, INT count);
01743    INT EXPRT ss_tape_rskip(INT channel, INT count);
01744    INT EXPRT ss_tape_rewind(INT channel);
01745    INT EXPRT ss_tape_spool(INT channel);
01746    INT EXPRT ss_tape_mount(INT channel);
01747    INT EXPRT ss_tape_unmount(INT channel);
01748    INT EXPRT ss_tape_get_blockn(INT channel);
01749 
01750    /*---- disk routines ----*/
01751    double EXPRT ss_disk_free(char *path);
01752    double EXPRT ss_file_size(char *path);
01753    INT EXPRT ss_file_remove(char *path);
01754    INT EXPRT ss_file_find(char *path, char *pattern, char **plist);
01755    double EXPRT ss_disk_size(char *path);
01756 
01757    /*---- history routines ----*/
01758    INT EXPRT hs_set_path(char *path);
01759    INT EXPRT hs_define_event(DWORD event_id, char *name, TAG * tag, DWORD size);
01760    INT EXPRT hs_write_event(DWORD event_id, void *data, DWORD size);
01761    INT EXPRT hs_count_events(DWORD ltime, DWORD * count);
01762    INT EXPRT hs_enum_events(DWORD ltime, char *event_name,
01763                             DWORD * name_size, INT event_id[], DWORD * id_size);
01764    INT EXPRT hs_count_vars(DWORD ltime, DWORD event_id, DWORD * count);
01765    INT EXPRT hs_enum_vars(DWORD ltime, DWORD event_id, char *var_name,
01766                           DWORD * size, DWORD * var_n, DWORD * n_size);
01767    INT EXPRT hs_get_var(DWORD ltime, DWORD event_id, char *var_name,
01768                         DWORD * type, INT * n_data);
01769    INT EXPRT hs_get_event_id(DWORD ltime, char *name, DWORD * id);
01770    INT EXPRT hs_read(DWORD event_id, DWORD start_time, DWORD end_time,
01771                      DWORD interval, char *tag_name, DWORD var_index,
01772                      DWORD * time_buffer, DWORD * tbsize,
01773                      void *data_buffer, DWORD * dbsize, DWORD * type, DWORD * n);
01774    INT EXPRT hs_dump(DWORD event_id, DWORD start_time, DWORD end_time,
01775                      DWORD interval, BOOL binary_time);
01776    INT EXPRT hs_fdump(char *file_name, DWORD id, BOOL binary_time);
01777 
01778    /*---- ELog functions ----*/
01779    INT EXPRT el_retrieve(char *tag, char *date, int *run, char *author,
01780                          char *type, char *system, char *subject,
01781                          char *text, int *textsize, char *orig_tag,
01782                          char *reply_tag, char *attachment1,
01783                          char *attachment2, char *attachment3, char *encoding);
01784    INT EXPRT el_submit(int run, char *author, char *type, char *system,
01785                        char *subject, char *text, char *reply_to,
01786                        char *encoding, char *afilename1, char *buffer1,
01787                        INT buffer_size1, char *afilename2, char *buffer2,
01788                        INT buffer_size2, char *afilename3, char *buffer3,
01789                        INT buffer_size3, char *tag, INT tag_size);
01790    INT EXPRT el_search_message(char *tag, int *fh, BOOL walk);
01791    INT EXPRT el_search_run(int run, char *return_tag);
01792    INT EXPRT el_delete_message(char *tag);
01793 
01794    /*---- alarm functions ----*/
01795    INT EXPRT al_check();
01796    INT EXPRT al_trigger_alarm(char *alarm_name, char *alarm_message,
01797                               char *default_class, char *cond_str, INT type);
01798    INT EXPRT al_trigger_class(char *alarm_class, char *alarm_message, BOOL first);
01799    INT EXPRT al_reset_alarm(char *alarm_name);
01800    BOOL EXPRT al_evaluate_condition(char *condition, char *value);
01801 
01802    /*---- frontend functions ----*/
01803    INT get_frontend_index();
01804    void register_cnaf_callback(int debug);
01805 
01806    /*---- analyzer functions ----*/
01807    void EXPRT test_register(ANA_TEST * t);
01808    void EXPRT add_data_dir(char *result, char *file);
01809    void EXPRT lock_histo(INT id);
01810 
01811    void EXPRT open_subfolder(char *name);
01812    void EXPRT close_subfolder();
01813 
01814    /*---- functions in strlcpy.c ----*/
01815    size_t EXPRT strlcpy(char *dst, const char *src, size_t size);
01816    size_t EXPRT strlcat(char *dst, const char *src, size_t size);
01817 
01818 #ifdef __cplusplus
01819 }
01820 #ifdef USE_ROOT
01821    /* root functions really are C++ functions */ extern TFolder *gManaHistosFolder;
01822 extern TObjArray *gHistoFolderStack;
01823 
01824    // book functions put a root object in a suitable folder
01825    // for histos, there are a lot of types, so we use templates.
01826    // for other objects we have one function per object
01827 template < typename TH1X >
01828     TH1X EXPRT * h1_book(const char *name, const char *title,
01829                          int bins, double min, double max)
01830 {
01831    TH1X *hist;
01832 
01833    /* check if histo already exists */
01834    if (!gHistoFolderStack->Last())
01835       hist = (TH1X *) gManaHistosFolder->FindObjectAny(name);
01836    else
01837       hist = (TH1X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
01838 
01839    if (hist == NULL) {
01840       hist = new TH1X(name, title, bins, min, max);
01841       if (!gHistoFolderStack->Last())
01842          gManaHistosFolder->Add(hist);
01843       else
01844          ((TFolder *) gHistoFolderStack->Last())->Add(hist);
01845    }
01846 
01847    return hist;
01848 }
01849 
01850 template < typename TH1X >
01851     TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double edges[])
01852 {
01853    TH1X *hist;
01854 
01855    /* check if histo already exists */
01856    if (!gHistoFolderStack->Last())
01857       hist = (TH1X *) gManaHistosFolder->FindObjectAny(name);
01858    else
01859       hist = (TH1X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
01860 
01861    if (hist == NULL) {
01862       hist = new TH1X(name, title, bins, edges);
01863       if (!gHistoFolderStack->Last())
01864          gManaHistosFolder->Add(hist);
01865       else
01866          ((TFolder *) gHistoFolderStack->Last())->Add(hist);
01867    }
01868 
01869    return hist;
01870 }
01871 
01872 template < typename TH2X >
01873     TH2X EXPRT * h2_book(const char *name, const char *title,
01874                          int xbins, double xmin, double xmax,
01875                          int ybins, double ymin, double ymax)
01876 {
01877    TH2X *hist;
01878 
01879    /* check if histo already exists */
01880    if (!gHistoFolderStack->Last())
01881       hist = (TH2X *) gManaHistosFolder->FindObjectAny(name);
01882    else
01883       hist = (TH2X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
01884 
01885    if (hist == NULL) {
01886       hist = new TH2X(name, title, xbins, xmin, xmax, ybins, ymin, ymax);
01887       if (!gHistoFolderStack->Last())
01888          gManaHistosFolder->Add(hist);
01889       else
01890          ((TFolder *) gHistoFolderStack->Last())->Add(hist);
01891    }
01892 
01893    return hist;
01894 }
01895 
01896 template < typename TH2X >
01897     TH2X EXPRT * h2_book(const char *name, const char *title,
01898                          int xbins, double xmin, double xmax, int ybins, double yedges[])
01899 {
01900    TH2X *hist;
01901 
01902    /* check if histo already exists */
01903    if (!gHistoFolderStack->Last())
01904       hist = (TH2X *) gManaHistosFolder->FindObjectAny(name);
01905    else
01906       hist = (TH2X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
01907 
01908    if (hist == NULL) {
01909       hist = new TH2X(name, title, xbins, xmin, xmax, ybins, yedges);
01910       if (!gHistoFolderStack->Last())
01911          gManaHistosFolder->Add(hist);
01912       else
01913          ((TFolder *) gHistoFolderStack->Last())->Add(hist);
01914    }
01915 
01916    return hist;
01917 }
01918 
01919 template < typename TH2X >
01920     TH2X EXPRT * h2_book(const char *name, const char *title,
01921                          int xbins, double xedges[], int ybins, double ymin, double ymax)
01922 {
01923    TH2X *hist;
01924 
01925    /* check if histo already exists */
01926    if (!gHistoFolderStack->Last())
01927       hist = (TH2X *) gManaHistosFolder->FindObjectAny(name);
01928    else
01929       hist = (TH2X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
01930 
01931    if (hist == NULL) {
01932       hist = new TH2X(name, title, xbins, xedges, ybins, ymin, ymax);
01933       if (!gHistoFolderStack->Last())
01934          gManaHistosFolder->Add(hist);
01935       else
01936          ((TFolder *) gHistoFolderStack->Last())->Add(hist);
01937    }
01938 
01939    return hist;
01940 }
01941 
01942 template < typename TH2X >
01943     TH2X EXPRT * h2_book(const char *name, const char *title,
01944                          int xbins, double xedges[], int ybins, double yedges[])
01945 {
01946    TH2X *hist;
01947 
01948    /* check if histo already exists */
01949    if (!gHistoFolderStack->Last())
01950       hist = (TH2X *) gManaHistosFolder->FindObjectAny(name);
01951    else
01952       hist = (TH2X *) ((TFolder *) gHistoFolderStack->Last())->FindObjectAny(name);
01953 
01954    if (hist == NULL) {
01955       hist = new TH2X(name, title, xbins, xedges, ybins, yedges);
01956       if (!gHistoFolderStack->Last())
01957          gManaHistosFolder->Add(hist);
01958       else
01959          ((TFolder *) gHistoFolderStack->Last())->Add(hist);
01960    }
01961 
01962    return hist;
01963 }
01964 
01965    /*
01966     * the following two macros allow for simple fortran like usage
01967     * for the most common histo types
01968     */
01969 #define H1_BOOK(n,t,b,min,max) (h1_book<TH1F>(n,t,b,min,max))
01970 #define H2_BOOK(n,t,xb,xmin,xmax,yb,ymin,ymax) (h2_book<TH2F>(n,t,xb,xmin,xmax,yb,ymin,ymax))
01971 
01972 TCutG *cut_book(const char *name);
01973 #endif                          /* USE_ROOT */
01974 
01975 #endif
01976 #endif                          /* _MIDAS_H */
01977 /**dox***************************************************************/
01978 #endif                          /* DOXYGEN_SHOULD_SKIP_THIS */
01979 
01980 /**dox***************************************************************/
01981           /** @} *//* end of msectionh */
01982 
01983 /**dox***************************************************************/
01984           /** @} *//* end of midasincludecode */

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