Fixes in alimdc package in order to be able to compile the code without HLT
[u/mrichter/AliRoot.git] / RAW / AliAltroRawStream.cxx
CommitLineData
3ea47630 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19///
20/// This class provides access to Altro digits in raw data.
21///
22/// It loops over all Altro digits in the raw data given by the AliRawReader.
23/// The Next method goes to the next digit. If there are no digits left
24/// it returns kFALSE.
25/// Several getters provide information about the current digit.
26///
27///////////////////////////////////////////////////////////////////////////////
28
29#include "AliAltroRawStream.h"
30#include "AliRawReader.h"
31
32ClassImp(AliAltroRawStream)
33
34
35//_____________________________________________________________________________
36AliAltroRawStream::AliAltroRawStream(AliRawReader* rawReader) :
37 fSector(-1),
38 fPrevSector(-1),
39 fRow(-1),
40 fPrevRow(-1),
41 fPad(-1),
42 fPrevPad(-1),
43 fTime(-1),
44 fSignal(-1),
45 fRawReader(rawReader),
46 fData(NULL),
47 fPosition(0),
48 fCount(0),
49 fBunchLength(0)
50{
51// create an object to read Altro raw digits
52
53}
54
55//_____________________________________________________________________________
56AliAltroRawStream::AliAltroRawStream(const AliAltroRawStream& stream) :
57 TObject(stream),
58 fSector(-1),
59 fPrevSector(-1),
60 fRow(-1),
61 fPrevRow(-1),
62 fPad(-1),
63 fPrevPad(-1),
64 fTime(-1),
65 fSignal(-1),
66 fRawReader(NULL),
67 fData(NULL),
68 fPosition(0),
69 fCount(0),
70 fBunchLength(0)
71{
72 Fatal("AliAltroRawStream", "copy constructor not implemented");
73}
74
75//_____________________________________________________________________________
76AliAltroRawStream& AliAltroRawStream::operator = (const AliAltroRawStream&
77 /* stream */)
78{
79 Fatal("operator =", "assignment operator not implemented");
80 return *this;
81}
82
83//_____________________________________________________________________________
84AliAltroRawStream::~AliAltroRawStream()
85{
86// clean up
87
88}
89
90
91//_____________________________________________________________________________
92Bool_t AliAltroRawStream::Next()
93{
94// read the next raw digit
95// returns kFALSE if there is no digit left
96
97 fPrevSector = fSector;
98 fPrevRow = fRow;
99 fPrevPad = fPad;
100
101 while (fCount == 0) { // next trailer
102 if (fPosition <= 0) { // next payload
103 do {
104 if (!fRawReader->ReadNextData(fData)) return kFALSE;
105 } while (fRawReader->GetDataSize() == 0);
106
107 fPosition = (fRawReader->GetDataSize() * 8) / 10;
108 while (Get10BitWord(fData, fPosition-1) == 0x2AA) fPosition--;
109 }
110
111 if (fPosition > 0) {
112 // read the trailer
113 if (fPosition <= 4) {
114 Error("Next", "could not read trailer");
115 return kFALSE;
116 }
117 fSector = Get10BitWord(fData, --fPosition);
118 fRow = Get10BitWord(fData, --fPosition);
119 fPad = Get10BitWord(fData, --fPosition);
120 fCount = Get10BitWord(fData, --fPosition);
121
122 fPosition -= (4 - (fCount % 4)) % 4; // skip fill words
123 fBunchLength = 0;
124 }
125 }
126
127 if (fBunchLength == 0) {
128 if (fPosition <= 0) {
129 Error("Next", "could not read bunch length");
130 return kFALSE;
131 }
132 fBunchLength = Get10BitWord(fData, --fPosition) - 2;
634692a1 133 fTimeBunch = fBunchLength;
3ea47630 134 fCount--;
135
136 if (fPosition <= 0) {
137 Error("Next", "could not read time bin");
138 return kFALSE;
139 }
140 fTime = Get10BitWord(fData, --fPosition);
141 fCount--;
142 } else {
143 fTime--;
144 }
145
146 if (fPosition <= 0) {
147 Error("Next", "could not read sample amplitude");
148 return kFALSE;
149 }
150 fSignal = Get10BitWord(fData, --fPosition);
151 fCount--;
152 fBunchLength--;
153
154 return kTRUE;
155}
156
157
158//_____________________________________________________________________________
159UShort_t AliAltroRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
160{
161// return a word in a 10 bit array as an UShort_t
162
163 Int_t iBit = position * 10;
164 Int_t iByte = iBit / 8;
165 Int_t shift = iBit % 8;
166// return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
167
168 // recalculate the byte numbers and the shift because
169 // the raw data is written as integers where the high bits are filled first
170 // -> little endian is assumed here !
171 Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
172 iByte++;
173 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
174 shift = 6 - shift;
175 return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;
176}