3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliHLTOUT.cxx
20 @author Matthias Richter
22 @brief The control class for HLTOUT data. */
24 // see header file for class documentation
26 // refer to README to build package
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
32 #include "AliHLTOUT.h"
34 /** ROOT macro for the implementation of ROOT specific class methods */
37 AliHLTOUT::AliHLTOUT()
39 fSearchDataType(kAliHLTVoidDataType),
40 fSearchSpecification(kAliHLTVoidDataSpec),
41 fSearchHandlerType(AliHLTModuleAgent::kUnknownOutput),
44 fCurrent(fBlockDescList.begin()),
49 // see header file for class documentation
51 // refer to README to build package
53 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 AliHLTOUT::~AliHLTOUT()
58 // see header file for class documentation
63 // see header file for class documentation
65 SetStatusFlag(kCollecting);
66 if ((iResult=GenerateIndex())>=0) {
67 if ((iResult=InitHandlers())>=0) {
70 ClearStatusFlag(kCollecting);
74 int AliHLTOUT::GetNofDataBlocks()
76 // see header file for class documentation
77 return fBlockDescList.size();
80 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
81 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
83 // see header file for class documentation
84 if (CheckStatusFlag(kLocked)) return -EPERM;
85 fCurrent=fBlockDescList.begin();
87 fSearchSpecification=spec;
88 fSearchHandlerType=handlerType;
89 return FindAndSelectDataBlock();
92 int AliHLTOUT::SelectNextDataBlock()
94 // see header file for class documentation
95 if (CheckStatusFlag(kLocked)) return -EPERM;
96 if (fCurrent==fBlockDescList.end()) return -ENOENT;
98 return FindAndSelectDataBlock();
101 int AliHLTOUT::FindAndSelectDataBlock()
103 // see header file for class documentation
104 if (CheckStatusFlag(kLocked)) return -EPERM;
106 while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
107 if ((*fCurrent)==fSearchDataType &&
108 (fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification) &&
109 (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent->GetIndex())==fSearchHandlerType)) {
110 iResult=fCurrent->GetIndex();
111 // TODO: check the byte order on the current system and the byte order of the
112 // data block, print warning when missmatch and user did not check
113 //AliHLTOUTByteOrder blockBO=CheckByteOrder();
116 if (blockBO!=fByteOrder) {
117 SetStatusFlag(kByteOrderWarning);
121 ClearStatusFlag(kByteOrderChecked);
123 // TODO: check the alignment on the current system and the alignment of the
124 // data block, print warning when missmatch and user did not check
125 ClearStatusFlag(kAlignmentChecked);
134 int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
136 // see header file for class documentation
138 if (fCurrent!=fBlockDescList.end()) {
146 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
148 // see header file for class documentation
149 if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
150 return fCurrent->GetIndex();
153 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
155 // see header file for class documentation
159 if (fCurrent!=fBlockDescList.end()) {
160 if ((iResult=GetDataBuffer(fCurrent->GetIndex(), pBuffer, size))>=0) {
167 int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
169 // see header file for class documentation
171 if (pBuffer==fpBuffer) {
174 HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
179 AliHLTOUTHandler* AliHLTOUT::GetHandler()
181 // see header file for class documentation
182 AliHLTOUTHandler* pHandler=NULL;
183 pHandler=FindHandlerDesc(GetDataBlockIndex());
187 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
189 // see header file for class documentation
190 if (!CheckStatusFlag(kCollecting)) return -EPERM;
192 fBlockDescList.push_back(desc);
196 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
198 // see header file for class documentation
199 if (fCurrent!=fBlockDescList.end()) {
200 SetStatusFlag(kByteOrderChecked);
201 AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder((*fCurrent).GetIndex());
204 return kInvalidByteOrder;
207 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
209 // see header file for class documentation
210 if (fCurrent!=fBlockDescList.end()) {
211 SetStatusFlag(kAlignmentChecked);
212 int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
218 int AliHLTOUT::InitHandlers()
220 // see header file for class documentation
222 AliHLTOUTIndexList remnants;
224 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
226 remnants.push_back(GetDataBlockIndex());
227 AliHLTComponentDataType dt=kAliHLTVoidDataType;
228 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
229 if (GetDataBlockDescription(dt, spec)<0) break;
230 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
231 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
232 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
233 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
234 InsertHandler(entry);
241 // warning if some of the data blocks are not selected by the kAliHLTAnyDataType
243 if (GetNofDataBlocks()>iCount) {
244 HLTWarning("incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, iCount);
247 // warning if handler not found
248 if (remnants.size()>0) {
249 HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), iCount);
250 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
251 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
252 for (int trials=0; trials<2; trials++) {
254 // we start searching the index from the current position in the block list
255 if ((*block).GetIndex()==*element) break;
256 } while ((++block)!=fBlockDescList.end());
257 if (block==fBlockDescList.end()) {
258 // rewind and try again
259 block=fBlockDescList.begin();
262 assert(block!=fBlockDescList.end());
263 if (block!=fBlockDescList.end()) {
264 HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
271 int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
273 // see header file for class documentation
275 AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
276 while (element!=fDataHandlers.end()) {
277 if (entry==(*element)) break;
280 if (element==fDataHandlers.end()) {
281 fDataHandlers.push_back(entry);
283 element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
288 const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
290 // see header file for class documentation
291 AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
292 while (element!=fDataHandlers.end()) {
293 if (element->HasIndex(blockIndex)) {
298 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
301 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
308 // see header file for class documentation
311 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
312 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
313 AliHLTModuleAgent* pAgent,
314 AliHLTUInt32_t index)
317 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
321 // see header file for class documentation
322 *fpHandlerDesc=handlerDesc;
323 fBlocks.push_back(index);
326 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
328 fpHandler(src.fpHandler),
329 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
330 fpAgent(src.fpAgent),
333 // see header file for class documentation
334 *fpHandlerDesc=*src.fpHandlerDesc;
335 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
338 AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
340 // see header file for class documentation
341 if (fpHandlerDesc) delete fpHandlerDesc;
345 AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
347 // see header file for class documentation
348 fpHandler=src.fpHandler;
349 if (src.fpHandlerDesc)
350 *fpHandlerDesc=*src.fpHandlerDesc;
352 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
356 AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
358 // see header file for class documentation
359 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
362 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
364 // see header file for class documentation
365 if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
366 assert(entry.fpAgent==fpAgent);
367 if (entry.fpAgent!=fpAgent) return false;
371 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const
373 // see header file for class documentation
374 if (!fpHandlerDesc) return false;
375 return *fpHandlerDesc==handlerType;
378 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
380 // see header file for class documentation
381 AliHLTOUTIndexList::iterator element;
382 for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
387 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
389 // see header file for class documentation
390 fBlocks.push_back(index);
393 bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index)
395 // see header file for class documentation
396 AliHLTOUTIndexList::iterator element;
397 for (element=fBlocks.begin(); element!=fBlocks.end(); element++) {
398 if (*element==index) return true;
403 const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
405 AliHLTUInt64_t AliHLTOUT::Swap(AliHLTUInt64_t src)
407 // see header file for class documentation
408 return ((src & 0xFFULL) << 56) |
409 ((src & 0xFF00ULL) << 40) |
410 ((src & 0xFF0000ULL) << 24) |
411 ((src & 0xFF000000ULL) << 8) |
412 ((src & 0xFF00000000ULL) >> 8) |
413 ((src & 0xFF0000000000ULL) >> 24) |
414 ((src & 0xFF000000000000ULL) >> 40) |
415 ((src & 0xFF00000000000000ULL) >> 56);
418 AliHLTUInt32_t AliHLTOUT::Swap(AliHLTUInt32_t src)
420 // see header file for class documentation
421 return ((src & 0xFFULL) << 24) |
422 ((src & 0xFF00ULL) << 8) |
423 ((src & 0xFF0000ULL) >> 8) |
424 ((src & 0xFF000000ULL) >> 24);