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