]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliRawReader.cxx
Names changed in order to avoid clash with FLUKA
[u/mrichter/AliRoot.git] / STEER / 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//
18// This is the base class for reading a raw data file and providing
19// information about digits
20//
21///////////////////////////////////////////////////////////////////////////////
22
23#include "AliRawReader.h"
24
25ClassImp(AliRawReader)
26
27
28AliRawReader::AliRawReader(const char* fileName, Bool_t addNumber)
29{
30// create an object to read digits from the given input file(s)
31// if addNumber is true, a number starting at 1 is appended to the file name
32
33 fFileName = fileName;
34 if (!addNumber) {
35 fFileNumber = -1;
1b580228 36#ifndef __DECCXX
a6e7b125 37 fStream = new fstream(fileName, ios::binary|ios::in);
1b580228 38#else
39 fStream = new fstream(fileName, ios::in);
40#endif
a6e7b125 41 } else {
42 fFileNumber = 0;
43 fStream = NULL;
44 OpenNextFile();
45 }
46 fCount = 0;
47}
48
49AliRawReader::~AliRawReader()
50{
51// close the input file
52
53 if (fStream) {
1b580228 54#if defined(__HP_aCC) || defined(__DECCXX)
f75eca3a 55 if (fStream->rdbuf()->is_open()) fStream->close();
1b580228 56#else
57 if (fStream->is_open()) fStream->close();
f75eca3a 58#endif
a6e7b125 59 delete fStream;
60 }
61}
62
63
64Bool_t AliRawReader::OpenNextFile()
65{
66 if (fStream) {
1b580228 67#if defined(__HP_aCC) || defined(__DECCXX)
f75eca3a 68 if (fStream->rdbuf()->is_open()) fStream->close();
1b580228 69#else
70 if (fStream->is_open()) fStream->close();
f75eca3a 71#endif
a6e7b125 72 delete fStream;
73 fStream = NULL;
74 }
75 if (fFileNumber < 0) return kFALSE;
76
77 fFileNumber++;
78 char fileName[256];
79 sprintf(fileName, "%s%d", fFileName, fFileNumber);
1b580228 80#ifndef __DECCXX
a6e7b125 81 fStream = new fstream(fileName, ios::binary|ios::in);
f75eca3a 82#else
1b580228 83 fStream = new fstream(fileName, ios::in);
84#endif
85#if defined(__HP_aCC) || defined(__DECCXX)
f75eca3a 86 return (fStream->rdbuf()->is_open());
1b580228 87#else
88 return (fStream->is_open());
f75eca3a 89#endif
a6e7b125 90}
91
92
93Bool_t AliRawReader::ReadMiniHeader()
94{
95// read a mini header at the current stream position
96// returns kFALSE if the mini header could not be read
97
98 if (!fStream) return kFALSE;
99 while (!fStream->read((char*) &fMiniHeader, sizeof(fMiniHeader))) {
100 if (!OpenNextFile()) return kFALSE;
101 }
102 if ((fMiniHeader.fMagicWord[2] != 0x12) ||
103 (fMiniHeader.fMagicWord[1] != 0x34) ||
104 (fMiniHeader.fMagicWord[0] != 0x56))
105 Error("ReadMiniHeader", "wrong magic word!");
106 fCount = fMiniHeader.fSize;
107 return kTRUE;
108}
109
110Bool_t AliRawReader::ReadNextInt(UInt_t& data)
111{
112// reads the next 4 bytes at the current stream position
113// returns kFALSE if the data not be read
114
115 while (fCount == 0) {
116 if (!ReadMiniHeader()) return kFALSE;
117 }
118 if (!fStream->read((char*) &data, sizeof(data))) {
119 Error("ReadNextInt", "could not read data!");
120 return kFALSE;
121 }
122 fCount -= sizeof(data);
123 return kTRUE;
124}
125
126Bool_t AliRawReader::ReadNextShort(UShort_t& data)
127{
128// reads the next 2 bytes at the current stream position
129// returns kFALSE if the data not be read
130
131 while (fCount == 0) {
132 if (!ReadMiniHeader()) return kFALSE;
133 }
134 if (!fStream->read((char*) &data, sizeof(data))) {
135 Error("ReadNextShort", "could not read data!");
136 return kFALSE;
137 }
138 fCount -= sizeof(data);
139 return kTRUE;
140}
141
142Bool_t AliRawReader::ReadNextChar(UChar_t& data)
143{
144// reads the next 1 byte at the current stream position
145// returns kFALSE if the data not be read
146
147 while (fCount == 0) {
148 if (!ReadMiniHeader()) return kFALSE;
149 }
150 if (!fStream->read((char*) &data, sizeof(data))) {
151 Error("ReadNextChar", "could not read data!");
152 return kFALSE;
153 }
154 fCount -= sizeof(data);
155 return kTRUE;
156}
157