**************************************************************************/
// $Id$
-// $MpId: AliMpDEIterator.cxx,v 1.4 2006/03/13 12:22:15 ivana Exp $
+// $MpId: AliMpDEIterator.cxx,v 1.6 2006/05/24 13:58:34 ivana Exp $
// Category: management
-// ------------------------
+//-----------------------------------------------------------------------------
// Class AliMpDEIterator
// ------------------------
-// The iterator over valid detection element IDs
+// 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"
#include "AliMpFiles.h"
#include <Riostream.h>
#include <TSystem.h>
-const Int_t AliMpDEIterator::fgkMaxNofDetElements = 250;
-TArrayI AliMpDEIterator::fgDetElemIds(fgkMaxNofDetElements);
-Int_t AliMpDEIterator::fgNofDetElemIds = 0;
-
+/// \cond CLASSIMP
ClassImp(AliMpDEIterator)
-
-//
-// static private methods
-//
-
-//______________________________________________________________________________
-Bool_t AliMpDEIterator::ReadDEIds(AliMpStationType station)
-{
-/// Read det element ids from the file specified by name
-/// and fill the map (the deNames are ignored)
-/// Return true if the data were read ok
-
- // Open file
- TString filePath = AliMpFiles::DENamesFilePath(station);
- std::ifstream in(filePath);
- if (!in.good()) {
- AliErrorClassStream() << "Cannot open file " << filePath << endl;;
- return false;
- }
-
- // Skip plane types per cathods + empty lines
- //
- char line[80];
- in.getline(line, 80);
- in.getline(line, 80);
- in.getline(line, 80);
-
- // Read DE Ids
- //
- Int_t detElemId;
- TString word;
- in >> word;
- while ( ! in.eof() ) {
- if ( word[0] == '#' ) {
- in.getline(line, 80);
- }
- else {
- detElemId = word.Atoi();
- in.getline(line, 80);
- AliDebugClassStream(1)
- << "Adding " << fgNofDetElemIds << " " << detElemId << endl;
- fgDetElemIds.AddAt(detElemId, fgNofDetElemIds++);
- }
- in >> word;
- }
-
- // Close file
- in.close();
-
- return true;
-}
-
-//______________________________________________________________________________
-void AliMpDEIterator::ReadData()
-{
-/// Fill DE Ids array from DE names files
-/// Return true if all data were read ok
-
- Bool_t result1 = ReadDEIds(kStation1);
- Bool_t result2 = ReadDEIds(kStation2);
- Bool_t result3 = ReadDEIds(kStation345);
- Bool_t result4 = ReadDEIds(kStationTrigger);
-
- Bool_t result = result1 && result2 && result3 && result4;
- if ( ! result ) {
- AliErrorClassStream() << "Error in reading DE names files" << endl;
- }
-}
-
-//
-// constructors, destructor
-//
+/// \endcond
//______________________________________________________________________________
AliMpDEIterator::AliMpDEIterator()
- : TObject(),
- fIndex(-1),
- fModuleId(-1)
+: TObject(),
+ fCurrentDE(0x0),
+ fIterator(AliMpDEStore::Instance()->fDetElements.CreateIterator()),
+ fChamberId(-1)
{
/// Standard and default constructor
-
- if (! fgNofDetElemIds ) ReadData();
-}
-
-//______________________________________________________________________________
-AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
- : TObject(rhs),
- fIndex(rhs.fIndex),
- fModuleId(rhs.fModuleId)
-{
-/// 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);
-
- fIndex = rhs.fIndex;
- fModuleId = rhs.fModuleId;
-
- return *this;
-}
+ delete fIterator;
+}
//
// public methods
{
/// Set iterator to the first DE Id defined
- fIndex = 0;
- fModuleId = -1;
+ fIterator->Reset();
+ fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
+ fChamberId = -1;
}
//______________________________________________________________________________
-void AliMpDEIterator::First(Int_t moduleId)
+void AliMpDEIterator::First(Int_t chamberId)
{
/// Reset the iterator, so that it points to the first DE
- fModuleId = -1;
- fIndex = -1;
- if ( ! AliMpDEManager::IsValidModuleId(moduleId) ) {
- AliErrorStream() << "Invalid module Id " << moduleId << endl;
+ if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) {
+ AliErrorStream() << "Invalid chamber Id " << chamberId << endl;
+ fIterator->Reset();
+ fChamberId = -1;
+ fCurrentDE = 0x0;
return;
}
- Int_t i=0;
- while ( i < fgNofDetElemIds && fModuleId < 0 ) {
- Int_t detElemId = fgDetElemIds.At(i);
- if ( AliMpDEManager::GetModuleId(detElemId) == moduleId ) {
- fModuleId = moduleId;
- fIndex = i;
- }
- i++;
+ fIterator->Reset();
+ fChamberId = -1;
+ while ( fChamberId != chamberId )
+ {
+ fCurrentDE = static_cast<AliMpDetElement*>(fIterator->Next());
+ if (!fCurrentDE) return;
+ fChamberId = AliMpDEManager::GetChamberId(CurrentDEId());
}
-
- if ( fModuleId < 0 ) {
- AliErrorStream()
- << "No DEs of Module Id " << moduleId << " found" << cout;
- return;
- }
-
}
//______________________________________________________________________________
{
/// Increment iterator to next DE
- fIndex++;
-
- // Invalidate if at the end
- if ( ( fIndex == fgNofDetElemIds ) ||
- ( fModuleId >= 0 &&
- AliMpDEManager::GetModuleId(CurrentDE()) != fModuleId ) ) {
- 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 );
}
//______________________________________________________________________________
-Int_t AliMpDEIterator::CurrentDE() const
+AliMpDetElement* AliMpDEIterator::CurrentDE() const
+{
+/// Current DE Id
+
+ return fCurrentDE;
+}
+
+//______________________________________________________________________________
+Int_t
+AliMpDEIterator::CurrentDEId() const
{
/// Current DE Id
- if ( ! IsDone() )
- return fgDetElemIds.At(fIndex);
+ if ( fCurrentDE )
+ {
+ return fCurrentDE->GetId();
+ }
else {
AliErrorStream()
<< "Not in valid position - returning invalid DE." << endl;