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