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 */
9 handling of data buffers for the HLT
13 #include "AliHLTLogging.h"
14 #include "AliHLTDataTypes.h"
15 #include "AliHLTDefinitions.h"
16 #include "AliHLTComponent.h"
20 /* internal data structure
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
29 /* internal data structure
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
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
42 class AliHLTConsumerDescriptor : public TObject, public AliHLTLogging {
44 AliHLTComponent* fpConsumer;
45 AliHLTComponent_DataType fDataType;
46 AliHLTDataSegment* fpSegment;
49 AliHLTConsumerDescriptor();
50 AliHLTConsumerDescriptor(AliHLTComponent* pConsumer, AliHLTComponent_DataType datatype);
51 ~AliHLTConsumerDescriptor();
53 AliHLTComponent* GetComponent() {return fpConsumer;}
54 AliHLTComponent_DataType GetDataType() {return fDataType;}
56 int SetActiveDataSegment(AliHLTDataSegment* pSegment);
57 int CheckActiveDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size);
58 int ReleaseActiveDataSegment();
61 class AliHLTDataBuffer : public AliHLTLogging, public TObject {
64 virtual ~AliHLTDataBuffer();
66 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
69 /* add component to the list of consumers
71 * pConsumer - a consumer of type AliHLTComponent
72 * datatype - data type of the segement, the consumer is registered for
74 int SetConsumer(AliHLTComponent* pConsumer, AliHLTComponent_DataType datatype);
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77 // component to component communication
79 /* subscribe to a segment of the data buffer
80 * the function prepares the block descriptor for subsequent use with the AliHLTComponent::ProcessEvent
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
88 int Subscribe(AliHLTComponent_DataType datatype, const AliHLTComponent* pConsumer, AliHLTComponent_BlockData* pBlockDesc);
90 /* release an instance of the data buffer
91 * resets the variables of the block descriptor
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
97 int Release(AliHLTComponent_BlockData* pBlockDesc, const AliHLTComponent* pConsumer);
99 /* get a target buffer if minimum size iMinSize
101 AliHLTUInt8_t* GetTargetBuffer(int iMinSize);
103 /* set the segments for the data buffer
104 * this is usually done after the component has written the data to the buffer
106 * pTgt - the target buffer the segments refer to
107 * arraySegments - the output block descriptors of the component
108 * iSize - size of the array
110 int SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponent_BlockData* arraySegments, int iSize);
112 /* check if the data buffer is empty
116 /* get the total and maximum size of the buffer
117 * lets see if this is needed later
119 //int GetTotalSize();
121 /* get the number of segments
123 int GetNofSegments();
125 /* get the number of consumers
127 int GetNofConsumers();
129 /* get the number of consumers
131 int GetNofActiveConsumers();
134 AliHLTDataSegment* FindDataSegment(AliHLTComponent_DataType datatype);
136 /* reset the data buffer
137 * removes all condumers back to the fConsumers list
139 int ResetDataBuffer();
142 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
143 // the data description
144 vector<AliHLTDataSegment> fSegments;// the data segments within this buffer
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
150 AliHLTRawBuffer* fpBuffer; // the buffer instance
152 AliHLTUInt32_t fFlags; // flags indicating the state of the buffer
154 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155 // global buffer handling
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
161 static AliHLTRawBuffer* CreateRawBuffer(AliHLTUInt32_t size);
163 /* mark a buffer as free
165 static int ReleaseRawBuffer(AliHLTRawBuffer* pBuffer);
167 /* deletes all the raw buffers
169 static int DeleteRawBuffers();
171 static int fNofInstances;
172 static vector<AliHLTRawBuffer*> fFreeBuffers;
173 static vector<AliHLTRawBuffer*> fActiveBuffers;
174 static AliHLTUInt32_t fMargin;
178 AliHLTConsumerDescriptor* FindConsumer(const AliHLTComponent* pConsumer, AliHLTComponent_DataType datatype, vector<AliHLTConsumerDescriptor*> &pList);
180 int ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, vector<AliHLTConsumerDescriptor*> &srcList, vector<AliHLTConsumerDescriptor*> &tgtList);
182 int CleanupConsumerList();
184 ClassDef(AliHLTDataBuffer, 0)
186 #endif // ALIHLTDATABUFFER_H