]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpStringObjMap.cxx
Update HFE v2 analyses
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpStringObjMap.cxx
CommitLineData
c623aa64 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16// $Id$
13985652 17// $MpId: AliMpStringObjMap.cxx,v 1.4 2006/05/24 13:58:29 ivana Exp $
f7006443 18
3d1463c8 19//-----------------------------------------------------------------------------
c623aa64 20// Class AliMpStringObjMap
21// ------------------------------------
22// Helper class that substitutes map <string, int>
23// which ALICE does not allow to use
c623aa64 24// Author: Ivana Hrivnacova, IPN Orsay
3d1463c8 25//-----------------------------------------------------------------------------
c623aa64 26
c623aa64 27#include "AliMpStringObjMap.h"
2c605e66 28
c623aa64 29#include "AliLog.h"
30
2c605e66 31#include <TObjString.h>
32#include <Riostream.h>
33
b80faac0 34using std::cout;
35using std::endl;
36using std::setw;
13985652 37/// \cond CLASSIMP
c623aa64 38ClassImp(AliMpStringObjMap)
13985652 39/// \endcond
c623aa64 40
31edb2d7 41//
42// static private methods
43//
44
45//______________________________________________________________________________
46const TString& AliMpStringObjMap::GetUndefinedKey()
47{
48 /// Undefined key string
49 static const TString kUndefinedKey = "Undefined";
50 return kUndefinedKey;
51}
52
53//
54// ctors, dtor
55//
2a116780 56
c623aa64 57//______________________________________________________________________________
973e9d18 58AliMpStringObjMap::AliMpStringObjMap(Bool_t isOwner)
c623aa64 59 : TObject(),
60 fNofItems(0),
61 fFirstArray(),
9993e7da 62 fSecondArray(),
63 fCurrentIndex(0)
c623aa64 64{
65/// Standard constructor
66
67 fFirstArray.SetOwner(true);
973e9d18 68 fSecondArray.SetOwner(isOwner);
c623aa64 69}
70
c623aa64 71//______________________________________________________________________________
72AliMpStringObjMap::~AliMpStringObjMap()
73{
74/// Destructor
75
76 fFirstArray.Delete();
77}
78
c623aa64 79//
80// public methods
81//
82
83//______________________________________________________________________________
84Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second)
85{
86/// Add map element if first not yet present
87
88 TObject* second2 = Get(first);
89 if ( second2 ) {
90 AliError(Form("%s is already present in the map", first.Data()));
91 return false;
92 }
93
94 fFirstArray.Add(new TObjString(first));
95 fSecondArray.Add(second);
96 fNofItems++;
97
98 return true;
99}
100
101//______________________________________________________________________________
102TObject* AliMpStringObjMap::Get(const TString& first) const
103{
104/// Find the element with specified key (first)
105
106 for (Int_t i=0; i<fNofItems; i++) {
107 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
108 return fSecondArray.At(i);
109 }
110
111 return 0;
112}
113
114//______________________________________________________________________________
115Int_t AliMpStringObjMap::GetNofItems() const
116{
117/// Return the number of elements
118
119 return fNofItems;
120}
121
122//______________________________________________________________________________
123void AliMpStringObjMap::Clear(Option_t* /*option*/)
124{
125/// Delete the elements
126
127 fNofItems = 0;
128 fFirstArray.Delete();
129 fSecondArray.Delete();
130}
131
132//______________________________________________________________________________
133void AliMpStringObjMap::Print(const char* /*option*/) const
134{
135/// Print the map elements
136
137 for (Int_t i=0; i<fNofItems; i++) {
138 cout << setw(4)
139 << i << " "
140 << ((TObjString*)fFirstArray.At(i))->GetString()
141 << " "
142 << setw(5)
143 << fSecondArray.At(i)
144 << endl;
145 }
146}
147
148//______________________________________________________________________________
149void AliMpStringObjMap::Print(const TString& key, ofstream& out) const
150{
f5671fc3 151/// Special printing
c623aa64 152
153 for (Int_t i=0; i<fNofItems; i++) {
154 out << key << " "
155 << ((TObjString*)fFirstArray.At(i))->GetString()
156 << " "
157 << setw(5)
158 << fSecondArray.At(i)
159 << endl;
160 }
161}
2a116780 162
163//______________________________________________________________________________
164void AliMpStringObjMap::First()
165{
166/// Set iterator to the first item and return its object
167
168 fCurrentIndex = 0;
169}
170
171
172//______________________________________________________________________________
173void AliMpStringObjMap::Next()
174{
175/// Set iterator to the next item and return its object
176/// Return 0 if there are no more items
177
178 ++fCurrentIndex;
179}
180
181
182//______________________________________________________________________________
183TObject* AliMpStringObjMap::CurrentItem()
184{
185/// Set iterator to the first item and return its object
186
187 if ( fCurrentIndex >= fNofItems ) return 0;
188
189 return fSecondArray.At(fCurrentIndex);
190}
191
192
193//______________________________________________________________________________
194TString AliMpStringObjMap::CurrentKey()
195{
196/// Set iterator to the first item and return its object
197
31edb2d7 198 if ( fCurrentIndex >= fNofItems ) return GetUndefinedKey();
2a116780 199
200 return ((TObjString*)fFirstArray.At(fCurrentIndex))->GetString();
201}
202
203
204//______________________________________________________________________________
205Bool_t AliMpStringObjMap::IsDone() const
206{
207/// Return true if the iterator reached the end of map
208
209 return fCurrentIndex >= fNofItems;
210}
211