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
41 AliRawReaderMemory::AliRawReaderMemory(UChar_t* memory, UInt_t size) :
47 // create an object to read digits from the given memory
50 AliRawReaderMemory::~AliRawReaderMemory()
52 // close the input memory
55 void AliRawReaderMemory::RequireHeader(Bool_t required)
57 // Reading of raw data in case of missing
58 // raw data header is not implemented for
61 Fatal("AliRawReaderMemory","Reading of raw data without raw data header is not implemented !");
63 AliRawReader::RequireHeader(required);
66 Bool_t AliRawReaderMemory::ReadHeader()
68 // read a data header at the current buffer position
69 // returns kFALSE if the mini header could not be read
71 if (fEquipmentId == -1)
73 Warning("ReadHeader", "The equipment ID is not set for the DDL memory buffer.");
76 if (!fBuffer) return kFALSE;
78 // Check if we would not read past the end of the buffer.
79 if ( fPosition+fCount+sizeof(AliRawDataHeader) > fBufferSize ) return kFALSE;
81 fHeader = reinterpret_cast<AliRawDataHeader*>(fBuffer+fPosition+fCount);
83 // Check that the header is sane, that is the size does not go past the buffer.
84 // Otherwise try again at the next word location.
85 if (fHeader->fSize == 0 or fPosition+fCount+fHeader->fSize > fBufferSize) {
86 if (fPosition + sizeof(UInt_t) <= fBufferSize) {
87 fPosition += sizeof(UInt_t);
90 Error("ReadHeader", "Could not find a valid DDL header!");
94 fPosition += fCount + sizeof(AliRawDataHeader);
97 if (fHeader->fSize != 0xFFFFFFFF) {
98 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
100 fCount = fBufferSize - fPosition - sizeof(AliRawDataHeader);
102 } while (!IsSelected());
107 Bool_t AliRawReaderMemory::ReadNextData(UChar_t*& data)
109 // reads the next payload at the current buffer position
110 // returns kFALSE if the data could not be read
112 while (fCount == 0) {
113 if (!ReadHeader()) return kFALSE;
115 UInt_t currentPosition = fPosition;
119 data = fBuffer+currentPosition;
123 Bool_t AliRawReaderMemory::ReadNext(UChar_t* data, Int_t size)
125 // reads the next block of data at the current buffer position
126 // returns kFALSE if the data could not be read
128 if ( fBufferSize-fPosition < (UInt_t)size ) return kFALSE;
130 memcpy( data, fBuffer+fPosition, size );
137 Bool_t AliRawReaderMemory::Reset()
139 // reset the current position in the buffer to the beginning of the curevent
147 Bool_t AliRawReaderMemory::NextEvent()
149 // each memory buffer always contains only one event
150 if (fEventNumber < 0) {
158 Bool_t AliRawReaderMemory::RewindEvents()
160 // reset the event counter
166 Bool_t AliRawReaderMemory::SetMemory( UChar_t* memory, ULong_t size )
173 return (fBuffer && fBufferSize>0) ? kTRUE : kFALSE;