]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCDigitReaderDecoder.cxx
removing DigitReaderPacked and DigitReaderDecoder, all raw data processing goes via...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderDecoder.cxx
CommitLineData
7e914051 1// $Id$
f8121cb1 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//* Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9//* Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
10//* for The ALICE HLT Project. *
11//* *
12//* Permission to use, copy, modify and distribute this software and its *
13//* documentation strictly for non-commercial purposes is hereby granted *
14//* without fee, provided that the above copyright notice appears in all *
15//* copies and that both the copyright notice and this permission notice *
16//* appear in the supporting documentation. The authors make no claims *
17//* about the suitability of this software for any purpose. It is *
18//* provided "as is" without express or implied warranty. *
19//**************************************************************************
20
21/** @file AliHLTTPCDigitReaderDecoder.cxx
22 @author Kenneth Aamodt, Matthias Richter
23 @date
24 @brief DigitReader implementation for the fast ALTRO Decoder
25*/
26
27#if __GNUC__>= 3
28using namespace std;
29#endif
30
7c9a4e09 31#include <cassert>
f8121cb1 32#include "AliHLTTPCDigitReaderDecoder.h"
7dceaa9b 33#include "AliHLTTPCMapping.h"
f8121cb1 34#include "AliAltroDecoder.h"
35#include "AliAltroData.h"
36#include "AliAltroBunch.h"
092a1374 37#include "AliHLTTPCTransform.h"
f8121cb1 38
39ClassImp(AliHLTTPCDigitReaderDecoder)
40
41AliHLTTPCDigitReaderDecoder::AliHLTTPCDigitReaderDecoder()
42 :
7dceaa9b 43 AliHLTTPCDigitReader(),
44 fAltroDecoder(NULL),
45 fAltroData(),
46 fAltroBunch(NULL),
47 fMapping(NULL),
7c9a4e09 48 // initialization due to the logic in NextSignals
49 fNextCounter(-1),
7dceaa9b 50 fNextSignalMethodUsed(kFALSE)
f8121cb1 51{
52 // see header file for class documentation
53 // or
54 // refer to README to build package
55 // or
56 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57}
58
5863c71a 59AliAltroDecoder* AliHLTTPCDigitReaderDecoder::fgpFreeInstance=NULL;
60AliAltroDecoder* AliHLTTPCDigitReaderDecoder::fgpIssuedInstance=NULL;
61
f8121cb1 62AliHLTTPCDigitReaderDecoder::~AliHLTTPCDigitReaderDecoder()
63{
64 // see header file for class documentation
7dceaa9b 65 if(fAltroDecoder){
5863c71a 66 ReleaseDecoderInstance(fAltroDecoder);
7dceaa9b 67 }
68 if(fAltroBunch){
69 delete fAltroBunch;
70 }
71 if(fMapping){
72 delete fMapping;
73 }
f8121cb1 74}
75
a74855c2 76int AliHLTTPCDigitReaderDecoder::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t /*slice*/)
f8121cb1 77{
78 // see header file for class documentation
7c9a4e09 79 // HLTDebug("Initializing block in decoder");
80 if(!fMapping){
81 fMapping = new AliHLTTPCMapping(patch);
82 }
5863c71a 83 fAltroDecoder=GetDecoderInstance();
7c9a4e09 84 if(!fAltroDecoder){
5863c71a 85 return -ENODEV;
7c9a4e09 86 }
87 if(!fAltroBunch){
88 fAltroBunch = new AliAltroBunch();
89 }
7dceaa9b 90 fAltroDecoder->SetMemory((UChar_t*)ptr, size);
91 fAltroDecoder->Decode();
f8121cb1 92 return 0;
93}
94
5863c71a 95int AliHLTTPCDigitReaderDecoder::Reset()
96{
97 // see header file for class documentation
4ea087a6 98 fAltroData.Reset();
99 fAltroData.SetIsComplete(false);
100 if (fAltroBunch) {
101 fAltroBunch->SetBunchSize(0);
102 fAltroBunch->SetData(NULL);
103 }
5863c71a 104 if (fAltroDecoder) ReleaseDecoderInstance(fAltroDecoder);
105 fAltroDecoder=NULL;
106 return 0;
107}
108
900fdfb2 109void AliHLTTPCDigitReaderDecoder::SetUnsorted(bool unsorted)
110{
111 // see header file for class documentation
112
113 // The DigitReaderDecoder does not support sorted data, forward to
114 // default if sorted data requested
115 if (!unsorted) AliHLTTPCDigitReader::SetUnsorted(unsorted);
116}
117
f8121cb1 118bool AliHLTTPCDigitReaderDecoder::NextChannel()
119{
120 // see header file for class documentation
5863c71a 121 if (!fAltroDecoder) return false;
d2f725e4 122 Bool_t result=fAltroDecoder->NextChannel(&fAltroData);
123 if(result && !fMapping->IsValidHWAddress(fAltroData.GetHadd())){
124 result = fAltroDecoder->NextChannel(&fAltroData);
125 }
126 return result;
f8121cb1 127}
128
129int AliHLTTPCDigitReaderDecoder::NextBunch()
130{
131 // see header file for class documentation
7dceaa9b 132 return fAltroData.NextBunch(fAltroBunch);
f8121cb1 133}
134
135bool AliHLTTPCDigitReaderDecoder::NextSignal()
136{
137 // see header file for class documentation
7c9a4e09 138 fNextSignalMethodUsed=kTRUE;
139 do {
140 if (fNextCounter>0) {
141 // there is data available in the current bunch
142 fNextCounter--;
143 return true;
7dceaa9b 144 }
7c9a4e09 145
146 // there is no data left in the current bunch, search for the next one
147 while (NextBunch()) if (GetBunchSize()>0) {
148 fNextCounter=GetBunchSize()-1;
149 return true;
7dceaa9b 150 }
7c9a4e09 151
152 fNextCounter=-1;
153 // there is no bunch left, go to the next channel
154 } while (NextChannel());
7dceaa9b 155
7c9a4e09 156 return false;
f8121cb1 157}
158
7dceaa9b 159const UInt_t* AliHLTTPCDigitReaderDecoder::GetSignals()
f8121cb1 160{
161 // see header file for class documentation
7dceaa9b 162 return fAltroBunch->GetData();
f8121cb1 163}
164
165int AliHLTTPCDigitReaderDecoder::GetRow()
166{
167 // see header file for class documentation
7dceaa9b 168 return fMapping->GetRow(fAltroData.GetHadd());
f8121cb1 169}
170
171int AliHLTTPCDigitReaderDecoder::GetPad()
172{
173 // see header file for class documentation
7dceaa9b 174 return fMapping->GetPad(fAltroData.GetHadd());
f8121cb1 175}
176
177int AliHLTTPCDigitReaderDecoder::GetSignal()
178{
179 // see header file for class documentation
7c9a4e09 180 if (fNextSignalMethodUsed) {
181 const UInt_t* pData=GetSignals();
182 if (pData && fNextCounter>=0) {
183 assert(fNextCounter<GetBunchSize());
184 return pData[fNextCounter];
185 }
186 }
f8121cb1 187 return 0;
188}
189
190int AliHLTTPCDigitReaderDecoder::GetTime()
191{
192 // see header file for class documentation
092a1374 193 int iResult=0;
7dceaa9b 194 if(!fNextSignalMethodUsed){// this is true if the bunch approach is used
092a1374 195
196 iResult= fAltroBunch->GetStartTimeBin();
7dceaa9b 197 }
198 else{
7c9a4e09 199 assert(fNextCounter>=0);
092a1374 200 iResult = fAltroBunch->GetStartTimeBin()+fNextCounter;
7dceaa9b 201 }
092a1374 202 if(iResult<0 || iResult>AliHLTTPCTransform::GetNTimeBins()){
203 iResult=0;
204 }
205 return iResult;
7dceaa9b 206}
207
208int AliHLTTPCDigitReaderDecoder::GetBunchSize()
209{
7c9a4e09 210 // see header file for class documentation
7dceaa9b 211 return fAltroBunch->GetBunchSize();
f8121cb1 212}
7c9a4e09 213
d2f725e4 214int AliHLTTPCDigitReaderDecoder::GetRowOffset() const
215{
216 return fMapping->GetRowOffset();
217}
7c9a4e09 218AliHLTUInt32_t AliHLTTPCDigitReaderDecoder::GetAltroBlockHWaddr() const
219{
220 // see header file for class documentation
221 return (AliHLTUInt32_t)fAltroData.GetHadd();
222}
092a1374 223AliHLTUInt32_t AliHLTTPCDigitReaderDecoder::GetAltroBlockHWaddr(Int_t row, Int_t pad) const
224{
225 // see header file for class documentation
226 if(fMapping){
227 return fMapping->GetHwAddress(row,pad);
228 }
229 else{
230 return 0;
231 }
232}
5863c71a 233
4ea087a6 234int AliHLTTPCDigitReaderDecoder::GetRCUTrailerSize()
235{
236 // see header file for class documentation
436467f5 237 if(fAltroDecoder){
238 return fAltroDecoder->GetRCUTrailerSize();
239 }
240 return 0;
241}
242
4ea087a6 243bool AliHLTTPCDigitReaderDecoder::GetRCUTrailerData(UChar_t*& trData)
244{
245 // see header file for class documentation
436467f5 246 if(fAltroDecoder){
247 return fAltroDecoder->GetRCUTrailerData(trData);
248 }
249 return false;
250}
251
5863c71a 252AliAltroDecoder* AliHLTTPCDigitReaderDecoder::GetDecoderInstance()
253{
254 // see header file for class documentation
255
256 // for the moment only a singleton of the decoder is foreseen
257 // could be extended but very unlikly to be worth the effort
258 // because AliAltroDecoder sooner or later will be deprecated.
259
260 // This is just a poor man's solution, no synchronization for the
261 // moment
262 if (fgpIssuedInstance) {
263 AliHLTLogging log;
264 log.LoggingVarargs(kHLTLogError, "AliHLTTPCDigitReaderDecoder", "GetDecoderInstance" , __FILE__ , __LINE__ ,
265 "instance of AltroDecoder has not been released or multiple instances requested. Only available as global singleton for DigitReaderDecoder");
266 return NULL;
267 }
268
269 if (!fgpFreeInstance) fgpFreeInstance=new AliAltroDecoder;
270 fgpIssuedInstance=fgpFreeInstance;
271 fgpFreeInstance=NULL;
272 return fgpIssuedInstance;
273}
274
275void AliHLTTPCDigitReaderDecoder::ReleaseDecoderInstance(AliAltroDecoder* pInstance)
276{
277 // see header file for class documentation
278 if (!pInstance) return;
279 if (pInstance!=fgpIssuedInstance) {
280 AliHLTLogging log;
281 log.LoggingVarargs(kHLTLogError, "AliHLTTPCDigitReaderDecoder", "ReleaseDecoderInstance" , __FILE__ , __LINE__ ,
282 "wrong instance %p, expecting %p", pInstance, fgpIssuedInstance);
283 return;
284 }
285 fgpFreeInstance=fgpIssuedInstance;
286 fgpIssuedInstance=NULL;
287}