]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTOUT.cxx
string.h instead of cstring on Solaris x86
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUT.cxx
CommitLineData
62bb3cd4 1// $Id$
2
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTOUT.cxx
20 @author Matthias Richter
21 @date
22 @brief The control class for HLTOUT data. */
23
4de7334f 24// see header file for class documentation
25// or
26// refer to README to build package
27// or
28// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62bb3cd4 29
4de7334f 30#include <cerrno>
5db0e774 31#include <cassert>
62bb3cd4 32#include "AliHLTOUT.h"
33
34/** ROOT macro for the implementation of ROOT specific class methods */
35ClassImp(AliHLTOUT)
36
37AliHLTOUT::AliHLTOUT()
4de7334f 38 :
39 fSearchDataType(kAliHLTVoidDataType),
40 fSearchSpecification(kAliHLTVoidDataSpec),
049b43b2 41 fFlags(0),
4de7334f 42 fBlockDescList(),
43 fCurrent(fBlockDescList.begin()),
5db0e774 44 fpBuffer(NULL),
45 fDataHandlers()
4de7334f 46{
62bb3cd4 47 // see header file for class documentation
48 // or
49 // refer to README to build package
50 // or
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52}
53
4b113031 54// definitions from ALICE internal note ALICE-INT-2002-010
55const unsigned char AliHLTOUT::fgkCDHStatusWord=4;
56const unsigned char AliHLTOUT::fgkCDHStatusFlagsOffset=12;
57
58// definitions from ALICE internal note ALICE-INT-2006-XXX
59const unsigned char AliHLTOUT::fgkCDHFlagsHLTDecision=6;
60const unsigned char AliHLTOUT::fgkCDHFlagsHLTPayload=7;
61
62bb3cd4 62AliHLTOUT::~AliHLTOUT()
4de7334f 63{
64 // see header file for class documentation
65}
66
5db0e774 67int AliHLTOUT::Init()
68{
69 // see header file for class documentation
70 int iResult=0;
18b56222 71 SetStatusFlag(kCollecting);
5db0e774 72 if ((iResult=GenerateIndex())>=0) {
73 if ((iResult=InitHandlers())>=0) {
74 }
75 }
18b56222 76 ClearStatusFlag(kCollecting);
5db0e774 77 return iResult;
78}
79
4de7334f 80int AliHLTOUT::GetNofDataBlocks()
81{
82 // see header file for class documentation
83 return fBlockDescList.size();
84}
85
5db0e774 86int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
87 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
4de7334f 88{
89 // see header file for class documentation
049b43b2 90 if (CheckStatusFlag(kLocked)) return -EPERM;
4de7334f 91 fCurrent=fBlockDescList.begin();
92 fSearchDataType=dt;
93 fSearchSpecification=spec;
5db0e774 94 //fSearchHandlerType=handlerType;
049b43b2 95 return FindAndSelectDataBlock();
4de7334f 96}
97
98int AliHLTOUT::SelectNextDataBlock()
99{
100 // see header file for class documentation
049b43b2 101 if (CheckStatusFlag(kLocked)) return -EPERM;
18b56222 102 if (fCurrent==fBlockDescList.end()) return -ENOENT;
049b43b2 103 fCurrent++;
104 return FindAndSelectDataBlock();
105}
106
107int AliHLTOUT::FindAndSelectDataBlock()
108{
109 // see header file for class documentation
110 if (CheckStatusFlag(kLocked)) return -EPERM;
4de7334f 111 int iResult=-ENOENT;
112 while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
d8f5c9fe 113 if ((*fCurrent)==fSearchDataType &&
5db0e774 114 fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification &&
115 1/*fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput*/) {
18b56222 116 iResult=fCurrent->GetIndex();
049b43b2 117 // TODO: check the byte order on the current system and the byte order of the
118 // data block, print warning when missmatch and user did not check
d76bc02a 119 //AliHLTOUTByteOrder_t blockBO=CheckByteOrder();
06f53caf 120 CheckByteOrder();
049b43b2 121 /*
122 if (blockBO!=fByteOrder) {
123 SetStatusFlag(kByteOrderWarning);
124
125 }
126 */
127 ClearStatusFlag(kByteOrderChecked);
128
129 // TODO: check the alignment on the current system and the alignment of the
130 // data block, print warning when missmatch and user did not check
131 ClearStatusFlag(kAlignmentChecked);
18b56222 132
133 break;
4de7334f 134 }
049b43b2 135 fCurrent++;
4de7334f 136 }
137 return iResult;
138}
139
140int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
141{
142 // see header file for class documentation
143 int iResult=-ENOENT;
144 if (fCurrent!=fBlockDescList.end()) {
145 iResult=0;
146 dt=(*fCurrent);
147 spec=(*fCurrent);
148 }
149 return iResult;
150}
151
5db0e774 152AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
153{
154 // see header file for class documentation
18b56222 155 if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
156 return fCurrent->GetIndex();
5db0e774 157}
158
4de7334f 159int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
160{
161 // see header file for class documentation
162 int iResult=-ENOENT;
163 pBuffer=NULL;
164 size=0;
165 if (fCurrent!=fBlockDescList.end()) {
e94eb049 166 if ((iResult=GetDataBuffer(fCurrent->GetIndex(), pBuffer, size))>=0) {
4de7334f 167 fpBuffer=pBuffer;
168 }
169 }
170 return iResult;
171}
172
173int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
174{
175 // see header file for class documentation
176 int iResult=0;
177 if (pBuffer==fpBuffer) {
178 fpBuffer=NULL;
179 } else {
180 HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
181 }
182 return iResult;
183}
184
626bfcc1 185AliHLTOUTHandler* AliHLTOUT::GetHandler()
186{
187 // see header file for class documentation
188 AliHLTOUTHandler* pHandler=NULL;
189 pHandler=FindHandlerDesc(GetDataBlockIndex());
190 return pHandler;
191}
192
4de7334f 193int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
194{
62bb3cd4 195 // see header file for class documentation
049b43b2 196 if (!CheckStatusFlag(kCollecting)) return -EPERM;
4de7334f 197 int iResult=0;
198 fBlockDescList.push_back(desc);
199 return iResult;
62bb3cd4 200}
049b43b2 201
202AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUT::CheckByteOrder()
203{
5db0e774 204 // see header file for class documentation
049b43b2 205 if (fCurrent!=fBlockDescList.end()) {
206 SetStatusFlag(kByteOrderChecked);
207 AliHLTOUT::AliHLTOUTByteOrder_t order=CheckBlockByteOrder((*fCurrent).GetIndex());
208 return order;
209 }
210 return kInvalidByteOrder;
211}
212
213int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type)
214{
5db0e774 215 // see header file for class documentation
049b43b2 216 if (fCurrent!=fBlockDescList.end()) {
217 SetStatusFlag(kAlignmentChecked);
218 int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
219 return alignment;
220 }
221 return -ENOENT;
222}
5db0e774 223
224int AliHLTOUT::InitHandlers()
225{
226 // see header file for class documentation
227 int iResult=0;
228 AliHLTOUTIndexList remnants;
a3ef3c1d 229 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
5db0e774 230 remnants.push_back(GetDataBlockIndex());
231 AliHLTComponentDataType dt=kAliHLTVoidDataType;
232 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
e94eb049 233 if (GetDataBlockDescription(dt, spec)<0) break;
5db0e774 234 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
235 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
626bfcc1 236 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
5db0e774 237 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
e94eb049 238 InsertHandler(entry);
5db0e774 239 remnants.pop_back();
240 break;
241 }
242 }
243 }
244 if (remnants.size()>0) {
245 HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), GetNofDataBlocks());
246 vector<AliHLTOUTBlockDescriptor>::iterator block=fBlockDescList.begin();
247 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
248 for (int trials=0; trials<2; trials++) {
249 do {
250 // we start searching the index from the current position in the block list
251 if ((*block).GetIndex()==*element) break;
252 } while ((++block)!=fBlockDescList.end());
253 if (block==fBlockDescList.end()) {
254 // rewind and try again
255 block=fBlockDescList.begin();
256 }
257 }
258 assert(block!=fBlockDescList.end());
259 if (block!=fBlockDescList.end()) {
260 HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
261 }
262 }
263 }
264 return iResult;
265}
266
267int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
268{
269 // see header file for class documentation
270 int iResult=0;
271 vector<AliHLTOUTHandlerListEntry>::iterator element=fDataHandlers.begin();
272 while (element!=fDataHandlers.end()) {
273 if (entry==(*element)) break;
274 element++;
275 }
276 if (element==fDataHandlers.end()) {
277 fDataHandlers.push_back(entry);
278 } else {
a3ef3c1d 279 element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
5db0e774 280 }
281 return iResult;
282}
283
626bfcc1 284AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
285{
286 // see header file for class documentation
626bfcc1 287 vector<AliHLTOUTHandlerListEntry>::iterator element=fDataHandlers.begin();
288 while (element!=fDataHandlers.end()) {
289 if (element->HasIndex(blockIndex)) {
290 return *element;
291 }
292 element++;
293 }
294 return AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
295}
296
297AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
298 :
299 fpHandler(NULL),
300 fpHandlerDesc(NULL),
301 fpAgent(NULL),
302 fBlocks()
303{
304 // see header file for class documentation
305}
306
5db0e774 307AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
308 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
309 AliHLTModuleAgent* pAgent,
310 AliHLTUInt32_t index)
311 :
312 fpHandler(pHandler),
626bfcc1 313 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
5db0e774 314 fpAgent(pAgent),
315 fBlocks()
316{
317 // see header file for class documentation
626bfcc1 318 *fpHandlerDesc=handlerDesc;
5db0e774 319 fBlocks.push_back(index);
320}
321
322AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
323 :
324 fpHandler(src.fpHandler),
626bfcc1 325 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
5db0e774 326 fpAgent(src.fpAgent),
327 fBlocks()
328{
329 // see header file for class documentation
626bfcc1 330 *fpHandlerDesc=*src.fpHandlerDesc;
5db0e774 331 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
332}
333
fb24bec7 334AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
335{
336 // see header file for class documentation
626bfcc1 337 if (fpHandlerDesc) delete fpHandlerDesc;
338 fpHandlerDesc=NULL;
fb24bec7 339}
340
5db0e774 341AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
342{
343 // see header file for class documentation
344 fpHandler=src.fpHandler;
626bfcc1 345 *fpHandlerDesc=*src.fpHandlerDesc;
5db0e774 346 fpAgent=src.fpAgent;
347 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
348 return *this;
349}
350
18b56222 351AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
352{
353 // see header file for class documentation
b0914d2e 354 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
5db0e774 355}
356
fb24bec7 357bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
358{
18b56222 359 // see header file for class documentation
a3ef3c1d 360 if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
361 assert(entry.fpAgent==fpAgent);
362 if (entry.fpAgent!=fpAgent) return false;
363 return true;
364}
365
366void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
367{
368 // see header file for class documentation
369 AliHLTOUTIndexList::iterator element;
370 for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
371 AddIndex(*element);
372 }
fb24bec7 373}
374
18b56222 375void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
376{
377 // see header file for class documentation
5db0e774 378 fBlocks.push_back(index);
379}
626bfcc1 380
200853e2 381bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index)
382{
383 // see header file for class documentation
a3ef3c1d 384 AliHLTOUTIndexList::iterator element;
385 for (element=fBlocks.begin(); element!=fBlocks.end(); element++) {
386 if (*element==index) return true;
387 }
200853e2 388 return false;
389}
390
626bfcc1 391const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;