]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderMemory.cxx
renamed CorrectionMatrix class
[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
299738b9 73void AliRawReaderMemory::RequireHeader(Bool_t required)
74{
75 // Reading of raw data in case of missing
76 // raw data header is not implemented for
77 // this class
78 if (!required)
79 Fatal("AliRawReaderMemory","Reading of raw data without raw data header is not implemented !");
80
81 AliRawReader::RequireHeader(required);
82}
83
7ab595b2 84Bool_t AliRawReaderMemory::ReadHeader()
85{
86// read a data header at the current buffer position
87// returns kFALSE if the mini header could not be read
88
89 if (!fBuffer) return kFALSE;
90 do {
91 if ( fPosition+fCount+sizeof(AliRawDataHeader) > fBufferSize ) return kFALSE;
92
93 memcpy( fHeader, fBuffer+fPosition+fCount, sizeof(AliRawDataHeader) );
299738b9 94 if (fHeader->fSize == 0) {
95 Warning("ReadHeader",
96 "Missing raw data header! Using the size of the memory buffer instead (%d) !",
97 fBufferSize - fPosition - fCount);
98 fHeader->fSize = fBufferSize - fPosition - fCount;
99 }
100 fPosition += fCount + sizeof(AliRawDataHeader);
7ab595b2 101
102 if (fHeader->fSize != 0xFFFFFFFF) {
103 // Check for fHeader->fSize < sizeof(AliRawDataHeader) ????
104 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
105 } else {
106 fCount = fBufferSize-fPosition;
107 }
108 } while (!IsSelected());
109 return kTRUE;
110}
111
112Bool_t AliRawReaderMemory::ReadNextData(UChar_t*& data)
113{
114// reads the next payload at the current buffer position
115// returns kFALSE if the data could not be read
116
117 while (fCount == 0) {
118 if (!ReadHeader()) return kFALSE;
119 }
120 UInt_t currentPosition = fPosition;
121 fPosition += fCount;
122 fCount = 0;
123
124 data = fBuffer+currentPosition;
125 return kTRUE;
126}
127
128Bool_t AliRawReaderMemory::ReadNext(UChar_t* data, Int_t size)
129{
130// reads the next block of data at the current buffer position
131// returns kFALSE if the data could not be read
132
133 if ( fBufferSize-fPosition < (UInt_t)size ) return kFALSE;
134
135 memcpy( data, fBuffer+fPosition, size );
136 fCount -= size;
137 fPosition += size;
138 return kTRUE;
139}
140
141
142Bool_t AliRawReaderMemory::Reset()
143{
144// reset the current position in the buffer to the beginning of the curevent
145
146 fCount = 0;
147 fPosition = 0;
148 return kTRUE;
149}
150
151Bool_t AliRawReaderMemory::NextEvent()
152{
153// each memory buffer always contains only one event
154 return kFALSE;
155}
156
157Bool_t AliRawReaderMemory::RewindEvents()
158{
159// reset the event counter
160
161 return Reset();
162}
163
164Bool_t AliRawReaderMemory::SetMemory( UChar_t* memory, ULong_t size )
165{
166 fBuffer = memory;
167 fBufferSize = size;
168 fCount = 0;
169 fPosition = 0;
170 return (fBuffer && fBufferSize>0) ? kTRUE : kFALSE;
171}
172