]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpDEIterator.cxx
Updated det element names (Christian)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEIterator.cxx
index be4e870c0d9b0bfcc76aeacaacbf11b3ff3a09c3..5dd4cdda9dd59def50c121b1b1d5053bf39f24ef 100644 (file)
 // ------------------------
 // Class AliMpDEIterator
 // ------------------------
-// The iterator over valid detection element IDs
+// The iterator over valid detection elements
 // Author: Ivana Hrivnacova, IPN Orsay
 
 #include "AliMpDEIterator.h"
+#include "AliMpDEStore.h"
+#include "AliMpDetElement.h"
 #include "AliMpDEManager.h"
 #include "AliMpFiles.h"
 
 ClassImp(AliMpDEIterator)
 /// \endcond
 
-const  Int_t  AliMpDEIterator::fgkMaxNofDetElements = 250;
-TArrayI  AliMpDEIterator::fgDetElemIds(fgkMaxNofDetElements);
-Int_t    AliMpDEIterator::fgNofDetElemIds = 0; 
-
-//
-// 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(3) 
-        << "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
-
-  AliDebugClass(2,"");
-
-  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
-//
-
 //______________________________________________________________________________
 AliMpDEIterator::AliMpDEIterator()
     : TObject(),
+      fDEStore(AliMpDEStore::Instance()),
       fIndex(-1),
       fChamberId(-1)
 {  
 /// Standard and default constructor
-
-  if (! fgNofDetElemIds ) ReadData();
 }
 
 //______________________________________________________________________________
 AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
  : TObject(rhs),
+   fDEStore(rhs.fDEStore),
    fIndex(rhs.fIndex),
    fChamberId(rhs.fChamberId)
 {
@@ -152,12 +76,25 @@ AliMpDEIterator&  AliMpDEIterator::operator=(const AliMpDEIterator& rhs)
   // 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));
+}
+
 //
 // public methods
 //
@@ -184,8 +121,8 @@ void AliMpDEIterator::First(Int_t chamberId)
   }    
 
   Int_t i=0;
-  while ( i < fgNofDetElemIds && fChamberId < 0 ) {
-    Int_t detElemId = fgDetElemIds.At(i);
+  while ( i < fDEStore->fDetElements.GetSize() && fChamberId < 0 ) {
+    Int_t detElemId = GetDetElement(i)->GetId();
     if ( AliMpDEManager::GetChamberId(detElemId) == chamberId ) {
       fChamberId = chamberId;
       fIndex = i;
@@ -209,9 +146,9 @@ void AliMpDEIterator::Next()
   fIndex++;
 
   // Invalidate if at the end
-  if ( ( fIndex == fgNofDetElemIds ) ||
+  if ( ( fIndex == fDEStore->fDetElements.GetSize() ) ||
        ( fChamberId >= 0 &&    
-         AliMpDEManager::GetChamberId(CurrentDE()) != fChamberId ) ) {
+         AliMpDEManager::GetChamberId(CurrentDEId()) != fChamberId ) ) {
     fIndex = -1;
   }   
 }
@@ -225,12 +162,26 @@ Bool_t AliMpDEIterator::IsDone() const
 }   
 
 //______________________________________________________________________________
-Int_t AliMpDEIterator::CurrentDE() const
+AliMpDetElement* AliMpDEIterator::CurrentDE() const
+{
+/// Current DE Id
+
+  if ( ! IsDone() )
+    return GetDetElement(fIndex);
+  else {   
+    AliErrorStream()
+      << "Not in valid position - returning invalid DE." << endl;
+    return 0;
+  }  
+}
+    
+//______________________________________________________________________________
+Int_t AliMpDEIterator::CurrentDEId() const
 {
 /// Current DE Id
 
   if ( ! IsDone() )
-    return fgDetElemIds.At(fIndex);
+    return GetDetElement(fIndex)->GetId();
   else {   
     AliErrorStream()
       << "Not in valid position - returning invalid DE." << endl;