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 **************************************************************************/
17 // $MpId: AliMpStringObjMap.cxx,v 1.4 2006/05/24 13:58:29 ivana Exp $
19 // ------------------------------------
20 // Class AliMpStringObjMap
21 // ------------------------------------
22 // Helper class that substitutes map <string, int>
23 // which ALICE does not allow to use
24 // Author: Ivana Hrivnacova, IPN Orsay
26 #include "AliMpStringObjMap.h"
30 #include <TObjString.h>
31 #include <Riostream.h>
34 ClassImp(AliMpStringObjMap)
37 //______________________________________________________________________________
38 AliMpStringObjMap::AliMpStringObjMap(Bool_t isOwner)
44 /// Standard constructor
46 fFirstArray.SetOwner(true);
47 fSecondArray.SetOwner(isOwner);
50 //______________________________________________________________________________
51 AliMpStringObjMap::~AliMpStringObjMap()
62 //______________________________________________________________________________
63 Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second)
65 /// Add map element if first not yet present
67 TObject* second2 = Get(first);
69 AliError(Form("%s is already present in the map", first.Data()));
73 fFirstArray.Add(new TObjString(first));
74 fSecondArray.Add(second);
80 //______________________________________________________________________________
81 TObject* AliMpStringObjMap::Get(const TString& first) const
83 /// Find the element with specified key (first)
85 for (Int_t i=0; i<fNofItems; i++) {
86 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
87 return fSecondArray.At(i);
93 //______________________________________________________________________________
94 Int_t AliMpStringObjMap::GetNofItems() const
96 /// Return the number of elements
101 //______________________________________________________________________________
102 void AliMpStringObjMap::Clear(Option_t* /*option*/)
104 /// Delete the elements
107 fFirstArray.Delete();
108 fSecondArray.Delete();
111 //______________________________________________________________________________
112 void AliMpStringObjMap::Print(const char* /*option*/) const
114 /// Print the map elements
116 for (Int_t i=0; i<fNofItems; i++) {
119 << ((TObjString*)fFirstArray.At(i))->GetString()
122 << fSecondArray.At(i)
127 //______________________________________________________________________________
128 void AliMpStringObjMap::Print(const TString& key, ofstream& out) const
130 // Prints the map elements
132 for (Int_t i=0; i<fNofItems; i++) {
134 << ((TObjString*)fFirstArray.At(i))->GetString()
137 << fSecondArray.At(i)