54#include "egs_functions.h"
56#include "egs_interpolator.h"
68std::vector<std::string> &
split(
const std::string &s,
char delim, std::vector<std::string> &elems) {
69 std::stringstream ss(s);
71 while (std::getline(ss, item, delim)) {
72 elems.push_back(item);
79std::vector<std::string>
split(
const std::string &s,
char delim) {
80 std::vector<std::string> elems;
81 split(s, delim, elems);
86static inline std::string <rim(std::string &s) {
87 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
unsigned char ch) {return !std::isspace(ch);}));
92static inline std::string &rtrim(std::string &s) {
93 s.erase(std::find_if(s.rbegin(), s.rend(), [](
unsigned char ch) {return !std::isspace(ch);}).base(), s.end());
98static inline std::string &trim(std::string &s) {
99 return ltrim(rtrim(s));
145 string cur_med_name, dummy;
151 if (trim(line).size() == 0) {
155 bool new_med = line.find(
MUEN_START) != string::npos;
160 cur_med_name = trim(
split(line,
'=')[1]);
161 for (
int i=0; i <
NSKIP; i++) {
163 if (trim(dummy).size() == 0) {
169 istringstream iss(line);
176 if (iss.fail() && in) {
177 egsWarning(
"MuenDataParser:: Invalid muen data file format. Last line was:\n%s\n ", line.c_str());
181 med_lines[cur_med_name].push_back(
MuenAtET(energy,
muen));
209 ifstream muen_data(filename.c_str());
230 size_t ndat =
med_data[med_name].size();
234 EGS_Float emin =
med_data[med_name][0].first;
235 EGS_Float emax=
med_data[med_name][ndat-1].first;
237 EGS_Float *fmuen =
new EGS_Float[ndat];
238 for (
size_t i=0; i < ndat; i++) {
239 fmuen[i] =
med_data[med_name][i].second;
242 EGS_Interpolator *
muen =
new EGS_Interpolator(ndat, log(emin), log(emax), fmuen);
class for parsing muen data from a file.
int setMuenFile(string filename)
MuenMapT splitFileByMed(ifstream &in)
does the actual parsing of data from the muen file
EGS_Interpolator * getMuenInterpolator(string med_name)
Create a new EGS_Interpolator of muen data for the requested medium and return pointer to it....
static const string MUEN_START
MuenDataParser()
construct class by parsing the data file. Note the actual EGS_Interpolator classes are only created w...
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Split a string on input delimeter.
map< string, vector< MuenAtET > > MuenMapT
Map from medium name to vector of (e, muen(e)) data for that medium.
pair< double, double > MuenAtET
pair of form (energy, muen(energy))