]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - RAW/AliRawReaderRoot.cxx
coding convention
[u/mrichter/AliRoot.git] / RAW / AliRawReaderRoot.cxx
... / ...
CommitLineData
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///////////////////////////////////////////////////////////////////////////////
17//
18// This is a class for reading a raw data from a root file and providing
19// information about digits
20//
21///////////////////////////////////////////////////////////////////////////////
22
23#include "AliRawReaderRoot.h"
24
25
26ClassImp(AliRawReaderRoot)
27
28
29AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber)
30{
31// create an object to read digits from the given input file for the
32// event with the given number
33
34 fFile = TFile::Open(fileName);
35 if (!fFile || !fFile->IsOpen()) {
36 Error("AliRawReaderRoot", "could not open file %s", fileName);
37 return;
38 }
39 TTree* tree = (TTree*) fFile->Get("RAW");
40 if (!tree) {
41 Error("AliRawReaderRoot", "no raw data tree found");
42 return;
43 }
44 TBranch* branch = tree->GetBranch("rawevent");
45 if (!branch) {
46 Error("AliRawReaderRoot", "no raw data branch found");
47 return;
48 }
49
50 fEvent = new AliRawEvent;
51 branch->SetAddress(&fEvent);
52 if (branch->GetEntry(eventNumber) <= 0) {
53 Error("AliRawReaderRoot", "no event with number %d found", eventNumber);
54 return;
55 }
56
57 fSubEventIndex = 0;
58 fSubEvent = NULL;
59 fRawData = NULL;
60 fMiniHeader = NULL;
61
62 fCount = 0;
63 fPosition = fEnd = NULL;
64}
65
66AliRawReaderRoot::AliRawReaderRoot(AliRawEvent* event)
67{
68// create an object to read digits from the given raw event
69
70 fFile = NULL;
71 fEvent = event;
72
73 fSubEventIndex = 0;
74 fSubEvent = NULL;
75 fRawData = NULL;
76 fMiniHeader = NULL;
77
78 fCount = 0;
79 fPosition = fEnd = NULL;
80}
81
82AliRawReaderRoot::~AliRawReaderRoot()
83{
84// delete objects and close root file
85
86 if (fFile) {
87 if (fEvent) delete fEvent;
88 fFile->Close();
89 delete fFile;
90 }
91}
92
93
94UInt_t AliRawReaderRoot::GetType()
95{
96// get the type from the event header
97
98 if (!fEvent) return 0;
99 return fEvent->GetHeader()->GetType();
100}
101
102UInt_t AliRawReaderRoot::GetRunNumber()
103{
104// get the run number from the event header
105
106 if (!fEvent) return 0;
107 return fEvent->GetHeader()->GetRunNumber();
108}
109
110const UInt_t* AliRawReaderRoot::GetEventId()
111{
112// get the event id from the event header
113
114 if (!fEvent) return NULL;
115 return fEvent->GetHeader()->GetId();
116}
117
118const UInt_t* AliRawReaderRoot::GetTriggerPattern()
119{
120// get the trigger pattern from the event header
121
122 if (!fEvent) return NULL;
123 return fEvent->GetHeader()->GetTriggerPattern();
124}
125
126const UInt_t* AliRawReaderRoot::GetDetectorPattern()
127{
128// get the detector pattern from the event header
129
130 if (!fEvent) return NULL;
131 return fEvent->GetHeader()->GetDetectorPattern();
132}
133
134const UInt_t* AliRawReaderRoot::GetAttributes()
135{
136// get the type attributes from the event header
137
138 if (!fEvent) return NULL;
139 return fEvent->GetHeader()->GetTypeAttribute();
140}
141
142UInt_t AliRawReaderRoot::GetGDCId()
143{
144// get the GDC Id from the event header
145
146 if (!fEvent) return 0;
147 return fEvent->GetHeader()->GetGDCId();
148}
149
150
151Bool_t AliRawReaderRoot::ReadMiniHeader()
152{
153// read a mini header at the current position
154// returns kFALSE if the mini header could not be read
155
156 if (!fEvent) return kFALSE;
157 do {
158 if (fCount > 0) fPosition += fCount; // skip payload if event was not selected
159 if (!fSubEvent || (fPosition >= fEnd)) { // new sub event
160 if (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
161 fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
162 fRawData = fSubEvent->GetRawData();
163 fCount = 0;
164 fPosition = (UChar_t*) fRawData->GetBuffer();
165 fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
166 }
167 if (fPosition >= fEnd) continue; // no data left in the payload
168 if (fPosition + sizeof(AliMiniHeader) > fEnd) {
169 Error("ReadMiniHeader", "could not read data!");
170 return kFALSE;
171 }
172 fMiniHeader = (AliMiniHeader*) fPosition;
173 fPosition += sizeof(AliMiniHeader);
174 CheckMiniHeader();
175 fCount = fMiniHeader->fSize;
176 if (fPosition + fCount > fEnd) { // check data size in mini header and sub event
177 Error("ReadMiniHeader", "size in mini header exceeds event size!");
178 fMiniHeader->fSize = fCount = fEnd - fPosition;
179 }
180 } while (!IsSelected());
181 return kTRUE;
182}
183
184Bool_t AliRawReaderRoot::ReadNextData(UChar_t*& data)
185{
186// reads the next payload at the current position
187// returns kFALSE if the data could not be read
188
189 while (fCount == 0) {
190 if (!ReadMiniHeader()) return kFALSE;
191 }
192 data = fPosition;
193 fPosition += fCount;
194 fCount = 0;
195 return kTRUE;
196}
197
198Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
199{
200// reads the next block of data at the current position
201// returns kFALSE if the data could not be read
202
203 if (fPosition + size > fEnd) {
204 Error("ReadNext", "could not read data!");
205 return kFALSE;
206 }
207 memcpy(data, fPosition, size);
208 fPosition += size;
209 fCount -= size;
210 return kTRUE;
211}
212
213
214Bool_t AliRawReaderRoot::Reset()
215{
216// reset the current position to the beginning of the event
217
218 fSubEventIndex = 0;
219 fSubEvent = NULL;
220 fRawData = NULL;
221 fMiniHeader = NULL;
222
223 fCount = 0;
224 fPosition = fEnd = NULL;
225 return kTRUE;
226}
227