3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
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. *
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 //**************************************************************************
21 /** @file AliHLTTPCDigitReaderDecoder.cxx
22 @author Kenneth Aamodt, Matthias Richter
24 @brief DigitReader implementation for the fast ALTRO Decoder
32 #include "AliHLTTPCDigitReaderDecoder.h"
33 #include "AliHLTTPCMapping.h"
34 #include "AliAltroDecoder.h"
35 #include "AliAltroData.h"
36 #include "AliAltroBunch.h"
37 #include "AliHLTTPCTransform.h"
39 ClassImp(AliHLTTPCDigitReaderDecoder)
41 AliHLTTPCDigitReaderDecoder::AliHLTTPCDigitReaderDecoder()
43 AliHLTTPCDigitReader(),
48 // initialization due to the logic in NextSignals
50 fNextSignalMethodUsed(kFALSE)
52 // see header file for class documentation
54 // refer to README to build package
56 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59 AliAltroDecoder* AliHLTTPCDigitReaderDecoder::fgpFreeInstance=NULL;
60 AliAltroDecoder* AliHLTTPCDigitReaderDecoder::fgpIssuedInstance=NULL;
62 AliHLTTPCDigitReaderDecoder::~AliHLTTPCDigitReaderDecoder()
64 // see header file for class documentation
66 ReleaseDecoderInstance(fAltroDecoder);
76 int AliHLTTPCDigitReaderDecoder::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t /*slice*/)
78 // see header file for class documentation
79 // HLTDebug("Initializing block in decoder");
81 fMapping = new AliHLTTPCMapping(patch);
83 fAltroDecoder=GetDecoderInstance();
88 fAltroBunch = new AliAltroBunch();
90 fAltroDecoder->SetMemory((UChar_t*)ptr, size);
91 fAltroDecoder->Decode();
95 int AliHLTTPCDigitReaderDecoder::Reset()
97 // see header file for class documentation
99 fAltroData.SetIsComplete(false);
101 fAltroBunch->SetBunchSize(0);
102 fAltroBunch->SetData(NULL);
104 if (fAltroDecoder) ReleaseDecoderInstance(fAltroDecoder);
109 void AliHLTTPCDigitReaderDecoder::SetUnsorted(bool unsorted)
111 // see header file for class documentation
113 // The DigitReaderDecoder does not support sorted data, forward to
114 // default if sorted data requested
115 if (!unsorted) AliHLTTPCDigitReader::SetUnsorted(unsorted);
118 bool AliHLTTPCDigitReaderDecoder::NextChannel()
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);
129 int AliHLTTPCDigitReaderDecoder::NextBunch()
131 // see header file for class documentation
132 return fAltroData.NextBunch(fAltroBunch);
135 bool AliHLTTPCDigitReaderDecoder::NextSignal()
137 // see header file for class documentation
138 fNextSignalMethodUsed=kTRUE;
140 if (fNextCounter>0) {
141 // there is data available in the current bunch
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;
153 // there is no bunch left, go to the next channel
154 } while (NextChannel());
159 const UInt_t* AliHLTTPCDigitReaderDecoder::GetSignals()
161 // see header file for class documentation
162 return fAltroBunch->GetData();
165 int AliHLTTPCDigitReaderDecoder::GetRow()
167 // see header file for class documentation
168 return fMapping->GetRow(fAltroData.GetHadd());
171 int AliHLTTPCDigitReaderDecoder::GetPad()
173 // see header file for class documentation
174 return fMapping->GetPad(fAltroData.GetHadd());
177 int AliHLTTPCDigitReaderDecoder::GetSignal()
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];
190 int AliHLTTPCDigitReaderDecoder::GetTime()
192 // see header file for class documentation
194 if(!fNextSignalMethodUsed){// this is true if the bunch approach is used
196 iResult= fAltroBunch->GetStartTimeBin();
199 assert(fNextCounter>=0);
200 iResult = fAltroBunch->GetStartTimeBin()+fNextCounter;
202 if(iResult<0 || iResult>AliHLTTPCTransform::GetNTimeBins()){
208 int AliHLTTPCDigitReaderDecoder::GetBunchSize()
210 // see header file for class documentation
211 return fAltroBunch->GetBunchSize();
214 int AliHLTTPCDigitReaderDecoder::GetRowOffset() const
216 return fMapping->GetRowOffset();
218 AliHLTUInt32_t AliHLTTPCDigitReaderDecoder::GetAltroBlockHWaddr() const
220 // see header file for class documentation
221 return (AliHLTUInt32_t)fAltroData.GetHadd();
223 AliHLTUInt32_t AliHLTTPCDigitReaderDecoder::GetAltroBlockHWaddr(Int_t row, Int_t pad) const
225 // see header file for class documentation
227 return fMapping->GetHwAddress(row,pad);
234 int AliHLTTPCDigitReaderDecoder::GetRCUTrailerSize()
236 // see header file for class documentation
238 return fAltroDecoder->GetRCUTrailerSize();
243 bool AliHLTTPCDigitReaderDecoder::GetRCUTrailerData(UChar_t*& trData)
245 // see header file for class documentation
247 return fAltroDecoder->GetRCUTrailerData(trData);
252 AliAltroDecoder* AliHLTTPCDigitReaderDecoder::GetDecoderInstance()
254 // see header file for class documentation
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.
260 // This is just a poor man's solution, no synchronization for the
262 if (fgpIssuedInstance) {
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");
269 if (!fgpFreeInstance) fgpFreeInstance=new AliAltroDecoder;
270 fgpIssuedInstance=fgpFreeInstance;
271 fgpFreeInstance=NULL;
272 return fgpIssuedInstance;
275 void AliHLTTPCDigitReaderDecoder::ReleaseDecoderInstance(AliAltroDecoder* pInstance)
277 // see header file for class documentation
278 if (!pInstance) return;
279 if (pInstance!=fgpIssuedInstance) {
281 log.LoggingVarargs(kHLTLogError, "AliHLTTPCDigitReaderDecoder", "ReleaseDecoderInstance" , __FILE__ , __LINE__ ,
282 "wrong instance %p, expecting %p", pInstance, fgpIssuedInstance);
285 fgpFreeInstance=fgpIssuedInstance;
286 fgpIssuedInstance=NULL;