coding convention
[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//
21///////////////////////////////////////////////////////////////////////////////
22
23#include "AliRawReader.h"
24
8de97894 25
a6e7b125 26ClassImp(AliRawReader)
27
28
8de97894 29AliRawReader::AliRawReader()
a6e7b125 30{
8de97894 31 fMiniHeader = NULL;
a6e7b125 32 fCount = 0;
8de97894 33
34 fSelectDetectorID = -1;
35 fSelectMinDDLID = -1;
36 fSelectMaxDDLID = -1;
a6e7b125 37}
38
8de97894 39
40void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
a6e7b125 41{
8de97894 42// read only data of the detector with the given ID and in the given
43// range of DDLs (minDDLID <= DDLID < maxDDLID).
44// no selection is applied if a value < 0 is used.
a6e7b125 45
8de97894 46 fSelectDetectorID = detectorID;
47 fSelectMinDDLID = minDDLID;
48 fSelectMaxDDLID = maxDDLID;
49}
a6e7b125 50
8de97894 51Bool_t AliRawReader::IsSelected()
a6e7b125 52{
8de97894 53// apply the selection (if any)
54
55 if (fSelectDetectorID >= 0) {
56 if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
57 if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
58 return kFALSE;
59 if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID >= fSelectMaxDDLID))
60 return kFALSE;
a6e7b125 61 }
8de97894 62 return kTRUE;
a6e7b125 63}
64
65
8de97894 66Bool_t AliRawReader::CheckMiniHeader()
a6e7b125 67{
8de97894 68// check the magic number of the mini header
a6e7b125 69
8de97894 70 if ((fMiniHeader->fMagicWord[2] != 0x12) ||
71 (fMiniHeader->fMagicWord[1] != 0x34) ||
72 (fMiniHeader->fMagicWord[0] != 0x56)) {
73 Error("CheckMiniHeader", "wrong magic word!");
74 return kFALSE;
a6e7b125 75 }
a6e7b125 76 return kTRUE;
77}
78
79Bool_t AliRawReader::ReadNextInt(UInt_t& data)
80{
8de97894 81// reads the next 4 bytes at the current position
82// returns kFALSE if the data could not be read
a6e7b125 83
84 while (fCount == 0) {
85 if (!ReadMiniHeader()) return kFALSE;
86 }
8de97894 87 if (fCount < (Int_t) sizeof(data)) {
88 Error("ReadNextInt",
89 "too few data left (%d bytes) to read an UInt_t!", fCount);
90 return kFALSE;
91 }
92 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 93 Error("ReadNextInt", "could not read data!");
94 return kFALSE;
95 }
a6e7b125 96 return kTRUE;
97}
98
99Bool_t AliRawReader::ReadNextShort(UShort_t& data)
100{
8de97894 101// reads the next 2 bytes at the current position
102// returns kFALSE if the data could not be read
a6e7b125 103
104 while (fCount == 0) {
105 if (!ReadMiniHeader()) return kFALSE;
106 }
8de97894 107 if (fCount < (Int_t) sizeof(data)) {
108 Error("ReadNextShort",
109 "too few data left (%d bytes) to read an UShort_t!", fCount);
110 return kFALSE;
111 }
112 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 113 Error("ReadNextShort", "could not read data!");
114 return kFALSE;
115 }
a6e7b125 116 return kTRUE;
117}
118
119Bool_t AliRawReader::ReadNextChar(UChar_t& data)
120{
121// reads the next 1 byte at the current stream position
8de97894 122// returns kFALSE if the data could not be read
a6e7b125 123
124 while (fCount == 0) {
125 if (!ReadMiniHeader()) return kFALSE;
126 }
8de97894 127 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
a6e7b125 128 Error("ReadNextChar", "could not read data!");
129 return kFALSE;
130 }
a6e7b125 131 return kTRUE;
132}
133