Interface to the new class for storing and retrieving of the raw-data decoding errors...
[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),
f3c1e83c 34 fPosition(0),
35 fEquipmentId(-1)
7ab595b2 36{
37// create an object to read digits from
38// the given memory location
39
40 fHeader = new AliRawDataHeader;
38cf12f3 41
42 fEventNumber = 0;
7ab595b2 43}
44
45AliRawReaderMemory::AliRawReaderMemory(UChar_t* memory, UInt_t size) :
46 fBuffer(memory),
47 fBufferSize(size),
f3c1e83c 48 fPosition(0),
49 fEquipmentId(-1)
7ab595b2 50{
51// create an object to read digits from the given memory
52
53 fHeader = new AliRawDataHeader;
38cf12f3 54
55 fEventNumber = 0;
7ab595b2 56}
57
58AliRawReaderMemory::~AliRawReaderMemory()
59{
60// close the input memory
61
62 delete fHeader;
63}
64
299738b9 65void AliRawReaderMemory::RequireHeader(Bool_t required)
66{
67 // Reading of raw data in case of missing
68 // raw data header is not implemented for
69 // this class
70 if (!required)
71 Fatal("AliRawReaderMemory","Reading of raw data without raw data header is not implemented !");
72
73 AliRawReader::RequireHeader(required);
74}
75
7ab595b2 76Bool_t AliRawReaderMemory::ReadHeader()
77{
78// read a data header at the current buffer position
79// returns kFALSE if the mini header could not be read
80
81 if (!fBuffer) return kFALSE;
82 do {
83 if ( fPosition+fCount+sizeof(AliRawDataHeader) > fBufferSize ) return kFALSE;
84
85 memcpy( fHeader, fBuffer+fPosition+fCount, sizeof(AliRawDataHeader) );
299738b9 86 if (fHeader->fSize == 0) {
87 Warning("ReadHeader",
88 "Missing raw data header! Using the size of the memory buffer instead (%d) !",
89 fBufferSize - fPosition - fCount);
90 fHeader->fSize = fBufferSize - fPosition - fCount;
91 }
92 fPosition += fCount + sizeof(AliRawDataHeader);
7ab595b2 93
94 if (fHeader->fSize != 0xFFFFFFFF) {
95 // Check for fHeader->fSize < sizeof(AliRawDataHeader) ????
96 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
97 } else {
98 fCount = fBufferSize-fPosition;
99 }
100 } while (!IsSelected());
101 return kTRUE;
102}
103
104Bool_t AliRawReaderMemory::ReadNextData(UChar_t*& data)
105{
106// reads the next payload at the current buffer position
107// returns kFALSE if the data could not be read
108
109 while (fCount == 0) {
110 if (!ReadHeader()) return kFALSE;
111 }
112 UInt_t currentPosition = fPosition;
113 fPosition += fCount;
114 fCount = 0;
115
116 data = fBuffer+currentPosition;
117 return kTRUE;
118}
119
120Bool_t AliRawReaderMemory::ReadNext(UChar_t* data, Int_t size)
121{
122// reads the next block of data at the current buffer position
123// returns kFALSE if the data could not be read
124
125 if ( fBufferSize-fPosition < (UInt_t)size ) return kFALSE;
126
127 memcpy( data, fBuffer+fPosition, size );
128 fCount -= size;
129 fPosition += size;
130 return kTRUE;
131}
132
133
134Bool_t AliRawReaderMemory::Reset()
135{
136// reset the current position in the buffer to the beginning of the curevent
137
138 fCount = 0;
139 fPosition = 0;
140 return kTRUE;
141}
142
143Bool_t AliRawReaderMemory::NextEvent()
144{
145// each memory buffer always contains only one event
146 return kFALSE;
147}
148
149Bool_t AliRawReaderMemory::RewindEvents()
150{
151// reset the event counter
152
153 return Reset();
154}
155
156Bool_t AliRawReaderMemory::SetMemory( UChar_t* memory, ULong_t size )
157{
158 fBuffer = memory;
159 fBufferSize = size;
160 fCount = 0;
161 fPosition = 0;
162 return (fBuffer && fBufferSize>0) ? kTRUE : kFALSE;
163}
164