**************************************************************************/
// $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()
{
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
//
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()));
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
{
//______________________________________________________________________________
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 << " "
<< 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;
+}