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"
12 /**************************************************************************
13 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
15 * Author: The ALICE Off-line Project. *
16 * Contributors are mentioned in the code where appropriate. *
18 * Permission to use, copy, modify and distribute this software and its *
19 * documentation strictly for non-commercial purposes is hereby granted *
20 * without fee, provided that the above copyright notice appears in all *
21 * copies and that both the copyright notice and this permission notice *
22 * appear in the supporting documentation. The authors make no claims *
23 * about the suitability of this software for any purpose. It is *
24 * provided "as is" without express or implied warranty. *
25 **************************************************************************/
27 /** \class AliL3DDLRawReaderFile
29 //_____________________________________________________________
30 // AliL3DDLRawReaderFile (taken from the offline AliROOT code,
31 // original authors: D.Favretto and A.K.Mohanty)
33 // This is the base class for reading ddl raw data
34 // and providing information about digits
39 ClassImp(AliL3DDLRawReaderFile)
42 AliL3DDLRawReaderFile::AliL3DDLRawReaderFile(const Char_t* name, Bool_t addnum)
44 // create an object to read digits from the given input file(s)
45 // if addNumber is true, a number starting at 1 is appended to the file name
47 fFileName = new Char_t[1024];
48 strcpy(fFileName,name);
51 fStream = new fstream(fFileName, ios::binary|ios::in);
57 fMiniHeader = new AliL3DDLMiniHeader;
62 AliL3DDLRawReaderFile::~AliL3DDLRawReaderFile()
64 // close the input file
65 if(fFileName) delete fFileName;
68 if (fStream->is_open()) fStream->close();
72 if (fBuffer) delete[] fBuffer;
75 Bool_t AliL3DDLRawReaderFile::OpenNextFile()
78 if (fStream->is_open()) fStream->close();
82 if (fFileNumber < 0) {
83 LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::OpenNextFile","File")
84 <<"Could not open file, file number is negative."<<ENDLOG;
89 Char_t fileName[1024];
90 sprintf(fileName, "%s%d", fFileName, fFileNumber);
92 fStream = new fstream(fileName, ios::binary|ios::in);
93 return (fStream->is_open());
96 Bool_t AliL3DDLRawReaderFile::ReadMiniHeader()
98 // read a mini header at the current stream position
99 // returns kFALSE if the mini header could not be read
101 if (!fStream) return kFALSE;
103 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
104 while (!fStream->read((Char_t*) fMiniHeader, sizeof(AliL3DDLMiniHeader))) {
105 if (!OpenNextFile()) return kFALSE;
107 //cout << fMiniHeader->fSize << " " << fMiniHeader->fDetectorID << " " << fMiniHeader->fVersion << " " << fMiniHeader->fCompressionFlag << " " << fMiniHeader->fDDLID << endl;
108 //cout << "loop here " << (Int_t)fMiniHeader->fDDLID<< endl;
110 fCount = fMiniHeader->fSize;
111 } while (!IsSelected());
115 Bool_t AliL3DDLRawReaderFile::ReadNextData(UChar_t*& data)
117 // reads the next payload at the current stream position
118 // returns kFALSE if the data could not be read
120 while (fCount == 0) {
121 if (!ReadMiniHeader()) return kFALSE;
123 if (fBufferSize < fCount) {
124 if (fBuffer) delete[] fBuffer;
125 fBufferSize = Int_t(fCount*1.2);
126 fBuffer = new UChar_t[fBufferSize];
128 if (!fStream->read((Char_t*) fBuffer, fCount)) {
129 LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::ReadNextData","Data")
130 <<"Could not read next data!"<<ENDLOG;
139 Bool_t AliL3DDLRawReaderFile::ReadNext(UChar_t* data, Int_t size)
141 // reads the next block of data at the current stream position
142 // returns kFALSE if the data could not be read
144 if (!fStream->read((Char_t*) data, size)) {
145 LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::ReadNext","Data")
146 <<"Could not read next data!"<<ENDLOG;
153 Bool_t AliL3DDLRawReaderFile::Reset()
155 // reset the current stream position to the beginning of the file
157 if ((fFileNumber > 0) && fStream) {
158 if (fStream->is_open()) fStream->close();
165 if (fFileNumber < 0) {
166 fStream = new fstream(fFileName, ios::binary|ios::in);
168 if (!OpenNextFile()){
169 LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::Reset","Data")
170 <<"Could not reset data stream!"<<ENDLOG;
176 if (!fStream || !fStream->rdbuf()->is_open()) return kFALSE;