Line data Source code
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
22 : @brief HLTOUT data wrapper for buffer in HOMER format. */
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>
31 : #include <cassert>
32 : #include "AliHLTOUTHomerBuffer.h"
33 : #include "AliHLTHOMERReader.h"
34 : #include "AliHLTHOMERLibManager.h"
35 :
36 : /** ROOT macro for the implementation of ROOT specific class methods */
37 126 : ClassImp(AliHLTOUTHomerBuffer)
38 :
39 4 : AliHLTOUTHomerBuffer::AliHLTOUTHomerBuffer(const AliHLTUInt8_t* pBuffer, int size)
40 : :
41 4 : AliHLTOUT(),
42 12 : fpManager(new AliHLTHOMERLibManager),
43 4 : fpBuffer(pBuffer),
44 4 : fSize(size),
45 4 : fpReader(NULL)
46 16 : {
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
52 : assert(sizeof(homer_uint64)==kAliHLTComponentDataTypefIDsize);
53 : assert(sizeof(homer_uint32)==kAliHLTComponentDataTypefOriginSize);
54 4 : assert(fpManager);
55 4 : }
56 :
57 0 : AliHLTOUTHomerBuffer::~AliHLTOUTHomerBuffer()
58 8 : {
59 : // see header file for class documentation
60 4 : if (fpManager) {
61 4 : if (fpReader) fpManager->DeleteReader(fpReader);
62 8 : delete fpManager;
63 4 : fpManager=NULL;
64 4 : fpReader=NULL;
65 4 : }
66 4 : }
67 :
68 : int AliHLTOUTHomerBuffer::GenerateIndex()
69 : {
70 : // see header file for class documentation
71 : int iResult=0;
72 0 : if (!fpReader) {
73 0 : if (fpManager) {
74 0 : fpReader=fpManager->OpenReaderBuffer(fpBuffer, fSize);
75 0 : }
76 : }
77 0 : if (fpReader) {
78 0 : iResult=ScanReader(fpReader);
79 0 : } else {
80 : iResult=-ENODEV;
81 : }
82 0 : return iResult;
83 : }
84 :
85 : int 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 0 : if (fpReader) {
91 0 : if ((pBuffer=static_cast<const AliHLTUInt8_t*>(fpReader->GetBlockData(index)))!=NULL) {
92 0 : size=fpReader->GetBlockDataLength(index);
93 0 : } else {
94 : iResult=-ENOENT;
95 : }
96 : } else {
97 : iResult=-ENODEV;
98 : }
99 0 : return iResult;
100 : }
101 :
102 : AliHLTOUT::AliHLTOUTByteOrder AliHLTOUTHomerBuffer::CheckBlockByteOrder(AliHLTUInt32_t index)
103 : {
104 0 : if (fpReader) {
105 0 : return static_cast<AliHLTOUTByteOrder>(fpReader->GetBlockByteOrder(index));
106 : }
107 0 : return kInvalidByteOrder;
108 0 : }
109 :
110 : int AliHLTOUTHomerBuffer::CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type)
111 : {
112 0 : if (fpReader) {
113 0 : return fpReader->GetBlockTypeAlignment(index, static_cast<homer_uint8>(type));
114 : }
115 0 : return -ENODATA;
116 0 : }
117 :
118 : int AliHLTOUTHomerBuffer::ScanReader(AliHLTMonitoringReader* pReader, AliHLTUInt32_t offset)
119 : {
120 : // see header file for class documentation
121 : int iResult=0;
122 0 : if (pReader && (iResult=pReader->ReadNextEvent())==0) {
123 0 : 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 0 : while (nofBlocks>tmp1 && tmp2>0) {
130 0 : if (tmp2&0x1) {
131 0 : HLTError("index range %#x exceeded for %d data blocks", nofBlocks, offset);
132 : iResult=-ERANGE;
133 0 : }
134 0 : tmp2>>=1;
135 0 : tmp1<<=1;
136 : }
137 :
138 : // loop over data blocks
139 : HLTDebug("generating index for %d data blocks of reader with offset %#x", nofBlocks, offset);
140 0 : for (AliHLTUInt32_t i=0; i<nofBlocks && iResult>=0; i++) {
141 0 : homer_uint64 id=pReader->GetBlockDataType( i );
142 0 : homer_uint32 origin=pReader->GetBlockDataOrigin( i );
143 0 : homer_uint32 spec=pReader->GetBlockDataSpec( i );
144 0 : AliHLTComponentDataType dt;
145 0 : AliHLTComponent::SetDataType(dt, ByteSwap64(id), ByteSwap32(origin));
146 0 : AliHLTOUTBlockDescriptor desc(dt, spec, offset|i, this);
147 : HLTDebug("adding block %d: %s %#x", i, AliHLTComponent::DataType2Text(dt).c_str(), spec);
148 0 : iResult=AddBlockDescriptor(desc);
149 0 : }
150 0 : } else {
151 0 : if (iResult==EBADMSG) {
152 0 : HLTWarning("Format error in data block");
153 0 : iResult*=-1;
154 0 : } else if (iResult==126/*ENOKEY*/) {
155 0 : HLTWarning("Format error in data block: can not find HOMER block descriptor id");
156 0 : iResult*=-1;
157 0 : } else {
158 : iResult=-ENODEV;
159 : }
160 : }
161 0 : return iResult;
162 0 : }
163 :
|