]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliAltroData.cxx
First version of the PHOS/EMCAL ALTRO decoder which derives from the new AliAltroRawS...
[u/mrichter/AliRoot.git] / RAW / AliAltroData.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        * 
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Author:  Per Thomas Hille  <perthi@fys.uio.no>                 *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          * 
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 #include "AliAltroData.h"
17 #include "AliAltroBunch.h"
18
19 ClassImp(AliAltroData)
20
21 AliAltroData::AliAltroData(): fData(0),
22                               fBunchData(0),
23                               fDataSize(0),
24                               fWc(0),
25                               fHadd(-1),
26                               fPrevHadd(-1),
27                               fBunchCounter(0),
28                               fIsComplete(0),
29                               fBufferLeft(0)
30 {
31
32
33 }
34
35
36
37 AliAltroData::~AliAltroData()
38 {
39
40
41 }
42
43
44 /*
45 bool
46 //AliHLTAltroData::NextBunch(AliHLTAltroBunch *altroBunch)
47 AliAltroData::NextBunch(AliAltroBunch *altroBunch)
48 {
49   //comment
50   if(fIsComplete == true)
51     {
52
53       if(fBunchCounter == 0)
54         {
55           fBunchData = &fData[fDataSize - 1];
56           altroBunch->fData = &fData[fDataSize - 1];
57           
58         }
59
60       if(fWc < fDataSize)
61         {
62           fWc += *fBunchData;
63           altroBunch->fBunchSize = *fBunchData;
64           altroBunch->fBunchDataSize = altroBunch->fBunchSize  -2;
65
66           fBunchData --;
67           altroBunch->fEndTimeBin = *fBunchData;
68           fBunchData ++;
69
70           fBunchData = fBunchData  -  (altroBunch->fBunchSize);
71           altroBunch->fData = altroBunch->fData -  (altroBunch->fBunchSize);
72           fBunchCounter ++;
73           return true;
74
75         }
76       else
77         {
78           fBunchCounter = 0;
79           fWc = 0;
80           return false;
81         }
82     }
83   else
84     {
85       printf("\nAliHLTAltroData::NextBunch: WARNING, dataset is not complet. 2AAA endmarker is missing ");
86       printf("\nfor branch %d, card %d, chip %d, channel %d\n",  GetBranch(), GetCard(), GetChip(), GetChannel());
87       return false;
88     }
89 }
90
91 */
92
93
94
95
96  //Bool_t AliAltroData::NextBunch(AliAltroBunch *altroBunch)
97 int AliAltroData::NextBunch(AliAltroBunch *altroBunch)
98 {
99
100   if(fIsComplete == kTRUE)
101     {
102       if(fBunchCounter == 0)
103         {
104           fBunchData = &fData[fDataSize - 1];
105         }
106
107       if(fWc < fDataSize)
108         {
109           if(*fBunchData == 0){ fWc += 1;};
110           fWc += *fBunchData;
111           altroBunch->SetData(fData + fDataSize - fWc);
112
113           int tmpsize =  *fBunchData -2;  
114
115           //      altroBunch->SetBunchSize(         *fBunchData -2       );
116           altroBunch->SetBunchSize( tmpsize );
117           
118
119           fBufferLeft -= *fBunchData;
120           //      printf("%s:%d, bufferleft = %d \n", __FILE__,  __LINE__ , fBufferLeft);
121           fBunchData --;
122           altroBunch->SetEndTimeBin( *fBunchData );
123           
124           // Matthias Oct 10 2008: those checks are certainly a bug, first the 
125           // bunch size is subtracted from fBufferLeft ... and than once again
126           // I can understand that it should not be negative but the check as
127           // committed in revision 29090 is wrong.
128           // Effectively, this is always skipping the last bunch of the last
129           // channel.
130           //      if( (fBufferLeft <=  7 ) || ( fBufferLeft - tmpsize)  <= 7)
131           //if( fBufferLeft - tmpsize  <= 7)
132           if( fBufferLeft < 0)
133             {
134               //              printf("%s:%d, ERROR, attempt too access buffer outside allowed range\n",  __FILE__ ,  __LINE__ );
135               return kFALSE;
136             }
137           
138
139           if(fBunchCounter >0)
140             {
141               int tmpret = altroBunch->CheckConsistency();
142               
143               if(tmpret != kTRUE)
144                 {
145                   return tmpret;
146                 }
147
148               /*
149                 if( altroBunch->CheckConsistency() == kFALSE)
150                 {
151                   return kFALSE;
152                 }
153               */
154             }
155
156           //      altroBunch->SetStartTimeBin(*fBunchData - fBunchSize);
157           fBunchData -= (altroBunch->GetBunchSize() +1);
158
159           // PATCH from Per Thomas Hille 250408 mke sure tha
160           // Data is consistent by cheking the start timebin, should never be negative
161           if( (int)altroBunch->GetStartTimeBin( ) < 0)
162             {
163               //              printf("ERROR altroBunch->GetStartTimeBin( ) is  %d", (int)altroBunch->GetStartTimeBin( ) );
164               return kFALSE;
165             }
166
167           fBunchCounter ++;
168           return kTRUE;
169         }
170       else
171         {
172           fBunchCounter = 0;
173           fWc = 0;
174           return kFALSE;
175         }
176     }
177   else
178     {
179       //     printf("\nAliAltroData::NextBunch: WARNING, dataset is not complet. 2AAA endmarker is missing ");
180       //     printf("\nfor branch %d, card %d, chip %d, channel %d\n",  GetBranch(), GetCard(), GetChip(), GetChannel());
181       return kFALSE;
182     }
183
184 }
185
186
187
188 void AliAltroData::Reset()
189 {
190    fWc = 0;
191    fBunchCounter = 0;
192 }
193
194
195 Int_t AliAltroData::GetChannel() const
196 {
197  return  fHadd & 0xf;
198 }
199
200 Int_t AliAltroData::GetChip() const
201 {
202  return  (fHadd & 0x70) >> 4 ;
203 }
204
205 Int_t AliAltroData::GetCard() const
206 {
207  return   (fHadd & 0x780) >>  7;
208 }
209
210
211 Int_t AliAltroData::GetBranch() const
212 {
213  return   (fHadd & 0x800 ) >> 11;
214 }