1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 // Class AliMUONStringIntMap
20 // ------------------------------------
21 // Helper class that substitutes map <string, int>
22 // which ALICE does not allow to use
23 // Author: Ivana Hrivnacova, IPN Orsay
24 //-----------------------------------------------------------------------------
26 #include <Riostream.h>
27 #include <TObjString.h>
29 #include "AliMUONStringIntMap.h"
33 ClassImp(AliMUONStringIntMap)
36 //______________________________________________________________________________
37 AliMUONStringIntMap::AliMUONStringIntMap()
44 /// Standard constructor
46 fFirstArray.SetOwner(true);
49 //______________________________________________________________________________
50 AliMUONStringIntMap::~AliMUONStringIntMap()
61 //______________________________________________________________________________
62 Bool_t AliMUONStringIntMap::Add(const TString& first, Int_t second)
64 /// Add map element if first not yet present
66 Int_t second2 = Get(first);
68 AliError(Form("%s is already present in the map", first.Data()));
72 // Resize TArrayI if needed
73 if (fSecondArray.GetSize() == fNofItems) fSecondArray.Set(2*fNofItems);
75 fFirstArray.Add(new TObjString(first));
76 fSecondArray.AddAt(second, fNofItems);
82 //______________________________________________________________________________
83 Bool_t AliMUONStringIntMap::Set(const TString& first, Int_t second)
87 Int_t index = Contains(first);
90 return Add(first,second);
93 fSecondArray.AddAt(second, index);
98 //______________________________________________________________________________
100 AliMUONStringIntMap::Contains(const TString& first) const
102 /// Whether this map contains the string 'first' or not
104 for (Int_t i=0; i<fNofItems; i++)
106 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
115 //______________________________________________________________________________
116 Int_t AliMUONStringIntMap::Get(const TString& first) const
118 /// Find the element with specified key (first)
120 for (Int_t i=0; i<fNofItems; i++) {
121 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
122 return fSecondArray.At(i);
128 //______________________________________________________________________________
129 Int_t AliMUONStringIntMap::GetNofItems() const
131 /// Return the number of elements
136 //______________________________________________________________________________
137 void AliMUONStringIntMap::Clear(Option_t* /*option*/)
139 /// Delete the elements
142 fFirstArray.Delete();
143 fSecondArray.Reset();
146 //______________________________________________________________________________
147 void AliMUONStringIntMap::Print(const char* /*option*/) const
149 /// Print the map elements
151 for (Int_t i=0; i<fNofItems; i++) {
154 << ((TObjString*)fFirstArray.At(i))->GetString()
157 << fSecondArray.At(i)
162 //______________________________________________________________________________
163 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
165 /// Print the map elements preceded by a key word
167 for (Int_t i=0; i<fNofItems; i++) {
169 << ((TObjString*)fFirstArray.At(i))->GetString()
172 << fSecondArray.At(i)
177 //______________________________________________________________________________
178 Bool_t AliMUONStringIntMap::Next(TString& first, Int_t& second)
180 /// Iterator: next method.
181 /// Returns false if the iterator reached the end.
184 if ( fCurrentIndex >= fNofItems ) return false;
186 TObjString* objString = (TObjString*)fFirstArray.At(fCurrentIndex);
187 first = objString->GetString();
189 second = fSecondArray.At(fCurrentIndex);
196 //______________________________________________________________________________
197 void AliMUONStringIntMap::ResetItr()