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
25 #include <Riostream.h>
26 #include <TObjString.h>
28 #include "AliMUONStringIntMap.h"
32 ClassImp(AliMUONStringIntMap)
35 //______________________________________________________________________________
36 AliMUONStringIntMap::AliMUONStringIntMap()
42 /// Standard constructor
44 fFirstArray.SetOwner(true);
47 //______________________________________________________________________________
48 AliMUONStringIntMap::~AliMUONStringIntMap()
59 //______________________________________________________________________________
60 Bool_t AliMUONStringIntMap::Add(const TString& first, Int_t second)
62 /// Add map element if first not yet present
64 Int_t second2 = Get(first);
66 AliError(Form("%s is already present in the map", first.Data()));
70 // Resize TArrayI if needed
71 if (fSecondArray.GetSize() == fNofItems) fSecondArray.Set(2*fNofItems);
73 fFirstArray.Add(new TObjString(first));
74 fSecondArray.AddAt(second, fNofItems);
80 //______________________________________________________________________________
81 Bool_t AliMUONStringIntMap::Set(const TString& first, Int_t second)
85 Int_t index = Contains(first);
88 return Add(first,second);
91 fSecondArray.AddAt(second, index);
96 //______________________________________________________________________________
98 AliMUONStringIntMap::Contains(const TString& first) const
100 /// Whether this map contains the string 'first' or not
102 for (Int_t i=0; i<fNofItems; i++)
104 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
113 //______________________________________________________________________________
114 Int_t AliMUONStringIntMap::Get(const TString& first) const
116 /// Find the element with specified key (first)
118 for (Int_t i=0; i<fNofItems; i++) {
119 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
120 return fSecondArray.At(i);
126 //______________________________________________________________________________
127 Int_t AliMUONStringIntMap::GetNofItems() const
129 /// Return the number of elements
134 //______________________________________________________________________________
135 void AliMUONStringIntMap::Clear(Option_t* /*option*/)
137 /// Delete the elements
140 fFirstArray.Delete();
141 fSecondArray.Reset();
144 //______________________________________________________________________________
145 void AliMUONStringIntMap::Print(const char* /*option*/) const
147 /// Print the map elements
149 for (Int_t i=0; i<fNofItems; i++) {
152 << ((TObjString*)fFirstArray.At(i))->GetString()
155 << fSecondArray.At(i)
160 //______________________________________________________________________________
161 void AliMUONStringIntMap::Print(const TString& key, ofstream& out) const
163 /// Print the map elements preceded by a key word
165 for (Int_t i=0; i<fNofItems; i++) {
167 << ((TObjString*)fFirstArray.At(i))->GetString()
170 << fSecondArray.At(i)