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