]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTDataBuffer.h
Record changes.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataBuffer.h
1 // @(#) $Id$
2
3 #ifndef ALIHLTDATABUFFER_H
4 #define ALIHLTDATABUFFER_H
5 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6  * See cxx source for full Copyright notice                               */
7
8 /* AliHLTDataBuffer
9    handling of data buffers for the HLT
10  */
11
12 #include <cerrno>
13 #include "AliHLTLogging.h"
14 #include "AliHLTDataTypes.h"
15 #include "AliHLTDefinitions.h"
16 #include "AliHLTComponent.h"
17 #include "TObject.h"
18 #include "TList.h"
19
20 /* internal data structure
21  */
22 struct AliHLTDataSegment {
23   AliHLTComponent_DataType fDataType; // the data type of this buffer
24   Int_t fSegmentOffset;               // offset in byte within the data buffer
25   Int_t fSegmentSize;                 // size of the actual content
26   AliHLTUInt32_t fSpecification;      // data specification
27 };
28
29 /* internal data structure
30  */
31 struct AliHLTRawBuffer {
32   AliHLTUInt32_t fSize;                        // size of the buffer
33   AliHLTUInt32_t fTotalSize;                   // total size of the buffer, including safety margin
34   void* fPtr;                         // the buffer
35 };
36
37 /* internal data structure
38  * there is unfortunately no unique determination of the data type from the component
39  * itself possible, thats way both component and data type have to be initialized
40  * and are stored in a compound
41  */
42 class AliHLTConsumerDescriptor : public TObject, public AliHLTLogging {
43  private:
44   AliHLTComponent* fpConsumer;
45   AliHLTComponent_DataType fDataType;
46   AliHLTDataSegment* fpSegment;
47
48  public:
49   AliHLTConsumerDescriptor();
50   AliHLTConsumerDescriptor(AliHLTComponent* pConsumer, AliHLTComponent_DataType datatype);
51   ~AliHLTConsumerDescriptor();
52
53   AliHLTComponent* GetComponent() {return fpConsumer;}
54   AliHLTComponent_DataType GetDataType() {return fDataType;}
55
56   int SetActiveDataSegment(AliHLTDataSegment* pSegment);
57   int CheckActiveDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size);
58   int ReleaseActiveDataSegment();
59 };
60
61 class AliHLTDataBuffer : public AliHLTLogging, public TObject {
62  public:
63   AliHLTDataBuffer();
64   virtual ~AliHLTDataBuffer();
65
66   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67   // initialization
68
69   /* add component to the list of consumers
70    * parameter:
71    *   pConsumer - a consumer of type AliHLTComponent
72    *   datatype - data type of the segement, the consumer is registered for
73    */
74   int SetConsumer(AliHLTComponent* pConsumer, AliHLTComponent_DataType datatype);
75
76   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77   // component to component communication
78
79   /* subscribe to a segment of the data buffer
80    * the function prepares the block descriptor for subsequent use with the AliHLTComponent::ProcessEvent
81    * method
82    * parameter:
83    *   datatype - type of the data segment
84    *   pConsumer - the component which subscribes to the buffer
85    *   pBlockDesc - pointer to receive the prepared block descriptor
86    * return: >0 if success, negative error code if failed
87    */
88   int Subscribe(AliHLTComponent_DataType datatype, const AliHLTComponent* pConsumer, AliHLTComponent_BlockData* pBlockDesc);
89
90   /* release an instance of the data buffer
91    * resets the variables of the block descriptor
92    * parameter:
93    *   pBlockDesc - descriptor of the data segment
94    *   pConsumer - the component which subscribes to the buffer
95    * return: >0 if success, negative error code if failed
96    */
97   int Release(AliHLTComponent_BlockData* pBlockDesc, const AliHLTComponent* pConsumer);
98
99   /* get a target buffer if minimum size iMinSize
100    */
101   AliHLTUInt8_t* GetTargetBuffer(int iMinSize);
102
103   /* set the segments for the data buffer
104    * this is usually done after the component has written the data to the buffer
105    * parameter:
106    *   pTgt - the target buffer the segments refer to
107    *   arraySegments - the output block descriptors of the component
108    *   iSize - size of the array
109    */
110   int SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponent_BlockData* arraySegments, int iSize);
111
112   /* check if the data buffer is empty
113    */
114   int IsEmpty();
115
116   /* get the total and maximum size of the buffer
117    * lets see if this is needed later
118    */
119   //int GetTotalSize();
120
121   /* get the number of segments
122    */
123   int GetNofSegments();
124
125   /* get the number of consumers
126    */
127   int GetNofConsumers();
128
129   /* get the number of consumers
130    */
131   int GetNofActiveConsumers();
132
133  private:
134   AliHLTDataSegment* FindDataSegment(AliHLTComponent_DataType datatype);
135
136   /* reset the data buffer
137    * removes all condumers back to the fConsumers list
138    */
139   int ResetDataBuffer();
140
141
142   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
143   // the data description
144   vector<AliHLTDataSegment> fSegments;// the data segments within this buffer
145
146   vector<AliHLTConsumerDescriptor*> fConsumers;                   // the list of all consumers which are going to subscribe to the buffer
147   vector<AliHLTConsumerDescriptor*> fActiveConsumers;             // the list of all consumers which are currently subscribed to the buffer
148   vector<AliHLTConsumerDescriptor*> fReleasedConsumers;           // the list of all consumers which are already released for the current event
149
150   AliHLTRawBuffer* fpBuffer;           // the buffer instance
151
152   AliHLTUInt32_t fFlags;                // flags indicating the state of the buffer
153
154   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155   // global buffer handling
156
157   /* create a raw buffer of a certain size
158    * the function tries to find a buffer of the given size (or a little bit bigger) from the list of free buffers
159    * if no buffer is available, a new one is created
160    */
161   static AliHLTRawBuffer* CreateRawBuffer(AliHLTUInt32_t size);
162
163   /* mark a buffer as free
164    */
165   static int ReleaseRawBuffer(AliHLTRawBuffer* pBuffer);
166
167   /* deletes all the raw buffers
168    */
169   static int DeleteRawBuffers();
170
171   static int fNofInstances;
172   static vector<AliHLTRawBuffer*> fFreeBuffers;
173   static vector<AliHLTRawBuffer*> fActiveBuffers;
174   static AliHLTUInt32_t fMargin;
175
176   /*
177    */
178   AliHLTConsumerDescriptor* FindConsumer(const AliHLTComponent* pConsumer, AliHLTComponent_DataType datatype, vector<AliHLTConsumerDescriptor*> &pList);
179
180   int ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, vector<AliHLTConsumerDescriptor*> &srcList, vector<AliHLTConsumerDescriptor*> &tgtList);
181
182   int CleanupConsumerList();
183
184   ClassDef(AliHLTDataBuffer, 0)
185 };
186 #endif // ALIHLTDATABUFFER_H