]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitReaderDecoder.cxx
Remove compilser warnings
[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 AliAltroDecoder* AliHLTTPCDigitReaderDecoder::fgpFreeInstance=NULL;
60 AliAltroDecoder* AliHLTTPCDigitReaderDecoder::fgpIssuedInstance=NULL;
61
62 AliHLTTPCDigitReaderDecoder::~AliHLTTPCDigitReaderDecoder()
63 {
64   // see header file for class documentation
65   if(fAltroDecoder){
66     ReleaseDecoderInstance(fAltroDecoder);
67   }
68   if(fAltroBunch){
69     delete fAltroBunch;
70   }
71   if(fMapping){
72     delete fMapping;
73   }
74 }
75
76 int AliHLTTPCDigitReaderDecoder::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t /*slice*/)
77 {
78   // see header file for class documentation
79   //  HLTDebug("Initializing block in decoder");
80   if(!fMapping){
81     fMapping = new AliHLTTPCMapping(patch);
82   }
83   fAltroDecoder=GetDecoderInstance();
84   if(!fAltroDecoder){
85     return -ENODEV;
86   }
87   if(!fAltroBunch){
88     fAltroBunch = new AliAltroBunch();
89   }
90   fAltroDecoder->SetMemory((UChar_t*)ptr, size);
91   fAltroDecoder->Decode();
92   return 0;
93 }
94
95 int AliHLTTPCDigitReaderDecoder::Reset()
96 {
97   // see header file for class documentation
98   fAltroData.Reset();
99   fAltroData.SetIsComplete(false);
100   if (fAltroBunch) {
101     fAltroBunch->SetBunchSize(0);
102     fAltroBunch->SetData(NULL);
103   }
104   if (fAltroDecoder) ReleaseDecoderInstance(fAltroDecoder);
105   fAltroDecoder=NULL;
106   return 0;
107 }
108
109 void 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
118 bool AliHLTTPCDigitReaderDecoder::NextChannel()
119 {
120   // see header file for class documentation
121   if (!fAltroDecoder) return false;
122   Bool_t result=fAltroDecoder->NextChannel(&fAltroData);
123   if(result && !fMapping->IsValidHWAddress(fAltroData.GetHadd())){
124     result = fAltroDecoder->NextChannel(&fAltroData);
125   }
126   return result;
127 }
128
129 int AliHLTTPCDigitReaderDecoder::NextBunch()
130 {
131   // see header file for class documentation
132   return fAltroData.NextBunch(fAltroBunch);
133 }
134
135 bool AliHLTTPCDigitReaderDecoder::NextSignal()
136 {
137   // see header file for class documentation
138   fNextSignalMethodUsed=kTRUE;
139   do {
140     if (fNextCounter>0) {
141       // there is data available in the current bunch
142       fNextCounter--;
143       return true;
144     }
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;
150     }
151
152     fNextCounter=-1;
153     // there is no bunch left, go to the next channel
154   } while (NextChannel());
155   
156   return false;
157 }
158
159 const UInt_t* AliHLTTPCDigitReaderDecoder::GetSignals()
160 {
161   // see header file for class documentation
162   return fAltroBunch->GetData();
163 }
164
165 int AliHLTTPCDigitReaderDecoder::GetRow()
166 {
167   // see header file for class documentation
168   return fMapping->GetRow(fAltroData.GetHadd());
169 }
170
171 int AliHLTTPCDigitReaderDecoder::GetPad()
172 {
173   // see header file for class documentation
174   return fMapping->GetPad(fAltroData.GetHadd());
175 }
176
177 int AliHLTTPCDigitReaderDecoder::GetSignal()
178 {
179   // see header file for class documentation
180   if (fNextSignalMethodUsed) {
181     const  UInt_t* pData=GetSignals();
182     if (pData && fNextCounter>=0) {
183       assert(fNextCounter<GetBunchSize());
184       return pData[fNextCounter];
185     }
186   }
187   return 0;
188 }
189
190 int AliHLTTPCDigitReaderDecoder::GetTime()
191 {
192   // see header file for class documentation
193   int iResult=0;
194   if(!fNextSignalMethodUsed){// this is true if the bunch approach is used
195     
196     iResult= fAltroBunch->GetStartTimeBin();
197   }
198   else{
199     assert(fNextCounter>=0);
200     iResult = fAltroBunch->GetStartTimeBin()+fNextCounter;
201   }
202   if(iResult<0 || iResult>AliHLTTPCTransform::GetNTimeBins()){
203     iResult=0;
204   }
205   return iResult;
206 }
207
208 int AliHLTTPCDigitReaderDecoder::GetBunchSize()
209 {
210   // see header file for class documentation
211   return fAltroBunch->GetBunchSize();
212 }
213
214 int AliHLTTPCDigitReaderDecoder::GetRowOffset() const
215 {
216   return fMapping->GetRowOffset();
217 }
218 AliHLTUInt32_t AliHLTTPCDigitReaderDecoder::GetAltroBlockHWaddr() const
219 {
220   // see header file for class documentation
221   return (AliHLTUInt32_t)fAltroData.GetHadd();
222 }
223 AliHLTUInt32_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 }
233
234 int AliHLTTPCDigitReaderDecoder::GetRCUTrailerSize()
235 {
236   // see header file for class documentation
237   if(fAltroDecoder){
238     return fAltroDecoder->GetRCUTrailerSize();
239   }
240   return 0;
241 }
242
243 bool AliHLTTPCDigitReaderDecoder::GetRCUTrailerData(UChar_t*& trData)
244 {
245   // see header file for class documentation
246   if(fAltroDecoder){
247     return fAltroDecoder->GetRCUTrailerData(trData);
248   }
249   return false;
250 }
251
252 AliAltroDecoder* 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
275 void 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 }