9 #include "G4UnitsTable.hh" 16 char chars[] =
"(),\"";
29 size_t leapos = in.find_first_not_of(
" \t");
30 size_t endpos = in.find_last_not_of(
" \t");
33 if(( string::npos == leapos ) || ( string::npos == endpos))
36 out = in.substr( leapos, endpos-leapos+1 );
46 vector<string> pvalues;
47 stringstream plist(input);
52 pvalues.push_back(tmp);
69 if(value.find(
"*") == string::npos)
72 return atof(value.c_str());
77 double answer = atof(value.substr(0, value.find(
"*")).c_str());
78 string units =
TrimSpaces(value.substr(value.find(
"*")+1, value.find(
"*") + 20));
79 if( units ==
"m") answer *= m;
80 else if( units ==
"inches") answer *= 2.54*cm;
81 else if( units ==
"cm") answer *= cm;
82 else if( units ==
"mm") answer *= mm;
83 else if( units ==
"um") answer *= 1E-6*m;
84 else if( units ==
"fm") answer *= 1E-15*m;
85 else if( units ==
"deg") answer *= deg;
86 else if( units ==
"arcmin") answer = answer/60.0*deg;
87 else if( units ==
"rad") answer *= rad;
88 else if( units ==
"mrad") answer *= mrad;
89 else if( units ==
"eV") answer *= eV;
90 else if( units ==
"MeV") answer *= MeV;
91 else if( units ==
"KeV") answer *= 0.001*MeV;
92 else if( units ==
"GeV") answer *= GeV;
93 else if( units ==
"T") answer *= tesla;
94 else if( units ==
"Tesla") answer *= tesla;
95 else if( units ==
"ns") answer *= ns;
96 else cout <<
">" << units <<
"<: unit not recognized for string <" << v <<
">" << endl;
108 for(
unsigned int i=0; i<s.size(); i++)
109 cout <<
"string element: " << i <<
" content: " << s[i] << endl;
vector< string > get_strings(string input)
returns a vector of strings from a stringstream
vector< string > get_info(string input)
get information from strings such as "5*GeV, 2*deg, 10*deg"
string replaceCharsWithSpaces(string input, char *x)
double get_number(string v)
Returns dimension from string, i.e. 100*cm.
string TrimSpaces(string in)
Removes leading and trailing spaces.
void print_vstring(vector< string > s)
prints each element of a string vector