]>
Commit | Line | Data |
---|---|---|
3f2a1b1c | 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 | ||
b22e91eb | 8 | /** @file AliHLTDataBuffer.h |
9 | @author Matthias Richter | |
10 | @date | |
11 | @brief Handling of Data Buffers for HLT components. | |
12 | @note The class is used in Offline (AliRoot) context | |
13 | */ | |
3f2a1b1c | 14 | |
8ede8717 | 15 | #include <vector> |
3f2a1b1c | 16 | #include "AliHLTLogging.h" |
17 | #include "AliHLTDataTypes.h" | |
66043029 | 18 | //#include "AliHLTDefinitions.h" |
3f2a1b1c | 19 | #include "TObject.h" |
70ed7d01 | 20 | //#include "TList.h" |
3f2a1b1c | 21 | |
b22e91eb | 22 | class AliHLTComponent; |
6235cd38 | 23 | class AliHLTConsumerDescriptor; |
3f2a1b1c | 24 | |
0c0c9d99 | 25 | /** |
bfccbf68 | 26 | * @class AliHLTDataBuffer |
27 | * @brief Handling of data buffers for the HLT. | |
b22e91eb | 28 | * |
70ed7d01 | 29 | * The class provides handling of data buffers for HLT tasks. Each task gets |
30 | * its own Data Buffer instance. The buffer is grouped into different data | |
31 | * segments according to the output of the component.<br> | |
32 | * The Data Buffer keeps control over the data requests of the 'child' | |
33 | * components. Each component can subscribe to a certain segment of the data | |
34 | * buffer. It's state is then changed from 'reserved' to 'active'. After the | |
35 | * data processing, the component has to release the segment and it's state is | |
36 | * set to 'processed'. If all components have requested and released their data, | |
37 | * the Raw Buffer is released and pushed back in the list of available buffers. | |
b22e91eb | 38 | * |
39 | * @note This class is only used for the @ref alihlt_system. | |
40 | * | |
41 | * @ingroup alihlt_system | |
0c0c9d99 | 42 | */ |
6235cd38 | 43 | class AliHLTDataBuffer : public TObject, public AliHLTLogging |
44 | { | |
3f2a1b1c | 45 | public: |
70ed7d01 | 46 | ////////////////////////////////////////////////////////////////////////////// |
6235cd38 | 47 | // constructors and destructors |
0c0c9d99 | 48 | |
49 | /* standard constructor | |
50 | */ | |
3f2a1b1c | 51 | AliHLTDataBuffer(); |
85869391 | 52 | /** not a valid copy constructor, defined according to effective C++ style */ |
53 | AliHLTDataBuffer(const AliHLTDataBuffer&); | |
54 | /** not a valid assignment op, but defined according to effective C++ style */ | |
55 | AliHLTDataBuffer& operator=(const AliHLTDataBuffer&); | |
56 | /** destructor */ | |
3f2a1b1c | 57 | virtual ~AliHLTDataBuffer(); |
58 | ||
70ed7d01 | 59 | ////////////////////////////////////////////////////////////////////////////// |
3f2a1b1c | 60 | // initialization |
61 | ||
0c0c9d99 | 62 | /** |
63 | * Add component to the list of consumers | |
64 | * @param pConsumer - a consumer of type AliHLTComponent | |
3f2a1b1c | 65 | */ |
0c0c9d99 | 66 | int SetConsumer(AliHLTComponent* pConsumer); |
3f2a1b1c | 67 | |
70ed7d01 | 68 | ////////////////////////////////////////////////////////////////////////////// |
3f2a1b1c | 69 | // component to component communication |
70 | ||
0c0c9d99 | 71 | /** |
70ed7d01 | 72 | * Determine the number of matching data blocks for the component and a |
73 | * consumer component. <br> | |
74 | * The first approach will support only one output data type for processing | |
75 | * components. | |
0c0c9d99 | 76 | * @param pConsumer the component which subscribes to the buffer |
77 | * @param tgtList (optional) the list to receive the data types | |
78 | * @return: number of data blocks which match the input data types | |
79 | * of the consumer, neg. error code if failed <br> | |
80 | * -EINVAL invalid parameter <br> | |
3f2a1b1c | 81 | */ |
70ed7d01 | 82 | int FindMatchingDataBlocks(const AliHLTComponent* pConsumer, |
83 | vector<AliHLTComponentDataType>* tgtList=NULL); | |
0c0c9d99 | 84 | |
85 | /** | |
86 | * Subscribe to a segment of the data buffer. | |
70ed7d01 | 87 | * The function prepares the block descriptor for subsequent use with the |
88 | * AliHLTComponent::ProcessEvent method, the method can prepare several block | |
89 | * descriptors up to the array size specified by iArraySize. The return value | |
90 | * is independent from the array size the number of block descriptors which | |
91 | * would have been prepared if there was enough space in the array<br> | |
0c0c9d99 | 92 | * The method is used by the consumer component. |
93 | * @param pConsumer the component which subscribes to the buffer | |
94 | * @param arrayBlockDesc pointer to block descriptor to be filled | |
95 | * @param iArraySize size of the block descriptor array | |
70ed7d01 | 96 | * @return: number of matching data blocks, neg. error code if failed<br> |
97 | * -EACCESS the consumer state can't be changed (activated) | |
0c0c9d99 | 98 | * -EBADF unresolved data segments <br> |
99 | * -ENOENT consumer component not found <br> | |
100 | * -ENODATA data buffer does not have raw data <br> | |
101 | * -EINVAL invalid parameter <br> | |
102 | */ | |
70ed7d01 | 103 | int Subscribe(const AliHLTComponent* pConsumer, |
104 | AliHLTComponentBlockData* arrayBlockDesc, | |
105 | int iArraySize); | |
0c0c9d99 | 106 | |
107 | /** | |
108 | * Release an instance of the data buffer. | |
109 | * Resets the variables of the block descriptor. | |
110 | * If all buffer segments are released, the Data Buffer is reseted | |
111 | * and the Raw Buffer released.<br> | |
112 | * The method is used by the consumer component. | |
113 | * @param pBlockDesc descriptor of the data segment | |
114 | * @param pConsumer the component which subscribes to the buffer | |
115 | * @return: >0 if success, negative error code if failed <br> | |
70ed7d01 | 116 | * -EACCESS the consumer state can not be changed (de-activated) |
117 | * -ENOENT consumer has not subscribed to the buffer <br> | |
0c0c9d99 | 118 | * -EINVAL invalid parameter <br> |
3f2a1b1c | 119 | */ |
8ede8717 | 120 | int Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTComponent* pConsumer); |
3f2a1b1c | 121 | |
0c0c9d99 | 122 | /** |
123 | * Get a target buffer of minimum size iMinSize. | |
124 | * The method is used by the component which owns the Data Buffer to | |
125 | * allocate a buffer for the data it is going to produce. | |
126 | * @param iMinSize minumum size of the requested buffer | |
127 | * @return: pointer to target buffer if | |
3f2a1b1c | 128 | */ |
129 | AliHLTUInt8_t* GetTargetBuffer(int iMinSize); | |
130 | ||
0c0c9d99 | 131 | /** |
132 | * Set the segments for the data buffer. | |
133 | * This is usually done after the component has written the data to the buffer, | |
134 | * which was requested by the @ref GetTargetBuffer method. The component might | |
135 | * produce different types of data, for each type a segment has to be defined | |
2d7ff710 | 136 | * which describes the data inside the buffer.<br> |
70ed7d01 | 137 | * The @ref AliHLTComponentBlockData segment descriptor comes directly from |
138 | * the @ref AliHLTComponent::ProcessEvent method. | |
0c0c9d99 | 139 | * @param pTgt the target buffer which the segments refer to |
140 | * @param arraySegments the output block descriptors of the component | |
141 | * @param iSize size of the array | |
3f2a1b1c | 142 | */ |
8ede8717 | 143 | int SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arraySegments, int iSize); |
3f2a1b1c | 144 | |
0c0c9d99 | 145 | /** |
146 | * Check if the data buffer is empty. | |
147 | * @return 1 if empty, 0 if not | |
3f2a1b1c | 148 | */ |
149 | int IsEmpty(); | |
150 | ||
0c0c9d99 | 151 | /** |
152 | * Get the total and maximum size of the buffer. | |
153 | * Lets see if this is needed later | |
3f2a1b1c | 154 | */ |
155 | //int GetTotalSize(); | |
156 | ||
0c0c9d99 | 157 | /** |
158 | * Get the number of segments | |
159 | * @return number of segments | |
3f2a1b1c | 160 | */ |
161 | int GetNofSegments(); | |
162 | ||
0c0c9d99 | 163 | /** |
164 | * Get the number of consumers | |
165 | * @return number of consumers | |
3f2a1b1c | 166 | */ |
167 | int GetNofConsumers(); | |
168 | ||
0c0c9d99 | 169 | /** |
170 | * Get the number of active consumers | |
171 | * @return number of active consumers | |
3f2a1b1c | 172 | */ |
173 | int GetNofActiveConsumers(); | |
174 | ||
9ce4bf4a | 175 | /** |
176 | * Check if a consumer is already in the list | |
177 | * @param pConsumer pointer to consumer component | |
178 | * @param bAllLists search in all lists if 1 | |
179 | * search only in fConsumer list if 0 | |
180 | * @return 1 if found, 0 if not | |
181 | */ | |
182 | int FindConsumer(AliHLTComponent* pConsumer, int bAllLists=1); | |
183 | ||
184 | /** | |
185 | * Public method to reset the buffer. | |
186 | * Eventually with some additional checks. In normal operation, | |
187 | * an external reset should not be necessary. | |
188 | */ | |
189 | int Reset(); | |
190 | ||
6235cd38 | 191 | /** |
192 | * @struct AliHLTDataSegment | |
193 | * @brief Descriptor of a data segment within the buffer. | |
194 | */ | |
66043029 | 195 | class AliHLTDataSegment { |
196 | public: | |
6235cd38 | 197 | AliHLTDataSegment() |
198 | : | |
199 | fDataType(), | |
200 | fSegmentOffset(0), | |
201 | fSegmentSize(0), | |
202 | fSpecification(0) | |
203 | { | |
204 | memset(&fDataType, 0, sizeof(AliHLTComponentDataType)); | |
205 | } | |
206 | AliHLTDataSegment(AliHLTUInt32_t offset, AliHLTUInt32_t size) | |
207 | : | |
208 | fDataType(), | |
209 | fSegmentOffset(offset), | |
210 | fSegmentSize(size), | |
211 | fSpecification(0) | |
212 | { | |
213 | memset(&fDataType, 0, sizeof(AliHLTComponentDataType)); | |
214 | } | |
215 | /** the data type of this segment */ | |
216 | AliHLTComponentDataType fDataType; // see above | |
217 | /** offset in byte within the data buffer */ | |
218 | AliHLTUInt32_t fSegmentOffset; // see above | |
219 | /** size of the actual content */ | |
220 | AliHLTUInt32_t fSegmentSize; // see above | |
221 | /** data specification */ | |
222 | AliHLTUInt32_t fSpecification; // see above | |
223 | }; | |
224 | ||
225 | /** | |
226 | * @struct AliHLTRawBuffer | |
227 | * @brief Descriptor of the raw data buffer which can host several segments. | |
228 | */ | |
66043029 | 229 | class AliHLTRawBuffer { |
230 | public: | |
231 | /** standard constructor */ | |
232 | AliHLTRawBuffer() : fSize(0), fTotalSize(0), fPtr(NULL) {} | |
233 | /** not a valid copy constructor, defined according to effective C++ style */ | |
234 | AliHLTRawBuffer(const AliHLTRawBuffer&) : fSize(0), fTotalSize(0), fPtr(NULL) {} | |
235 | /** not a valid assignment op, but defined according to effective C++ style */ | |
236 | AliHLTRawBuffer& operator=(const AliHLTRawBuffer&) {return *this;} | |
237 | /** standard destructor */ | |
238 | virtual ~AliHLTRawBuffer() {} | |
6235cd38 | 239 | /** size of the currently occupied partition of the buffer */ |
240 | AliHLTUInt32_t fSize; // see above | |
241 | /** total size of the buffer, including safety margin */ | |
242 | AliHLTUInt32_t fTotalSize; // see above | |
243 | /** the buffer */ | |
244 | void* fPtr; //! transient | |
245 | }; | |
246 | ||
3f2a1b1c | 247 | private: |
0c0c9d99 | 248 | /* lets see if this is needed |
6235cd38 | 249 | AliHLTDataSegment* FindDataSegment(AliHLTComponentDataType datatype); |
0c0c9d99 | 250 | */ |
251 | ||
252 | /** | |
253 | * Find those data segments which match the input types of a component. | |
254 | * @param pConsumer the component which subscribes to the buffer | |
255 | * @param tgtList the list to receive the data segment descriptors | |
256 | * @return: number of data blocks which match the input data types | |
257 | * of the consumer, neg. error code if failed <br> | |
258 | * -EINVAL invalid parameter <br> | |
259 | */ | |
90ebac25 | 260 | int FindMatchingDataSegments(const AliHLTComponent* pConsumer, |
261 | vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList); | |
3f2a1b1c | 262 | |
0c0c9d99 | 263 | /** |
264 | * Reset the data buffer. | |
9ce4bf4a | 265 | * Removes all consumers back to the @ref fConsumers list, deletes |
266 | * segments and releases the Raw Buffer. | |
3f2a1b1c | 267 | */ |
268 | int ResetDataBuffer(); | |
269 | ||
70ed7d01 | 270 | ////////////////////////////////////////////////////////////////////////////// |
271 | ||
3f2a1b1c | 272 | // the data description |
3f2a1b1c | 273 | |
0c0c9d99 | 274 | // the data segments within this buffer |
70ed7d01 | 275 | vector<AliHLTDataSegment> fSegments; // see above |
3f2a1b1c | 276 | |
0c0c9d99 | 277 | // the list of all consumers which are going to subscribe to the buffer |
70ed7d01 | 278 | vector<AliHLTConsumerDescriptor*> fConsumers; // see above |
0c0c9d99 | 279 | // the list of all consumers which are currently subscribed to the buffer |
70ed7d01 | 280 | vector<AliHLTConsumerDescriptor*> fActiveConsumers; // see above |
0c0c9d99 | 281 | // the list of all consumers which are already released for the current event |
70ed7d01 | 282 | vector<AliHLTConsumerDescriptor*> fReleasedConsumers; // see above |
3f2a1b1c | 283 | |
0c0c9d99 | 284 | // the buffer instance |
70ed7d01 | 285 | AliHLTRawBuffer* fpBuffer; //! transient |
3f2a1b1c | 286 | |
0c0c9d99 | 287 | // flags indicating the state of the buffer |
70ed7d01 | 288 | AliHLTUInt32_t fFlags; // see above |
3f2a1b1c | 289 | |
70ed7d01 | 290 | ////////////////////////////////////////////////////////////////////////////// |
0c0c9d99 | 291 | // global buffer handling, internal use only |
292 | ||
293 | /** | |
294 | * Create a raw buffer of a certain size. | |
295 | * The function tries to find a buffer of the given size (or a bit bigger by a | |
9ddaea75 | 296 | * certain margin @ref fgMargin) from the list of free buffers. |
0c0c9d99 | 297 | * If no buffer is available, a new one is created and added to the buffer handling. |
298 | * @param size min. size of the requested buffer | |
299 | * @return pointer to raw buffer | |
3f2a1b1c | 300 | */ |
301 | static AliHLTRawBuffer* CreateRawBuffer(AliHLTUInt32_t size); | |
302 | ||
0c0c9d99 | 303 | /** |
304 | * Mark a buffer as free. | |
70ed7d01 | 305 | * After the Data Buffer has finnished using the raw buffer, it is released |
306 | * and added to the list of available buffers. | |
0c0c9d99 | 307 | * @param pBuffer the raw buffer to release |
308 | * @return >=0 if succeeded, neg. error code if failed | |
3f2a1b1c | 309 | */ |
310 | static int ReleaseRawBuffer(AliHLTRawBuffer* pBuffer); | |
311 | ||
0c0c9d99 | 312 | /** |
313 | * Deletes all the raw buffers. | |
70ed7d01 | 314 | * When the last Data Buffer object is destructed, all raw data buffers are |
315 | * relesed. | |
3f2a1b1c | 316 | */ |
317 | static int DeleteRawBuffers(); | |
318 | ||
0c0c9d99 | 319 | /** |
320 | * Number of instances of AliHLTDataBuffer. | |
70ed7d01 | 321 | * The statice variable is incremented and decremented in the constructor/ |
322 | * destructor. All internal data structures are cleaned up when the last | |
323 | * instance is exiting. | |
0c0c9d99 | 324 | */ |
70ed7d01 | 325 | static int fgNofInstances; // see above |
0c0c9d99 | 326 | /** global list of free raw buffers */ |
70ed7d01 | 327 | static vector<AliHLTRawBuffer*> fgFreeBuffers; // see above |
0c0c9d99 | 328 | /** global list of currently active raw buffers */ |
70ed7d01 | 329 | static vector<AliHLTRawBuffer*> fgActiveBuffers; // see above |
0c0c9d99 | 330 | /** determines the raw buffer size margin at buffer requests */ |
70ed7d01 | 331 | static AliHLTUInt32_t fgMargin; // see above |
3f2a1b1c | 332 | |
0c0c9d99 | 333 | /** global instance to HLT logging class for static methods */ |
70ed7d01 | 334 | static AliHLTLogging fgLogging; // see above |
3f2a1b1c | 335 | |
8451168b | 336 | /** size of the safety pattern */ |
337 | static const Int_t fgkSafetyPatternSize; // see above | |
338 | ||
339 | /** the safety pattern */ | |
340 | static const char fgkSafetyPattern[]; //!transient | |
341 | ||
70ed7d01 | 342 | ////////////////////////////////////////////////////////////////////////////// |
0c0c9d99 | 343 | // internal helper functions |
344 | ||
345 | /** | |
346 | * Find the consumer descriptor for a certain component and data type in | |
347 | * a list of consumers.<br> | |
70ed7d01 | 348 | * <b>Note:</b> There are three lists which contain the consumers in the |
349 | * different states. | |
0c0c9d99 | 350 | * @param pConsumer pointer to consumer component |
351 | * @param list list where to search for the consumer | |
352 | */ | |
70ed7d01 | 353 | AliHLTConsumerDescriptor* FindConsumer(const AliHLTComponent* pConsumer, |
354 | vector<AliHLTConsumerDescriptor*> &list) const; | |
0c0c9d99 | 355 | |
356 | /** | |
357 | * Change the state of a consumer. | |
70ed7d01 | 358 | * The state of a consumer is determined by the list it is strored in, the |
359 | * method moves a consumer from the source to the target list. | |
0c0c9d99 | 360 | * @param pDesc pointer to consumer descriptor |
361 | * @param srcList list where the consumer is currently to be found | |
362 | * @param tgtList list where to move the consumer | |
363 | */ | |
70ed7d01 | 364 | int ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, |
365 | vector<AliHLTConsumerDescriptor*> &srcList, | |
366 | vector<AliHLTConsumerDescriptor*> &tgtList); | |
3f2a1b1c | 367 | |
0c0c9d99 | 368 | /** |
369 | * Cleanup a consumer list. | |
370 | * Release all allocated data structures. <b>Note:</b> Not the component itself! | |
371 | */ | |
3f2a1b1c | 372 | int CleanupConsumerList(); |
373 | ||
374 | ClassDef(AliHLTDataBuffer, 0) | |
375 | }; | |
6235cd38 | 376 | |
3f2a1b1c | 377 | #endif // ALIHLTDATABUFFER_H |