]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpStringObjMap.cxx
Work around for CINT bug in root 5.10/00, with gcc4.0.2
[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$
f7006443 17// $MpId: $
18
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
25
26#include <Riostream.h>
27#include <TObjString.h>
28
29#include "AliMpStringObjMap.h"
30#include "AliLog.h"
31
32ClassImp(AliMpStringObjMap)
33
34//______________________________________________________________________________
35AliMpStringObjMap::AliMpStringObjMap()
36 : TObject(),
37 fNofItems(0),
38 fFirstArray(),
39 fSecondArray()
40{
41/// Standard constructor
42
43 fFirstArray.SetOwner(true);
44}
45
46//______________________________________________________________________________
47AliMpStringObjMap::AliMpStringObjMap(const AliMpStringObjMap& rhs)
48 : TObject(rhs)
49{
50/// Protected copy constructor
51
52 AliFatal("Copy constructor is not implemented.");
53}
54
55//______________________________________________________________________________
56AliMpStringObjMap::~AliMpStringObjMap()
57{
58/// Destructor
59
60 fFirstArray.Delete();
61}
62
63//______________________________________________________________________________
64AliMpStringObjMap&
65AliMpStringObjMap::operator = (const AliMpStringObjMap& rhs)
66{
67/// Protected assignement operator
68
69 // check assignement to self
70 if (this == &rhs) return *this;
71
72 AliFatal("Assignment operator is not implemented.");
73
74 return *this;
75}
76
77
78//
79// public methods
80//
81
82//______________________________________________________________________________
83Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second)
84{
85/// Add map element if first not yet present
86
87 TObject* second2 = Get(first);
88 if ( second2 ) {
89 AliError(Form("%s is already present in the map", first.Data()));
90 return false;
91 }
92
93 fFirstArray.Add(new TObjString(first));
94 fSecondArray.Add(second);
95 fNofItems++;
96
97 return true;
98}
99
100//______________________________________________________________________________
101TObject* AliMpStringObjMap::Get(const TString& first) const
102{
103/// Find the element with specified key (first)
104
105 for (Int_t i=0; i<fNofItems; i++) {
106 if ( ((TObjString*)fFirstArray.At(i))->GetString() == first )
107 return fSecondArray.At(i);
108 }
109
110 return 0;
111}
112
113//______________________________________________________________________________
114Int_t AliMpStringObjMap::GetNofItems() const
115{
116/// Return the number of elements
117
118 return fNofItems;
119}
120
121//______________________________________________________________________________
122void AliMpStringObjMap::Clear(Option_t* /*option*/)
123{
124/// Delete the elements
125
126 fNofItems = 0;
127 fFirstArray.Delete();
128 fSecondArray.Delete();
129}
130
131//______________________________________________________________________________
132void AliMpStringObjMap::Print(const char* /*option*/) const
133{
134/// Print the map elements
135
136 for (Int_t i=0; i<fNofItems; i++) {
137 cout << setw(4)
138 << i << " "
139 << ((TObjString*)fFirstArray.At(i))->GetString()
140 << " "
141 << setw(5)
142 << fSecondArray.At(i)
143 << endl;
144 }
145}
146
147//______________________________________________________________________________
148void AliMpStringObjMap::Print(const TString& key, ofstream& out) const
149{
150// Prints the map elements
151
152 for (Int_t i=0; i<fNofItems; i++) {
153 out << key << " "
154 << ((TObjString*)fFirstArray.At(i))->GetString()
155 << " "
156 << setw(5)
157 << fSecondArray.At(i)
158 << endl;
159 }
160}