3 // Author: Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3RootTypes.h"
7 #include "AliL3StandardIncludes.h"
8 #include "AliL3Logging.h"
10 #include "AliL3DDLRawReaderFile.h"
16 /**************************************************************************
17 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
19 * Author: The ALICE Off-line Project. *
20 * Contributors are mentioned in the code where appropriate. *
22 * Permission to use, copy, modify and distribute this software and its *
23 * documentation strictly for non-commercial purposes is hereby granted *
24 * without fee, provided that the above copyright notice appears in all *
25 * copies and that both the copyright notice and this permission notice *
26 * appear in the supporting documentation. The authors make no claims *
27 * about the suitability of this software for any purpose. It is *
28 * provided "as is" without express or implied warranty. *
29 **************************************************************************/
31 /** \class AliL3DDLRawReaderFile
33 //_____________________________________________________________
34 // AliL3DDLRawReaderFile (taken from the offline AliROOT code,
35 // original authors: D.Favretto and A.K.Mohanty)
37 // This is the base class for reading ddl raw data
38 // and providing information about digits
42 ClassImp(AliL3DDLRawReaderFile)
44 AliL3DDLRawReaderFile::AliL3DDLRawReaderFile(const Char_t* name, Bool_t addnum)
46 // create an object to read digits from the given input file(s)
47 // if addNumber is true, a number starting at 1 is appended to the file name
49 fFileName = new Char_t[1024];
50 strcpy(fFileName,name);
54 fStream = new fstream(fFileName, ios::binary|ios::in);
56 fStream = new fstream(fFileName, ios::in);
63 fMiniHeader = new AliL3DDLMiniHeader;
68 AliL3DDLRawReaderFile::~AliL3DDLRawReaderFile()
70 // close the input file
71 if(fFileName) delete fFileName;
74 #if defined(__HP_aCC) || defined(__DECCXX)
75 if (fStream->rdbuf()->is_open()) fStream->close();
77 if (fStream->is_open()) fStream->close();
82 if (fBuffer) delete[] fBuffer;
85 Bool_t AliL3DDLRawReaderFile::OpenNextFile()
88 #if defined(__HP_aCC) || defined(__DECCXX)
89 if (fStream->rdbuf()->is_open()) fStream->close();
91 if (fStream->is_open()) fStream->close();
96 if (fFileNumber < 0) {
97 LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::OpenNextFile","File")
98 <<"Could not open file, file number is negative."<<ENDLOG;
103 Char_t fileName[1024];
104 sprintf(fileName, "%s%d", fFileName, fFileNumber);
107 fStream = new fstream(fileName, ios::binary|ios::in);
109 fStream = new fstream(fileName, ios::in);
111 #if defined(__HP_aCC) || defined(__DECCXX)
112 return (fStream->rdbuf()->is_open());
114 return (fStream->is_open());
118 Bool_t AliL3DDLRawReaderFile::ReadMiniHeader()
120 // read a mini header at the current stream position
121 // returns kFALSE if the mini header could not be read
123 if (!fStream) return kFALSE;
125 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
126 while (!fStream->read((Char_t*) fMiniHeader, sizeof(AliL3DDLMiniHeader))) {
127 if (!OpenNextFile()) return kFALSE;
129 //cout << fMiniHeader->fSize << " " << fMiniHeader->fDetectorID << " " << fMiniHeader->fVersion << " " << fMiniHeader->fCompressionFlag << " " << fMiniHeader->fDDLID << endl;
130 //cout << "loop here " << (Int_t)fMiniHeader->fDDLID<< endl;
132 fCount = fMiniHeader->fSize;
133 } while (!IsSelected());
137 Bool_t AliL3DDLRawReaderFile::ReadNextData(UChar_t*& data)
139 // reads the next payload at the current stream position
140 // returns kFALSE if the data could not be read
142 while (fCount == 0) {
143 if (!ReadMiniHeader()) return kFALSE;
145 if (fBufferSize < fCount) {
146 if (fBuffer) delete[] fBuffer;
147 fBufferSize = Int_t(fCount*1.2);
148 fBuffer = new UChar_t[fBufferSize];
150 if (!fStream->read((Char_t*) fBuffer, fCount)) {
151 LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::ReadNextData","Data")
152 <<"Could not read next data!"<<ENDLOG;
161 Bool_t AliL3DDLRawReaderFile::ReadNext(UChar_t* data, Int_t size)
163 // reads the next block of data at the current stream position
164 // returns kFALSE if the data could not be read
166 if (!fStream->read((Char_t*) data, size)) {
167 LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::ReadNext","Data")
168 <<"Could not read next data!"<<ENDLOG;
175 Bool_t AliL3DDLRawReaderFile::Reset()
177 // reset the current stream position to the beginning of the file
179 if ((fFileNumber > 0) && fStream) {
180 #if defined(__HP_aCC) || defined(__DECCXX)
181 if (fStream->rdbuf()->is_open()) fStream->close();
183 if (fStream->is_open()) fStream->close();
191 if (fFileNumber < 0) {
193 fStream = new fstream(fFileName, ios::binary|ios::in);
195 fStream = new fstream(fFileName, ios::in);
198 if (!OpenNextFile()){
199 LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::Reset","Data")
200 <<"Could not reset data stream!"<<ENDLOG;
206 if (!fStream || !fStream->rdbuf()->is_open()) return kFALSE;