Coding conventions (Laurent)
[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$
17// $MpId: AliMpHelper.cxx,v 1.3 2005/09/19 19:01:31 ivana Exp $
18
19#include "AliMpHelper.h"
20
dee1d5f1 21#include "TArrayI.h"
dee1d5f1 22#include "TObjArray.h"
23#include "TObjString.h"
24#include "TString.h"
25
85fec35d 26///
27/// \class AliMpHelper
28///
29/// Helper class used to parse mapping files for St345 slats.
30///
31/// \author L. Aphecetche
32
dee1d5f1 33ClassImp(AliMpHelper)
34
35//_____________________________________________________________________________
36AliMpHelper::AliMpHelper() : TObject()
37{
38 //
39 // Default (empty) ctor.
40 //
41}
42
43//_____________________________________________________________________________
44AliMpHelper::~AliMpHelper()
45{
46 //
47 // Dtor.
48 //
49}
50
51//_____________________________________________________________________________
52void AliMpHelper::DecodeName(const char* name, char sep, TArrayI& theList)
53{
54 //
55 // From a string of the form "i-j;k;l;m-n" returns an integer array
56 // containing all the integers from i to j, then k, l and then from m to
57 // n.
58 //
59 theList.Set(0);
60
61 TString str(name);
62
63 if ( str.Length() == 0 )
64 {
65 // protection against empty input string.
66 return;
67 }
68
69 // Get substrings separated by 'sep'
70 TObjArray* ranges = str.Tokenize(sep);
71
72 // Finally takes each substring (which ought to be a range of the form
73 // x-y), and decode it into the theList integer vector.
74 for ( Int_t i = 0; i < ranges->GetEntriesFast(); ++i )
75 {
76 int m1;
77 int m2;
78 int n;
79 int incr;
80 TString& s = ((TObjString*)ranges->At(i))->String();
81 GetRange(s.Data(),m1,m2,incr,n);
82 int m = m1;
83 while ( n > 0 )
84 {
85 theList.Set(theList.GetSize()+1);
86 theList[theList.GetSize()-1] = m;
87 m += incr;
88 --n;
89 }
90 }
91
92 delete ranges;
93}
94
95//_____________________________________________________________________________
96void
97AliMpHelper::GetRange(const char* cstr, Int_t& begin, Int_t& end,
98 Int_t& incr, Int_t& n)
99{
100 //
101 // From a string of the form "m-n" returns a range (begin,end),
102 // its ordering (incr=+-1) and its size (abs(begin-end)+1)
103 //
104 TString str(cstr);
105
106 incr = 1;
107 Ssiz_t pos = str.First('-');
108 if ( pos < 0 )
109 {
110 begin = str.Atoi();
111 end = -1;
112 n = 1;
113 }
114 else
115 {
116 begin = str.Atoi();
117 end = TString(str(pos+1,str.Length()-pos)).Atoi();
118 if ( begin > end )
119 {
120 incr = -1;
121 n = begin-end+1;
122 }
123 else
124 {
125 n = end-begin+1;
126 }
127 }
128}
129
130//_____________________________________________________________________________
131TString AliMpHelper::Normalize(const char* line)
132{
133 //
134 // Remove multiple blanks, and blanks in the begining/end.
135 //
136 TString rv(line);
137
138 if ( rv.Length() <= 0 ) return TString();
139
140 while ( rv[0] == ' ' )
141 {
142 rv.Remove(0,1);
143 }
144 while ( rv[rv.Length()-1] == ' ' )
145 {
146 rv.Remove(rv.Length()-1,1);
147 }
148 Ssiz_t i(0);
149 bool kill = false;
150 for ( i = 0; i < rv.Length(); ++i )
151 {
152 if ( rv[i] == ' ' )
153 {
154 if (kill)
155 {
156 rv.Remove(i,1);
157 --i;
158 }
159 else
160 {
161 kill = true;
162 }
163 }
164 else
165 {
166 kill = false;
167 }
168 }
169 return rv;
170}