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),
43 fCurrent(fBlockDescList.begin()),
47 // see header file for class documentation
49 // refer to README to build package
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54 AliHLTOUT::~AliHLTOUT()
56 // see header file for class documentation
61 // see header file for class documentation
63 SetStatusFlag(kCollecting);
64 if ((iResult=GenerateIndex())>=0) {
65 if ((iResult=InitHandlers())>=0) {
68 ClearStatusFlag(kCollecting);
72 int AliHLTOUT::GetNofDataBlocks()
74 // see header file for class documentation
75 return fBlockDescList.size();
78 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
79 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
81 // see header file for class documentation
82 if (CheckStatusFlag(kLocked)) return -EPERM;
83 fCurrent=fBlockDescList.begin();
85 fSearchSpecification=spec;
86 //fSearchHandlerType=handlerType;
87 return FindAndSelectDataBlock();
90 int AliHLTOUT::SelectNextDataBlock()
92 // see header file for class documentation
93 if (CheckStatusFlag(kLocked)) return -EPERM;
94 if (fCurrent==fBlockDescList.end()) return -ENOENT;
96 return FindAndSelectDataBlock();
99 int AliHLTOUT::FindAndSelectDataBlock()
101 // see header file for class documentation
102 if (CheckStatusFlag(kLocked)) return -EPERM;
104 while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
105 if ((*fCurrent)==fSearchDataType &&
106 fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification &&
107 1/*fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput*/) {
108 iResult=fCurrent->GetIndex();
109 // TODO: check the byte order on the current system and the byte order of the
110 // data block, print warning when missmatch and user did not check
111 //AliHLTOUTByteOrder blockBO=CheckByteOrder();
114 if (blockBO!=fByteOrder) {
115 SetStatusFlag(kByteOrderWarning);
119 ClearStatusFlag(kByteOrderChecked);
121 // TODO: check the alignment on the current system and the alignment of the
122 // data block, print warning when missmatch and user did not check
123 ClearStatusFlag(kAlignmentChecked);
132 int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
134 // see header file for class documentation
136 if (fCurrent!=fBlockDescList.end()) {
144 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
146 // see header file for class documentation
147 if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
148 return fCurrent->GetIndex();
151 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
153 // see header file for class documentation
157 if (fCurrent!=fBlockDescList.end()) {
158 if ((iResult=GetDataBuffer(fCurrent->GetIndex(), pBuffer, size))>=0) {
165 int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
167 // see header file for class documentation
169 if (pBuffer==fpBuffer) {
172 HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
177 AliHLTOUTHandler* AliHLTOUT::GetHandler()
179 // see header file for class documentation
180 AliHLTOUTHandler* pHandler=NULL;
181 pHandler=FindHandlerDesc(GetDataBlockIndex());
185 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
187 // see header file for class documentation
188 if (!CheckStatusFlag(kCollecting)) return -EPERM;
190 fBlockDescList.push_back(desc);
194 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
196 // see header file for class documentation
197 if (fCurrent!=fBlockDescList.end()) {
198 SetStatusFlag(kByteOrderChecked);
199 AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder((*fCurrent).GetIndex());
202 return kInvalidByteOrder;
205 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
207 // see header file for class documentation
208 if (fCurrent!=fBlockDescList.end()) {
209 SetStatusFlag(kAlignmentChecked);
210 int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
216 int AliHLTOUT::InitHandlers()
218 // see header file for class documentation
220 AliHLTOUTIndexList remnants;
221 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
222 remnants.push_back(GetDataBlockIndex());
223 AliHLTComponentDataType dt=kAliHLTVoidDataType;
224 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
225 if (GetDataBlockDescription(dt, spec)<0) break;
226 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
227 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
228 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
229 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
230 InsertHandler(entry);
236 if (remnants.size()>0) {
237 HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), GetNofDataBlocks());
238 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
239 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
240 for (int trials=0; trials<2; trials++) {
242 // we start searching the index from the current position in the block list
243 if ((*block).GetIndex()==*element) break;
244 } while ((++block)!=fBlockDescList.end());
245 if (block==fBlockDescList.end()) {
246 // rewind and try again
247 block=fBlockDescList.begin();
250 assert(block!=fBlockDescList.end());
251 if (block!=fBlockDescList.end()) {
252 HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
259 int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
261 // see header file for class documentation
263 AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
264 while (element!=fDataHandlers.end()) {
265 if (entry==(*element)) break;
268 if (element==fDataHandlers.end()) {
269 fDataHandlers.push_back(entry);
271 element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
276 AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
278 // see header file for class documentation
279 AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
280 while (element!=fDataHandlers.end()) {
281 if (element->HasIndex(blockIndex)) {
286 return AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
289 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
296 // see header file for class documentation
299 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
300 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
301 AliHLTModuleAgent* pAgent,
302 AliHLTUInt32_t index)
305 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
309 // see header file for class documentation
310 *fpHandlerDesc=handlerDesc;
311 fBlocks.push_back(index);
314 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
316 fpHandler(src.fpHandler),
317 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
318 fpAgent(src.fpAgent),
321 // see header file for class documentation
322 *fpHandlerDesc=*src.fpHandlerDesc;
323 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
326 AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
328 // see header file for class documentation
329 if (fpHandlerDesc) delete fpHandlerDesc;
333 AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
335 // see header file for class documentation
336 fpHandler=src.fpHandler;
337 *fpHandlerDesc=*src.fpHandlerDesc;
339 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
343 AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
345 // see header file for class documentation
346 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
349 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
351 // see header file for class documentation
352 if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
353 assert(entry.fpAgent==fpAgent);
354 if (entry.fpAgent!=fpAgent) return false;
358 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
360 // see header file for class documentation
361 AliHLTOUTIndexList::iterator element;
362 for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
367 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
369 // see header file for class documentation
370 fBlocks.push_back(index);
373 bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index)
375 // see header file for class documentation
376 AliHLTOUTIndexList::iterator element;
377 for (element=fBlocks.begin(); element!=fBlocks.end(); element++) {
378 if (*element==index) return true;
383 const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;