1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This is a class for reading raw data memory buffers.
22 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliRawReaderMemory.h"
28 ClassImp(AliRawReaderMemory)
31 AliRawReaderMemory::AliRawReaderMemory() :
36 // create an object to read digits from
37 // the given memory location
39 fHeader = new AliRawDataHeader;
42 AliRawReaderMemory::AliRawReaderMemory(UChar_t* memory, UInt_t size) :
47 // create an object to read digits from the given memory
49 fHeader = new AliRawDataHeader;
52 AliRawReaderMemory::~AliRawReaderMemory()
54 // close the input memory
60 AliRawReaderMemory::AliRawReaderMemory(const AliRawReaderMemory& rawReader) :
61 AliRawReader(rawReader)
63 Fatal("AliRawReaderMemory", "copy constructor not implemented");
66 AliRawReaderMemory& AliRawReaderMemory::operator = (const AliRawReaderMemory&
69 Fatal("operator =", "assignment operator not implemented");
73 void AliRawReaderMemory::RequireHeader(Bool_t required)
75 // Reading of raw data in case of missing
76 // raw data header is not implemented for
79 Fatal("AliRawReaderMemory","Reading of raw data without raw data header is not implemented !");
81 AliRawReader::RequireHeader(required);
84 Bool_t AliRawReaderMemory::ReadHeader()
86 // read a data header at the current buffer position
87 // returns kFALSE if the mini header could not be read
89 if (!fBuffer) return kFALSE;
91 if ( fPosition+fCount+sizeof(AliRawDataHeader) > fBufferSize ) return kFALSE;
93 memcpy( fHeader, fBuffer+fPosition+fCount, sizeof(AliRawDataHeader) );
94 if (fHeader->fSize == 0) {
96 "Missing raw data header! Using the size of the memory buffer instead (%d) !",
97 fBufferSize - fPosition - fCount);
98 fHeader->fSize = fBufferSize - fPosition - fCount;
100 fPosition += fCount + sizeof(AliRawDataHeader);
102 if (fHeader->fSize != 0xFFFFFFFF) {
103 // Check for fHeader->fSize < sizeof(AliRawDataHeader) ????
104 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
106 fCount = fBufferSize-fPosition;
108 } while (!IsSelected());
112 Bool_t AliRawReaderMemory::ReadNextData(UChar_t*& data)
114 // reads the next payload at the current buffer position
115 // returns kFALSE if the data could not be read
117 while (fCount == 0) {
118 if (!ReadHeader()) return kFALSE;
120 UInt_t currentPosition = fPosition;
124 data = fBuffer+currentPosition;
128 Bool_t AliRawReaderMemory::ReadNext(UChar_t* data, Int_t size)
130 // reads the next block of data at the current buffer position
131 // returns kFALSE if the data could not be read
133 if ( fBufferSize-fPosition < (UInt_t)size ) return kFALSE;
135 memcpy( data, fBuffer+fPosition, size );
142 Bool_t AliRawReaderMemory::Reset()
144 // reset the current position in the buffer to the beginning of the curevent
151 Bool_t AliRawReaderMemory::NextEvent()
153 // each memory buffer always contains only one event
157 Bool_t AliRawReaderMemory::RewindEvents()
159 // reset the event counter
164 Bool_t AliRawReaderMemory::SetMemory( UChar_t* memory, ULong_t size )
170 return (fBuffer && fBufferSize>0) ? kTRUE : kFALSE;