]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTDataBuffer.h
fix for 64bit architectures after last commit
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataBuffer.h
index 274fa7a96db62ef9ac48a09a9ed0dbf875b2db7f..672e6e643298db0f19ee2073128f17689cada18d 100644 (file)
     @note   The class is used in Offline (AliRoot) context
 */
 
-#include <cerrno>
+// see below for class documentation
+// or
+// refer to README to build package
+// or
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+
 #include <vector>
 #include "AliHLTLogging.h"
 #include "AliHLTDataTypes.h"
-#include "AliHLTDefinitions.h"
 #include "TObject.h"
-//#include "TList.h"
 
 class AliHLTComponent;
-/* @name internal data structures
- */
-
-/**
- * @struct AliHLTDataSegment
- * @brief  Descriptor of a data segment within the buffer.
- * @ingroup alihlt_system
- */
-struct AliHLTDataSegment {
-  AliHLTDataSegment()
-    :
-    fDataType(),
-    fSegmentOffset(0),
-    fSegmentSize(0),
-    fSpecification(0)
-  {
-    memset(&fDataType, 0, sizeof(AliHLTComponentDataType));
-  }
-  AliHLTDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size) 
-    :
-    fDataType(),
-    fSegmentOffset(offset),
-    fSegmentSize(size),
-    fSpecification(0)
-  {
-    memset(&fDataType, 0, sizeof(AliHLTComponentDataType));
-  }
-  /** the data type of this segment */
-  AliHLTComponentDataType fDataType;                               // see above
-  /** offset in byte within the data buffer */
-  AliHLTUInt32_t fSegmentOffset;                                   // see above
-  /** size of the actual content */
-  AliHLTUInt32_t fSegmentSize;                                     // see above
-  /** data specification */
-  AliHLTUInt32_t fSpecification;                                   // see above
-};
-
-/**
- * @struct AliHLTRawBuffer
- * @brief  Descriptor of the raw data buffer which can host several segments.
- * @ingroup alihlt_system
- */
-struct AliHLTRawBuffer {
-  /** size of the currently occupied partition of the buffer */
-  AliHLTUInt32_t fSize;                                            // see above
-  /** total size of the buffer, including safety margin */
-  AliHLTUInt32_t fTotalSize;                                       // see above
-  /** the buffer */
-  void* fPtr;                                                      //! transient
-};
-
-/**
- * @class AliHLTConsumerDescriptor
- * @brief Helper class to describe a consumer component.
- *
- * There is unfortunately no unique determination of the data type from the
- * component itself possible, thats why both component and data type have to
- * be initialized and are stored in a compound. The class is intended to make
- * bookkeeping easier.
- *
- * @note This class is only used for the @ref alihlt_system.
- *
- * @ingroup alihlt_system
- */
-class AliHLTConsumerDescriptor : public TObject, public AliHLTLogging {
- public:
-  /** standard constructur */
-  AliHLTConsumerDescriptor();
-  /** constructur 
-   * @param pConsumer pointer to the consumer component
-   */
-  AliHLTConsumerDescriptor(AliHLTComponent* pConsumer);
-  /** not a valid copy constructor, defined according to effective C++ style */
-  AliHLTConsumerDescriptor(const AliHLTConsumerDescriptor&);
-  /** not a valid assignment op, but defined according to effective C++ style */
-  AliHLTConsumerDescriptor& operator=(const AliHLTConsumerDescriptor&);
-  /** destructor */
-  ~AliHLTConsumerDescriptor();
-
-  /**
-   * Get the component of this descriptor.
-   * @return pointer to the component
-   */
-  AliHLTComponent* GetComponent() {return fpConsumer;}
-
-  /**
-   * Set an active data segment.
-   * the pointer will be handled in a container, no allocation, copy or
-   * cleanup.
-   * @param offset  offset of the segment in the buffer
-   * @param size    size of the segment in the buffer
-   * @return >=0 if succeeded
-   */
-  int SetActiveDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size);
-
-  /**
-   * Check whether there is an active data segment of certain size with
-   * certain offset.
-   * @param offset  offset of the data segment in the data buffer
-   * @param size    size of the data segment in the data buffer
-   * @return > if existend, 0 if not
-   */
-  int CheckActiveDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size);
-
-  /** find an active data segment of certain size with certain offset
-   * will see if this is necessary
-   * @param offset  offset of the data segment in the data buffer
-   * @param size    size of the data segment in the data buffer
-   * @return offset of the data segment
-   */
-  //AliHLTUInt32_t FindActiveDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size);
-
-  /** get the number of active segments for this consumer
-   * @return number of active segments
-   */
-  int GetNofActiveSegments() {return fSegments.size();};
-
-  /**
-   */
-  int ReleaseActiveDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size);
-
- private:
-  /** consumer object */
-  AliHLTComponent* fpConsumer;                                     //! transient
-
-  /** list of data segments */
-  vector<AliHLTDataSegment> fSegments;                             // see above
-
-  //ClassDef(AliHLTConsumerDescriptor, 0)
-};
+class AliHLTConsumerDescriptor;
 
 /**
  * @class AliHLTDataBuffer
@@ -170,18 +44,15 @@ class AliHLTConsumerDescriptor : public TObject, public AliHLTLogging {
  *
  * @ingroup alihlt_system
  */
-class AliHLTDataBuffer : public TObject, public AliHLTLogging {
+class AliHLTDataBuffer : public TObject, public AliHLTLogging 
+{
  public:
   //////////////////////////////////////////////////////////////////////////////
-  // condtructors and destructors
+  // constructors and destructors
 
   /* standard constructor
    */
   AliHLTDataBuffer();
-  /** not a valid copy constructor, defined according to effective C++ style */
-  AliHLTDataBuffer(const AliHLTDataBuffer&);
-  /** not a valid assignment op, but defined according to effective C++ style */
-  AliHLTDataBuffer& operator=(const AliHLTDataBuffer&);
   /** destructor */
   virtual ~AliHLTDataBuffer();
 
@@ -290,13 +161,21 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging {
   int GetNofSegments();
 
   /**
-   * Get the number of consumers
+   * Get the total number of consumers.
+   * This gives the number of consumers regardless of their state.
    * @return number of consumers
    */
   int GetNofConsumers();
 
   /**
-   * Get the number of active consumers
+   * Get the number of consumers which still need to be processed during
+   * the current event.
+   * @return number of consumers
+   */
+  int GetNofPendingConsumers();
+
+  /**
+   * Get the number of consumers currently under processing.
    * @return number of active consumers
    */
   int GetNofActiveConsumers();
@@ -317,9 +196,132 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging {
    */
   int Reset();
 
+  /**
+   * @class AliHLTDataSegment
+   * @brief  Descriptor of a data segment within the buffer.
+   */
+  class AliHLTDataSegment {
+  friend class AliHLTDataBuffer;
+  friend class AliHLTConsumerDescriptor;
+  public:
+    AliHLTDataSegment()
+      :
+      fDataType(),
+      fSegmentOffset(0),
+      fSegmentSize(0),
+      fSpecification(0)
+    {
+      memset(&fDataType, 0, sizeof(AliHLTComponentDataType));
+    }
+    AliHLTDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size) 
+      :
+      fDataType(),
+      fSegmentOffset(offset),
+      fSegmentSize(size),
+      fSpecification(0)
+    {
+      memset(&fDataType, 0, sizeof(AliHLTComponentDataType));
+    }
+  private:
+    /** the data type of this segment */
+    AliHLTComponentDataType fDataType;                             // see above
+    /** offset in byte within the data buffer */
+    AliHLTUInt32_t fSegmentOffset;                                 // see above
+    /** size of the actual content */
+    AliHLTUInt32_t fSegmentSize;                                   // see above
+    /** data specification */
+    AliHLTUInt32_t fSpecification;                                 // see above
+  };
+
+  /**
+   * @class AliHLTRawBuffer
+   * @brief  Descriptor of the raw data buffer which can host several segments.
+   */
+  class AliHLTRawBuffer {
+  public:
+    /** standard constructor */
+    AliHLTRawBuffer() : fSize(0), fTotalSize(0), fPtr(NULL) {}
+    /** constructor */
+    AliHLTRawBuffer(AliHLTUInt32_t size);
+    /** destructor */
+    virtual ~AliHLTRawBuffer();
+
+    /**
+     * Use a fraction of the buffer.
+     * @param size    size in bytes to be used
+     * @return pointer to buffer
+     */
+    AliHLTUInt8_t* UseBuffer(AliHLTUInt32_t size);
+
+    /**
+     * Check whether buffer fits for a request.
+     * @param size    size of the request in bytes
+     * @return 1 if buffer is big enough, 0 if not
+     */
+    int CheckSize(AliHLTUInt32_t size) const;
+
+    /**
+     * Get used size of the buffer
+     */
+    AliHLTUInt32_t GetUsedSize() const {return fSize;}
+
+    /**
+     * Get total size of the buffer
+     */
+    AliHLTUInt32_t GetTotalSize() const {return fTotalSize;}
+
+    /**
+     * Get pointer of data buffer
+     */
+    AliHLTUInt8_t* GetPointer() const {return fPtr;}
+
+    /**
+     * Write check pattern
+     */
+    int WritePattern(const char* pattern, int size);
+
+    /**
+     * Check pattern
+     */
+    int CheckPattern(const char* pattern, int size) const;
+
+    /**
+     * Reset buffer.
+     * Data buffer remains allocated, used size set to 0
+     */
+    int Reset();
+
+    int operator==(void*) const;
+    int operator==(AliHLTUInt8_t* ptr) const {return fPtr==ptr;}
+    int operator<=(void*) const;
+    int operator>(void*) const;
+    int operator-(void*) const;
+
+    operator void*() const {return fPtr;}
+    operator AliHLTUInt8_t*() const {return fPtr;}
+
+  private:
+    /** copy constructor prohibited */
+    AliHLTRawBuffer(const AliHLTRawBuffer&);
+    /** assignment operator prohibited */
+    AliHLTRawBuffer& operator=(const AliHLTRawBuffer&);
+
+    /** size of the currently occupied partition of the buffer */
+    AliHLTUInt32_t fSize;                                          // see above
+    /** total size of the buffer, including safety margin */
+    AliHLTUInt32_t fTotalSize;                                     // see above
+    /** the buffer */
+    AliHLTUInt8_t* fPtr;                                           //! transient
+  };
+
  private:
+  /** copy constructor prohibited */
+  AliHLTDataBuffer(const AliHLTDataBuffer&);
+  /** assignment operator prohibited */
+  AliHLTDataBuffer& operator=(const AliHLTDataBuffer&);
+
   /* lets see if this is needed
-  AliHLTDataSegment* FindDataSegment(AliHLTComponentDataType datatype);
+     AliHLTDataSegment* FindDataSegment(AliHLTComponentDataType datatype);
   */
 
   /**
@@ -330,7 +332,8 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging {
    *          of the consumer, neg. error code if failed <br>
    *          -EINVAL       invalid parameter <br>
    */
-  int FindMatchingDataSegments(const AliHLTComponent* pConsumer, vector<AliHLTDataSegment>& tgtList);
+  int FindMatchingDataSegments(const AliHLTComponent* pConsumer, 
+                              vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList);
 
   /**
    * Reset the data buffer.
@@ -405,6 +408,12 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging {
   /** global instance to HLT logging class for static methods */
   static AliHLTLogging fgLogging;                                  // see above
 
+  /** size of the safety pattern */
+  static const Int_t fgkSafetyPatternSize;                         // see above
+
+  /** the safety pattern */
+  static const char fgkSafetyPattern[];                            //!transient
+
   //////////////////////////////////////////////////////////////////////////////
   // internal helper functions
 
@@ -439,4 +448,5 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging {
 
   ClassDef(AliHLTDataBuffer, 0)
 };
+
 #endif // ALIHLTDATABUFFER_H