]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderMemory.cxx
Added comments for inline functions
[u/mrichter/AliRoot.git] / RAW / AliRawReaderMemory.cxx
CommitLineData
7ab595b2 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19///
20/// This is a class for reading raw data memory buffers.
21///
22///////////////////////////////////////////////////////////////////////////////
23
24#include "AliRawReaderMemory.h"
25#include <TSystem.h>
26
27
28ClassImp(AliRawReaderMemory)
29
30
31AliRawReaderMemory::AliRawReaderMemory() :
32 fBuffer(NULL),
33 fBufferSize(0),
34 fPosition(0)
35{
36// create an object to read digits from
37// the given memory location
38
39 fHeader = new AliRawDataHeader;
40}
41
42AliRawReaderMemory::AliRawReaderMemory(UChar_t* memory, UInt_t size) :
43 fBuffer(memory),
44 fBufferSize(size),
45 fPosition(0)
46{
47// create an object to read digits from the given memory
48
49 fHeader = new AliRawDataHeader;
50}
51
52AliRawReaderMemory::~AliRawReaderMemory()
53{
54// close the input memory
55
56 delete fHeader;
57}
58
59
60AliRawReaderMemory::AliRawReaderMemory(const AliRawReaderMemory& rawReader) :
61 AliRawReader(rawReader)
62{
63 Fatal("AliRawReaderMemory", "copy constructor not implemented");
64}
65
66AliRawReaderMemory& AliRawReaderMemory::operator = (const AliRawReaderMemory&
67 /* rawReader */)
68{
69 Fatal("operator =", "assignment operator not implemented");
70 return *this;
71}
72
73Bool_t AliRawReaderMemory::ReadHeader()
74{
75// read a data header at the current buffer position
76// returns kFALSE if the mini header could not be read
77
78 if (!fBuffer) return kFALSE;
79 do {
80 if ( fPosition+fCount+sizeof(AliRawDataHeader) > fBufferSize ) return kFALSE;
81
82 memcpy( fHeader, fBuffer+fPosition+fCount, sizeof(AliRawDataHeader) );
83 fPosition += fCount+sizeof(AliRawDataHeader);
84
85 if (fHeader->fSize != 0xFFFFFFFF) {
86 // Check for fHeader->fSize < sizeof(AliRawDataHeader) ????
87 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
88 } else {
89 fCount = fBufferSize-fPosition;
90 }
91 } while (!IsSelected());
92 return kTRUE;
93}
94
95Bool_t AliRawReaderMemory::ReadNextData(UChar_t*& data)
96{
97// reads the next payload at the current buffer position
98// returns kFALSE if the data could not be read
99
100 while (fCount == 0) {
101 if (!ReadHeader()) return kFALSE;
102 }
103 UInt_t currentPosition = fPosition;
104 fPosition += fCount;
105 fCount = 0;
106
107 data = fBuffer+currentPosition;
108 return kTRUE;
109}
110
111Bool_t AliRawReaderMemory::ReadNext(UChar_t* data, Int_t size)
112{
113// reads the next block of data at the current buffer position
114// returns kFALSE if the data could not be read
115
116 if ( fBufferSize-fPosition < (UInt_t)size ) return kFALSE;
117
118 memcpy( data, fBuffer+fPosition, size );
119 fCount -= size;
120 fPosition += size;
121 return kTRUE;
122}
123
124
125Bool_t AliRawReaderMemory::Reset()
126{
127// reset the current position in the buffer to the beginning of the curevent
128
129 fCount = 0;
130 fPosition = 0;
131 return kTRUE;
132}
133
134Bool_t AliRawReaderMemory::NextEvent()
135{
136// each memory buffer always contains only one event
137 return kFALSE;
138}
139
140Bool_t AliRawReaderMemory::RewindEvents()
141{
142// reset the event counter
143
144 return Reset();
145}
146
147Bool_t AliRawReaderMemory::SetMemory( UChar_t* memory, ULong_t size )
148{
149 fBuffer = memory;
150 fBufferSize = size;
151 fCount = 0;
152 fPosition = 0;
153 return (fBuffer && fBufferSize>0) ? kTRUE : kFALSE;
154}
155