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 // definitions from ALICE internal note ALICE-INT-2002-010
55 const unsigned char AliHLTOUT::fgkCDHStatusWord=4;
56 const unsigned char AliHLTOUT::fgkCDHStatusFlagsOffset=12;
58 // definitions from ALICE internal note ALICE-INT-2006-XXX
59 const unsigned char AliHLTOUT::fgkCDHFlagsHLTDecision=6;
60 const unsigned char AliHLTOUT::fgkCDHFlagsHLTPayload=7;
62 AliHLTOUT::~AliHLTOUT()
64 // see header file for class documentation
69 // see header file for class documentation
71 SetStatusFlag(kCollecting);
72 if ((iResult=GenerateIndex())>=0) {
73 if ((iResult=InitHandlers())>=0) {
76 ClearStatusFlag(kCollecting);
80 int AliHLTOUT::GetNofDataBlocks()
82 // see header file for class documentation
83 return fBlockDescList.size();
86 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
87 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
89 // see header file for class documentation
90 if (CheckStatusFlag(kLocked)) return -EPERM;
91 fCurrent=fBlockDescList.begin();
93 fSearchSpecification=spec;
94 //fSearchHandlerType=handlerType;
95 return FindAndSelectDataBlock();
98 int AliHLTOUT::SelectNextDataBlock()
100 // see header file for class documentation
101 if (CheckStatusFlag(kLocked)) return -EPERM;
102 if (fCurrent==fBlockDescList.end()) return -ENOENT;
104 return FindAndSelectDataBlock();
107 int AliHLTOUT::FindAndSelectDataBlock()
109 // see header file for class documentation
110 if (CheckStatusFlag(kLocked)) return -EPERM;
112 while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
113 if ((*fCurrent)==fSearchDataType &&
114 fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification &&
115 1/*fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput*/) {
116 iResult=fCurrent->GetIndex();
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
119 //AliHLTOUTByteOrder_t blockBO=CheckByteOrder();
122 if (blockBO!=fByteOrder) {
123 SetStatusFlag(kByteOrderWarning);
127 ClearStatusFlag(kByteOrderChecked);
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);
140 int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
142 // see header file for class documentation
144 if (fCurrent!=fBlockDescList.end()) {
152 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
154 // see header file for class documentation
155 if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
156 return fCurrent->GetIndex();
159 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
161 // see header file for class documentation
165 if (fCurrent!=fBlockDescList.end()) {
166 if ((iResult=GetDataBuffer((*fCurrent).GetIndex(), pBuffer, size))>=0) {
173 int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
175 // see header file for class documentation
177 if (pBuffer==fpBuffer) {
180 HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
185 AliHLTOUTHandler* AliHLTOUT::GetHandler()
187 // see header file for class documentation
188 AliHLTOUTHandler* pHandler=NULL;
189 pHandler=FindHandlerDesc(GetDataBlockIndex());
193 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
195 // see header file for class documentation
196 if (!CheckStatusFlag(kCollecting)) return -EPERM;
198 fBlockDescList.push_back(desc);
202 AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUT::CheckByteOrder()
204 // see header file for class documentation
205 if (fCurrent!=fBlockDescList.end()) {
206 SetStatusFlag(kByteOrderChecked);
207 AliHLTOUT::AliHLTOUTByteOrder_t order=CheckBlockByteOrder((*fCurrent).GetIndex());
210 return kInvalidByteOrder;
213 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type)
215 // see header file for class documentation
216 if (fCurrent!=fBlockDescList.end()) {
217 SetStatusFlag(kAlignmentChecked);
218 int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
224 int AliHLTOUT::InitHandlers()
226 // see header file for class documentation
228 AliHLTOUTIndexList remnants;
229 for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); iResult>=0; iResult=SelectNextDataBlock()) {
230 remnants.push_back(GetDataBlockIndex());
231 AliHLTComponentDataType dt=kAliHLTVoidDataType;
232 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
233 if ((iResult=GetDataBlockDescription(dt, spec))<0) break;
234 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
235 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
236 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
237 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
238 iResult=InsertHandler(entry);
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++) {
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();
258 assert(block!=fBlockDescList.end());
259 if (block!=fBlockDescList.end()) {
260 HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
267 int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
269 // see header file for class documentation
271 vector<AliHLTOUTHandlerListEntry>::iterator element=fDataHandlers.begin();
272 while (element!=fDataHandlers.end()) {
273 if (entry==(*element)) break;
276 if (element==fDataHandlers.end()) {
277 fDataHandlers.push_back(entry);
284 AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
286 // see header file for class documentation
287 vector<AliHLTOUTHandlerListEntry>::iterator element=fDataHandlers.begin();
288 while (element!=fDataHandlers.end()) {
289 if (element->HasIndex(blockIndex)) {
294 return AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
297 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
304 // see header file for class documentation
307 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
308 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
309 AliHLTModuleAgent* pAgent,
310 AliHLTUInt32_t index)
313 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
317 // see header file for class documentation
318 *fpHandlerDesc=handlerDesc;
319 fBlocks.push_back(index);
322 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
324 fpHandler(src.fpHandler),
325 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
326 fpAgent(src.fpAgent),
329 // see header file for class documentation
330 *fpHandlerDesc=*src.fpHandlerDesc;
331 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
334 AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
336 // see header file for class documentation
337 if (fpHandlerDesc) delete fpHandlerDesc;
341 AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
343 // see header file for class documentation
344 fpHandler=src.fpHandler;
345 *fpHandlerDesc=*src.fpHandlerDesc;
347 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
351 AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
353 // see header file for class documentation
354 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
357 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
359 // see header file for class documentation
360 assert(0); // not yet implemented
364 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
366 // see header file for class documentation
367 fBlocks.push_back(index);
370 bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index)
372 // see header file for class documentation
376 const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;