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