1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Artur Szostak
4 // Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
6 ////////////////////////////////////////////////////////////////////////////////
8 #include "AliRoot/TrackSink.hpp"
9 #include "AliRoot/Base.hpp"
11 ClassImp(AliMUONHLT::TrackSink)
12 ClassImp(AliMUONHLT::TrackSink::EventData)
18 TrackSink::TrackSink() :
19 TObject(), fEventList(TrackSink::EventData::Class())
27 TrackSink::~TrackSink()
29 DebugMsg(1, "TrackSink::~TrackSink()");
30 fEventList.Clear("C");
34 void TrackSink::AddEvent(Int_t eventnumber)
36 DebugMsg(1, "TrackSink::AddEvent(" << eventnumber << ")");
40 Error("AddEvent", "The event number must be positive, got: %d", eventnumber);
44 // Make sure that the event number is not already added to the list of events.
45 TIter next(&fEventList);
47 while ((current = (EventData*)next()))
49 if (current->fEventNumber == eventnumber)
51 Error("AddEvent", "The event number %d is already stored.", eventnumber);
56 fEventIndex = fEventList.GetEntriesFast();
57 new ( fEventList[fEventIndex] ) EventData(eventnumber);
58 fCurrentEvent = (EventData*) fEventList[fEventIndex];
60 // Remember to reset the other pointers because the new event is empty.
63 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
64 << " , fTrackIndex = " << fTrackIndex
69 void TrackSink::AddBlock()
71 DebugMsg(1, "TrackSink::AddBlock()");
73 if (fCurrentEvent == NULL)
75 Error("AddBlock", "No event selected.");
79 fBlockIndex = fCurrentEvent->fBlocks.GetEntriesFast();
80 new ( fCurrentEvent->fBlocks[fBlockIndex] ) TClonesArray(Track::Class());
81 fCurrentBlock = (TClonesArray*) fCurrentEvent->fBlocks[fBlockIndex];
83 // Remember to reset the track pointer because the new block is empty.
86 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
87 << " , fTrackIndex = " << fTrackIndex
92 void TrackSink::AddTrack(const Track& track)
94 DebugMsg(1, "TrackSink::AddTrack()");
96 if (fCurrentBlock == NULL)
98 Error("AddTrack", "No block selected.");
102 fTrackIndex = fCurrentBlock->GetEntriesFast();
103 new ( (*fCurrentBlock)[fTrackIndex] ) Track(track);
104 fCurrentTrack = (Track*) (*fCurrentBlock)[fTrackIndex];
106 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
107 << " , fTrackIndex = " << fTrackIndex
112 Track* TrackSink::AddTrack()
114 DebugMsg(1, "TrackSink::AddTrack()");
116 if (fCurrentBlock == NULL)
118 Error("AddTrack", "No block selected.");
122 fTrackIndex = fCurrentBlock->GetEntriesFast();
123 fCurrentTrack = (Track*) fCurrentBlock->New(fTrackIndex);
125 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
126 << " , fTrackIndex = " << fTrackIndex
128 return fCurrentTrack;
132 void TrackSink::AddTrack(
133 Int_t triggerid, Int_t sign, Float_t momentum,
134 Float_t pt, const Point hits[10], const Region regions[10]
137 DebugMsg(1, "TrackSink::AddTrack(" << triggerid << ", " << sign << ", "
138 << momentum << ", " << pt << ", " << (void*)(&hits[0]) << ", "
139 << (void*)(®ions[0]) << ")"
142 if (fCurrentBlock == NULL)
144 Error("AddTrack", "No block selected.");
148 fTrackIndex = fCurrentBlock->GetEntriesFast();
149 new ( (*fCurrentBlock)[fTrackIndex] ) Track(triggerid, sign, momentum, pt, hits, regions);
150 fCurrentTrack = (Track*) (*fCurrentBlock)[fTrackIndex];
152 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
153 << " , fTrackIndex = " << fTrackIndex
158 void TrackSink::SetNames(const TriggerSource* triggersource)
160 fFilename = triggersource->FileName();
161 fFoldername = triggersource->FolderName();
165 void TrackSink::Clear()
170 fEventList.Clear("C");
174 Bool_t TrackSink::GetEvent(Int_t eventnumber) const
176 DebugMsg(1, "TrackSink::GetEvent(" << eventnumber << ")" );
178 // Try find the corresponding event in the list of events.
179 for (Int_t i = 0; i < fEventList.GetEntriesFast(); i++)
181 EventData* current = (EventData*) fEventList[i];
182 if (current->fEventNumber == eventnumber)
185 fCurrentEvent = current;
187 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
188 << " , fTrackIndex = " << fTrackIndex
197 Bool_t TrackSink::GetFirstEvent() const
199 DebugMsg(1, "TrackSink::GetFirstEvent()");
200 if (fEventList.GetEntriesFast() > 0)
203 fCurrentEvent = (EventData*) fEventList[0];
205 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
206 << " , fTrackIndex = " << fTrackIndex
212 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
213 << " , fTrackIndex = " << fTrackIndex
220 Bool_t TrackSink::MoreEvents() const
222 return 0 <= fEventIndex and fEventIndex < fEventList.GetEntriesFast();
226 Bool_t TrackSink::GetNextEvent() const
228 DebugMsg(1, "TrackSink::GetNextEvent()");
229 if (fEventIndex < fEventList.GetEntriesFast() - 1)
231 fCurrentEvent = (EventData*) fEventList[ ++fEventIndex ];
233 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
234 << " , fTrackIndex = " << fTrackIndex
246 Int_t TrackSink::CurrentEvent() const
248 if (fCurrentEvent != NULL)
249 return fCurrentEvent->fEventNumber;
255 Int_t TrackSink::NumberOfBlocks() const
257 DebugMsg(1, "TrackSink::NumberOfBlocks()");
258 if (fCurrentEvent == NULL)
260 Error("NumberOfBlocks", "No event selected.");
264 return fCurrentEvent->fBlocks.GetEntriesFast();
268 Bool_t TrackSink::GetBlock(Int_t index) const
270 DebugMsg(1, "TrackSink::GetBlock(" << index << ")");
272 // Note NumberOfBlocks() also checks if the event was selected.
273 Int_t numberofblocks = NumberOfBlocks();
274 if (numberofblocks < 0) return kFALSE;
276 if ( 0 <= index and index < numberofblocks )
279 fCurrentBlock = (TClonesArray*) fCurrentEvent->fBlocks[index];
281 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
282 << " , fTrackIndex = " << fTrackIndex
288 // The index is out of bounds so inform the user.
289 if (numberofblocks > 0)
291 "The block index (%d) is out of bounds. Valid range is [0, %d]",
292 index, numberofblocks - 1
296 "The block index (%d) is out of bounds. No blocks found.",
304 Bool_t TrackSink::GetFirstBlock() const
306 DebugMsg(1, "TrackSink::GetFirstBlock()");
307 // Note: NumberOfBlocks() also checks if fCurrentEvent != NULL.
308 if (NumberOfBlocks() > 0)
311 fCurrentBlock = (TClonesArray*) fCurrentEvent->fBlocks[fBlockIndex];
313 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
314 << " , fTrackIndex = " << fTrackIndex
323 Bool_t TrackSink::MoreBlocks() const
325 return 0 <= fBlockIndex and fBlockIndex < NumberOfBlocks();
329 Bool_t TrackSink::GetNextBlock() const
331 DebugMsg(1, "TrackSink::GetNextBlock()");
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)
337 fCurrentBlock = (TClonesArray*) fCurrentEvent->fBlocks[ ++fBlockIndex ];
339 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
340 << " , fTrackIndex = " << fTrackIndex
346 ResetBlockPointers();
352 Int_t TrackSink::NumberOfTracks() const
354 DebugMsg(1, "TrackSink::NumberOfTracks()");
355 if (fCurrentBlock == NULL)
357 Error("NumberOfTracks", "No block selected.");
361 return fCurrentBlock->GetEntriesFast();
365 const Track* TrackSink::GetTrack(Int_t index) const
367 DebugMsg(1, "TrackSink::GetTrack(" << index << ")");
369 // Note NumberOfTracks() also checks if the event and block was selected.
370 Int_t numberoftracks = NumberOfTracks();
371 if (numberoftracks < 0) return NULL;
373 if ( 0 <= index and index < numberoftracks )
376 fCurrentTrack = (Track*) fCurrentBlock->At(index);
377 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
378 << " , fTrackIndex = " << fTrackIndex
380 return fCurrentTrack;
384 // The index is out of bounds so inform the user.
385 if (numberoftracks > 0)
387 "The track index (%d) is out of bounds. Valid range is [0, %d]",
388 index, numberoftracks - 1
392 "The track index (%d) is out of bounds. No tracks found.",
400 const Track* TrackSink::GetFirstTrack() const
402 DebugMsg(1, "TrackSink::GetFirstTrack()");
403 // Note: NumberOfTracks() also checks if fCurrentBlock != NULL.
404 if (NumberOfTracks() > 0)
407 fCurrentTrack = (Track*) fCurrentBlock->At(0);
408 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
409 << " , fTrackIndex = " << fTrackIndex
411 return fCurrentTrack;
418 Bool_t TrackSink::MoreTracks() const
420 return 0 <= fTrackIndex and fTrackIndex < NumberOfTracks();
424 const Track* TrackSink::GetNextTrack() const
426 DebugMsg(1, "TrackSink::GetNextTrack()");
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)
432 fCurrentTrack = (Track*) fCurrentBlock->At( ++fTrackIndex );
433 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
434 << " , fTrackIndex = " << fTrackIndex
436 return fCurrentTrack;
440 ResetTrackPointers();
446 void TrackSink::ResetAllPointers() const
449 fCurrentEvent = NULL;
451 fCurrentBlock = NULL;
453 fCurrentTrack = NULL;
454 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
455 << " , fTrackIndex = " << fTrackIndex
460 void TrackSink::ResetBlockPointers() const
463 fCurrentBlock = NULL;
465 fCurrentTrack = NULL;
466 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
467 << " , fTrackIndex = " << fTrackIndex
472 void TrackSink::ResetTrackPointers() const
475 fCurrentTrack = NULL;
476 DebugMsg(2, "\tfEventIndex = " << fEventIndex << " , fBlockIndex = " << fBlockIndex
477 << " , fTrackIndex = " << fTrackIndex
482 TrackSink::EventData::EventData() : fBlocks(TClonesArray::Class())
488 TrackSink::EventData::EventData(Int_t eventnumber)
489 : fBlocks(TClonesArray::Class())
491 fEventNumber = eventnumber;
493 // If the following is not set then we do not write the fBlocks properly.
494 fBlocks.BypassStreamer(kFALSE);
498 TrackSink::EventData::~EventData()
500 DebugMsg(1, "TrackSink::EventData::~EventData()");