]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTDataBuffer.h
code documentation; minor enhancement of BlockFilter
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataBuffer.h
index 7c03243013537adc57edd4779358514f21a815d4..e7823c4c1d6243f57892586b5a8535d41dd772d5 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 "TObject.h"
 #include "AliHLTLogging.h"
 #include "AliHLTDataTypes.h"
-#include "AliHLTDefinitions.h"
-#include "TObject.h"
-//#include "TList.h"
+#include "AliHLTComponent.h"
 
-class AliHLTComponent;
 class AliHLTConsumerDescriptor;
+class AliHLTTask;
+
+/** list of AliHLTConsumerDescriptor pointers */
+typedef vector<AliHLTConsumerDescriptor*> AliHLTConsumerDescriptorPList;
+
+typedef AliHLTUInt8_t* AliHLTUInt8Pointer_t;
 
 /**
  * @class AliHLTDataBuffer
@@ -50,10 +59,6 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
   /* 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();
 
@@ -81,7 +86,7 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
    *          -EINVAL       invalid parameter <br>
    */
   int FindMatchingDataBlocks(const AliHLTComponent* pConsumer,
-                            vector<AliHLTComponentDataType>* tgtList=NULL);
+                            AliHLTComponentDataTypeList* tgtList=NULL);
 
   /**
    * Subscribe to a segment of the data buffer.
@@ -92,8 +97,7 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
    * would have been prepared if there was enough space in the array<br>
    * The method is used by the consumer component.
    * @param pConsumer       the component which subscribes to the buffer
-   * @param arrayBlockDesc  pointer to block descriptor to be filled
-   * @param iArraySize      size of the block descriptor array
+   * @param blockDescList   block descriptor vector to be filled
    * @return: number of matching data blocks, neg. error code if failed<br>
    *          -EACCESS      the consumer state can't be changed (activated)
    *          -EBADF        unresolved data segments <br>
@@ -102,8 +106,7 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
    *          -EINVAL       invalid parameter <br>
    */
   int Subscribe(const AliHLTComponent* pConsumer,
-               AliHLTComponentBlockData* arrayBlockDesc,
-               int iArraySize);
+               AliHLTComponentBlockDataList& blockDescList);
 
   /**
    * Release an instance of the data buffer.
@@ -113,12 +116,24 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
    * The method is used by the consumer component.
    * @param pBlockDesc      descriptor of the data segment
    * @param pConsumer       the component which subscribes to the buffer
+   * @param pOwnerTask      task owning this buffer
    * @return: >0 if success, negative error code if failed <br>
    *          -EACCESS      the consumer state can not be changed (de-activated)
    *          -ENOENT       consumer has not subscribed to the buffer <br>
    *          -EINVAL       invalid parameter <br>
    */
-  int Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTComponent* pConsumer);
+  int Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTComponent* pConsumer,
+             const AliHLTTask* pOwnerTask);
+
+  /**
+   * Register an input data block for forwarding.
+   * Consumer of this data buffer subscribe to forwarded data blocks in te same way.
+   * Forwarded data blocks are released when the last consumer has released the
+   * blocks.
+   * @param pSrcTask        original source task of the data block
+   * @param pBlockDesc      descriptor of the data segment
+   */
+  int Forward(AliHLTTask* pSrcTask, AliHLTComponentBlockData* pBlockDesc);
 
   /**
    * Get a target buffer of minimum size iMinSize.
@@ -162,13 +177,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();
@@ -190,30 +213,75 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
   int Reset();
 
   /**
-   * @struct AliHLTDataSegment
+   * Set local logging level
+   * logging filter for individual object
+   */
+  void SetLocalLoggingLevel(AliHLTComponentLogSeverity level)
+  {fgLogging.SetLocalLoggingLevel(level); AliHLTLogging::SetLocalLoggingLevel(level);}
+
+  /**
+   * @class AliHLTDataSegment
    * @brief  Descriptor of a data segment within the buffer.
    */
-  struct AliHLTDataSegment {
+  class AliHLTDataSegment {
+    friend class AliHLTDataBuffer;
+    friend class AliHLTConsumerDescriptor;
+  public:
     AliHLTDataSegment()
       :
-      fDataType(),
+      fDataType(kAliHLTVoidDataType),
+      fPtr(NULL),
       fSegmentOffset(0),
       fSegmentSize(0),
       fSpecification(0)
     {
-      memset(&fDataType, 0, sizeof(AliHLTComponentDataType));
     }
-    AliHLTDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size) 
+
+    AliHLTDataSegment(AliHLTUInt8_t* ptr, AliHLTUInt32_t offset, AliHLTUInt32_t size) 
       :
-      fDataType(),
+      fDataType(kAliHLTVoidDataType),
+      fPtr(ptr),
       fSegmentOffset(offset),
       fSegmentSize(size),
       fSpecification(0)
     {
-      memset(&fDataType, 0, sizeof(AliHLTComponentDataType));
     }
+
+    AliHLTDataSegment(void* ptr, AliHLTUInt32_t offset, AliHLTUInt32_t size) 
+      :
+      fDataType(kAliHLTVoidDataType),
+      fPtr((AliHLTUInt8_t*)ptr),
+      fSegmentOffset(offset),
+      fSegmentSize(size),
+      fSpecification(0)
+    {
+    }
+
+    AliHLTDataSegment(void* ptr, AliHLTUInt32_t offset, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliHLTUInt32_t spec)
+      :
+      fDataType(dt),
+      fPtr((AliHLTUInt8_t*)ptr),
+      fSegmentOffset(offset),
+      fSegmentSize(size),
+      fSpecification(spec)
+    {
+    }
+
+    AliHLTUInt8_t* GetPtr() const {return (AliHLTUInt8_t*)*this;}
+
+    AliHLTUInt32_t GetSize() const {return fSegmentSize;}
+    
+    int operator==(const AliHLTDataSegment& seg) const
+    {
+      return (fPtr+fSegmentOffset==seg.fPtr+seg.fSegmentOffset) && (fSegmentSize==seg.fSegmentSize);
+    }
+    operator AliHLTUInt8_t*() const {return fPtr+fSegmentOffset;}
+
+  private:
     /** the data type of this segment */
     AliHLTComponentDataType fDataType;                             // see above
+    /** pointer to the buffer */
+    AliHLTUInt8Pointer_t fPtr;                                     //!transient
     /** offset in byte within the data buffer */
     AliHLTUInt32_t fSegmentOffset;                                 // see above
     /** size of the actual content */
@@ -223,19 +291,92 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
   };
 
   /**
-   * @struct AliHLTRawBuffer
+   * @class AliHLTRawBuffer
    * @brief  Descriptor of the raw data buffer which can host several segments.
    */
-  struct AliHLTRawBuffer {
+  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 */
-    void* fPtr;                                                    //! transient
+    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);
   */
@@ -248,7 +389,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.
@@ -265,11 +407,11 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
   vector<AliHLTDataSegment> fSegments;                             // see above
 
   // the list of all consumers which are going to subscribe to the buffer
-  vector<AliHLTConsumerDescriptor*> fConsumers;                    // see above
+  AliHLTConsumerDescriptorPList fConsumers;                         // see above
   // the list of all consumers which are currently subscribed to the buffer
-  vector<AliHLTConsumerDescriptor*> fActiveConsumers;              // see above
+  AliHLTConsumerDescriptorPList fActiveConsumers;                   // see above
   // the list of all consumers which are already released for the current event
-  vector<AliHLTConsumerDescriptor*> fReleasedConsumers;            // see above
+  AliHLTConsumerDescriptorPList fReleasedConsumers;                 // see above
 
   // the buffer instance
   AliHLTRawBuffer* fpBuffer;                                       //! transient
@@ -277,6 +419,12 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
   // flags indicating the state of the buffer
   AliHLTUInt32_t fFlags;                                           // see above
 
+  /** list of tasks with forwarded data blocks */
+  vector<AliHLTTask*> fForwardedSegmentSources;                    //! transient
+
+  /** list of forwarded block descriptors */
+  vector<AliHLTDataSegment> fForwardedSegments;                    //! transient
+
   //////////////////////////////////////////////////////////////////////////////
   // global buffer handling, internal use only
 
@@ -341,7 +489,7 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
    * @param list            list where to search for the consumer
    */
   AliHLTConsumerDescriptor* FindConsumer(const AliHLTComponent* pConsumer,
-                                        vector<AliHLTConsumerDescriptor*> &list) const;
+                                        AliHLTConsumerDescriptorPList &list) const;
 
   /**
    * Change the state of a consumer.
@@ -352,8 +500,8 @@ class AliHLTDataBuffer : public TObject, public AliHLTLogging
    * @param tgtList         list where to move the consumer
    */
   int ChangeConsumerState(AliHLTConsumerDescriptor* pDesc,
-                         vector<AliHLTConsumerDescriptor*> &srcList,
-                         vector<AliHLTConsumerDescriptor*> &tgtList);
+                         AliHLTConsumerDescriptorPList &srcList,
+                         AliHLTConsumerDescriptorPList &tgtList);
 
   /**
    * Cleanup a consumer list.