]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 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 purpeateose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
13985652 | 17 | // $MpId: AliMpHelper.cxx,v 1.5 2006/05/24 13:58:50 ivana Exp $ |
dee1d5f1 | 18 | |
19 | #include "AliMpHelper.h" | |
20 | ||
dee1d5f1 | 21 | #include "TArrayI.h" |
dee1d5f1 | 22 | #include "TObjArray.h" |
23 | #include "TObjString.h" | |
24 | #include "TString.h" | |
315c1275 | 25 | #include "TMap.h" |
dee1d5f1 | 26 | |
3d1463c8 | 27 | //----------------------------------------------------------------------------- |
85fec35d | 28 | /// \class AliMpHelper |
29 | /// | |
30 | /// Helper class used to parse mapping files for St345 slats. | |
31 | /// | |
32 | /// \author L. Aphecetche | |
3d1463c8 | 33 | //----------------------------------------------------------------------------- |
85fec35d | 34 | |
13985652 | 35 | /// \cond CLASSIMP |
dee1d5f1 | 36 | ClassImp(AliMpHelper) |
13985652 | 37 | /// \endcond |
dee1d5f1 | 38 | |
39 | //_____________________________________________________________________________ | |
40 | AliMpHelper::AliMpHelper() : TObject() | |
41 | { | |
f5671fc3 | 42 | /// |
43 | /// Default (empty) ctor. | |
44 | /// | |
dee1d5f1 | 45 | } |
46 | ||
47 | //_____________________________________________________________________________ | |
48 | AliMpHelper::~AliMpHelper() | |
49 | { | |
f5671fc3 | 50 | /// |
51 | /// Dtor. | |
52 | /// | |
dee1d5f1 | 53 | } |
54 | ||
315c1275 | 55 | //_____________________________________________________________________________ |
56 | TMap* | |
57 | AliMpHelper::Decode(const TString& s) | |
58 | { | |
59 | /// \todo add comment | |
60 | ||
61 | TString ss(s); | |
62 | ss.ToUpper(); | |
63 | ||
64 | TMap* m = new TMap; | |
65 | m->SetOwner(true); | |
66 | ||
67 | TObjArray* a = ss.Tokenize(";"); | |
68 | TIter next(a); | |
69 | TObjString* o; | |
70 | ||
71 | while ( ( o = static_cast<TObjString*>(next()) ) ) | |
72 | { | |
73 | TString& os(o->String()); | |
74 | TObjArray* b = os.Tokenize("="); | |
75 | if (b->GetEntries()==2) | |
76 | { | |
77 | m->Add(b->At(0),b->At(1)); | |
78 | } | |
79 | } | |
80 | return m; | |
81 | } | |
82 | ||
83 | //_____________________________________________________________________________ | |
84 | Bool_t | |
85 | AliMpHelper::Decode(const TMap& m, const TString& key, TString& value) | |
86 | { | |
87 | /// \todo add comment | |
88 | ||
89 | TString skey(key); | |
90 | skey.ToUpper(); | |
91 | value = ""; | |
92 | TPair* p = static_cast<TPair*>(m.FindObject(skey)); | |
93 | if (p) | |
94 | { | |
95 | value = (static_cast<TObjString*>(p->Value()))->String(); | |
96 | return kTRUE; | |
97 | } | |
98 | return kFALSE; | |
99 | } | |
100 | ||
dee1d5f1 | 101 | //_____________________________________________________________________________ |
102 | void AliMpHelper::DecodeName(const char* name, char sep, TArrayI& theList) | |
103 | { | |
f5671fc3 | 104 | /// |
105 | /// From a string of the form "i-j;k;l;m-n" returns an integer array | |
106 | /// containing all the integers from i to j, then k, l and then from m to | |
107 | /// n. | |
108 | /// | |
dee1d5f1 | 109 | theList.Set(0); |
110 | ||
111 | TString str(name); | |
112 | ||
113 | if ( str.Length() == 0 ) | |
114 | { | |
115 | // protection against empty input string. | |
116 | return; | |
117 | } | |
118 | ||
119 | // Get substrings separated by 'sep' | |
120 | TObjArray* ranges = str.Tokenize(sep); | |
121 | ||
122 | // Finally takes each substring (which ought to be a range of the form | |
123 | // x-y), and decode it into the theList integer vector. | |
124 | for ( Int_t i = 0; i < ranges->GetEntriesFast(); ++i ) | |
125 | { | |
126 | int m1; | |
127 | int m2; | |
128 | int n; | |
129 | int incr; | |
130 | TString& s = ((TObjString*)ranges->At(i))->String(); | |
131 | GetRange(s.Data(),m1,m2,incr,n); | |
132 | int m = m1; | |
133 | while ( n > 0 ) | |
134 | { | |
135 | theList.Set(theList.GetSize()+1); | |
136 | theList[theList.GetSize()-1] = m; | |
137 | m += incr; | |
138 | --n; | |
139 | } | |
140 | } | |
141 | ||
142 | delete ranges; | |
143 | } | |
144 | ||
145 | //_____________________________________________________________________________ | |
146 | void | |
147 | AliMpHelper::GetRange(const char* cstr, Int_t& begin, Int_t& end, | |
148 | Int_t& incr, Int_t& n) | |
149 | { | |
f5671fc3 | 150 | /// |
151 | /// From a string of the form "m-n" returns a range (begin,end), | |
152 | /// its ordering (incr=+-1) and its size (abs(begin-end)+1) | |
153 | /// | |
dee1d5f1 | 154 | TString str(cstr); |
155 | ||
156 | incr = 1; | |
157 | Ssiz_t pos = str.First('-'); | |
158 | if ( pos < 0 ) | |
159 | { | |
160 | begin = str.Atoi(); | |
161 | end = -1; | |
162 | n = 1; | |
163 | } | |
164 | else | |
165 | { | |
166 | begin = str.Atoi(); | |
167 | end = TString(str(pos+1,str.Length()-pos)).Atoi(); | |
168 | if ( begin > end ) | |
169 | { | |
170 | incr = -1; | |
171 | n = begin-end+1; | |
172 | } | |
173 | else | |
174 | { | |
175 | n = end-begin+1; | |
176 | } | |
177 | } | |
178 | } | |
179 | ||
180 | //_____________________________________________________________________________ | |
181 | TString AliMpHelper::Normalize(const char* line) | |
182 | { | |
f5671fc3 | 183 | /// |
184 | /// Remove multiple blanks, and blanks in the begining/end. | |
185 | /// | |
dee1d5f1 | 186 | TString rv(line); |
187 | ||
188 | if ( rv.Length() <= 0 ) return TString(); | |
189 | ||
190 | while ( rv[0] == ' ' ) | |
191 | { | |
192 | rv.Remove(0,1); | |
193 | } | |
194 | while ( rv[rv.Length()-1] == ' ' ) | |
195 | { | |
196 | rv.Remove(rv.Length()-1,1); | |
197 | } | |
198 | Ssiz_t i(0); | |
199 | bool kill = false; | |
200 | for ( i = 0; i < rv.Length(); ++i ) | |
201 | { | |
202 | if ( rv[i] == ' ' ) | |
203 | { | |
204 | if (kill) | |
205 | { | |
206 | rv.Remove(i,1); | |
207 | --i; | |
208 | } | |
209 | else | |
210 | { | |
211 | kill = true; | |
212 | } | |
213 | } | |
214 | else | |
215 | { | |
216 | kill = false; | |
217 | } | |
218 | } | |
219 | return rv; | |
220 | } |