]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTOUTHomerBuffer.cxx
minor coverity defects: assignment operators corrected
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUTHomerBuffer.cxx
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 ClassImp(AliHLTOUTHomerBuffer)
38
39 AliHLTOUTHomerBuffer::AliHLTOUTHomerBuffer(const AliHLTUInt8_t* pBuffer, int size)
40   :
41   AliHLTOUT(),
42   fpManager(new AliHLTHOMERLibManager),
43   fpBuffer(pBuffer),
44   fSize(size),
45   fpReader(NULL)
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
52   assert(sizeof(homer_uint64)==kAliHLTComponentDataTypefIDsize);
53   assert(sizeof(homer_uint32)==kAliHLTComponentDataTypefOriginSize);
54   assert(fpManager);
55 }
56
57 AliHLTOUTHomerBuffer::~AliHLTOUTHomerBuffer()
58 {
59   // see header file for class documentation
60   if (fpManager) {
61     if (fpReader) fpManager->DeleteReader(fpReader);
62     delete fpManager;
63     fpManager=NULL;
64     fpReader=NULL;
65   }
66 }
67
68 int AliHLTOUTHomerBuffer::GenerateIndex()
69 {
70   // see header file for class documentation
71   int iResult=0;
72   if (!fpReader) {
73     if (fpManager) {
74       fpReader=fpManager->OpenReaderBuffer(fpBuffer, fSize);
75     }
76   }
77   if (fpReader) {
78     iResult=ScanReader(fpReader);
79   } else {
80     iResult=-ENODEV;
81   }
82   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   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 }
101
102 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUTHomerBuffer::CheckBlockByteOrder(AliHLTUInt32_t index)
103 {
104   if (fpReader) {
105     return static_cast<AliHLTOUTByteOrder>(fpReader->GetBlockByteOrder(index));
106   }
107   return kInvalidByteOrder;
108 }
109
110 int AliHLTOUTHomerBuffer::CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type)
111 {
112   if (fpReader) {
113     return fpReader->GetBlockTypeAlignment(index, static_cast<homer_uint8>(type));
114   }
115   return -ENODATA;
116 }
117
118 int AliHLTOUTHomerBuffer::ScanReader(AliHLTMonitoringReader* pReader, AliHLTUInt32_t offset)
119 {
120   // see header file for class documentation
121   int iResult=0;
122   if (pReader && (iResult=pReader->ReadNextEvent())==0) {
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       }
134       tmp2>>=1;
135       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     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);
149     }
150   } else {
151     if (iResult==EBADMSG) {
152       HLTWarning("Format error in data block");
153       iResult*=-1;
154     } else if (iResult==126/*ENOKEY*/) {
155       HLTWarning("Format error in data block: can not find HOMER block descriptor id");
156       iResult*=-1;
157     } else {
158       iResult=-ENODEV;
159     }
160   }
161   return iResult;
162 }
163