]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSt1Decoder.cxx
Improved response simulation for station 1.
[u/mrichter/AliRoot.git] / MUON / AliMUONSt1Decoder.cxx
CommitLineData
ba030c0e 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 purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/*
17$Log$
18*/
19
20// Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
21//
22// Class AliMUONSt1Decoder
23// -----------------------
24// A generic set of functions (defined in the <decoder> namespace).
25// Used to decode formatted strings, eg. a list of integer ranges,
26// or a list of sub-strings separated by delimiters such as '(','{','[', ... .
27// Example:
28// (string 1) (string 2) [string3] {string4} [ (string5.1) (string5.2) ]
29// note : |_____________________|
30// |
31// this is just ONE substring.
32
33
34#include "AliMUONSt1Decoder.h"
35
36using namespace std;
37
38//_____________________________________________________________________
39vector<string> decoder::SplitNtuples(const string& s,
40 const string& leftSep,
41 const string& rightSep)
42
43{
44// separate substrings in <s>, by using the first level of delimiters
45// given in the argument
46// Example:
47// (string 1) (string 2) [string3] {string4} [ (string5.1) (string5.2) ]
48// returns a list of 5 substrings
49// "string 1"
50// "string 2"
51// "string 3"
52// "string 4" and
53// " (string5.1) (string5.2) "
54// --
55 vector<string> ans;
56 string::size_type idx = 0;
57 do {
58 idx = s.find_first_of(leftSep,idx);
59 if (idx != string::npos) {
60 string::size_type sepNum = leftSep.find_first_of(s[idx],0);
61 if (sepNum>=rightSep.length()){
62 idx++;
63 continue;
64 }
65 int count=1;
66 string::size_type idx2 = idx+1;
67 while ((count>0) && (idx2<s.length())){
68 if (s[idx2] == leftSep[sepNum]) count++;
69 if (s[idx2] == rightSep[sepNum]) count--;
70 idx2++;
71 }
72 if (count != 0) return ans; // bad format...stop here
73 ans.push_back(s.substr(idx+1,idx2-idx-2));
74 idx=idx2;
75 }
76 } while (idx != string::npos);
77 return ans;
78}
79
80//_____________________________________________________________________
81vector<string> decoder::SplitList(const string& s,const string& sep)
82{
83// split <s> into several substrings, by using any of the delimters in <sep>
84// Example : str1 ; str2 , str3
85// gives a list of 3 substrings ("str1", "str2" and "str3") if
86// the delimiter parameter is ",;"
87// and a list of 2 substrings ("str1","str2,str3") if
88// the delimiter parameter is ";"
89// --
90 vector<string> ans;
91 string::size_type i=0,j;
92 while ((j=s.find_first_of(sep,i))!=string::npos){
93 ans.push_back(s.substr(i,j-i));
94 i=j+1;
95 }
96 ans.push_back(s.substr(i,s.length()-i));
97 return ans;
98}
99
100//_____________________________________________________________________
101vector<int>
102decoder::DecodeListRanges(const string& s,const string& sep,const string& rangeSep)
103{
104// decode <s> as a list of integers
105// Example: 192/199 ; -10/-7
106// gives a list of 12 integers:
107// 192, 193, 194, 195, 196, 197, 198, 199, -10, -9, -8, -7
108// --
109 vector<int> ans;
110 vector< pair <int,int> > rangeList = DecodeListOfIntRanges(s,sep,rangeSep);
111 for (unsigned int i = 0 ;i<rangeList.size();i++){
112 for (int j=rangeList[i].first;j<=rangeList[i].second;j++){
113 ans.push_back(j);
114 }
115 }
116 return ans;
117}
118
119//_____________________________________________________________________
120vector< pair <int,int> >
121decoder::DecodeListOfIntRanges(const string& s,const string& sep,const string& rangeSep)
122{
123// decodes <s> as a list of int ranges
124// Example: 192/303 ; -10/-1
125// gives a list of two int pairs:
126// pair(192,303) and another pair (-10,-1)
127// --
128 string::size_type i=0;
129 vector< pair <int,int> > ans;
130 if (s.empty()) return ans;
131
132 vector<string> parts = decoder::SplitList(s,sep);
133
134 for (unsigned int k=0;k<parts.size();k++){
135 i=parts[k].find_first_of(rangeSep);
136 int from,to;
137 if (i == string::npos) {
138 from = atoi(parts[k].c_str());
139 to = from;
140 } else {
141 from=atoi(parts[k].substr(0,i).c_str());
142 to =atoi(parts[k].substr(i+1,parts[k].length()-i-1).c_str());
143 }
144 ans.push_back(pair<int,int>(from,to));
145 }
146 return ans;
147}
148
149//_____________________________________________________________________
150vector< pair <double,double> >
151decoder::DecodeListOfFloatRanges(const string& s,const string& sep,const string& rangeSep)
152{
153// decodes <s> as a list of double (floating point) ranges
154// Example : 192.33/303.26 ; -10.2/-1.41
155// gives a list of two double precision floating point (phew!) pairs:
156// pair (192.33,303.26) and another pair (-10.2,-1.41)
157// --
158 string::size_type i=0;
159 vector< pair <double,double> > ans;
160 if (s.empty()) return ans;
161
162 vector<string> parts = decoder::SplitList(s,sep);
163
164 for (unsigned int k=0;k<parts.size();k++){
165 i=parts[k].find_first_of(rangeSep);
166 double from,to;
167 if (i == string::npos) {
168 from = atof(parts[k].c_str());
169 to = from;
170 } else {
171 from=atof(parts[k].substr(0,i).c_str());
172 to =atof(parts[k].substr(i+1,parts[k].length()-i-1).c_str());
173 }
174 ans.push_back(pair<double,double>(from,to));
175 }
176 return ans;
177}