10 #include "CLHEP/Units/PhysicalConstants.h" 11 using namespace CLHEP;
16 string chars(
"(),\"");
28 size_t leapos = in.find_first_not_of(
" \t");
29 size_t endpos = in.find_last_not_of(
" \t");
32 if(( string::npos == leapos ) || ( string::npos == endpos))
35 out = in.substr( leapos, endpos-leapos+1 );
45 vector<string> pvalues;
46 stringstream plist(input);
62 vector<string> pvalues;
63 stringstream plist(input);
69 if(tmp.find(ignore) == string::npos)
80 vector<string> pvalues;
83 for(
unsigned int i=0; i<input.size(); i++)
90 pvalues.push_back(tmp);
95 if(i==input.size() - 1)
97 pvalues.push_back(tmp);
110 while(
char c=str[i++])
if(isalpha(c) && !(c==
'-' || c==
'+' || c==
'e' || c==
'E') )
112 cout <<
"WARNING: Unexpected Alphanumberic character found in number string:" << str << endl;
131 if(value.find(
"*") == string::npos)
135 if(value.length()>0 && warn_no_unit &&
stringToDouble(value) != 0) cout <<
"Warning: All numbers should be paired with a unit: " << v << endl;
141 double answer =
scan_number(value.substr(0, value.find(
"*")).c_str());
142 string units =
TrimSpaces(value.substr(value.find(
"*")+1, value.find(
"*") + 20));
143 if( units ==
"m") answer *= m;
144 else if( units ==
"inches") answer *= 2.54*cm;
145 else if( units ==
"inch") answer *= 2.54*cm;
146 else if( units ==
"cm") answer *= cm;
147 else if( units ==
"mm") answer *= mm;
148 else if( units ==
"um") answer *= 1E-6*m;
149 else if( units ==
"fm") answer *= 1E-15*m;
150 else if( units ==
"deg") answer *= deg;
151 else if( units ==
"degrees") answer *= deg;
152 else if( units ==
"arcmin") answer = answer/60.0*deg;
153 else if( units ==
"rad") answer *= rad;
154 else if( units ==
"mrad") answer *= mrad;
155 else if( units ==
"eV") answer *= eV;
156 else if( units ==
"MeV") answer *= MeV;
157 else if( units ==
"KeV") answer *= 0.001*MeV;
158 else if( units ==
"GeV") answer *= GeV;
159 else if( units ==
"T") answer *= tesla;
160 else if( units ==
"T/m") answer *= tesla/m;
161 else if( units ==
"Tesla") answer *= tesla;
162 else if( units ==
"gauss") answer *= gauss;
163 else if( units ==
"kilogauss") answer *= gauss*1000;
164 else if( units ==
"ns") answer *= ns;
165 else if( units ==
"na") answer *= 1;
166 else if( units ==
"counts") answer *= 1;
167 else cout <<
">" << units <<
"<: unit not recognized for string <" << v <<
">" << endl;
179 for(
unsigned int i=0; i<s.size(); i++)
180 cout <<
"string element: " << i <<
" content: " << s[i] << endl;
187 string variation = var;
189 if(vars[0] ==
"main" && vars.size() > 1)
198 if(var.find(
"main:") == 0)
207 ostream &operator<<(ostream &stream, map<string, string> smap)
210 for(map<string, string>::iterator it = smap.begin(); it != smap.end(); it++)
211 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)
get information from strings such as "5*GeV, 2*deg, 10*deg"
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