]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONStringIntMap.cxx
updates in Kaon Femto train
[u/mrichter/AliRoot.git] / MUON / AliMUONStringIntMap.cxx
index 24ac2e7c9b6049dd86b64b0886b1beefff289adb..abfd8e32db0b500141b7e2660b645d0260fb9964 100644 (file)
  **************************************************************************/
 
 // $Id$
-//
-// ------------------------------------ 
+
+//-----------------------------------------------------------------------------
 // Class AliMUONStringIntMap
 // ------------------------------------ 
 // Helper class that substitutes map <string, int> 
 // which ALICE does not allow to use 
 // Author: Ivana Hrivnacova, IPN Orsay
+//-----------------------------------------------------------------------------
 
 #include <Riostream.h>
 #include <TObjString.h>
 #include "AliMUONStringIntMap.h"
 #include "AliLog.h"
 
+using std::cout;
+using std::setw;
+using std::endl;
+/// \cond CLASSIMP
 ClassImp(AliMUONStringIntMap)
+/// \endcond
 
 //______________________________________________________________________________
 AliMUONStringIntMap::AliMUONStringIntMap()
  : TObject(),
    fNofItems(0),
    fFirstArray(100),
-   fSecondArray(100)
+   fSecondArray(100),
+   fCurrentIndex(0)
 {
 /// Standard constructor
 
   fFirstArray.SetOwner(true);
 }
 
-//______________________________________________________________________________
-AliMUONStringIntMap::AliMUONStringIntMap(const AliMUONStringIntMap& rhs)
-  : TObject(rhs)
-{
-/// Protected copy constructor
-
-  AliFatal("Copy constructor is not implemented.");
-}
-
 //______________________________________________________________________________
 AliMUONStringIntMap::~AliMUONStringIntMap()
 {
@@ -59,21 +57,6 @@ AliMUONStringIntMap::~AliMUONStringIntMap()
   fFirstArray.Delete();
 }
 
-//______________________________________________________________________________
-AliMUONStringIntMap& 
-AliMUONStringIntMap::operator = (const AliMUONStringIntMap& rhs) 
-{
-/// Protected assignement operator
-
-  // check assignement to self
-  if (this == &rhs) return *this;
-
-  AliFatal("Assignment operator is not implemented.");
-    
-  return *this;  
-}
-
-
 //
 // public methods
 //
@@ -82,7 +65,7 @@ AliMUONStringIntMap::operator = (const AliMUONStringIntMap& rhs)
 Bool_t  AliMUONStringIntMap::Add(const TString& first, Int_t second)
 {
 /// Add map element if first not yet present
-
+  
   Int_t second2 = Get(first);
   if ( second2 > 0 ) {
     AliError(Form("%s is already present in the map", first.Data()));
@@ -99,6 +82,39 @@ Bool_t  AliMUONStringIntMap::Add(const TString& first, Int_t second)
   return true;
 }  
 
+//______________________________________________________________________________
+Bool_t  AliMUONStringIntMap::Set(const TString& first, Int_t second)
+{
+  /// Set map element
+
+  Int_t index = Contains(first);
+  if ( index < 0 )
+  {
+    return Add(first,second);
+  }
+    
+  fSecondArray.AddAt(second, index);
+  
+  return true;
+}  
+
+//______________________________________________________________________________
+Int_t 
+AliMUONStringIntMap::Contains(const TString& first) const
+{
+  /// Whether this map contains the string 'first' or not
+  
+  for (Int_t i=0; i<fNofItems; i++) 
+  {
+    if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
+    {
+      return i;
+    }
+  }
+  
+  return -1;
+}      
+
 //______________________________________________________________________________
 Int_t  AliMUONStringIntMap::Get(const TString& first) const
 {
@@ -149,7 +165,7 @@ void AliMUONStringIntMap::Print(const char* /*option*/) const
 //______________________________________________________________________________
 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
 {
-// Prints the map elements
+/// Print the map elements preceded by a key word
 
   for (Int_t i=0; i<fNofItems; i++) {
     out  << key << "  "
@@ -160,3 +176,30 @@ void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
         << endl;
   }
 }       
+
+//______________________________________________________________________________
+Bool_t  AliMUONStringIntMap::Next(TString& first, Int_t& second)
+{
+/// Iterator: next method.
+/// Returns false if the iterator reached the end.
+
+  if ( fCurrentIndex >= fNofItems ) return false;
+  
+  TObjString* objString = (TObjString*)fFirstArray.At(fCurrentIndex);
+  first = objString->GetString();
+  
+  second = fSecondArray.At(fCurrentIndex);
+  
+  ++fCurrentIndex;
+  
+  return true;
+}  
+
+//______________________________________________________________________________
+void  AliMUONStringIntMap::ResetItr()
+{
+/// Reset iterator
+  fCurrentIndex = 0;
+}