Old TOF library: removing
[u/mrichter/AliRoot.git] / FMD / AliFMDRawStream.cxx
CommitLineData
4347b38f 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// Buffer to read RAW ALTRO FMD format from a AliRawReader
21//
22// Currently, I had to overload the Next member function and introduce
23// my own members fMyData, fMyPosition, fMyCount, and fMyBunchLength.
24// The reason is, that we can use the fMyCount to determine the
25// sampling rate used in the ALTRO. However,
26// AliAltroBuffer::fCount is private, so we can not access it.
27//
28// If it wasn't I'd implement Next as
29//
30// Bool_t
31// AliFMDRawStreamer::Next()
32// {
33// if (AliAltroRawStreamer::Next()) {
34// if (fPrevPad != fPad)
35// fSampleRate = (fCount - 2) / 128;
36// return kTRUE;
37// }
38// return kFALSE;
39// }
40//
41//////////////////////////////////////////////////////////////////////
42#ifndef ALIFMDRAWSTREAM_H
43# include "AliFMDRawStream.h"
44#endif
45#ifndef ALIRAWREADER_H
46# include "AliRawReader.h"
47#endif
48#ifndef __IOSTREAM__
49# include <iostream>
50#endif
51
52//____________________________________________________________________
53ClassImp(AliFMDRawStream);
54
55//____________________________________________________________________
56AliFMDRawStream::AliFMDRawStream(AliRawReader* reader)
57 : AliAltroRawStream(reader),
58 // fMyData(0),
59 // fMyPosition(0),
60 // fMyCount(0),
61 // fMyBunchLength(0),
62 fPrevTime(-1)
63{}
64
65
66
67//_____________________________________________________________________________
68Bool_t
69AliFMDRawStream::Next()
70{
71 // read the next raw digit
72 // returns kFALSE if there is no digit left
73 fPrevTime = fTime;
74 if (AliAltroRawStream::Next()) {
75 if (fPrevPad != fPad) {
76 fSampleRate = fTimeBunch / 128;
48f3f263 77#if 0
4347b38f 78 std::cout << "Setting Sample rate to (" << fTimeBunch << "/"
79 << 128 << "=" << fSampleRate << std::endl;
80#endif
81 }
82 return kTRUE;
83 }
84 return kFALSE;
85}
86
87#if 0
88//_____________________________________________________________________________
89Bool_t
90AliFMDRawStream::Next()
91{
92 // read the next raw digit
93 // returns kFALSE if there is no digit left
94 fPrevSector = fSector;
95 fPrevRow = fRow;
96 fPrevPad = fPad;
97 fPrevTime = fTime;
98
99 while (fMyCount == 0) { // next trailer
100 if (fMyPosition <= 0) { // next payload
101 do {
102 if (!fRawReader->ReadNextData(fMyData)) return kFALSE;
103 } while (fRawReader->GetDataSize() == 0);
104
105 fMyPosition = (fRawReader->GetDataSize() * 8) / 10;
106 while (Get10BitWord(fMyData, fMyPosition-1) == 0x2AA) fMyPosition--;
107 }
108
109 if (fMyPosition > 0) {
110 // read the trailer
111 if (fMyPosition <= 4) {
112 Error("Next", "could not read trailer");
113 return kFALSE;
114 }
115 fSector = Get10BitWord(fMyData, --fMyPosition);
116 fRow = Get10BitWord(fMyData, --fMyPosition);
117 fPad = Get10BitWord(fMyData, --fMyPosition);
118 fMyCount = Get10BitWord(fMyData, --fMyPosition);
119
120 fMyPosition -= (4 - (fMyCount % 4)) % 4; // skip fill words
121 fMyBunchLength = 0;
122
123 // Set the sample rate, based on the number of samples in the
124 // channel.
125 fSampleRate = (fMyCount - 2) / 128;
126#if 0
127 std::cout << "Setting Sample rate to (" << fMyCount << " - 2)/"
128 << 128 << "=" << fSampleRate << std::endl;
129#endif
130 }
131 }
132
133 if (fMyBunchLength == 0) {
134 if (fMyPosition <= 0) {
135 Error("Next", "could not read bunch length");
136 return kFALSE;
137 }
138 fMyBunchLength = Get10BitWord(fMyData, --fMyPosition) - 2;
139 fMyCount--;
140
141
142 if (fMyPosition <= 0) {
143 Error("Next", "could not read time bin");
144 return kFALSE;
145 }
146 fTime = Get10BitWord(fMyData, --fMyPosition);
147 fMyCount--;
148 } else {
149 fTime--;
150 }
151
152 if (fMyPosition <= 0) {
153 Error("Next", "could not read sample amplitude");
154 return kFALSE;
155 }
156 fSignal = Get10BitWord(fMyData, --fMyPosition);
157 fMyCount--;
158 fMyBunchLength--;
159
160 return kTRUE;
161}
162
163//_____________________________________________________________________________
164UShort_t
165AliFMDRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
166{
167// return a word in a 10 bit array as an UShort_t
168
169 Int_t iBit = position * 10;
170 Int_t iByte = iBit / 8;
171 Int_t shift = iBit % 8;
172// return ((buffer[iByte+1] * 256 + buffer[iByte]) >> shift) & 0x03FF;
173
174 // recalculate the byte numbers and the shift because
175 // the raw data is written as integers where the high bits are filled first
176 // -> little endian is assumed here !
177 Int_t iByteHigh = 4 * (iByte / 4) + 3 - (iByte % 4);
178 iByte++;
179 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
180 shift = 6 - shift;
181 return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;
182}
183#endif
184//_____________________________________________________________________________
185//
186// EOF
187//