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