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