1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpHelper.cxx,v 1.5 2006/05/24 13:58:50 ivana Exp $
19 #include "AliMpHelper.h"
22 #include "TObjArray.h"
23 #include "TObjString.h"
27 //-----------------------------------------------------------------------------
28 /// \class AliMpHelper
30 /// Helper class used to parse mapping files for St345 slats.
32 /// \author L. Aphecetche
33 //-----------------------------------------------------------------------------
39 //_____________________________________________________________________________
40 AliMpHelper::AliMpHelper() : TObject()
43 /// Default (empty) ctor.
47 //_____________________________________________________________________________
48 AliMpHelper::~AliMpHelper()
55 //_____________________________________________________________________________
57 AliMpHelper::Decode(const TString& s)
67 TObjArray* a = ss.Tokenize(";");
71 while ( ( o = static_cast<TObjString*>(next()) ) )
73 TString& os(o->String());
74 TObjArray* b = os.Tokenize("=");
75 if (b->GetEntries()==2)
77 m->Add(b->At(0),b->At(1));
83 //_____________________________________________________________________________
85 AliMpHelper::Decode(const TMap& m, const TString& key, TString& value)
92 TPair* p = static_cast<TPair*>(m.FindObject(skey));
95 value = (static_cast<TObjString*>(p->Value()))->String();
101 //_____________________________________________________________________________
102 void AliMpHelper::DecodeName(const char* name, char sep, TArrayI& theList)
105 /// From a string of the form "i-j;k;l;m-n" returns an integer array
106 /// containing all the integers from i to j, then k, l and then from m to
113 if ( str.Length() == 0 )
115 // protection against empty input string.
119 // Get substrings separated by 'sep'
120 TObjArray* ranges = str.Tokenize(sep);
122 // Finally takes each substring (which ought to be a range of the form
123 // x-y), and decode it into the theList integer vector.
124 for ( Int_t i = 0; i < ranges->GetEntriesFast(); ++i )
130 TString& s = ((TObjString*)ranges->At(i))->String();
131 GetRange(s.Data(),m1,m2,incr,n);
135 theList.Set(theList.GetSize()+1);
136 theList[theList.GetSize()-1] = m;
145 //_____________________________________________________________________________
147 AliMpHelper::GetRange(const char* cstr, Int_t& begin, Int_t& end,
148 Int_t& incr, Int_t& n)
151 /// From a string of the form "m-n" returns a range (begin,end),
152 /// its ordering (incr=+-1) and its size (abs(begin-end)+1)
157 Ssiz_t pos = str.First('-');
167 end = TString(str(pos+1,str.Length()-pos)).Atoi();
180 //_____________________________________________________________________________
181 TString AliMpHelper::Normalize(const char* line)
184 /// Remove multiple blanks, and blanks in the begining/end.
188 if ( rv.Length() <= 0 ) return TString();
190 while ( rv[0] == ' ' )
194 while ( rv[rv.Length()-1] == ' ' )
196 rv.Remove(rv.Length()-1,1);
200 for ( i = 0; i < rv.Length(); ++i )