various fixes in the HLTOUT treatment
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUTHomerBuffer.cxx
CommitLineData
4de7334f 1// $Id$
2
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
6 * *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
9 * *
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 **************************************************************************/
18
19/** @file AliHLTOUTHomerBuffer.cxx
20 @author Matthias Richter
21 @date
049b43b2 22 @brief HLTOUT data wrapper for buffer in HOMER format. */
4de7334f 23
24// see header file for class documentation
25// or
26// refer to README to build package
27// or
28// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30#include <cerrno>
049b43b2 31#include <cassert>
4de7334f 32#include "AliHLTOUTHomerBuffer.h"
33#include "AliHLTHOMERReader.h"
049b43b2 34#include "AliHLTHOMERLibManager.h"
4de7334f 35
36/** ROOT macro for the implementation of ROOT specific class methods */
37ClassImp(AliHLTOUTHomerBuffer)
38
049b43b2 39AliHLTOUTHomerBuffer::AliHLTOUTHomerBuffer(const AliHLTUInt8_t* pBuffer, int size)
4de7334f 40 :
41 AliHLTOUT(),
4b113031 42 fpManager(new AliHLTHOMERLibManager),
4de7334f 43 fpBuffer(pBuffer),
049b43b2 44 fSize(size),
4b113031 45 fpReader(NULL)
4de7334f 46{
47 // see header file for class documentation
48 // or
49 // refer to README to build package
50 // or
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
049b43b2 52 assert(sizeof(homer_uint64)==kAliHLTComponentDataTypefIDsize);
53 assert(sizeof(homer_uint32)==kAliHLTComponentDataTypefOriginSize);
54 assert(fpManager);
4de7334f 55}
56
57AliHLTOUTHomerBuffer::~AliHLTOUTHomerBuffer()
58{
59 // see header file for class documentation
049b43b2 60 if (fpManager) {
61 if (fpReader) fpManager->DeleteReader(fpReader);
62 delete fpManager;
63 fpManager=NULL;
64 fpReader=NULL;
65 }
4de7334f 66}
67
68int AliHLTOUTHomerBuffer::GenerateIndex()
69{
70 // see header file for class documentation
71 int iResult=0;
049b43b2 72 if (!fpReader) {
73 if (fpManager) {
18b56222 74 fpReader=fpManager->OpenReaderBuffer(fpBuffer, fSize);
049b43b2 75 }
76 }
77 if (fpReader) {
78 iResult=ScanReader(fpReader);
79 } else {
80 iResult=-ENODEV;
81 }
4de7334f 82 return iResult;
83}
84
85int AliHLTOUTHomerBuffer::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer,
86 AliHLTUInt32_t& size)
87{
88 // see header file for class documentation
89 int iResult=0;
90 if (fpReader) {
91 if ((pBuffer=static_cast<const AliHLTUInt8_t*>(fpReader->GetBlockData(index)))!=NULL) {
92 size=fpReader->GetBlockDataLength(index);
93 } else {
94 iResult=-ENOENT;
95 }
96 } else {
97 iResult=-ENODEV;
98 }
99 return iResult;
100}
049b43b2 101
102AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUTHomerBuffer::CheckBlockByteOrder(AliHLTUInt32_t index)
103{
104 if (fpReader) {
105 return static_cast<AliHLTOUTByteOrder_t>(fpReader->GetBlockByteOrder(index));
106 }
107 return kInvalidByteOrder;
108}
109
110int AliHLTOUTHomerBuffer::CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType_t type)
111{
112 if (fpReader) {
113 return fpReader->GetBlockTypeAlignment(index, static_cast<homer_uint8>(type));
114 }
115 return -ENODATA;
116}
117
a183f221 118int AliHLTOUTHomerBuffer::ScanReader(AliHLTMonitoringReader* pReader, AliHLTUInt32_t offset)
049b43b2 119{
120 // see header file for class documentation
121 int iResult=0;
18b56222 122 if (pReader && pReader->ReadNextEvent()==0) {
049b43b2 123 AliHLTUInt32_t nofBlocks=pReader->GetBlockCnt();
124 AliHLTUInt32_t tmp1=0x1;
125 AliHLTUInt32_t tmp2=offset;
126
127 // first check if the offset allows to add all data blocks without exceeding the
128 // range
129 while (nofBlocks<tmp1 && tmp2>0) {
130 if (tmp2&0x1) {
131 HLTError("index range %#x exceeded for %d data blocks", nofBlocks, offset);
132 iResult=-ERANGE;
133 }
4b113031 134 tmp2>>=1;
135 tmp1<<=1;
049b43b2 136 }
137
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++) {
a183f221 141 homer_uint64 id=pReader->GetBlockDataType( i );
142 homer_uint32 origin=pReader->GetBlockDataOrigin( i );
143 homer_uint32 spec=pReader->GetBlockDataSpec( i );
144 AliHLTComponentDataType dt;
18b56222 145 AliHLTComponent::SetDataType(dt, id, origin);
a183f221 146 AliHLTOUTBlockDescriptor desc(dt, spec, offset|i);
18b56222 147 HLTDebug("adding block %d: %s %#x", i, AliHLTComponent::DataType2Text(dt).c_str(), spec);
a183f221 148 iResult=AddBlockDescriptor(desc);
049b43b2 149 }
150 } else {
151 iResult=-ENODEV;
152 }
153 return iResult;
154}
155