10 #include "CLHEP/Units/PhysicalConstants.h" 11 using namespace CLHEP;
13 vector<string>
get_info(
string input,
string chars)
23 string chars(
"(),\"");
35 size_t leapos = in.find_first_not_of(
" \t");
36 size_t endpos = in.find_last_not_of(
" \t");
39 if(( string::npos == leapos ) || ( string::npos == endpos))
42 out = in.substr( leapos, endpos-leapos+1 );
52 vector<string> pvalues;
53 stringstream plist(input);
69 vector<string> pvalues;
70 stringstream plist(input);
76 if(tmp.find(ignore) == string::npos)
87 vector<string> pvalues;
90 for(
unsigned int i=0; i<input.size(); i++)
97 pvalues.push_back(tmp);
102 if(i==input.size() - 1)
104 pvalues.push_back(tmp);
117 while(
char c=str[i++])
if(isalpha(c) && !(c==
'-' || c==
'+' || c==
'e' || c==
'E') )
119 cout <<
"WARNING: Unexpected Alphanumberic character found in number string:" << str << endl;
138 if(value.find(
"*") == string::npos)
142 if(value.length()>0 && warn_no_unit &&
stringToDouble(value) != 0) cout <<
"Warning: All numbers should be paired with a unit: " << v << endl;
148 double answer =
scan_number(value.substr(0, value.find(
"*")).c_str());
149 string units =
TrimSpaces(value.substr(value.find(
"*")+1, value.find(
"*") + 20));
150 if( units ==
"m") answer *= m;
151 else if( units ==
"inches") answer *= 2.54*cm;
152 else if( units ==
"inch") answer *= 2.54*cm;
153 else if( units ==
"cm") answer *= cm;
154 else if( units ==
"mm") answer *= mm;
155 else if( units ==
"um") answer *= 1E-6*m;
156 else if( units ==
"fm") answer *= 1E-15*m;
157 else if( units ==
"deg") answer *= deg;
158 else if( units ==
"degrees") answer *= deg;
159 else if( units ==
"arcmin") answer = answer/60.0*deg;
160 else if( units ==
"rad") answer *= rad;
161 else if( units ==
"mrad") answer *= mrad;
162 else if( units ==
"eV") answer *= eV;
163 else if( units ==
"MeV") answer *= MeV;
164 else if( units ==
"KeV") answer *= 0.001*MeV;
165 else if( units ==
"GeV") answer *= GeV;
166 else if( units ==
"T") answer *= tesla;
167 else if( units ==
"T/m") answer *= tesla/m;
168 else if( units ==
"Tesla") answer *= tesla;
169 else if( units ==
"gauss") answer *= gauss;
170 else if( units ==
"kilogauss") answer *= gauss*1000;
171 else if( units ==
"ns") answer *= ns;
172 else if( units ==
"na") answer *= 1;
173 else if( units ==
"counts") answer *= 1;
174 else cout <<
">" << units <<
"<: unit not recognized for string <" << v <<
">" << endl;
186 for(
unsigned int i=0; i<s.size(); i++)
187 cout <<
"string element: " << i <<
" content: " << s[i] << endl;
194 string variation = var;
196 if(vars[0] ==
"main" && vars.size() > 1)
205 if(var.find(
"main:") == 0)
214 ostream &operator<<(ostream &stream, map<string, string> smap)
217 for(map<string, string>::iterator it = smap.begin(); it != smap.end(); it++)
218 cout << it->first <<
" " << it->second << endl;
vector< string > get_strings(string input)
returns a vector of strings from a stringstream, space is delimiter
vector< string > get_info(string input, string chars)
get information from strings such as "5*GeV, 2*deg, 10*deg", parses out strings in second argument ...
double scan_number(const char *str)
string get_variation(string var)
parse variation name from string
string replaceCharWithChars(string input, string x, string y)
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
double stringToDouble(string v)
bool is_main_variation(string var)
returns 1 if the string "main:" is found on the input
string TrimSpaces(string in)
Removes leading and trailing spaces.
vector< string > get_strings_except(string input, string ignore)
returns a vector of strings from a stringstream, space is delimiter, ignore string with second argume...
void print_vstring(vector< string > s)
prints each element of a string vector