#include "ATOOLS/Org/Data_Reader.H" #include "ATOOLS/Org/My_Limits.H" #include "ATOOLS/Org/Message.H" #include "ATOOLS/Org/MyStrStream.H" #include "ATOOLS/Phys/NLO_Types.H" #include #include using namespace ATOOLS; Data_Reader::Data_Reader(): Read_Write_Base(2,0), m_allowunits(false) { SetInFileMode(fom::permanent); } Data_Reader::~Data_Reader() { CloseInFile(0); CloseInFile(1); } Data_Reader::Data_Reader(const std::string &wordsep,const std::string &linesep, const std::string &comment,const std::string &ignore): Read_Write_Base(2,0,wordsep,linesep,comment,ignore), m_allowunits(false) { SetInFileMode(fom::permanent); } void Data_Reader::SetString(const std::string string, bool multiline) { if (multiline) { size_t linebreak = string.find("\n"); if (linebreak!=std::string::npos) { std::string line, endline = ""; for (int k(0);k<(int)string.length();++k) { line+=string[k]; endline=string[k]; if (endline=="\n") { AddFileContent(line,1); line=""; } } } } else { m_string=string; FileContent(1).clear(); AddFileContent(m_string,1); #ifdef DEBUG__Data_Reader msg_IODebugging()< Read_Type Data_Reader::Convert(std::string cur) const { if (cur==nullstring) return Default(); Read_Type value; if (typeid(value)==typeid(int) || typeid(value)==typeid(unsigned int) || typeid(value)==typeid(long) || typeid(value)==typeid(float) || typeid(value)==typeid(double)) { if (!AllowNans()) if (cur=="nan" || cur=="inf" || cur=="NAN" || cur=="INF") cur="1"; if (AllowUnits()) cur=ReplaceUnits(cur); if (Interprete()) cur=Interpreter()->Interprete(StripEscapes(cur)); } return ATOOLS::ToType(cur); } template Read_Type Data_Reader::ReadValue(const std::string ¶meter, const size_t &file) { if (file==0) OpenInFile(file); std::string cur; for (size_t i(0);i(cur); } template std::vector Data_Reader::ReadVector(const std::string ¶meter,const size_t &file) { if (file==0) OpenInFile(file); Read_Type value; std::vector values; size_t last(0); bool found(false); for (size_t i(0);i(cur); found=true; } else { if (i>last) values.clear(); values.push_back(Convert(cur)); for (++j;j(FileContent(file)[i][j])); last=i; } } } if (VectorType()==vtc::vertical) { if (found) values.push_back(value); found=false; } } return values; } template std::vector< std::vector > Data_Reader::ReadMatrix(const std::string ¶meter,const size_t &file) { if (file==0) OpenInFile(file); std::vector< std::vector > values; for (size_t i(0);i(1,Convert(cur))); for (++j;j (FileContent(file)[i][j])); } } } if (MatrixType()==mtc::transposed || values.empty()) return values; std::vector< std::vector > nvalues; size_t max(std::numeric_limits::max()); for (size_t j(0);jvalues[j].size()) max=values[j].size(); nvalues.resize(max,std::vector (values.size(),Default())); for (size_t i(0);i bool Data_Reader:: ReadFromFile(Read_Type &result,std::string parameter) { if ((result=ReadValue(parameter,0))!= Default()) return true; return false; } template bool Data_Reader:: ReadFromString(Read_Type &result,std::string parameter) { if ((result=ReadValue(parameter,1))!= Default()) return true; return false; } template bool Data_Reader:: VectorFromFile(std::vector &result,std::string parameter) { if ((result=ReadVector(parameter,0)).size()!=0) return true; return false; } template bool Data_Reader:: VectorFromString(std::vector &result,std::string parameter) { if ((result=ReadVector(parameter,1)).size()!=0) return true; return false; } template bool Data_Reader:: MatrixFromFile(std::vector > &result, std::string parameter) { if ((result=ReadMatrix(parameter,0)).size()!=0) return true; else return false; } template bool Data_Reader:: MatrixFromString(std::vector > &result, std::string parameter) { if ((result=ReadMatrix(parameter,1)).size()!=0) return true; else return false; } std::string Data_Reader::GetStringNormalisingNoneLikeValues(const std::string ¶meter, const std::string &def) { std::string val = GetValue(parameter, def); NormaliseNoneLikeValue(val); return val; } bool Data_Reader::StringVectorFromFileNormalisingNoneLikeValues(std::vector& vals, std::string parameter) { const bool is_filled = VectorFromFile(vals, parameter); for (std::vector::iterator it = vals.begin(); it != vals.end(); ++it) { NormaliseNoneLikeValue(*it); } return is_filled; } bool Data_Reader::StringVectorFromStringNormalisingNoneLikeValues(std::vector& vals, std::string parameter) { const bool is_filled = VectorFromString(vals, parameter); for (std::vector::iterator it = vals.begin(); it != vals.end(); ++it) { NormaliseNoneLikeValue(*it); } return is_filled; } namespace ATOOLS { template bool Data_Reader::ReadFromFile (bool &,std::string); template bool Data_Reader::ReadFromFile (int &,std::string); template bool Data_Reader::ReadFromFile (unsigned int &,std::string); template bool Data_Reader::ReadFromFile (long int &,std::string); template bool Data_Reader::ReadFromFile (unsigned long int &,std::string); template bool Data_Reader::ReadFromFile (float &,std::string); template bool Data_Reader::ReadFromFile (double &,std::string); template bool Data_Reader::ReadFromFile (std::string &,std::string); template bool Data_Reader::ReadFromFile (cs_itype::type &,std::string); template bool Data_Reader::ReadFromFile (sbt::subtype &,std::string); template bool Data_Reader::ReadFromString (int &,std::string); template bool Data_Reader::ReadFromString (unsigned int &,std::string); template bool Data_Reader::ReadFromString (long int &,std::string); template bool Data_Reader::ReadFromString (unsigned long int &,std::string); template bool Data_Reader::ReadFromString (float &,std::string); template bool Data_Reader::ReadFromString (double &,std::string); template bool Data_Reader::ReadFromString (std::string &,std::string); template bool Data_Reader::ReadFromString (cs_itype::type &,std::string); template bool Data_Reader::ReadFromString (sbt::subtype &,std::string); template bool Data_Reader::VectorFromFile (std::vector &,std::string); template bool Data_Reader::VectorFromFile (std::vector &,std::string); template bool Data_Reader::VectorFromFile (std::vector &,std::string); template bool Data_Reader::VectorFromFile (std::vector &,std::string); template bool Data_Reader::VectorFromFile (std::vector &,std::string); template bool Data_Reader::VectorFromFile (std::vector &,std::string); template bool Data_Reader::VectorFromFile (std::vector &,std::string); template bool Data_Reader::VectorFromFile (std::vector &,std::string); template bool Data_Reader::VectorFromString (std::vector &,std::string); template bool Data_Reader::VectorFromString (std::vector &,std::string); template bool Data_Reader::VectorFromString (std::vector &,std::string); template bool Data_Reader::VectorFromString (std::vector &,std::string); template bool Data_Reader::VectorFromString (std::vector &,std::string); template bool Data_Reader::VectorFromString (std::vector &,std::string); template bool Data_Reader::VectorFromString (std::vector &,std::string); template bool Data_Reader::MatrixFromFile (std::vector > &,std::string); template bool Data_Reader::MatrixFromFile (std::vector > &,std::string); template bool Data_Reader::MatrixFromFile (std::vector > &,std::string); template bool Data_Reader::MatrixFromFile (std::vector > &,std::string); template bool Data_Reader::MatrixFromFile (std::vector > &,std::string); template bool Data_Reader::MatrixFromFile (std::vector > &,std::string); template bool Data_Reader::MatrixFromFile (std::vector > &,std::string); template bool Data_Reader::MatrixFromFile (std::vector > &,std::string); template bool Data_Reader::MatrixFromString (std::vector > &,std::string); template bool Data_Reader::MatrixFromString (std::vector > &,std::string); template bool Data_Reader::MatrixFromString (std::vector > &,std::string); template bool Data_Reader::MatrixFromString (std::vector > &,std::string); template bool Data_Reader::MatrixFromString (std::vector > &,std::string); template bool Data_Reader::MatrixFromString (std::vector > &,std::string); template bool Data_Reader::MatrixFromString (std::vector > &,std::string); }