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