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.3 2006/03/17 11:34:46 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>
33 ClassImp(AliMpStringObjMap)
35 //______________________________________________________________________________
36 AliMpStringObjMap::AliMpStringObjMap()
42 /// Standard constructor
44 fFirstArray.SetOwner(true);
47 //______________________________________________________________________________
48 AliMpStringObjMap::AliMpStringObjMap(const AliMpStringObjMap& rhs)
51 /// Protected copy constructor
53 AliFatal("Copy constructor is not implemented.");
56 //______________________________________________________________________________
57 AliMpStringObjMap::~AliMpStringObjMap()
64 //______________________________________________________________________________
66 AliMpStringObjMap::operator = (const AliMpStringObjMap& rhs)
68 /// Protected assignement operator
70 // check assignement to self
71 if (this == &rhs) return *this;
73 AliFatal("Assignment operator is not implemented.");
83 //______________________________________________________________________________
84 Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second)
86 /// Add map element if first not yet present
88 TObject* second2 = Get(first);
90 AliError(Form("%s is already present in the map", first.Data()));
94 fFirstArray.Add(new TObjString(first));
95 fSecondArray.Add(second);
101 //______________________________________________________________________________
102 TObject* AliMpStringObjMap::Get(const TString& first) const
104 /// Find the element with specified key (first)
106 for (Int_t i=0; i<fNofItems; i++) {
107 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
108 return fSecondArray.At(i);
114 //______________________________________________________________________________
115 Int_t AliMpStringObjMap::GetNofItems() const
117 /// Return the number of elements
122 //______________________________________________________________________________
123 void AliMpStringObjMap::Clear(Option_t* /*option*/)
125 /// Delete the elements
128 fFirstArray.Delete();
129 fSecondArray.Delete();
132 //______________________________________________________________________________
133 void AliMpStringObjMap::Print(const char* /*option*/) const
135 /// Print the map elements
137 for (Int_t i=0; i<fNofItems; i++) {
140 << ((TObjString*)fFirstArray.At(i))->GetString()
143 << fSecondArray.At(i)
148 //______________________________________________________________________________
149 void AliMpStringObjMap::Print(const TString& key, ofstream& out) const
151 // Prints the map elements
153 for (Int_t i=0; i<fNofItems; i++) {
155 << ((TObjString*)fFirstArray.At(i))->GetString()
158 << fSecondArray.At(i)