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