Added class AliHLTITSCompressRawDataSDDComponent
[u/mrichter/AliRoot.git] / HLT / ITS / AliHLTITSCompressRawDataSDDComponent.cxx
CommitLineData
0c7d42ab 1// $Id: AliHLTTPCClusterFinderComponent.cxx 27006 2008-07-01 09:21:45Z richterm $
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: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
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 AliHLTITSCompressRawDataSDDComponent.cxx
20 @author Jochen Thaeder <thaeder@kip.uni-heidelberg.de>
21 @date
22 @brief Component to run data compression for SDD
23*/
24
25#if __GNUC__>= 3
26using namespace std;
27#endif
28
29
30#include "AliHLTITSCompressRawDataSDDComponent.h"
31
32#include "AliCDBEntry.h"
33#include "AliCDBManager.h"
34
35#include <cstdlib>
36#include <cerrno>
37#include "TString.h"
38#include "TObjString.h"
39#include <sys/time.h>
40
41/** ROOT macro for the implementation of ROOT specific class methods */
42ClassImp(AliHLTITSCompressRawDataSDDComponent);
43
44AliHLTITSCompressRawDataSDDComponent::AliHLTITSCompressRawDataSDDComponent()
45 :
46 fDataCompressor(NULL),
47 fRawReader(NULL) {
48 // see header file for class documentation
49 // or
50 // refer to README to build package
51 // or
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53}
54
55AliHLTITSCompressRawDataSDDComponent::~AliHLTITSCompressRawDataSDDComponent() {
56 // see header file for class documentation
57}
58
59// Public functions to implement AliHLTComponent's interface.
60// These functions are required for the registration process
61
62const char* AliHLTITSCompressRawDataSDDComponent::GetComponentID()
63{
64 // see header file for class documentation
65
66 return "ITSDataCompressorSDD";
67}
68
69void AliHLTITSCompressRawDataSDDComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
70 // see header file for class documentation
71 list.clear();
72 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITS );
73
74}
75
76AliHLTComponentDataType AliHLTITSCompressRawDataSDDComponent::GetOutputDataType() {
77 // see header file for class documentation
78 return (kAliHLTDataTypeDDLRaw| kAliHLTDataOriginITS);
79}
80
81void AliHLTITSCompressRawDataSDDComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
82 // see header file for class documentation
83
84 constBase = 0;
85 inputMultiplier = 0.05;
86}
87
88AliHLTComponent* AliHLTITSCompressRawDataSDDComponent::Spawn() {
89 // see header file for class documentation
90 return new AliHLTITSCompressRawDataSDDComponent();
91}
92
93Int_t AliHLTITSCompressRawDataSDDComponent::DoInit( int /*argc*/, const char** /*argv*/ ) {
94 // see header file for class documentation
95
96 if ( fDataCompressor )
97 return EINPROGRESS;
98
99 fDataCompressor = new AliITSCompressRawDataSDD();
100
101 if ( fRawReader )
102 return EINPROGRESS;
103
104 fRawReader = new AliRawReaderMemory();
105
106 return 0;
107}
108
109Int_t AliHLTITSCompressRawDataSDDComponent::DoDeinit() {
110 // see header file for class documentation
111
112 if ( fRawReader )
113 delete fRawReader;
114 fRawReader = NULL;
115
116 if ( fDataCompressor )
117 delete fDataCompressor;
118 fDataCompressor = NULL;
119
120 return 0;
121}
122
123Int_t AliHLTITSCompressRawDataSDDComponent::DoEvent( const AliHLTComponentEventData& evtData,
124 const AliHLTComponentBlockData* blocks,
125 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
126 AliHLTUInt32_t& size,
127 vector<AliHLTComponentBlockData>& outputBlocks ) {
128 // see header file for class documentation
129
130 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
131 size=0;
132 return 0;
133 }
134
135 // -- Iterator over Data Blocks --
136 const AliHLTComponentBlockData* iter = NULL;
137
138 // -- Ptr to output shm region --
139 AliHLTUInt8_t* outShmPtr = outputPtr;
140
141 // -- Initialize out sizes
142 UInt_t offset = 0; // offset of current outblock
143 UInt_t mySize = 0; // out size produced from current block
144 UInt_t totalSize = 0; // total out size of this event
145 UInt_t availSize = 0; // still availible out size for this event
146
147 // -- Loop over blocks
148 for ( ULong_t ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
149
150 iter = blocks+ndx;
151
152 mySize = 0;
153 offset = totalSize;
154 availSize = size - totalSize;
155
156 // -- Debug output of datatype --
157 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
158 evtData.fEventID, evtData.fEventID,
159 DataType2Text(iter->fDataType).c_str(),
160 DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITS).c_str());
161
162 // -- Check for the correct data type
163 if ( iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITS) ) {
164 HLTError("WRONG FORMAT");
165 continue;
166 }
167
168 // -- Set RawReader
169 fRawReader->SetMemory( (UChar_t*) iter->fPtr, iter->fSize );
170
171 // -- Get equipment ID out of specification
172 AliHLTUInt32_t spec = iter->fSpecification;
173
174 Int_t id = 256;
175 for ( Int_t ii = 0; ii < 24 ; ii++ ) {
176 if ( spec & 0x00000001 ) {
177 id += ii;
178 break;
179 }
180 spec = spec >> 1 ;
181 }
182
183 // -- Set equipment ID to the raw reader
184 fRawReader->SetEquipmentID( id );
185
186 // -- Set raw reader
187 fDataCompressor->SetRawReader( fRawReader );
188
189 // -- Set ptr to output shm
190 fDataCompressor->SetPointerToData( (UChar_t*) outShmPtr );
191
192 // -- Set availible outputspace
193 fDataCompressor->SetSize( (UInt_t) availSize );
194
195 // -- Compress event
196 mySize = fDataCompressor->CompressEvent( (UChar_t*) iter->fPtr );
197
198 // -- Fill output blocks
199 AliHLTComponentBlockData bd;
200 FillBlockData( bd );
201 bd.fOffset = offset;
202 bd.fSize = mySize;
203 bd.fSpecification = iter->fSpecification;
204 bd.fDataType = iter->fDataType;
205 outputBlocks.push_back( bd );
206
207 // -- Increase size counters
208 totalSize += mySize;
209
210 // -- Increase output shm ptr
211 outShmPtr += mySize;
212
213 // -- Check if data was written over allowed buffer
214 if ( totalSize > size ) {
215 HLTFatal( "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu.", totalSize, size );
216 return EMSGSIZE;
217 }
218
219 } // for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
220
221 // -- Set total output size
222 size = totalSize;
223
224 return 0;
225}