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() :
37 // create an object to read digits from
38 // the given memory location
40 fHeader = new AliRawDataHeader;
43 AliRawReaderMemory::AliRawReaderMemory(UChar_t* memory, UInt_t size) :
49 // create an object to read digits from the given memory
51 fHeader = new AliRawDataHeader;
54 AliRawReaderMemory::~AliRawReaderMemory()
56 // close the input memory
61 void AliRawReaderMemory::RequireHeader(Bool_t required)
63 // Reading of raw data in case of missing
64 // raw data header is not implemented for
67 Fatal("AliRawReaderMemory","Reading of raw data without raw data header is not implemented !");
69 AliRawReader::RequireHeader(required);
72 Bool_t AliRawReaderMemory::ReadHeader()
74 // read a data header at the current buffer position
75 // returns kFALSE if the mini header could not be read
77 if (!fBuffer) return kFALSE;
79 if ( fPosition+fCount+sizeof(AliRawDataHeader) > fBufferSize ) return kFALSE;
81 memcpy( fHeader, fBuffer+fPosition+fCount, sizeof(AliRawDataHeader) );
82 if (fHeader->fSize == 0) {
84 "Missing raw data header! Using the size of the memory buffer instead (%d) !",
85 fBufferSize - fPosition - fCount);
86 fHeader->fSize = fBufferSize - fPosition - fCount;
88 fPosition += fCount + sizeof(AliRawDataHeader);
90 if (fHeader->fSize != 0xFFFFFFFF) {
91 // Check for fHeader->fSize < sizeof(AliRawDataHeader) ????
92 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
94 fCount = fBufferSize-fPosition;
96 } while (!IsSelected());
100 Bool_t AliRawReaderMemory::ReadNextData(UChar_t*& data)
102 // reads the next payload at the current buffer position
103 // returns kFALSE if the data could not be read
105 while (fCount == 0) {
106 if (!ReadHeader()) return kFALSE;
108 UInt_t currentPosition = fPosition;
112 data = fBuffer+currentPosition;
116 Bool_t AliRawReaderMemory::ReadNext(UChar_t* data, Int_t size)
118 // reads the next block of data at the current buffer position
119 // returns kFALSE if the data could not be read
121 if ( fBufferSize-fPosition < (UInt_t)size ) return kFALSE;
123 memcpy( data, fBuffer+fPosition, size );
130 Bool_t AliRawReaderMemory::Reset()
132 // reset the current position in the buffer to the beginning of the curevent
139 Bool_t AliRawReaderMemory::NextEvent()
141 // each memory buffer always contains only one event
142 if (fEventNumber < 0) {
150 Bool_t AliRawReaderMemory::RewindEvents()
152 // reset the event counter
158 Bool_t AliRawReaderMemory::SetMemory( UChar_t* memory, ULong_t size )
164 return (fBuffer && fBufferSize>0) ? kTRUE : kFALSE;