Coding Violations Corrected.
[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;
a6e7b125 54}
55
42d20574 56AliRawReader::AliRawReader(const AliRawReader& rawReader) :
57 TObject(rawReader)
58{
59// copy constructor
60
61 fMiniHeader = rawReader.fMiniHeader;
62 fCount = rawReader.fCount;
63
64 fSelectDetectorID = rawReader.fSelectDetectorID;
65 fSelectMinDDLID = rawReader.fSelectMinDDLID;
66 fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
67}
68
69AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
70{
71// assignment operator
72
73 fMiniHeader = rawReader.fMiniHeader;
74 fCount = rawReader.fCount;
75
76 fSelectDetectorID = rawReader.fSelectDetectorID;
77 fSelectMinDDLID = rawReader.fSelectMinDDLID;
78 fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
79
80 return *this;
81}
82
8de97894 83
84void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
a6e7b125 85{
8de97894 86// read only data of the detector with the given ID and in the given
87// range of DDLs (minDDLID <= DDLID < maxDDLID).
88// no selection is applied if a value < 0 is used.
a6e7b125 89
8de97894 90 fSelectDetectorID = detectorID;
91 fSelectMinDDLID = minDDLID;
92 fSelectMaxDDLID = maxDDLID;
93}
a6e7b125 94
42d20574 95Bool_t AliRawReader::IsSelected() const
a6e7b125 96{
8de97894 97// apply the selection (if any)
98
99 if (fSelectDetectorID >= 0) {
100 if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
101 if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
102 return kFALSE;
103 if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID >= fSelectMaxDDLID))
104 return kFALSE;
a6e7b125 105 }
8de97894 106 return kTRUE;
a6e7b125 107}
108
109
42d20574 110Bool_t AliRawReader::CheckMiniHeader() const
a6e7b125 111{
8de97894 112// check the magic number of the mini header
a6e7b125 113
8de97894 114 if ((fMiniHeader->fMagicWord[2] != 0x12) ||
115 (fMiniHeader->fMagicWord[1] != 0x34) ||
116 (fMiniHeader->fMagicWord[0] != 0x56)) {
117 Error("CheckMiniHeader", "wrong magic word!");
118 return kFALSE;
a6e7b125 119 }
a6e7b125 120 return kTRUE;
121}
122
123Bool_t AliRawReader::ReadNextInt(UInt_t& data)
124{
8de97894 125// reads the next 4 bytes at the current position
126// returns kFALSE if the data could not be read
a6e7b125 127
128 while (fCount == 0) {
129 if (!ReadMiniHeader()) return kFALSE;
130 }
8de97894 131 if (fCount < (Int_t) sizeof(data)) {
132 Error("ReadNextInt",
133 "too few data left (%d bytes) to read an UInt_t!", fCount);
134 return kFALSE;
135 }
136 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 137 Error("ReadNextInt", "could not read data!");
138 return kFALSE;
139 }
a6e7b125 140 return kTRUE;
141}
142
143Bool_t AliRawReader::ReadNextShort(UShort_t& data)
144{
8de97894 145// reads the next 2 bytes at the current position
146// returns kFALSE if the data could not be read
a6e7b125 147
148 while (fCount == 0) {
149 if (!ReadMiniHeader()) return kFALSE;
150 }
8de97894 151 if (fCount < (Int_t) sizeof(data)) {
152 Error("ReadNextShort",
153 "too few data left (%d bytes) to read an UShort_t!", fCount);
154 return kFALSE;
155 }
156 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 157 Error("ReadNextShort", "could not read data!");
158 return kFALSE;
159 }
a6e7b125 160 return kTRUE;
161}
162
163Bool_t AliRawReader::ReadNextChar(UChar_t& data)
164{
165// reads the next 1 byte at the current stream position
8de97894 166// returns kFALSE if the data could not be read
a6e7b125 167
168 while (fCount == 0) {
169 if (!ReadMiniHeader()) return kFALSE;
170 }
8de97894 171 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 172 Error("ReadNextChar", "could not read data!");
173 return kFALSE;
174 }
a6e7b125 175 return kTRUE;
176}
177