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 AliHLTOUTHomerBuffer.cxx
20 @author Matthias Richter
22 @brief HLTOUT data wrapper for buffer in HOMER format. */
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 "AliHLTOUTHomerBuffer.h"
33 #include "AliHLTHOMERReader.h"
34 #include "AliHLTHOMERLibManager.h"
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTOUTHomerBuffer)
39 AliHLTOUTHomerBuffer::AliHLTOUTHomerBuffer(const AliHLTUInt8_t* pBuffer, int size)
42 fpManager(new AliHLTHOMERLibManager),
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
52 assert(sizeof(homer_uint64)==kAliHLTComponentDataTypefIDsize);
53 assert(sizeof(homer_uint32)==kAliHLTComponentDataTypefOriginSize);
57 AliHLTOUTHomerBuffer::~AliHLTOUTHomerBuffer()
59 // see header file for class documentation
61 if (fpReader) fpManager->DeleteReader(fpReader);
68 int AliHLTOUTHomerBuffer::GenerateIndex()
70 // see header file for class documentation
74 fpReader=fpManager->OpenReaderBuffer(fpBuffer, fSize);
78 iResult=ScanReader(fpReader);
85 int AliHLTOUTHomerBuffer::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer,
88 // see header file for class documentation
91 if ((pBuffer=static_cast<const AliHLTUInt8_t*>(fpReader->GetBlockData(index)))!=NULL) {
92 size=fpReader->GetBlockDataLength(index);
102 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUTHomerBuffer::CheckBlockByteOrder(AliHLTUInt32_t index)
105 return static_cast<AliHLTOUTByteOrder>(fpReader->GetBlockByteOrder(index));
107 return kInvalidByteOrder;
110 int AliHLTOUTHomerBuffer::CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type)
113 return fpReader->GetBlockTypeAlignment(index, static_cast<homer_uint8>(type));
118 int AliHLTOUTHomerBuffer::ScanReader(AliHLTMonitoringReader* pReader, AliHLTUInt32_t offset)
120 // see header file for class documentation
122 if (pReader && (iResult=pReader->ReadNextEvent())==0) {
123 AliHLTUInt32_t nofBlocks=pReader->GetBlockCnt();
124 AliHLTUInt32_t tmp1=0x1;
125 AliHLTUInt32_t tmp2=offset;
127 // first check if the offset allows to add all data blocks without exceeding the
129 while (nofBlocks>tmp1 && tmp2>0) {
131 HLTError("index range %#x exceeded for %d data blocks", nofBlocks, offset);
138 // loop over data blocks
139 HLTDebug("generating index for %d data blocks of reader with offset %#x", nofBlocks, offset);
140 for (AliHLTUInt32_t i=0; i<nofBlocks && iResult>=0; i++) {
141 homer_uint64 id=pReader->GetBlockDataType( i );
142 homer_uint32 origin=pReader->GetBlockDataOrigin( i );
143 homer_uint32 spec=pReader->GetBlockDataSpec( i );
144 AliHLTComponentDataType dt;
145 AliHLTComponent::SetDataType(dt, ByteSwap64(id), ByteSwap32(origin));
146 AliHLTOUTBlockDescriptor desc(dt, spec, offset|i, this);
147 HLTDebug("adding block %d: %s %#x", i, AliHLTComponent::DataType2Text(dt).c_str(), spec);
148 iResult=AddBlockDescriptor(desc);
151 if (iResult==EBADMSG) {
152 HLTWarning("Format error in data block");
154 } else if (iResult==126/*ENOKEY*/) {
155 HLTWarning("Format error in data block: can not find HOMER block descriptor id");