Correction of Acorde's Preprocessor (Luciano Diaz)
[u/mrichter/AliRoot.git] / ACORDE / AliACORDERawStream.cxx
CommitLineData
0a59828d 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///////////////////////////////////////////////////////////////////////////////
17// //
18// Reads ACORDE DDL raw data from raw data stream //
19// //
20///////////////////////////////////////////////////////////////////////////////
21
22#include "AliACORDERawStream.h"
23#include "AliRawReader.h"
24#include "AliLog.h"
25#include "AliDAQ.h"
26
27ClassImp(AliACORDERawStream)
28
29//_____________________________________________________________________________
30AliACORDERawStream::AliACORDERawStream(AliRawReader* rawReader) :
31 fRawReader(rawReader),
32 fPosition(-1),
33 fData(NULL),
34 fDataSize(0)
35{
36 //
37 // Create an object to read ACORDE raw data
38 //
39 // Created: 04 Feb 2008 Mario Sitta
40 //
41
42 // Select the raw data corresponding to the ACORDE detector id
43// fRawReader->Reset();
44 AliDebug(1,Form("Selecting raw data for detector %d",AliDAQ::DetectorID("ACORDE")));
45 fRawReader->Select("ACORDE");
46
47}
48
49//_____________________________________________________________________________
50AliACORDERawStream::~AliACORDERawStream()
51{
52 // Default destructor
53}
54
55//_____________________________________________________________________________
56void AliACORDERawStream::Reset()
57{
58 //
59 // Reset the raw stream parameters
60 //
61 // Input:
62 //
63 // Output:
64 //
65 // Created: 04 Feb 2008 Mario Sitta
66 //
67
68 fPosition = -1;
69 fData = NULL;
70
71 if (fRawReader) fRawReader->Reset();
72}
73
74//_____________________________________________________________________________
75Bool_t AliACORDERawStream::Next()
76{
77 //
78 // Read next digit from the ACORDE raw data stream;
79 // return kFALSE in case of error or no digits left
80 //
81 // Input:
82 //
83 // Output:
84 //
85 // Created: 04 Feb 2008 Mario Sitta
86 //
87
88 if (fPosition >= 0) return kFALSE;
89
90 if (!fRawReader->ReadNextData(fData)) return kFALSE;
91 if (fRawReader->GetDataSize() == 0) return kFALSE;
92
93 fDataSize = fRawReader->GetDataSize();
94 if (fDataSize != 16) {
95 fRawReader->AddFatalErrorLog(kRawDataSizeErr,Form("size %d != 5488",fDataSize));
96 AliWarning(Form("Wrong ACORDE raw data size: %d, expected 5488 bytes!",fDataSize));
97 return kFALSE;
98 }
99
100 fPosition = 0;
101
102 for (Int_t i=0; i<4; i++)
103 fWord[i] = GetNextWord();
104
105 return kTRUE;
106}
107
108//_____________________________________________________________________________
109UInt_t AliACORDERawStream::GetWord(Int_t index) const
110{
111 //
112 // Returns the ``index'' word from ACORDE raw data.
113 //
114 // Input:
115 // index : the index of the requested word
116 // Output:
117 // word : the 32 bit ``index'' word
118 //
119 // Created: 12 Feb 2008 Mario Sitta
120 //
121
122 if (index < 0 || index > 3) {
123 AliWarning(Form("Wrong word index %d, returning 0",index));
124 return 0;
125 } else {
126 return fWord[index];
127 }
128
129}
130
131//_____________________________________________________________________________
132UInt_t AliACORDERawStream::GetNextWord()
133{
134 //
135 // Returns the next 32 bit word inside the raw data payload.
136 // The method is supposed to be endian (platform) independent.
137 //
138 // Input:
139 //
140 // Output:
141 // word : a 32 bit word containing the data
142 //
143 // Created: 04 Feb 2008 Mario Sitta
144 //
145
146 if (!fData || fPosition < 0)
147 AliFatal("Raw data payload buffer is not yet initialized !");
148
149 UInt_t word = 0;
150 word |= fData[fPosition++];
151 word |= fData[fPosition++] << 8;
152 word |= fData[fPosition++] << 16;
153 word |= fData[fPosition++] << 24;
154
155 return word;
156}
157
158//_____________________________________________________________________________
159UShort_t AliACORDERawStream::GetNextShort()
160{
161 //
162 // Returns the next 16 bit word inside the raw data payload.
163 // The method is supposed to be endian (platform) independent.
164 //
165 // Input:
166 //
167 // Output:
168 // word : a 16 bit word containing the data
169 //
170 // Created: 04 Feb 2008 Mario Sitta
171 //
172
173 if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !");
174
175 UShort_t word = 0;
176 word |= fData[fPosition++];
177 word |= fData[fPosition++] << 8;
178
179 return word;
180}
181