// $MpId: AliMpDEIterator.cxx,v 1.6 2006/05/24 13:58:34 ivana Exp $
// Category: management
-// ------------------------
+//-----------------------------------------------------------------------------
// Class AliMpDEIterator
// ------------------------
// The iterator over valid detection elements
// Author: Ivana Hrivnacova, IPN Orsay
+//-----------------------------------------------------------------------------
#include "AliMpDEIterator.h"
+
+#include "AliMpExMapIterator.h"
#include "AliMpDEStore.h"
#include "AliMpDetElement.h"
#include "AliMpDEManager.h"
//______________________________________________________________________________
AliMpDEIterator::AliMpDEIterator()
- : TObject(),
- fDEStore(AliMpDEStore::Instance()),
- fIndex(-1),
- fChamberId(-1)
+: TObject(),
+ fCurrentDE(0x0),
+ fIterator(AliMpDEStore::Instance()->fDetElements.CreateIterator()),
+ fChamberId(-1)
{
/// Standard and default constructor
}
-//______________________________________________________________________________
-AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
- : TObject(rhs),
- fDEStore(rhs.fDEStore),
- fIndex(rhs.fIndex),
- fChamberId(rhs.fChamberId)
-{
-/// Copy constructor
-}
-
//______________________________________________________________________________
AliMpDEIterator::~AliMpDEIterator()
{
/// Destructor
-}
-
-//______________________________________________________________________________
-AliMpDEIterator& AliMpDEIterator::operator=(const AliMpDEIterator& rhs)
-{
-/// Assignement operator
-
- // check assignment to self
- if (this == &rhs) return *this;
-
- // base class assignment
- TObject::operator=(rhs);
-
- fDEStore = rhs.fDEStore;
- fIndex = rhs.fIndex;
- fChamberId = rhs.fChamberId;
-
- return *this;
-}
-
-//
-// private methods
-//
-
-//______________________________________________________________________________
-AliMpDetElement* AliMpDEIterator::GetDetElement(Int_t index) const
-{
-/// Return the detection element from the map via index
- return static_cast<AliMpDetElement*>(fDEStore->fDetElements.GetObject(index));
+ delete fIterator;
}
//
{
/// Set iterator to the first DE Id defined
- fIndex = 0;
+ fIterator->Reset();
+ fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
fChamberId = -1;
}
{
/// Reset the iterator, so that it points to the first DE
- fChamberId = -1;
- fIndex = -1;
if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) {
AliErrorStream() << "Invalid chamber Id " << chamberId << endl;
+ fIterator->Reset();
+ fChamberId = -1;
+ fCurrentDE = 0x0;
return;
}
- Int_t i=0;
- while ( i < fDEStore->fDetElements.GetSize() && fChamberId < 0 ) {
- Int_t detElemId = GetDetElement(i)->GetId();
- if ( AliMpDEManager::GetChamberId(detElemId) == chamberId ) {
- fChamberId = chamberId;
- fIndex = i;
- }
- i++;
+ fIterator->Reset();
+ fChamberId = -1;
+ while ( fChamberId != chamberId )
+ {
+ fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
+ if (!fCurrentDE) return;
+ fChamberId = AliMpDEManager::GetChamberId(CurrentDEId());
}
-
- if ( fChamberId < 0 ) {
- AliErrorStream()
- << "No DEs of Chamber Id " << chamberId << " found" << endl;
- return;
- }
-
}
//______________________________________________________________________________
{
/// Increment iterator to next DE
- fIndex++;
-
- // Invalidate if at the end
- if ( ( fIndex == fDEStore->fDetElements.GetSize() ) ||
- ( fChamberId >= 0 &&
- AliMpDEManager::GetChamberId(CurrentDEId()) != fChamberId ) ) {
- fIndex = -1;
- }
+ if ( fChamberId < 0 )
+ {
+ fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
+ }
+ else
+ {
+ fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
+
+ while ( fCurrentDE && (AliMpDEManager::GetChamberId(fCurrentDE->GetId()) != fChamberId) )
+ {
+ fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
+ if (!fCurrentDE) return;
+ }
+ }
}
//______________________________________________________________________________
{
/// Is the iterator in the end?
- return ( fIndex < 0 );
+ return ( fCurrentDE == 0x0 );
}
//______________________________________________________________________________
{
/// Current DE Id
- if ( ! IsDone() )
- return GetDetElement(fIndex);
- else {
- AliErrorStream()
- << "Not in valid position - returning invalid DE." << endl;
- return 0;
- }
+ return fCurrentDE;
}
//______________________________________________________________________________
-Int_t AliMpDEIterator::CurrentDEId() const
+Int_t
+AliMpDEIterator::CurrentDEId() const
{
/// Current DE Id
- if ( ! IsDone() )
- return GetDetElement(fIndex)->GetId();
+ if ( fCurrentDE )
+ {
+ return fCurrentDE->GetId();
+ }
else {
AliErrorStream()
<< "Not in valid position - returning invalid DE." << endl;