3 // Author: Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright © ALICE HLT Group
12 #include "AliHLTRootTypes.h"
13 #include "AliHLTStandardIncludes.h"
14 #include "AliHLTLogging.h"
16 #include "AliHLTDDLRawReaderFile.h"
22 /**************************************************************************
23 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
25 * Author: The ALICE Off-line Project. *
26 * Contributors are mentioned in the code where appropriate. *
28 * Permission to use, copy, modify and distribute this software and its *
29 * documentation strictly for non-commercial purposes is hereby granted *
30 * without fee, provided that the above copyright notice appears in all *
31 * copies and that both the copyright notice and this permission notice *
32 * appear in the supporting documentation. The authors make no claims *
33 * about the suitability of this software for any purpose. It is *
34 * provided "as is" without express or implied warranty. *
35 **************************************************************************/
37 /** \class AliHLTDDLRawReaderFile
39 //_____________________________________________________________
40 // AliHLTDDLRawReaderFile (taken from the offline AliROOT code,
41 // original authors: D.Favretto and A.K.Mohanty)
43 // This is the base class for reading ddl raw data
44 // and providing information about digits
48 ClassImp(AliHLTDDLRawReaderFile)
50 AliHLTDDLRawReaderFile::AliHLTDDLRawReaderFile(const Char_t* name, Bool_t addnum)
52 // create an object to read digits from the given input file(s)
53 // if addNumber is true, a number starting at 1 is appended to the file name
55 fFileName = new Char_t[1024];
56 strcpy(fFileName,name);
60 fStream = new fstream(fFileName, ios::binary|ios::in);
62 fStream = new fstream(fFileName, ios::in);
69 fMiniHeader = new AliHLTDDLMiniHeader;
74 AliHLTDDLRawReaderFile::~AliHLTDDLRawReaderFile()
76 // close the input file
77 if(fFileName) delete fFileName;
80 #if defined(__HP_aCC) || defined(__DECCXX)
81 if (fStream->rdbuf()->is_open()) fStream->close();
83 if (fStream->is_open()) fStream->close();
88 if (fBuffer) delete[] fBuffer;
91 Bool_t AliHLTDDLRawReaderFile::OpenNextFile()
94 #if defined(__HP_aCC) || defined(__DECCXX)
95 if (fStream->rdbuf()->is_open()) fStream->close();
97 if (fStream->is_open()) fStream->close();
102 if (fFileNumber < 0) {
103 LOG(AliHLTLog::kError,"AliHLTDDLRawReaderFile::OpenNextFile","File")
104 <<"Could not open file, file number is negative."<<ENDLOG;
109 Char_t fileName[1024];
110 sprintf(fileName, "%s%d", fFileName, fFileNumber);
113 fStream = new fstream(fileName, ios::binary|ios::in);
115 fStream = new fstream(fileName, ios::in);
117 #if defined(__HP_aCC) || defined(__DECCXX)
118 return (fStream->rdbuf()->is_open());
120 return (fStream->is_open());
124 Bool_t AliHLTDDLRawReaderFile::ReadMiniHeader()
126 // read a mini header at the current stream position
127 // returns kFALSE if the mini header could not be read
129 if (!fStream) return kFALSE;
131 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
132 while (!fStream->read((Char_t*) fMiniHeader, sizeof(AliHLTDDLMiniHeader))) {
133 if (!OpenNextFile()) return kFALSE;
135 //cout << fMiniHeader->fSize << " " << fMiniHeader->fDetectorID << " " << fMiniHeader->fVersion << " " << fMiniHeader->fCompressionFlag << " " << fMiniHeader->fDDLID << endl;
136 //cout << "loop here " << (Int_t)fMiniHeader->fDDLID<< endl;
138 fCount = fMiniHeader->fSize;
139 } while (!IsSelected());
143 Bool_t AliHLTDDLRawReaderFile::ReadNextData(UChar_t*& data)
145 // reads the next payload at the current stream position
146 // returns kFALSE if the data could not be read
148 while (fCount == 0) {
149 if (!ReadMiniHeader()) return kFALSE;
151 if (fBufferSize < fCount) {
152 if (fBuffer) delete[] fBuffer;
153 fBufferSize = Int_t(fCount*1.2);
154 fBuffer = new UChar_t[fBufferSize];
156 if (!fStream->read((Char_t*) fBuffer, fCount)) {
157 LOG(AliHLTLog::kError,"AliHLTDDLRawReaderFile::ReadNextData","Data")
158 <<"Could not read next data!"<<ENDLOG;
167 Bool_t AliHLTDDLRawReaderFile::ReadNext(UChar_t* data, Int_t size)
169 // reads the next block of data at the current stream position
170 // returns kFALSE if the data could not be read
172 if (!fStream->read((Char_t*) data, size)) {
173 LOG(AliHLTLog::kError,"AliHLTDDLRawReaderFile::ReadNext","Data")
174 <<"Could not read next data!"<<ENDLOG;
181 Bool_t AliHLTDDLRawReaderFile::Reset()
183 // reset the current stream position to the beginning of the file
185 if ((fFileNumber > 0) && fStream) {
186 #if defined(__HP_aCC) || defined(__DECCXX)
187 if (fStream->rdbuf()->is_open()) fStream->close();
189 if (fStream->is_open()) fStream->close();
197 if (fFileNumber < 0) {
199 fStream = new fstream(fFileName, ios::binary|ios::in);
201 fStream = new fstream(fFileName, ios::in);
204 if (!OpenNextFile()){
205 LOG(AliHLTLog::kError,"AliHLTDDLRawReaderFile::Reset","Data")
206 <<"Could not reset data stream!"<<ENDLOG;
212 if (!fStream || !fStream->rdbuf()->is_open()) return kFALSE;