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 if ((iResult=GenerateIndex())>=0) {
72 if ((iResult=InitHandlers())>=0) {
78 int AliHLTOUT::GetNofDataBlocks()
80 // see header file for class documentation
81 return fBlockDescList.size();
84 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
85 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
87 // see header file for class documentation
88 if (CheckStatusFlag(kLocked)) return -EPERM;
89 fCurrent=fBlockDescList.begin();
91 fSearchSpecification=spec;
92 //fSearchHandlerType=handlerType;
93 return FindAndSelectDataBlock();
96 int AliHLTOUT::SelectNextDataBlock()
98 // see header file for class documentation
99 if (CheckStatusFlag(kLocked)) return -EPERM;
101 return FindAndSelectDataBlock();
104 int AliHLTOUT::FindAndSelectDataBlock()
106 // see header file for class documentation
107 if (CheckStatusFlag(kLocked)) return -EPERM;
109 while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
110 if ((fSearchDataType==kAliHLTAnyDataType || (*fCurrent)==fSearchDataType) &&
111 fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification &&
112 1/*fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput*/) {
114 // TODO: check the byte order on the current system and the byte order of the
115 // data block, print warning when missmatch and user did not check
116 //AliHLTOUTByteOrder_t blockBO=CheckByteOrder();
119 if (blockBO!=fByteOrder) {
120 SetStatusFlag(kByteOrderWarning);
124 ClearStatusFlag(kByteOrderChecked);
126 // TODO: check the alignment on the current system and the alignment of the
127 // data block, print warning when missmatch and user did not check
128 ClearStatusFlag(kAlignmentChecked);
135 int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
137 // see header file for class documentation
139 if (fCurrent!=fBlockDescList.end()) {
147 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
149 // see header file for class documentation
150 assert(0); // not implemented
151 return AliHLTOUTInvalidIndex;
154 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
156 // see header file for class documentation
160 if (fCurrent!=fBlockDescList.end()) {
161 if ((iResult=GetDataBuffer((*fCurrent).GetIndex(), pBuffer, size))>=0) {
168 int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
170 // see header file for class documentation
172 if (pBuffer==fpBuffer) {
175 HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
180 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
182 // see header file for class documentation
183 if (!CheckStatusFlag(kCollecting)) return -EPERM;
185 fBlockDescList.push_back(desc);
189 AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUT::CheckByteOrder()
191 // see header file for class documentation
192 if (fCurrent!=fBlockDescList.end()) {
193 SetStatusFlag(kByteOrderChecked);
194 AliHLTOUT::AliHLTOUTByteOrder_t order=CheckBlockByteOrder((*fCurrent).GetIndex());
197 return kInvalidByteOrder;
200 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type)
202 // see header file for class documentation
203 if (fCurrent!=fBlockDescList.end()) {
204 SetStatusFlag(kAlignmentChecked);
205 int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
211 int AliHLTOUT::InitHandlers()
213 // see header file for class documentation
215 AliHLTOUTIndexList remnants;
216 for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); iResult>0; iResult=SelectNextDataBlock()) {
217 remnants.push_back(GetDataBlockIndex());
218 AliHLTComponentDataType dt=kAliHLTVoidDataType;
219 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
220 if ((iResult=GetDataBlockDescription(dt, spec))<0) break;
221 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
222 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
223 if (pAgent->GetHandlerDescription(dt, spec, &handlerDesc)>0) {
224 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
225 iResult=InsertHandler(entry);
231 if (remnants.size()>0) {
232 HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), GetNofDataBlocks());
233 vector<AliHLTOUTBlockDescriptor>::iterator block=fBlockDescList.begin();
234 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
235 for (int trials=0; trials<2; trials++) {
237 // we start searching the index from the current position in the block list
238 if ((*block).GetIndex()==*element) break;
239 } while ((++block)!=fBlockDescList.end());
240 if (block==fBlockDescList.end()) {
241 // rewind and try again
242 block=fBlockDescList.begin();
245 assert(block!=fBlockDescList.end());
246 if (block!=fBlockDescList.end()) {
247 HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
254 int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
256 // see header file for class documentation
258 vector<AliHLTOUTHandlerListEntry>::iterator element=fDataHandlers.begin();
259 while (element!=fDataHandlers.end()) {
260 if (entry==(*element)) break;
263 if (element==fDataHandlers.end()) {
264 fDataHandlers.push_back(entry);
271 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
272 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
273 AliHLTModuleAgent* pAgent,
274 AliHLTUInt32_t index)
277 fHandlerDesc(handlerDesc),
281 // see header file for class documentation
282 fBlocks.push_back(index);
285 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
287 fpHandler(src.fpHandler),
288 fHandlerDesc(src.fHandlerDesc),
289 fpAgent(src.fpAgent),
292 // see header file for class documentation
293 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
296 AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
298 // see header file for class documentation
301 AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
303 // see header file for class documentation
304 fpHandler=src.fpHandler;
305 fHandlerDesc=src.fHandlerDesc;
307 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
311 AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const {
312 return fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
315 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
320 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index) {
321 fBlocks.push_back(index);