]>
Commit | Line | Data |
---|---|---|
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 | 34 | ClassImp(AliMpStringObjMap) |
13985652 | 35 | /// \endcond |
c623aa64 | 36 | |
37 | //______________________________________________________________________________ | |
38 | AliMpStringObjMap::AliMpStringObjMap() | |
39 | : TObject(), | |
40 | fNofItems(0), | |
41 | fFirstArray(), | |
42 | fSecondArray() | |
43 | { | |
44 | /// Standard constructor | |
45 | ||
46 | fFirstArray.SetOwner(true); | |
47 | } | |
48 | ||
c623aa64 | 49 | //______________________________________________________________________________ |
50 | AliMpStringObjMap::~AliMpStringObjMap() | |
51 | { | |
52 | /// Destructor | |
53 | ||
54 | fFirstArray.Delete(); | |
55 | } | |
56 | ||
c623aa64 | 57 | // |
58 | // public methods | |
59 | // | |
60 | ||
61 | //______________________________________________________________________________ | |
62 | Bool_t AliMpStringObjMap::Add(const TString& first, TObject* second) | |
63 | { | |
64 | /// Add map element if first not yet present | |
65 | ||
66 | TObject* second2 = Get(first); | |
67 | if ( second2 ) { | |
68 | AliError(Form("%s is already present in the map", first.Data())); | |
69 | return false; | |
70 | } | |
71 | ||
72 | fFirstArray.Add(new TObjString(first)); | |
73 | fSecondArray.Add(second); | |
74 | fNofItems++; | |
75 | ||
76 | return true; | |
77 | } | |
78 | ||
79 | //______________________________________________________________________________ | |
80 | TObject* AliMpStringObjMap::Get(const TString& first) const | |
81 | { | |
82 | /// Find the element with specified key (first) | |
83 | ||
84 | for (Int_t i=0; i<fNofItems; i++) { | |
85 | if ( ((TObjString*)fFirstArray.At(i))->GetString() == first ) | |
86 | return fSecondArray.At(i); | |
87 | } | |
88 | ||
89 | return 0; | |
90 | } | |
91 | ||
92 | //______________________________________________________________________________ | |
93 | Int_t AliMpStringObjMap::GetNofItems() const | |
94 | { | |
95 | /// Return the number of elements | |
96 | ||
97 | return fNofItems; | |
98 | } | |
99 | ||
100 | //______________________________________________________________________________ | |
101 | void AliMpStringObjMap::Clear(Option_t* /*option*/) | |
102 | { | |
103 | /// Delete the elements | |
104 | ||
105 | fNofItems = 0; | |
106 | fFirstArray.Delete(); | |
107 | fSecondArray.Delete(); | |
108 | } | |
109 | ||
110 | //______________________________________________________________________________ | |
111 | void AliMpStringObjMap::Print(const char* /*option*/) const | |
112 | { | |
113 | /// Print the map elements | |
114 | ||
115 | for (Int_t i=0; i<fNofItems; i++) { | |
116 | cout << setw(4) | |
117 | << i << " " | |
118 | << ((TObjString*)fFirstArray.At(i))->GetString() | |
119 | << " " | |
120 | << setw(5) | |
121 | << fSecondArray.At(i) | |
122 | << endl; | |
123 | } | |
124 | } | |
125 | ||
126 | //______________________________________________________________________________ | |
127 | void AliMpStringObjMap::Print(const TString& key, ofstream& out) const | |
128 | { | |
129 | // Prints the map elements | |
130 | ||
131 | for (Int_t i=0; i<fNofItems; i++) { | |
132 | out << key << " " | |
133 | << ((TObjString*)fFirstArray.At(i))->GetString() | |
134 | << " " | |
135 | << setw(5) | |
136 | << fSecondArray.At(i) | |
137 | << endl; | |
138 | } | |
139 | } |