]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitReaderDecoder.cxx
TPCZeroSuppressionComponent finalized, utility methods in digit reader interface...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderDecoder.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 //*                  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
28 using namespace std;
29 #endif
30
31 #include <cassert>
32 #include "AliHLTTPCDigitReaderDecoder.h"
33 #include "AliHLTTPCMapping.h"
34 #include "AliAltroDecoder.h"
35 #include "AliAltroData.h"
36 #include "AliAltroBunch.h"
37 #include "AliHLTTPCTransform.h"
38
39 ClassImp(AliHLTTPCDigitReaderDecoder)
40
41 AliHLTTPCDigitReaderDecoder::AliHLTTPCDigitReaderDecoder()
42   :
43   AliHLTTPCDigitReader(),
44   fAltroDecoder(NULL),
45   fAltroData(),
46   fAltroBunch(NULL),
47   fMapping(NULL),
48   // initialization due to the logic in NextSignals
49   fNextCounter(-1),
50   fNextSignalMethodUsed(kFALSE)
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
59 AliHLTTPCDigitReaderDecoder::~AliHLTTPCDigitReaderDecoder()
60 {
61   // see header file for class documentation
62   if(fAltroDecoder){
63     delete fAltroDecoder;
64   }
65   if(fAltroBunch){
66     delete fAltroBunch;
67   }
68   if(fMapping){
69     delete fMapping;
70   }
71 }
72
73 int AliHLTTPCDigitReaderDecoder::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t /*slice*/)
74 {
75   // see header file for class documentation
76   //  HLTDebug("Initializing block in decoder");
77   if(!fMapping){
78     fMapping = new AliHLTTPCMapping(patch);
79   }
80   if(!fAltroDecoder){
81     fAltroDecoder = new AliAltroDecoder();
82   }
83   if(!fAltroBunch){
84     fAltroBunch = new AliAltroBunch();
85   }
86   fAltroDecoder->SetMemory((UChar_t*)ptr, size);
87   fAltroDecoder->Decode();
88   return 0;
89 }
90
91 bool AliHLTTPCDigitReaderDecoder::NextChannel()
92 {
93   // see header file for class documentation
94   Bool_t result=fAltroDecoder->NextChannel(&fAltroData);
95   if(result && !fMapping->IsValidHWAddress(fAltroData.GetHadd())){
96     result = fAltroDecoder->NextChannel(&fAltroData);
97   }
98   return result;
99 }
100
101 int AliHLTTPCDigitReaderDecoder::NextBunch()
102 {
103   // see header file for class documentation
104   return fAltroData.NextBunch(fAltroBunch);
105 }
106
107 bool AliHLTTPCDigitReaderDecoder::NextSignal()
108 {
109   // see header file for class documentation
110   fNextSignalMethodUsed=kTRUE;
111   do {
112     if (fNextCounter>0) {
113       // there is data available in the current bunch
114       fNextCounter--;
115       return true;
116     }
117
118     // there is no data left in the current bunch, search for the next one
119     while (NextBunch()) if (GetBunchSize()>0) {
120       fNextCounter=GetBunchSize()-1;
121       return true;
122     }
123
124     fNextCounter=-1;
125     // there is no bunch left, go to the next channel
126   } while (NextChannel());
127   
128   return false;
129 }
130
131 const UInt_t* AliHLTTPCDigitReaderDecoder::GetSignals()
132 {
133   // see header file for class documentation
134   return fAltroBunch->GetData();
135 }
136
137 int AliHLTTPCDigitReaderDecoder::GetRow()
138 {
139   // see header file for class documentation
140   return fMapping->GetRow(fAltroData.GetHadd());
141 }
142
143 int AliHLTTPCDigitReaderDecoder::GetPad()
144 {
145   // see header file for class documentation
146   return fMapping->GetPad(fAltroData.GetHadd());
147 }
148
149 int AliHLTTPCDigitReaderDecoder::GetSignal()
150 {
151   // see header file for class documentation
152   if (fNextSignalMethodUsed) {
153     const  UInt_t* pData=GetSignals();
154     if (pData && fNextCounter>=0) {
155       assert(fNextCounter<GetBunchSize());
156       return pData[fNextCounter];
157     }
158   }
159   return 0;
160 }
161
162 int AliHLTTPCDigitReaderDecoder::GetTime()
163 {
164   // see header file for class documentation
165   int iResult=0;
166   if(!fNextSignalMethodUsed){// this is true if the bunch approach is used
167     
168     iResult= fAltroBunch->GetStartTimeBin();
169   }
170   else{
171     assert(fNextCounter>=0);
172     iResult = fAltroBunch->GetStartTimeBin()+fNextCounter;
173   }
174   if(iResult<0 || iResult>AliHLTTPCTransform::GetNTimeBins()){
175     iResult=0;
176   }
177   return iResult;
178 }
179
180 int AliHLTTPCDigitReaderDecoder::GetBunchSize()
181 {
182   // see header file for class documentation
183   return fAltroBunch->GetBunchSize();
184 }
185
186 int AliHLTTPCDigitReaderDecoder::GetRowOffset() const
187 {
188   return fMapping->GetRowOffset();
189 }
190 AliHLTUInt32_t AliHLTTPCDigitReaderDecoder::GetAltroBlockHWaddr() const
191 {
192   // see header file for class documentation
193   return (AliHLTUInt32_t)fAltroData.GetHadd();
194 }
195 AliHLTUInt32_t AliHLTTPCDigitReaderDecoder::GetAltroBlockHWaddr(Int_t row, Int_t pad) const
196 {
197   // see header file for class documentation
198   if(fMapping){
199     return fMapping->GetHwAddress(row,pad);
200   }
201   else{
202     return 0;
203   }
204 }