]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReader.cxx
extended check
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
CommitLineData
a6e7b125 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//
8de97894 18// This is the base class for reading raw data and providing
a6e7b125 19// information about digits
20//
42d20574 21// The derived classes, which operate on concrete raw data formats,
22// should implement
23// - ReadMiniHeader to read the next mini header
24// - ReadNextData to read the next raw data block (=1 DDL)
25// - ReadNext to read a given number of bytes
26// - several getters like GetType
27//
28// Sequential access to the raw data is provided by the methods
29// ReadMiniHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
30//
31// If only data from a specific detector (and a given range of DDL numbers)
32// should be read, this can be achieved by the Select method.
33// Several getter provide information about the current event and the
34// current type of raw data.
35//
a6e7b125 36///////////////////////////////////////////////////////////////////////////////
37
38#include "AliRawReader.h"
39
8de97894 40
a6e7b125 41ClassImp(AliRawReader)
42
43
8de97894 44AliRawReader::AliRawReader()
a6e7b125 45{
42d20574 46// default constructor: initialize data members
47
8de97894 48 fMiniHeader = NULL;
a6e7b125 49 fCount = 0;
8de97894 50
51 fSelectDetectorID = -1;
52 fSelectMinDDLID = -1;
53 fSelectMaxDDLID = -1;
b4857df7 54
55 fErrorCode = 0;
a6e7b125 56}
57
42d20574 58AliRawReader::AliRawReader(const AliRawReader& rawReader) :
59 TObject(rawReader)
60{
61// copy constructor
62
63 fMiniHeader = rawReader.fMiniHeader;
64 fCount = rawReader.fCount;
65
66 fSelectDetectorID = rawReader.fSelectDetectorID;
67 fSelectMinDDLID = rawReader.fSelectMinDDLID;
68 fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
b4857df7 69
70 fErrorCode = 0;
42d20574 71}
72
73AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
74{
75// assignment operator
76
77 fMiniHeader = rawReader.fMiniHeader;
78 fCount = rawReader.fCount;
79
80 fSelectDetectorID = rawReader.fSelectDetectorID;
81 fSelectMinDDLID = rawReader.fSelectMinDDLID;
82 fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
83
b4857df7 84 fErrorCode = rawReader.fErrorCode;
85
42d20574 86 return *this;
87}
88
8de97894 89
90void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
a6e7b125 91{
8de97894 92// read only data of the detector with the given ID and in the given
93// range of DDLs (minDDLID <= DDLID < maxDDLID).
94// no selection is applied if a value < 0 is used.
a6e7b125 95
8de97894 96 fSelectDetectorID = detectorID;
97 fSelectMinDDLID = minDDLID;
98 fSelectMaxDDLID = maxDDLID;
99}
a6e7b125 100
42d20574 101Bool_t AliRawReader::IsSelected() const
a6e7b125 102{
8de97894 103// apply the selection (if any)
104
105 if (fSelectDetectorID >= 0) {
106 if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
107 if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
108 return kFALSE;
109 if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID >= fSelectMaxDDLID))
110 return kFALSE;
a6e7b125 111 }
8de97894 112 return kTRUE;
a6e7b125 113}
114
115
b4857df7 116Bool_t AliRawReader::CheckMiniHeader(AliMiniHeader* miniHeader) const
a6e7b125 117{
8de97894 118// check the magic number of the mini header
a6e7b125 119
b4857df7 120 if (!miniHeader) miniHeader = fMiniHeader;
121 if ((miniHeader->fMagicWord[2] != 0x12) ||
122 (miniHeader->fMagicWord[1] != 0x34) ||
123 (miniHeader->fMagicWord[0] != 0x56)) {
8de97894 124 return kFALSE;
a6e7b125 125 }
a6e7b125 126 return kTRUE;
127}
128
129Bool_t AliRawReader::ReadNextInt(UInt_t& data)
130{
8de97894 131// reads the next 4 bytes at the current position
132// returns kFALSE if the data could not be read
a6e7b125 133
134 while (fCount == 0) {
135 if (!ReadMiniHeader()) return kFALSE;
136 }
8de97894 137 if (fCount < (Int_t) sizeof(data)) {
138 Error("ReadNextInt",
139 "too few data left (%d bytes) to read an UInt_t!", fCount);
140 return kFALSE;
141 }
142 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 143 Error("ReadNextInt", "could not read data!");
144 return kFALSE;
145 }
a6e7b125 146 return kTRUE;
147}
148
149Bool_t AliRawReader::ReadNextShort(UShort_t& data)
150{
8de97894 151// reads the next 2 bytes at the current position
152// returns kFALSE if the data could not be read
a6e7b125 153
154 while (fCount == 0) {
155 if (!ReadMiniHeader()) return kFALSE;
156 }
8de97894 157 if (fCount < (Int_t) sizeof(data)) {
158 Error("ReadNextShort",
159 "too few data left (%d bytes) to read an UShort_t!", fCount);
160 return kFALSE;
161 }
162 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 163 Error("ReadNextShort", "could not read data!");
164 return kFALSE;
165 }
a6e7b125 166 return kTRUE;
167}
168
169Bool_t AliRawReader::ReadNextChar(UChar_t& data)
170{
171// reads the next 1 byte at the current stream position
8de97894 172// returns kFALSE if the data could not be read
a6e7b125 173
174 while (fCount == 0) {
175 if (!ReadMiniHeader()) return kFALSE;
176 }
8de97894 177 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 178 Error("ReadNextChar", "could not read data!");
179 return kFALSE;
180 }
a6e7b125 181 return kTRUE;
182}
183
b4857df7 184
185Int_t AliRawReader::CheckData() const
186{
187// check the consistency of the data
188// derived classes should overwrite the default method which returns 0 (no err)
189
190 return 0;
191}
192