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"
36 ClassImp(AliMUONStringIntMap)
39 //______________________________________________________________________________
40 AliMUONStringIntMap::AliMUONStringIntMap()
47 /// Standard constructor
49 fFirstArray.SetOwner(true);
52 //______________________________________________________________________________
53 AliMUONStringIntMap::~AliMUONStringIntMap()
64 //______________________________________________________________________________
65 Bool_t AliMUONStringIntMap::Add(const TString& first, Int_t second)
67 /// Add map element if first not yet present
69 Int_t second2 = Get(first);
71 AliError(Form("%s is already present in the map", first.Data()));
75 // Resize TArrayI if needed
76 if (fSecondArray.GetSize() == fNofItems) fSecondArray.Set(2*fNofItems);
78 fFirstArray.Add(new TObjString(first));
79 fSecondArray.AddAt(second, fNofItems);
85 //______________________________________________________________________________
86 Bool_t AliMUONStringIntMap::Set(const TString& first, Int_t second)
90 Int_t index = Contains(first);
93 return Add(first,second);
96 fSecondArray.AddAt(second, index);
101 //______________________________________________________________________________
103 AliMUONStringIntMap::Contains(const TString& first) const
105 /// Whether this map contains the string 'first' or not
107 for (Int_t i=0; i<fNofItems; i++)
109 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
118 //______________________________________________________________________________
119 Int_t AliMUONStringIntMap::Get(const TString& first) const
121 /// Find the element with specified key (first)
123 for (Int_t i=0; i<fNofItems; i++) {
124 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
125 return fSecondArray.At(i);
131 //______________________________________________________________________________
132 Int_t AliMUONStringIntMap::GetNofItems() const
134 /// Return the number of elements
139 //______________________________________________________________________________
140 void AliMUONStringIntMap::Clear(Option_t* /*option*/)
142 /// Delete the elements
145 fFirstArray.Delete();
146 fSecondArray.Reset();
149 //______________________________________________________________________________
150 void AliMUONStringIntMap::Print(const char* /*option*/) const
152 /// Print the map elements
154 for (Int_t i=0; i<fNofItems; i++) {
157 << ((TObjString*)fFirstArray.At(i))->GetString()
160 << fSecondArray.At(i)
165 //______________________________________________________________________________
166 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
168 /// Print the map elements preceded by a key word
170 for (Int_t i=0; i<fNofItems; i++) {
172 << ((TObjString*)fFirstArray.At(i))->GetString()
175 << fSecondArray.At(i)
180 //______________________________________________________________________________
181 Bool_t AliMUONStringIntMap::Next(TString& first, Int_t& second)
183 /// Iterator: next method.
184 /// Returns false if the iterator reached the end.
187 if ( fCurrentIndex >= fNofItems ) return false;
189 TObjString* objString = (TObjString*)fFirstArray.At(fCurrentIndex);
190 first = objString->GetString();
192 second = fSecondArray.At(fCurrentIndex);
199 //______________________________________________________________________________
200 void AliMUONStringIntMap::ResetItr()