]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/src/AliRoot/TrackSink.cxx
Replacing some non-standard operators (not,and,or) with the standard ones. Code clean-up
[u/mrichter/AliRoot.git] / HLT / MUON / src / AliRoot / TrackSink.cxx
CommitLineData
8356cc1d 1////////////////////////////////////////////////////////////////////////////////
2//
3// Author: Artur Szostak
4// Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
5//
6////////////////////////////////////////////////////////////////////////////////
7
8#include "AliRoot/TrackSink.hpp"
9#include "AliRoot/Base.hpp"
10
cbee67e7 11ClassImp(AliMUONHLT::TrackSink)
12ClassImp(AliMUONHLT::TrackSink::EventData)
8356cc1d 13
14namespace AliMUONHLT
15{
16
17
18TrackSink::TrackSink() :
19 TObject(), fEventList(TrackSink::EventData::Class())
20{
21 fFilename = "";
22 fFoldername = "";
23 ResetAllPointers();
cbee67e7 24}
8356cc1d 25
26
27TrackSink::~TrackSink()
28{
29 DebugMsg(1, "TrackSink::~TrackSink()");
30 fEventList.Clear("C");
cbee67e7 31}
8356cc1d 32
33
e33f3609 34void TrackSink::AddEvent(Int_t eventnumber)
8356cc1d 35{
36 DebugMsg(1, "TrackSink::AddEvent(" << eventnumber << ")");
37
38 if (eventnumber < 0)
39 {
40 Error("AddEvent", "The event number must be positive, got: %d", eventnumber);
41 return;
42 };
43
44 // Make sure that the event number is not already added to the list of events.
45 TIter next(&fEventList);
46 EventData* current;
47 while ((current = (EventData*)next()))
48 {
49 if (current->fEventNumber == eventnumber)
50 {
51 Error("AddEvent", "The event number %d is already stored.", eventnumber);
52 return;
53 };
54 };
55
56 fEventIndex = fEventList.GetEntriesFast();
57 new ( fEventList[fEventIndex] ) EventData(eventnumber);
58 fCurrentEvent = (EventData*) fEventList[fEventIndex];
59
60 // Remember to reset the other pointers because the new event is empty.
61 ResetBlockPointers();
62
63 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
64 << " , fTrackIndex = " << fTrackIndex
65 );
cbee67e7 66}
8356cc1d 67
68
69void TrackSink::AddBlock()
70{
71 DebugMsg(1, "TrackSink::AddBlock()");
72
73 if (fCurrentEvent == NULL)
74 {
75 Error("AddBlock", "No event selected.");
76 return;
77 };
78
79 fBlockIndex = fCurrentEvent->fBlocks.GetEntriesFast();
80 new ( fCurrentEvent->fBlocks[fBlockIndex] ) TClonesArray(Track::Class());
81 fCurrentBlock = (TClonesArray*) fCurrentEvent->fBlocks[fBlockIndex];
82
83 // Remember to reset the track pointer because the new block is empty.
84 ResetTrackPointers();
85
86 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
87 << " , fTrackIndex = " << fTrackIndex
88 );
cbee67e7 89}
8356cc1d 90
91
92void TrackSink::AddTrack(const Track& track)
93{
94 DebugMsg(1, "TrackSink::AddTrack()");
95
96 if (fCurrentBlock == NULL)
97 {
98 Error("AddTrack", "No block selected.");
99 return;
100 };
101
102 fTrackIndex = fCurrentBlock->GetEntriesFast();
103 new ( (*fCurrentBlock)[fTrackIndex] ) Track(track);
104 fCurrentTrack = (Track*) (*fCurrentBlock)[fTrackIndex];
105
106 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
107 << " , fTrackIndex = " << fTrackIndex
108 );
cbee67e7 109}
8356cc1d 110
111
112Track* TrackSink::AddTrack()
113{
114 DebugMsg(1, "TrackSink::AddTrack()");
115
116 if (fCurrentBlock == NULL)
117 {
118 Error("AddTrack", "No block selected.");
119 return NULL;
120 };
121
122 fTrackIndex = fCurrentBlock->GetEntriesFast();
123 fCurrentTrack = (Track*) fCurrentBlock->New(fTrackIndex);
124
125 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
126 << " , fTrackIndex = " << fTrackIndex
127 );
128 return fCurrentTrack;
129};
130
131
132void TrackSink::AddTrack(
e33f3609 133 Int_t triggerid, Int_t sign, Float_t momentum,
134 Float_t pt, const Point hits[10], const Region regions[10]
8356cc1d 135 )
136{
137 DebugMsg(1, "TrackSink::AddTrack(" << triggerid << ", " << sign << ", "
138 << momentum << ", " << pt << ", " << (void*)(&hits[0]) << ", "
139 << (void*)(&regions[0]) << ")"
140 );
141
142 if (fCurrentBlock == NULL)
143 {
144 Error("AddTrack", "No block selected.");
145 return;
146 };
147
148 fTrackIndex = fCurrentBlock->GetEntriesFast();
149 new ( (*fCurrentBlock)[fTrackIndex] ) Track(triggerid, sign, momentum, pt, hits, regions);
150 fCurrentTrack = (Track*) (*fCurrentBlock)[fTrackIndex];
151
152 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
153 << " , fTrackIndex = " << fTrackIndex
154 );
cbee67e7 155}
8356cc1d 156
157
158void TrackSink::SetNames(const TriggerSource* triggersource)
159{
160 fFilename = triggersource->FileName();
161 fFoldername = triggersource->FolderName();
cbee67e7 162}
8356cc1d 163
164
12ab84fc 165void TrackSink::Clear(Option_t* /*option*/)
8356cc1d 166{
167 fFilename = "";
168 fFoldername = "";
169 ResetAllPointers();
170 fEventList.Clear("C");
cbee67e7 171}
8356cc1d 172
173
e33f3609 174Bool_t TrackSink::GetEvent(Int_t eventnumber) const
8356cc1d 175{
176 DebugMsg(1, "TrackSink::GetEvent(" << eventnumber << ")" );
177
178 // Try find the corresponding event in the list of events.
179 for (Int_t i = 0; i < fEventList.GetEntriesFast(); i++)
180 {
181 EventData* current = (EventData*) fEventList[i];
182 if (current->fEventNumber == eventnumber)
183 {
184 fEventIndex = i;
185 fCurrentEvent = current;
186 GetFirstBlock();
187 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
188 << " , fTrackIndex = " << fTrackIndex
189 );
190 return kTRUE;
cbee67e7 191 }
192 }
8356cc1d 193 return kFALSE;
cbee67e7 194}
8356cc1d 195
196
197Bool_t TrackSink::GetFirstEvent() const
198{
199 DebugMsg(1, "TrackSink::GetFirstEvent()");
200 if (fEventList.GetEntriesFast() > 0)
201 {
202 fEventIndex = 0;
203 fCurrentEvent = (EventData*) fEventList[0];
204 GetFirstBlock();
205 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
206 << " , fTrackIndex = " << fTrackIndex
207 );
208 return kTRUE;
209 }
210 else
211 {
212 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
213 << " , fTrackIndex = " << fTrackIndex
214 );
215 return kFALSE;
cbee67e7 216 }
217}
8356cc1d 218
219
220Bool_t TrackSink::MoreEvents() const
221{
f086c81b 222 return 0 <= fEventIndex && fEventIndex < fEventList.GetEntriesFast();
cbee67e7 223}
8356cc1d 224
225
226Bool_t TrackSink::GetNextEvent() const
227{
228 DebugMsg(1, "TrackSink::GetNextEvent()");
229 if (fEventIndex < fEventList.GetEntriesFast() - 1)
230 {
231 fCurrentEvent = (EventData*) fEventList[ ++fEventIndex ];
232 GetFirstBlock();
233 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
234 << " , fTrackIndex = " << fTrackIndex
235 );
236 return kTRUE;
237 }
238 else
239 {
240 ResetAllPointers();
241 return kFALSE;
242 };
243};
244
245
246Int_t TrackSink::CurrentEvent() const
247{
248 if (fCurrentEvent != NULL)
249 return fCurrentEvent->fEventNumber;
250 else
251 return -1;
cbee67e7 252}
8356cc1d 253
254
255Int_t TrackSink::NumberOfBlocks() const
256{
257 DebugMsg(1, "TrackSink::NumberOfBlocks()");
258 if (fCurrentEvent == NULL)
259 {
260 Error("NumberOfBlocks", "No event selected.");
261 return -1;
262 }
263 else
264 return fCurrentEvent->fBlocks.GetEntriesFast();
cbee67e7 265}
8356cc1d 266
267
e33f3609 268Bool_t TrackSink::GetBlock(Int_t index) const
8356cc1d 269{
270 DebugMsg(1, "TrackSink::GetBlock(" << index << ")");
271
272 // Note NumberOfBlocks() also checks if the event was selected.
273 Int_t numberofblocks = NumberOfBlocks();
274 if (numberofblocks < 0) return kFALSE;
275
f086c81b 276 if ( 0 <= index && index < numberofblocks )
8356cc1d 277 {
278 fBlockIndex = index;
279 fCurrentBlock = (TClonesArray*) fCurrentEvent->fBlocks[index];
280 GetFirstTrack();
281 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
282 << " , fTrackIndex = " << fTrackIndex
283 );
284 return kTRUE;
285 }
286 else
287 {
288 // The index is out of bounds so inform the user.
289 if (numberofblocks > 0)
290 Error( "GetBlock",
291 "The block index (%d) is out of bounds. Valid range is [0, %d]",
292 index, numberofblocks - 1
293 );
294 else
295 Error( "GetBlock",
296 "The block index (%d) is out of bounds. No blocks found.",
297 index
298 );
299 return kFALSE;
cbee67e7 300 }
301}
8356cc1d 302
303
304Bool_t TrackSink::GetFirstBlock() const
305{
306 DebugMsg(1, "TrackSink::GetFirstBlock()");
307 // Note: NumberOfBlocks() also checks if fCurrentEvent != NULL.
308 if (NumberOfBlocks() > 0)
309 {
310 fBlockIndex = 0;
311 fCurrentBlock = (TClonesArray*) fCurrentEvent->fBlocks[fBlockIndex];
312 GetFirstTrack();
313 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
314 << " , fTrackIndex = " << fTrackIndex
315 );
316 return kTRUE;
317 }
318 else
319 return kFALSE;
cbee67e7 320}
8356cc1d 321
322
323Bool_t TrackSink::MoreBlocks() const
324{
f086c81b 325 return 0 <= fBlockIndex && fBlockIndex < NumberOfBlocks();
cbee67e7 326}
8356cc1d 327
328
329Bool_t TrackSink::GetNextBlock() const
330{
331 DebugMsg(1, "TrackSink::GetNextBlock()");
332
333 // Note: NumberOfBlocks() checks if fCurrentEvent != NULL. If it is then it returns -1
334 // and since fBlockIndex is always >= -1 the if statement must go to the else part.
335 if (fBlockIndex < NumberOfBlocks() - 1)
336 {
337 fCurrentBlock = (TClonesArray*) fCurrentEvent->fBlocks[ ++fBlockIndex ];
338 GetFirstTrack();
339 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
340 << " , fTrackIndex = " << fTrackIndex
341 );
342 return kTRUE;
343 }
344 else
345 {
346 ResetBlockPointers();
347 return kFALSE;
cbee67e7 348 }
349}
8356cc1d 350
351
352Int_t TrackSink::NumberOfTracks() const
353{
354 DebugMsg(1, "TrackSink::NumberOfTracks()");
355 if (fCurrentBlock == NULL)
356 {
357 Error("NumberOfTracks", "No block selected.");
358 return -1;
359 }
360 else
361 return fCurrentBlock->GetEntriesFast();
362};
363
364
e33f3609 365const Track* TrackSink::GetTrack(Int_t index) const
8356cc1d 366{
367 DebugMsg(1, "TrackSink::GetTrack(" << index << ")");
368
369 // Note NumberOfTracks() also checks if the event and block was selected.
370 Int_t numberoftracks = NumberOfTracks();
371 if (numberoftracks < 0) return NULL;
372
f086c81b 373 if ( 0 <= index && index < numberoftracks )
8356cc1d 374 {
375 fTrackIndex = index;
376 fCurrentTrack = (Track*) fCurrentBlock->At(index);
377 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
378 << " , fTrackIndex = " << fTrackIndex
379 );
380 return fCurrentTrack;
381 }
382 else
383 {
384 // The index is out of bounds so inform the user.
385 if (numberoftracks > 0)
386 Error( "GetTrack",
387 "The track index (%d) is out of bounds. Valid range is [0, %d]",
388 index, numberoftracks - 1
389 );
390 else
391 Error( "GetTrack",
392 "The track index (%d) is out of bounds. No tracks found.",
393 index
394 );
395 return NULL;
cbee67e7 396 }
397}
8356cc1d 398
399
400const Track* TrackSink::GetFirstTrack() const
401{
402 DebugMsg(1, "TrackSink::GetFirstTrack()");
403 // Note: NumberOfTracks() also checks if fCurrentBlock != NULL.
404 if (NumberOfTracks() > 0)
405 {
406 fTrackIndex = 0;
407 fCurrentTrack = (Track*) fCurrentBlock->At(0);
408 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
409 << " , fTrackIndex = " << fTrackIndex
410 );
411 return fCurrentTrack;
412 }
413 else
414 return NULL;
cbee67e7 415}
8356cc1d 416
417
418Bool_t TrackSink::MoreTracks() const
419{
f086c81b 420 return 0 <= fTrackIndex && fTrackIndex < NumberOfTracks();
cbee67e7 421}
8356cc1d 422
423
424const Track* TrackSink::GetNextTrack() const
425{
426 DebugMsg(1, "TrackSink::GetNextTrack()");
427
428 // Note: NumberOfTracks() checks if fCurrentBlock != NULL. If it is then it returns -1
429 // and since fTrackIndex is always >= -1 the if statement must go to the else part.
430 if (fTrackIndex < NumberOfTracks() - 1)
431 {
432 fCurrentTrack = (Track*) fCurrentBlock->At( ++fTrackIndex );
433 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
434 << " , fTrackIndex = " << fTrackIndex
435 );
436 return fCurrentTrack;
437 }
438 else
439 {
440 ResetTrackPointers();
441 return NULL;
cbee67e7 442 }
443}
8356cc1d 444
445
446void TrackSink::ResetAllPointers() const
447{
448 fEventIndex = -1;
449 fCurrentEvent = NULL;
450 fBlockIndex = -1;
451 fCurrentBlock = NULL;
452 fTrackIndex = -1;
453 fCurrentTrack = NULL;
454 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
455 << " , fTrackIndex = " << fTrackIndex
456 );
cbee67e7 457}
8356cc1d 458
459
460void TrackSink::ResetBlockPointers() const
461{
462 fBlockIndex = -1;
463 fCurrentBlock = NULL;
464 fTrackIndex = -1;
465 fCurrentTrack = NULL;
466 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
467 << " , fTrackIndex = " << fTrackIndex
468 );
cbee67e7 469}
8356cc1d 470
471
472void TrackSink::ResetTrackPointers() const
473{
474 fTrackIndex = -1;
475 fCurrentTrack = NULL;
476 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
477 << " , fTrackIndex = " << fTrackIndex
478 );
cbee67e7 479}
8356cc1d 480
481
482TrackSink::EventData::EventData() : fBlocks(TClonesArray::Class())
483{
484 fEventNumber = -1;
cbee67e7 485}
8356cc1d 486
487
e33f3609 488TrackSink::EventData::EventData(Int_t eventnumber)
8356cc1d 489 : fBlocks(TClonesArray::Class())
490{
491 fEventNumber = eventnumber;
492
493 // If the following is not set then we do not write the fBlocks properly.
494 fBlocks.BypassStreamer(kFALSE);
cbee67e7 495}
8356cc1d 496
497
498TrackSink::EventData::~EventData()
499{
500 DebugMsg(1, "TrackSink::EventData::~EventData()");
501 fBlocks.Clear("C");
cbee67e7 502}
8356cc1d 503
504
cbee67e7 505} // AliMUONHLT