]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitReaderUnpacked.cxx
additional boundary checks (Kenneth)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderUnpacked.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   AliHLTTPCDigitReaderUnpacked.cxx
22     @author Timm Steinbeck, Jochen Thaeder, Matthias Richter
23     @date   
24     @brief  A digit reader implementation for unpacked TPC data.
25 */
26
27 #if __GNUC__== 3
28 using namespace std;
29 #endif
30
31 #include "AliHLTTPCDigitReaderUnpacked.h"
32 #include "AliHLTTPCDigitData.h"
33 #include "AliHLTTPCTransform.h"
34 #include "AliHLTStdIncludes.h"
35
36 ClassImp(AliHLTTPCDigitReaderUnpacked)
37
38 AliHLTTPCDigitReaderUnpacked::AliHLTTPCDigitReaderUnpacked()
39   :
40   fDigitRowData(NULL),
41   fActRowData(NULL),
42   fData(NULL),
43   fPtr(NULL),
44   fSize(0),
45   fBin(0),
46   fRow(0),
47   fFirstRow(0),
48   fLastRow(0)
49 {
50   // see header file for class documentation
51   // or
52   // refer to README to build package
53   // or
54   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 }
56
57 AliHLTTPCDigitReaderUnpacked::~AliHLTTPCDigitReaderUnpacked(){
58   // see header file for class documentation
59 }
60
61 int AliHLTTPCDigitReaderUnpacked::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){
62   // see header file for class documentation
63   AliHLTTPCUnpackedRawData *tmpptr=NULL;
64   fPtr = ptr;
65   fSize = size;
66
67   tmpptr = reinterpret_cast<AliHLTTPCUnpackedRawData*>(fPtr);
68   fDigitRowData = (AliHLTTPCDigitRowData*) tmpptr->fDigits;
69   fActRowData = (AliHLTTPCDigitRowData*) fDigitRowData;
70
71   fBin = -1;
72
73   int dummy=0;
74   AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetFirstRow(patch), dummy, fFirstRow);
75   AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetLastRow(patch), dummy, fLastRow);
76
77   fRow = fFirstRow; 
78
79   if ((Int_t)fActRowData->fRow != fRow){
80       HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
81   }
82   return 0;
83 }
84
85 bool AliHLTTPCDigitReaderUnpacked::Next(){
86   // see header file for class documentation
87   bool rreadvalue = true;
88
89   fBin++;
90
91   if ( fBin >= (Int_t)fActRowData->fNDigit ){
92
93     fRow++;
94
95     if ((fRow >= fFirstRow) && (fRow <= fLastRow)){
96
97       //new row 
98       Byte_t *tmp = (Byte_t*) fActRowData;
99       Int_t size = sizeof(AliHLTTPCDigitRowData) + fActRowData->fNDigit*sizeof(AliHLTTPCDigitData);
100       tmp += size;
101       fActRowData = (AliHLTTPCDigitRowData*) tmp;
102      
103       if (((Byte_t*)fPtr) + fSize <= tmp){
104         rreadvalue = false;
105         return rreadvalue;
106       }
107
108       fBin = 0;
109     }
110     else {
111       rreadvalue = false;
112       return rreadvalue;
113     }
114     
115     if ((Int_t)fActRowData->fRow != fRow){
116       HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
117     }
118   }
119
120   fData = fActRowData->fDigitData;
121  
122   return rreadvalue;
123 }
124
125 int AliHLTTPCDigitReaderUnpacked::GetRow(){
126   // see header file for class documentation
127   int rrow;
128   rrow = fRow;
129   return rrow;
130 }
131
132 int AliHLTTPCDigitReaderUnpacked::GetPad(){
133   // see header file for class documentation
134   int rpad;
135   rpad = (int)fData[fBin].fPad;
136   return rpad   ;
137 }
138
139 int AliHLTTPCDigitReaderUnpacked::GetSignal(){ 
140   // see header file for class documentation
141   int rsignal;
142   rsignal = (int)fData[fBin].fCharge;
143   return rsignal;
144 }
145
146 int AliHLTTPCDigitReaderUnpacked::GetTime(){
147   // see header file for class documentation
148   int rtime;
149   rtime = (int)fData[fBin].fTime;
150   return rtime;
151 }