AliRoot Core  a565103 (a565103)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpHelper.cxx
Go to the documentation of this file.
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$
17 // $MpId: AliMpHelper.cxx,v 1.5 2006/05/24 13:58:50 ivana Exp $
18 
19 #include "AliMpHelper.h"
20 
21 #include "TArrayI.h"
22 #include "TObjArray.h"
23 #include "TObjString.h"
24 #include "TString.h"
25 #include "TMap.h"
26 
27 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
34 
38 
39 //_____________________________________________________________________________
40 AliMpHelper::AliMpHelper() : TObject()
41 {
45 }
46 
47 //_____________________________________________________________________________
49 {
53 }
54 
55 //_____________________________________________________________________________
56 TMap*
57 AliMpHelper::Decode(const TString& s)
58 {
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  delete a;
81  return m;
82 }
83 
84 //_____________________________________________________________________________
85 Bool_t
86 AliMpHelper::Decode(const TMap& m, const TString& key, TString& value)
87 {
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 
102 //_____________________________________________________________________________
103 void AliMpHelper::DecodeName(const char* name, char sep, TArrayI& theList)
104 {
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 //_____________________________________________________________________________
147 void
148 AliMpHelper::GetRange(const char* cstr, Int_t& begin, Int_t& end,
149  Int_t& incr, Int_t& n)
150 {
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 //_____________________________________________________________________________
182 TString AliMpHelper::Normalize(const char* line)
183 {
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 }
Helper class to parse slat mapping ascii files.
Definition: AliMpHelper.h:24
virtual ~AliMpHelper()
Definition: AliMpHelper.cxx:48
#define TObjArray
static TString Normalize(const char *line)
static void GetRange(const char *str, Int_t &begin, Int_t &end, Int_t &incr, Int_t &n)
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
static TMap * Decode(const TString &s)
Definition: AliMpHelper.cxx:57
static void DecodeName(const char *manus, char sep, TArrayI &theList)