1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //////////////////////////////////////////////////////////////////////
20 // Buffer to read RAW ALTRO FMD format from a AliRawReader
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.
28 // If it wasn't I'd implement Next as
31 // AliFMDRawStreamer::Next()
33 // if (AliAltroRawStreamer::Next()) {
34 // if (fPrevPad != fPad)
35 // fSampleRate = (fCount - 2) / 128;
41 //////////////////////////////////////////////////////////////////////
42 #ifndef ALIFMDRAWSTREAM_H
43 # include "AliFMDRawStream.h"
45 #ifndef ALIRAWREADER_H
46 # include "AliRawReader.h"
52 //____________________________________________________________________
53 ClassImp(AliFMDRawStream);
55 //____________________________________________________________________
56 AliFMDRawStream::AliFMDRawStream(AliRawReader* reader)
57 : AliAltroRawStream(reader),
67 //_____________________________________________________________________________
69 AliFMDRawStream::Next()
71 // read the next raw digit
72 // returns kFALSE if there is no digit left
74 if (AliAltroRawStream::Next()) {
75 if (fPrevPad != fPad) {
76 fSampleRate = fTimeBunch / 128;
78 std::cout << "Setting Sample rate to (" << fTimeBunch << "/"
79 << 128 << "=" << fSampleRate << std::endl;
88 //_____________________________________________________________________________
90 AliFMDRawStream::Next()
92 // read the next raw digit
93 // returns kFALSE if there is no digit left
94 fPrevSector = fSector;
99 while (fMyCount == 0) { // next trailer
100 if (fMyPosition <= 0) { // next payload
102 if (!fRawReader->ReadNextData(fMyData)) return kFALSE;
103 } while (fRawReader->GetDataSize() == 0);
105 fMyPosition = (fRawReader->GetDataSize() * 8) / 10;
106 while (Get10BitWord(fMyData, fMyPosition-1) == 0x2AA) fMyPosition--;
109 if (fMyPosition > 0) {
111 if (fMyPosition <= 4) {
112 Error("Next", "could not read trailer");
115 fSector = Get10BitWord(fMyData, --fMyPosition);
116 fRow = Get10BitWord(fMyData, --fMyPosition);
117 fPad = Get10BitWord(fMyData, --fMyPosition);
118 fMyCount = Get10BitWord(fMyData, --fMyPosition);
120 fMyPosition -= (4 - (fMyCount % 4)) % 4; // skip fill words
123 // Set the sample rate, based on the number of samples in the
125 fSampleRate = (fMyCount - 2) / 128;
127 std::cout << "Setting Sample rate to (" << fMyCount << " - 2)/"
128 << 128 << "=" << fSampleRate << std::endl;
133 if (fMyBunchLength == 0) {
134 if (fMyPosition <= 0) {
135 Error("Next", "could not read bunch length");
138 fMyBunchLength = Get10BitWord(fMyData, --fMyPosition) - 2;
142 if (fMyPosition <= 0) {
143 Error("Next", "could not read time bin");
146 fTime = Get10BitWord(fMyData, --fMyPosition);
152 if (fMyPosition <= 0) {
153 Error("Next", "could not read sample amplitude");
156 fSignal = Get10BitWord(fMyData, --fMyPosition);
163 //_____________________________________________________________________________
165 AliFMDRawStream::Get10BitWord(UChar_t* buffer, Int_t position) const
167 // return a word in a 10 bit array as an UShort_t
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;
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);
179 Int_t iByteLow = 4 * (iByte / 4) + 3 - (iByte % 4);
181 return ((buffer[iByteHigh] * 256 + buffer[iByteLow]) >> shift) & 0x03FF;
184 //_____________________________________________________________________________