]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpDEIterator.cxx
Commenting out the infamous speed eater = StdoutToAliDebug until a better solution...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEIterator.cxx
index 5857dbc80537fed36202954e3ef7985885bce783..5dd4cdda9dd59def50c121b1b1d5053bf39f24ef 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/* $Id$ */
+// $Id$ 
+// $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 "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(),
+      fDEStore(AliMpDEStore::Instance()),
       fIndex(-1),
-      fModuleId(-1)
+      fChamberId(-1)
 {  
 /// Standard and default constructor
-
-  if (! fgNofDetElemIds ) ReadData();
 }
 
 //______________________________________________________________________________
 AliMpDEIterator::AliMpDEIterator(const AliMpDEIterator& rhs)
  : TObject(rhs),
+   fDEStore(rhs.fDEStore),
    fIndex(rhs.fIndex),
-   fModuleId(rhs.fModuleId)
+   fChamberId(rhs.fChamberId)
 {
 /// Copy constructor
 }
@@ -140,12 +76,25 @@ AliMpDEIterator&  AliMpDEIterator::operator=(const AliMpDEIterator& rhs)
   // base class assignment
   TObject::operator=(rhs);
 
-  fIndex    = rhs.fIndex;
-  fModuleId = rhs.fModuleId;
+  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
 //
@@ -156,33 +105,34 @@ void AliMpDEIterator::First()
 /// Set iterator to the first DE Id defined 
 
   fIndex = 0;
-  fModuleId = -1;
+  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;
+  fChamberId = -1;
   fIndex = -1;  
-  if ( ! AliMpDEManager::IsValidModuleId(moduleId) ) {
-    AliErrorStream() << "Invalid module Id " << moduleId << endl;
+  if ( ! AliMpDEManager::IsValidChamberId(chamberId) ) {
+    AliErrorStream() << "Invalid chamber Id " << chamberId << endl;
     return;
   }    
 
   Int_t i=0;
-  while ( i < fgNofDetElemIds && fModuleId < 0 ) {
-    Int_t detElemId = fgDetElemIds.At(i);
-    if ( AliMpDEManager::GetModuleId(detElemId) == moduleId ) {
-      fModuleId = moduleId;
+  while ( i < fDEStore->fDetElements.GetSize() && fChamberId < 0 ) {
+    Int_t detElemId = GetDetElement(i)->GetId();
+    if ( AliMpDEManager::GetChamberId(detElemId) == chamberId ) {
+      fChamberId = chamberId;
       fIndex = i;
     } 
     i++; 
   }
 
-  if ( fModuleId < 0 ) {
+  if ( fChamberId < 0 ) {
     AliErrorStream() 
-      << "No DEs of Module Id " << moduleId << " found" << cout;
+      << "No DEs of Chamber Id " << chamberId << " found" << endl;
     return;
   }    
 
@@ -191,12 +141,14 @@ void AliMpDEIterator::First(Int_t moduleId)
 //______________________________________________________________________________
 void AliMpDEIterator::Next()
 {
+/// Increment iterator to next DE
+
   fIndex++;
 
   // Invalidate if at the end
-  if ( ( fIndex == fgNofDetElemIds ) ||
-       ( fModuleId >= 0 &&    
-         AliMpDEManager::GetModuleId(CurrentDE()) != fModuleId ) ) {
+  if ( ( fIndex == fDEStore->fDetElements.GetSize() ) ||
+       ( fChamberId >= 0 &&    
+         AliMpDEManager::GetChamberId(CurrentDEId()) != fChamberId ) ) {
     fIndex = -1;
   }   
 }
@@ -204,14 +156,32 @@ void AliMpDEIterator::Next()
 //______________________________________________________________________________
 Bool_t AliMpDEIterator::IsDone() const
 {
+/// Is the iterator in the end?
+
   return ( fIndex < 0 );
 }   
 
 //______________________________________________________________________________
-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;