]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/HOMER/AliHLTHOMERReader.h
Changes from Svein Lindal
[u/mrichter/AliRoot.git] / HLT / BASE / HOMER / AliHLTHOMERReader.h
index 4e537d1a7b8d9dfbd7163f7e1a3a4ab9f842b403..1287f715e2fa0ad8b13134ba7d444b7a691c1b0f 100644 (file)
@@ -1,11 +1,11 @@
 // XEMacs -*-C++-*-
-#ifndef _HOMER_H_
-#define _HOMER_H_
+#ifndef AliHLTHOMERREADER_H
+#define AliHLTHOMERREADER_H
 /* This file is property of and copyright by the ALICE HLT Project        * 
  * ALICE Experiment at CERN, All rights reserved.                         *
  * See cxx source for full Copyright notice                               */
 
-/** @file   AliHLTHomerReader.h
+/** @file   AliHLTHOMERReader.h
     @author Timm Steinbeck
     @date   Sep 14 2007
     @brief  HLT Online Monitoring Environment including ROOT - Reader
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include "AliHLTHOMERData.h"
+#include <TObject.h>
 
 
 
-
-class MonitoringReader
+/**
+ * @class AliHLTMonitoringReader
+ * The class provides a virtual interface for the HOMER reader.
+ * Used for dynamic generation of HOMER readers and dynamic loading of
+ * the libAliHLTHOMER library.
+ * @see AliHLTHOMERLibManager
+ * 
+ * @ingroup alihlt_homer
+ */
+class AliHLTMonitoringReader
     {
     public:
 
-       MonitoringReader() {};
-       virtual ~MonitoringReader() {};
+       AliHLTMonitoringReader() {};
+       virtual ~AliHLTMonitoringReader() {};
+
+       /* Return the status of the connection as established by one of the constructors.
+          0 means connection is ok, non-zero specifies the type of error that occured. */
+        virtual int GetConnectionStatus() const = 0;
+
+       /* Return the index of the connection for which an error given by the above
+          function occured. */
+        virtual unsigned int GetErrorConnectionNdx() const = 0;
        
        /* Read in the next available event */
        virtual int ReadNextEvent() = 0;
@@ -78,33 +95,56 @@ class MonitoringReader
 
        virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const = 0;
 
+       /* Return the type of the data in the current event's data
+          block with the given block index (starting at 0). */
+       virtual homer_uint64 GetBlockDataType( unsigned long ndx ) const = 0;
+       /* Return the origin of the data in the current event's data
+          block with the given block index (starting at 0). */
+       virtual homer_uint32 GetBlockDataOrigin( unsigned long ndx ) const = 0;
+       /* Return a specification of the data in the current event's data
+          block with the given block index (starting at 0). */
+       virtual homer_uint32 GetBlockDataSpec( unsigned long ndx ) const = 0;
+
+       /* Find the next data block in the current event with the given
+          data type, origin, and specification. Returns the block's 
+          index. */
+       virtual unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin, 
+                                   homer_uint32 spec, unsigned long startNdx=0 ) const = 0;
+
+       /* Find the next data block in the current event with the given
+          data type, origin, and specification. Returns the block's 
+          index. */
+       virtual unsigned long FindBlockNdx( char type[8], char origin[4], 
+                                   homer_uint32 spec, unsigned long startNdx=0 ) const = 0;
 #ifdef USE_ROOT
-        ClassDef(MonitoringReader,1);
+        ClassDef(AliHLTMonitoringReader,1);
 #endif
     };
 
 
 
-class HOMERReader: public MonitoringReader
+class AliHLTHOMERReader: public AliHLTMonitoringReader, public TObject 
     {
     public:
 #ifdef USE_ROOT
-       HOMERReader();
+       AliHLTHOMERReader();
 #endif
 
        /* Constructors & destructors, HOMER specific */
        /* For reading from a TCP port */
-       HOMERReader( const char* hostname, unsigned short port );
+       AliHLTHOMERReader( const char* hostname, unsigned short port );
        /* For reading from multiple TCP ports */
-       HOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports );
+       AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports );
        /* For reading from a System V shared memory segment */
-       HOMERReader( key_t shmKey, int shmSize );
+       AliHLTHOMERReader( key_t shmKey, int shmSize );
        /* For reading from multiple System V shared memory segments */
-       HOMERReader( unsigned int shmCnt, key_t* shmKey, int* shmSize );
+       AliHLTHOMERReader( unsigned int shmCnt, key_t* shmKey, int* shmSize );
        /* For reading from multiple TCP ports and multiple System V shared memory segments */
-       HOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports, 
+       AliHLTHOMERReader( unsigned int tcpCnt, const char** hostnames, unsigned short* ports, 
                     unsigned int shmCnt, key_t* shmKey, int* shmSize );
-       virtual ~HOMERReader();
+       /* For reading from a buffer */
+       AliHLTHOMERReader( const void* pBuffer, int size );
+       virtual ~AliHLTHOMERReader();
 
        /* Return the status of the connection as established by one of the constructors.
           0 means connection is ok, non-zero specifies the type of error that occured. */
@@ -120,55 +160,56 @@ class HOMERReader: public MonitoringReader
                return fErrorConnection;
                }
 
-       void SetEventRequestAdvanceTime( unsigned long time_us )
+       void SetEventRequestAdvanceTime( unsigned long time )
                {
-               fEventRequestAdvanceTime_us = time_us;
+               // advance time in us
+               fEventRequestAdvanceTime = time;
                }
 
-       /* Defined in MonitoringReader */
-       /* Read in the next available event */
+       /* Defined in AliHLTMonitoringReader */
+       /** Read in the next available event */
        virtual int  ReadNextEvent();
-       /* Read in the next available event */
+       /** Read in the next available event */
        virtual int ReadNextEvent( unsigned long timeout );
 
-       /* Return the type of the current event */
+       /** Return the type of the current event */
        virtual homer_uint64 GetEventType() const
                {
                return fCurrentEventType;
                }
 
-       /* Return the ID of the current event */
+       /** Return the ID of the current event */
        virtual homer_uint64 GetEventID() const
                {
                return fCurrentEventID;
                }
 
-       /* Return the number of data blocks in the current event */
+       /** Return the number of data blocks in the current event */
        virtual unsigned long GetBlockCnt() const
                {
                return fBlockCnt;
                }
 
-       /* Return the size (in bytes) of the current event's data
+       /** Return a pointer to the start of the current event's data
           block with the given block index (starting at 0). */
        virtual const void* GetBlockData( unsigned long ndx ) const;
-       /* Return a pointer to the start of the current event's data
+       /** Return the size (in bytes) of the current event's data
           block with the given block index (starting at 0). */
        virtual unsigned long GetBlockDataLength( unsigned long ndx ) const;
-       /* Return IP address or hostname of node which sent the 
+       /** Return IP address or hostname of node which sent the 
           current event's data block with the given block index 
           (starting at 0).
           For HOMER this is the ID of the node on which the subscriber 
           that provided this data runs/ran. */
        virtual const char* GetBlockSendNodeID( unsigned long ndx ) const;
-       /* Return byte order of the data stored in the 
+       /** Return byte order of the data stored in the 
           current event's data block with the given block 
           index (starting at 0). 
           0 is unknown alignment, 
           1 ist little endian, 
           2 is big endian. */
        virtual homer_uint8 GetBlockByteOrder( unsigned long ndx ) const;
-       /* Return the alignment (in bytes) of the given datatype 
+       /** Return the alignment (in bytes) of the given datatype 
           in the data stored in the current event's data block
           with the given block index (starting at 0). 
           Possible values for the data type are
@@ -184,45 +225,44 @@ class HOMERReader: public MonitoringReader
        virtual homer_uint64 GetBlockStatusFlags( unsigned long ndx ) const;
 
        /* HOMER specific */
-       /* Return the type of the data in the current event's data
+       /** Return the type of the data in the current event's data
           block with the given block index (starting at 0). */
        homer_uint64 GetBlockDataType( unsigned long ndx ) const;
-       /* Return the origin of the data in the current event's data
+       /** Return the origin of the data in the current event's data
           block with the given block index (starting at 0). */
        homer_uint32 GetBlockDataOrigin( unsigned long ndx ) const;
-       /* Return a specification of the data in the current event's data
+       /** Return a specification of the data in the current event's data
           block with the given block index (starting at 0). */
        homer_uint32 GetBlockDataSpec( unsigned long ndx ) const;
 
-       /* Find the next data block in the current event with the given
+       /** Find the next data block in the current event with the given
           data type, origin, and specification. Returns the block's 
           index. */
        unsigned long FindBlockNdx( homer_uint64 type, homer_uint32 origin, 
                                    homer_uint32 spec, unsigned long startNdx=0 ) const;
 
-       /* Find the next data block in the current event with the given
+       /** Find the next data block in the current event with the given
           data type, origin, and specification. Returns the block's 
           index. */
        unsigned long FindBlockNdx( char type[8], char origin[4], 
                                    homer_uint32 spec, unsigned long startNdx=0 ) const;
        
-       /* Return the ID of the node that actually produced this data block.
+       /** Return the ID of the node that actually produced this data block.
           This may be different from the node which sent the data to this
           monitoring object as returned by GetBlockSendNodeID. */
        const char* GetBlockCreateNodeID( unsigned long ndx ) const;
 
     protected:
 
-       enum DataSourceType { kUndef=0, kTCP, kShm };
+      enum DataSourceType { kUndef=0, kTCP, kShm, kBuf};
        struct DataSource
            {
-               DataSource() { fType = kUndef; };
-               DataSourceType fType;
+               DataSourceType fType; // source type (TCP or Shm)
                unsigned fNdx; // This source's index
                const char* fHostname; // Filled for both Shm and TCP
-               unsigned short fTCPPort;
-               key_t fShmKey;
-               int fShmSize;
+               unsigned short fTCPPort; // port if type TCP
+               key_t fShmKey; // shm key if type Shm
+               int fShmSize; // shm size if type Shm
                int fTCPConnection; // File descriptor for the TCP connection
                int fShmID; // ID of the shared memory area
                void* fShmPtr; // Pointer to shared memory area
@@ -236,80 +276,115 @@ class HOMERReader: public MonitoringReader
        bool AllocDataSources( unsigned int sourceCnt );
        int AddDataSource( const char* hostname, unsigned short port, DataSource& source );
        int AddDataSource( key_t shmKey, int shmSize, DataSource& source );
+        int AddDataSource( void* pBuffer, int size, DataSource& source );
        void FreeDataSources();
        int FreeShmDataSource( DataSource& source );
        int FreeTCPDataSource( DataSource& source );
        int ReadNextEvent( bool useTimeout, unsigned long timeout );
        void ReleaseCurrentEvent();
        int TriggerTCPSource( DataSource& source, bool useTimeout, unsigned long timeout );
-       int TriggerShmSource( DataSource& source, bool useTimeout, unsigned long timeout );
+       int TriggerShmSource( DataSource& source, bool useTimeout, unsigned long timeout ) const;
        int ReadDataFromTCPSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
        int ReadDataFromShmSources( unsigned sourceCnt, DataSource* sources, bool useTimeout, unsigned long timeout );
        int ParseSourceData( DataSource& source );
        int ReAllocBlocks( unsigned long newCnt );
        homer_uint64 GetSourceEventID( DataSource& source );
        homer_uint64 GetSourceEventType( DataSource& source );
-       homer_uint64 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint64 source )
-               {
-               if ( destFormat == sourceFormat )
-                   return source;
-               else
-                   return ((source & 0xFFULL) << 56) | 
-                       ((source & 0xFF00ULL) << 40) | 
-                       ((source & 0xFF0000ULL) << 24) | 
-                       ((source & 0xFF000000ULL) << 8) | 
-                       ((source & 0xFF00000000ULL) >> 8) | 
-                       ((source & 0xFF0000000000ULL) >> 24) | 
-                       ((source & 0xFF000000000000ULL) >>  40) | 
-                       ((source & 0xFF00000000000000ULL) >> 56);
-               }
-       homer_uint32 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint32 source )
-               {
-               if ( destFormat == sourceFormat )
-                   return source;
-               else
-                   return ((source & 0xFFUL) << 24) | 
-                       ((source & 0xFF00UL) << 8) | 
-                       ((source & 0xFF0000UL) >> 8) | 
-                       ((source & 0xFF000000UL) >> 24);
-               }
+        homer_uint64 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint64 source ) const;
+
+        homer_uint32 Swap( homer_uint8 destFormat, homer_uint8 sourceFormat, homer_uint32 source ) const;
 
 
        struct DataBlock
            {
                unsigned int fSource; // Index of originating data source
-               void* fData;
-               unsigned long fLength;
+               void* fData; // pointer to data
+               unsigned long fLength; // buffer length
                homer_uint64* fMetaData; // Pointer to meta data describing data itself.
-               const char* fOriginatingNodeID;
+               const char* fOriginatingNodeID; // node id from which the data originates
            };
 
-       homer_uint64 fCurrentEventType;
-       homer_uint64 fCurrentEventID;
-       unsigned long fBlockCnt;
-       unsigned long fMaxBlockCnt;
-       DataBlock* fBlocks;
-       
-       unsigned int fDataSourceCnt;
-       unsigned int fTCPDataSourceCnt;
-       unsigned int fShmDataSourceCnt;
-       unsigned int fDataSourceMaxCnt;
-       DataSource* fDataSources;
-
-       
-       int fConnectionStatus;
-       unsigned fErrorConnection;
-
-       unsigned long fEventRequestAdvanceTime_us;
+        /** type of the current event */
+       homer_uint64 fCurrentEventType;                             //!transient
+       /** ID of the current event */
+       homer_uint64 fCurrentEventID;                               //!transient
+       /** no of blocks currently used */
+       unsigned long fBlockCnt;                                    //!transient
+       /** available space in the block array */
+       unsigned long fMaxBlockCnt;                                 //!transient
+       /** block array */
+       DataBlock* fBlocks;                                         //!transient
+               
+       /** total no of data sources */
+       unsigned int fDataSourceCnt;                                //!transient
+       /** no of TCP data sources */
+       unsigned int fTCPDataSourceCnt;                             //!transient
+       /** no of Shm data sources */
+       unsigned int fShmDataSourceCnt;                             //!transient
+       /** available space in the sources array */
+       unsigned int fDataSourceMaxCnt;                             //!transient
+       /** array of data source descriptions */
+       DataSource* fDataSources;                                   //!transient
+       
+       /** status of the connection */
+       int fConnectionStatus;                                      //!transient
+       /** flag an error for */
+       unsigned fErrorConnection;                                  //!transient
+       
+       /** */
+       unsigned long fEventRequestAdvanceTime;                     //!transient
     private:
-      /** copy constructor prohibited */
-      HOMERReader(const HOMERReader&);
-      /** assignment operator prohibited */
-      HOMERReader& operator=(const HOMERReader&);
-
+       /** copy constructor prohibited */
+       AliHLTHOMERReader(const AliHLTHOMERReader&);
+       /** assignment operator prohibited */
+       AliHLTHOMERReader& operator=(const AliHLTHOMERReader&);
+       
 #ifdef USE_ROOT
-        ClassDef(HOMERReader,2);
+        ClassDef(AliHLTHOMERReader,2);
 #endif
     };
 
-#endif /* _HOMER_H_ */
+/** defined for backward compatibility */
+typedef AliHLTMonitoringReader MonitoringReader;
+/** defined for backward compatibility */
+typedef AliHLTHOMERReader HOMERReader;
+
+// external interface of the HOMER reader
+#define ALIHLTHOMERREADER_CREATE_FROM_TCPPORT  "AliHLTHOMERReaderCreateFromTCPPort"
+#define ALIHLTHOMERREADER_CREATE_FROM_TCPPORTS "AliHLTHOMERReaderCreateFromTCPPorts"
+#define ALIHLTHOMERREADER_CREATE_FROM_BUFFER   "AliHLTHOMERReaderCreateFromBuffer"
+#define ALIHLTHOMERREADER_DELETE               "AliHLTHOMERReaderDelete"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+  typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromTCPPort_t)(const char* hostname, unsigned short port );
+  typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromTCPPorts_t)(unsigned int tcpCnt, const char** hostnames, unsigned short* ports);
+  typedef AliHLTHOMERReader* (*AliHLTHOMERReaderCreateFromBuffer_t)(const void* pBuffer, int size);
+  typedef void (*AliHLTHOMERReaderDelete_t)(AliHLTHOMERReader* pInstance);
+
+  /**
+   * Create instance of HOMER reader working on a TCP port.
+   */
+  AliHLTHOMERReader* AliHLTHOMERReaderCreateFromTCPPort(const char* hostname, unsigned short port );
+  
+  /**
+   * Create instance of HOMER reader working on multiple TCP ports.
+   */
+  AliHLTHOMERReader* AliHLTHOMERReaderCreateFromTCPPorts(unsigned int tcpCnt, const char** hostnames, unsigned short* ports);
+
+  /**
+   * Create instance of HOMER reader working on buffer.
+   */
+  AliHLTHOMERReader* AliHLTHOMERReaderCreateFromBuffer(const void* pBuffer, int size);
+
+  /**
+   * Delete instance of HOMER reader.
+   */
+  void AliHLTHOMERReaderDelete(AliHLTHOMERReader* pInstance);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AliHLTHOMERREADER_H */