]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderMemory.cxx
Write trigger digits if SAVEDIGITS activated (Bogdan)
[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
7ab595b2 39}
40
41AliRawReaderMemory::AliRawReaderMemory(UChar_t* memory, UInt_t size) :
42 fBuffer(memory),
43 fBufferSize(size),
f3c1e83c 44 fPosition(0),
45 fEquipmentId(-1)
7ab595b2 46{
47// create an object to read digits from the given memory
7ab595b2 48}
49
50AliRawReaderMemory::~AliRawReaderMemory()
51{
52// close the input memory
7ab595b2 53}
54
299738b9 55void AliRawReaderMemory::RequireHeader(Bool_t required)
56{
57 // Reading of raw data in case of missing
58 // raw data header is not implemented for
59 // this class
60 if (!required)
61 Fatal("AliRawReaderMemory","Reading of raw data without raw data header is not implemented !");
62
63 AliRawReader::RequireHeader(required);
64}
65
7ab595b2 66Bool_t AliRawReaderMemory::ReadHeader()
67{
68// read a data header at the current buffer position
69// returns kFALSE if the mini header could not be read
70
b6ae8ba1 71 if (fEquipmentId == -1)
72 {
73 Warning("ReadHeader", "The equipment ID is not set for the DDL memory buffer.");
74 }
75
7ab595b2 76 if (!fBuffer) return kFALSE;
77 do {
b6ae8ba1 78 // Check if we would not read past the end of the buffer.
7ab595b2 79 if ( fPosition+fCount+sizeof(AliRawDataHeader) > fBufferSize ) return kFALSE;
b6ae8ba1 80
81 fHeader = reinterpret_cast<AliRawDataHeader*>(fBuffer+fPosition+fCount);
82
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.
76a7ad7a 85 if ( ( (fHeader->fSize == 0) ||
86 ((Int_t)fPosition + fCount + (Int_t)fHeader->fSize > (Int_t)fBufferSize ) )
87 && fHeader->fSize != 0xFFFFFFFF) {
88
b6ae8ba1 89 if (fPosition + sizeof(UInt_t) <= fBufferSize) {
90 fPosition += sizeof(UInt_t);
91 continue;
92 } else {
93 Error("ReadHeader", "Could not find a valid DDL header!");
94 return kFALSE;
299738b9 95 }
b6ae8ba1 96 } else {
97 fPosition += fCount + sizeof(AliRawDataHeader);
98 }
7ab595b2 99
100 if (fHeader->fSize != 0xFFFFFFFF) {
7ab595b2 101 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
102 } else {
76a7ad7a 103 fCount = fBufferSize - sizeof(AliRawDataHeader);
7ab595b2 104 }
105 } while (!IsSelected());
b6ae8ba1 106
7ab595b2 107 return kTRUE;
108}
109
110Bool_t AliRawReaderMemory::ReadNextData(UChar_t*& data)
111{
112// reads the next payload at the current buffer position
113// returns kFALSE if the data could not be read
114
115 while (fCount == 0) {
116 if (!ReadHeader()) return kFALSE;
117 }
118 UInt_t currentPosition = fPosition;
119 fPosition += fCount;
120 fCount = 0;
121
122 data = fBuffer+currentPosition;
123 return kTRUE;
124}
125
126Bool_t AliRawReaderMemory::ReadNext(UChar_t* data, Int_t size)
127{
128// reads the next block of data at the current buffer position
129// returns kFALSE if the data could not be read
130
131 if ( fBufferSize-fPosition < (UInt_t)size ) return kFALSE;
132
133 memcpy( data, fBuffer+fPosition, size );
134 fCount -= size;
135 fPosition += size;
136 return kTRUE;
137}
138
139
140Bool_t AliRawReaderMemory::Reset()
141{
142// reset the current position in the buffer to the beginning of the curevent
143
b6ae8ba1 144 fHeader = NULL;
7ab595b2 145 fCount = 0;
146 fPosition = 0;
147 return kTRUE;
148}
149
150Bool_t AliRawReaderMemory::NextEvent()
151{
152// each memory buffer always contains only one event
59a76075 153 if (fEventNumber < 0) {
154 fEventNumber++;
155 return kTRUE;
156 }
157 else
158 return kFALSE;
7ab595b2 159}
160
161Bool_t AliRawReaderMemory::RewindEvents()
162{
163// reset the event counter
59a76075 164 fEventNumber = -1;
7ab595b2 165
166 return Reset();
167}
168
169Bool_t AliRawReaderMemory::SetMemory( UChar_t* memory, ULong_t size )
170{
171 fBuffer = memory;
172 fBufferSize = size;
b6ae8ba1 173 fHeader = NULL;
7ab595b2 174 fCount = 0;
175 fPosition = 0;
176 return (fBuffer && fBufferSize>0) ? kTRUE : kFALSE;
177}
178