mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-06-19 07:47:05 +01:00
LatCore compatibility
This commit is contained in:
@ -146,7 +146,7 @@ void Chi2Function::resizeBuffer(void) const
|
||||
|
||||
// compute variance matrix inverse /////////////////////////////////////////////
|
||||
void Chi2Function::setVarianceBlock(const Index l1, const Index l2,
|
||||
ConstBlock<DMatBase> m) const
|
||||
ConstBlock<MatBase<double>> m) const
|
||||
{
|
||||
const Index nPoint = data_.getNFitPoint();
|
||||
|
||||
|
@ -67,7 +67,7 @@ private:
|
||||
|
||||
// compute variance matrix inverse
|
||||
void setVarianceBlock(const Index l1, const Index l2,
|
||||
ConstBlock<DMatBase> m) const;
|
||||
ConstBlock<MatBase<double>> m) const;
|
||||
void initBuffer(void) const;
|
||||
private:
|
||||
const XYStatData &data_;
|
||||
|
@ -31,22 +31,3 @@ const string Env::msgPrefix = "[" + strFrom(PACKAGE_NAME) + " v"
|
||||
|
||||
void Env::function(void)
|
||||
{}
|
||||
|
||||
ostream & Latan::operator<<(ostream &out, const ProgressBar &&bar)
|
||||
{
|
||||
const Index nTick = bar.nCol_*bar.current_/bar.total_;
|
||||
|
||||
out << "[";
|
||||
for (Index i = 0; i < nTick; ++i)
|
||||
{
|
||||
out << "=";
|
||||
}
|
||||
for (Index i = nTick; i < bar.nCol_; ++i)
|
||||
{
|
||||
out << " ";
|
||||
}
|
||||
out << "] " << bar.current_ << "/" << bar.total_;
|
||||
out.flush();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
238
lib/Global.hpp
238
lib/Global.hpp
@ -20,10 +20,7 @@
|
||||
#ifndef Latan_Global_hpp_
|
||||
#define Latan_Global_hpp_
|
||||
|
||||
// supress warning for the osbolete use of 'register' keyword in Eigen
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-register"
|
||||
|
||||
#include <LatAnalyze/Eigen/Dense>
|
||||
#include <LatCore/LatCore.hpp>
|
||||
#include <complex>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@ -34,117 +31,18 @@
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
#define BEGIN_LATAN_NAMESPACE namespace Latan {
|
||||
#define BEGIN_LATAN_NAMESPACE \
|
||||
namespace Latan {\
|
||||
using namespace LatCore;
|
||||
#define END_LATAN_NAMESPACE }
|
||||
|
||||
// macro utilities
|
||||
#define unique_arg(...) __VA_ARGS__
|
||||
#define DEBUG_VAR(x) std::cout << #x << "= " << x << std::endl
|
||||
#define DEBUG_MAT(m) std::cout << #m << "=\n" << m << std::endl
|
||||
|
||||
// attribute to switch off unused warnings with gcc
|
||||
#ifndef __GNUC__
|
||||
#define __unused
|
||||
#endif
|
||||
|
||||
// max length for paths
|
||||
#define MAX_PATH_LENGTH 512u
|
||||
|
||||
// copy/assignement from Eigen expression
|
||||
#define EIGEN_EXPR_CTOR(ctorName, Class, Base, ExprType) \
|
||||
template <typename Derived>\
|
||||
ctorName(const ExprType<Derived> &m): Base(m) {}\
|
||||
template<typename Derived>\
|
||||
Class & operator=(const ExprType<Derived> &m)\
|
||||
{\
|
||||
this->Base::operator=(m);\
|
||||
return *this;\
|
||||
}
|
||||
|
||||
BEGIN_LATAN_NAMESPACE
|
||||
|
||||
// Eigen type aliases //////////////////////////////////////////////////////////
|
||||
const int dynamic = -1;
|
||||
|
||||
// array types
|
||||
template <typename Derived>
|
||||
using ArrayExpr = Eigen::ArrayBase<Derived>;
|
||||
|
||||
template <typename T, int nRow = dynamic, int nCol = dynamic>
|
||||
using Array = Eigen::Array<T, nRow, nCol>;
|
||||
|
||||
// matrix types
|
||||
template <typename Derived>
|
||||
using MatExpr = Eigen::MatrixBase<Derived>;
|
||||
|
||||
template <typename T, int nRow = dynamic, int nCol = dynamic>
|
||||
using MatBase = Eigen::Matrix<T, nRow, nCol>;
|
||||
|
||||
typedef MatBase<double> DMatBase;
|
||||
|
||||
// vector types
|
||||
template <typename T>
|
||||
using Vec = MatBase<T, dynamic, 1>;
|
||||
|
||||
typedef Vec<int> IVec;
|
||||
typedef Vec<long int> LVec;
|
||||
typedef Vec<double> DVec;
|
||||
typedef Vec<std::complex<double>> CVec;
|
||||
|
||||
#define FOR_VEC(vec, i) for (Latan::Index i = 0; i < (vec).size(); ++i)
|
||||
#define FOR_ARRAY(ar, i) FOR_VEC(ar, i)
|
||||
|
||||
// block types
|
||||
template <typename Derived>
|
||||
using Block = Eigen::Block<Derived>;
|
||||
template <typename Derived>
|
||||
using ConstBlock = const Eigen::Block<const Derived>;
|
||||
|
||||
template <typename Derived>
|
||||
using Row = typename Derived::RowXpr;
|
||||
template <typename Derived>
|
||||
using ConstRow = typename Derived::ConstRowXpr;
|
||||
|
||||
template <typename Derived>
|
||||
using Col = typename Derived::ColXpr;
|
||||
template <typename Derived>
|
||||
using ConstCol = typename Derived::ConstColXpr;
|
||||
|
||||
// map type
|
||||
template <typename Derived>
|
||||
using Map = Eigen::Map<Derived>;
|
||||
template <typename Derived>
|
||||
using ConstMap = Eigen::Map<const Derived>;
|
||||
|
||||
// Index type //////////////////////////////////////////////////////////////////
|
||||
typedef MatBase<double>::Index Index;
|
||||
|
||||
// Placeholder type ////////////////////////////////////////////////////////////
|
||||
struct PlaceHolder {};
|
||||
|
||||
extern PlaceHolder _;
|
||||
|
||||
// Type utilities //////////////////////////////////////////////////////////////
|
||||
// pointer type test
|
||||
template <typename Derived, typename Base>
|
||||
inline bool isDerivedFrom(const Base *pt)
|
||||
{
|
||||
return (dynamic_cast<const Derived *>(pt) != nullptr);
|
||||
}
|
||||
|
||||
// static logical or
|
||||
template <bool... b>
|
||||
struct static_or;
|
||||
|
||||
template <bool... tail>
|
||||
struct static_or<true, tail...> : static_or<tail...> {};
|
||||
|
||||
template <bool... tail>
|
||||
struct static_or<false, tail...> : std::false_type {};
|
||||
|
||||
template <>
|
||||
struct static_or<> : std::true_type {};
|
||||
|
||||
// Environment /////////////////////////////////////////////////////////////////
|
||||
namespace Env
|
||||
{
|
||||
@ -156,134 +54,6 @@ namespace Env
|
||||
void function(void);
|
||||
}
|
||||
|
||||
// String conversions //////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline T strTo(const std::string &str)
|
||||
{
|
||||
T buf;
|
||||
std::istringstream stream(str);
|
||||
|
||||
stream >> buf;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
// optimized specializations
|
||||
template <>
|
||||
inline float strTo<float>(const std::string &str)
|
||||
{
|
||||
return strtof(str.c_str(), (char **)NULL);
|
||||
}
|
||||
template <>
|
||||
inline double strTo<double>(const std::string &str)
|
||||
{
|
||||
return strtod(str.c_str(), (char **)NULL);
|
||||
}
|
||||
template <>
|
||||
inline int strTo<int>(const std::string &str)
|
||||
{
|
||||
return (int)(strtol(str.c_str(), (char **)NULL, 10));
|
||||
}
|
||||
template <>
|
||||
inline long strTo<long>(const std::string &str)
|
||||
{
|
||||
return strtol(str.c_str(), (char **)NULL, 10);
|
||||
}
|
||||
template <>
|
||||
inline std::string strTo<std::string>(const std::string &str)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::string strFrom(const T x)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
|
||||
stream << x;
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
// specialization for vectors
|
||||
template<>
|
||||
inline DVec strTo<DVec>(const std::string &str)
|
||||
{
|
||||
DVec res;
|
||||
std::vector<double> vbuf;
|
||||
double buf;
|
||||
std::istringstream stream(str);
|
||||
|
||||
while (!stream.eof())
|
||||
{
|
||||
stream >> buf;
|
||||
vbuf.push_back(buf);
|
||||
}
|
||||
res = Map<DVec>(vbuf.data(), static_cast<Index>(vbuf.size()));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline IVec strTo<IVec>(const std::string &str)
|
||||
{
|
||||
IVec res;
|
||||
std::vector<int> vbuf;
|
||||
int buf;
|
||||
std::istringstream stream(str);
|
||||
|
||||
while (!stream.eof())
|
||||
{
|
||||
stream >> buf;
|
||||
vbuf.push_back(buf);
|
||||
}
|
||||
res = Map<IVec>(vbuf.data(), static_cast<Index>(vbuf.size()));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// Manifest file reader ////////////////////////////////////////////////////////
|
||||
inline std::vector<std::string> readManifest(const std::string manFileName)
|
||||
{
|
||||
std::vector<std::string> list;
|
||||
std::ifstream manFile;
|
||||
char buf[MAX_PATH_LENGTH];
|
||||
|
||||
manFile.open(manFileName);
|
||||
while (!manFile.eof())
|
||||
{
|
||||
manFile.getline(buf, MAX_PATH_LENGTH);
|
||||
if (!std::string(buf).empty())
|
||||
{
|
||||
list.push_back(buf);
|
||||
}
|
||||
}
|
||||
manFile.close();
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// Progress bar class //////////////////////////////////////////////////////////
|
||||
class ProgressBar
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
template <typename A, typename B>
|
||||
ProgressBar(const A current, const B total, const Index nCol = 60);
|
||||
// IO
|
||||
friend std::ostream & operator<<(std::ostream &out,
|
||||
const ProgressBar &&bar);
|
||||
private:
|
||||
Index current_, total_, nCol_;
|
||||
};
|
||||
|
||||
template <typename A, typename B>
|
||||
ProgressBar::ProgressBar(const A current, const B total, const Index nCol)
|
||||
: current_(static_cast<Index>(current))
|
||||
, total_(static_cast<Index>(total))
|
||||
, nCol_(nCol)
|
||||
{}
|
||||
|
||||
END_LATAN_NAMESPACE
|
||||
|
||||
#include <LatAnalyze/Exceptions.hpp>
|
||||
|
@ -1,29 +1,19 @@
|
||||
if CC_GNU
|
||||
COM_CFLAGS = -Wall -W -pedantic
|
||||
else
|
||||
if CC_INTEL
|
||||
COM_CFLAGS = -Wall
|
||||
endif
|
||||
endif
|
||||
|
||||
COM_CXXFLAGS = -Wall -Wconversion
|
||||
if CXX_GNU
|
||||
COM_CXXFLAGS = -Wall -W -pedantic
|
||||
COM_CXXFLAGS += -W -pedantic
|
||||
else
|
||||
if CXX_INTEL
|
||||
COM_CXXFLAGS = -Wall
|
||||
COM_CXXFLAGS +=
|
||||
endif
|
||||
endif
|
||||
|
||||
AM_LFLAGS = -olex.yy.c
|
||||
AM_YFLAGS = -d
|
||||
|
||||
include eigen_files.mk
|
||||
nobase_dist_pkginclude_HEADERS = $(eigen_files) XML/tinyxml2.hpp
|
||||
|
||||
BUILT_SOURCES = AsciiParser.hpp MathParser.hpp
|
||||
|
||||
lib_LTLIBRARIES = libLatAnalyze.la
|
||||
|
||||
lib_LTLIBRARIES = libLatAnalyze.la
|
||||
|
||||
libLatAnalyze_la_SOURCES = \
|
||||
AsciiFile.cpp \
|
||||
AsciiParser.ypp \
|
||||
@ -53,10 +43,8 @@ libLatAnalyze_la_SOURCES = \
|
||||
RootFinder.cpp \
|
||||
Solver.cpp \
|
||||
TabFunction.cpp \
|
||||
XmlReader.cpp \
|
||||
XYSampleData.cpp \
|
||||
XYStatData.cpp \
|
||||
XML/tinyxml2.cpp \
|
||||
../config.h
|
||||
libLatAnalyze_ladir = $(pkgincludedir)
|
||||
libLatAnalyze_la_HEADERS = \
|
||||
@ -88,15 +76,12 @@ libLatAnalyze_la_HEADERS = \
|
||||
TabFunction.hpp \
|
||||
Solver.hpp \
|
||||
StatArray.hpp \
|
||||
XmlReader.hpp \
|
||||
XYSampleData.hpp \
|
||||
XYStatData.hpp
|
||||
if HAVE_MINUIT
|
||||
libLatAnalyze_la_SOURCES += MinuitMinimizer.cpp
|
||||
libLatAnalyze_la_HEADERS += MinuitMinimizer.hpp
|
||||
libLatAnalyze_la_SOURCES += MinuitMinimizer.cpp
|
||||
libLatAnalyze_la_HEADERS += MinuitMinimizer.hpp
|
||||
endif
|
||||
|
||||
libLatAnalyze_la_CFLAGS = $(COM_CFLAGS)
|
||||
libLatAnalyze_la_CXXFLAGS = $(COM_CXXFLAGS)
|
||||
|
||||
ACLOCAL_AMFLAGS = -I .buildutils/m4
|
||||
|
2194
lib/XML/tinyxml2.cpp
2194
lib/XML/tinyxml2.cpp
File diff suppressed because it is too large
Load Diff
2076
lib/XML/tinyxml2.hpp
2076
lib/XML/tinyxml2.hpp
File diff suppressed because it is too large
Load Diff
@ -89,36 +89,40 @@ void XYStatData::reinitChi2(const bool doReinit)
|
||||
reinitChi2_ = doReinit;
|
||||
}
|
||||
|
||||
Block<DMatBase> XYStatData::x(const PlaceHolder ph1 __unused,
|
||||
const PlaceHolder ph2 __unused)
|
||||
Block<MatBase<double>> XYStatData::x(const PlaceHolder ph1 __unused,
|
||||
const PlaceHolder ph2 __unused)
|
||||
{
|
||||
return x_.block(0, 0, getNData(), getXDim());
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::x(const PlaceHolder ph1 __unused,
|
||||
const PlaceHolder ph2 __unused) const
|
||||
ConstBlock<MatBase<double>> XYStatData::x(const PlaceHolder ph1 __unused,
|
||||
const PlaceHolder ph2 __unused)
|
||||
const
|
||||
{
|
||||
return x_.block(0, 0, getNData(), getXDim());
|
||||
}
|
||||
|
||||
Block<DMatBase> XYStatData::x(const Index i, const PlaceHolder ph2 __unused)
|
||||
Block<MatBase<double>> XYStatData::x(const Index i,
|
||||
const PlaceHolder ph2 __unused)
|
||||
{
|
||||
return x_.block(0, i, getNData(), 1);
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::x(const Index i,
|
||||
const PlaceHolder ph2 __unused) const
|
||||
ConstBlock<MatBase<double>> XYStatData::x(const Index i,
|
||||
const PlaceHolder ph2 __unused)
|
||||
const
|
||||
{
|
||||
return x_.block(0, i, getNData(), 1);
|
||||
}
|
||||
|
||||
Block<DMatBase> XYStatData::x(const PlaceHolder ph1 __unused, const Index k)
|
||||
Block<MatBase<double>> XYStatData::x(const PlaceHolder ph1 __unused,
|
||||
const Index k)
|
||||
{
|
||||
return x_.block(k, 0, 1, getXDim());
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::x(const PlaceHolder ph1 __unused,
|
||||
const Index k) const
|
||||
ConstBlock<MatBase<double>> XYStatData::x(const PlaceHolder ph1 __unused,
|
||||
const Index k) const
|
||||
{
|
||||
return x_.block(k, 0, 1, getXDim());
|
||||
}
|
||||
@ -133,36 +137,39 @@ const double & XYStatData::x(const Index i, const Index k) const
|
||||
return x_(k, i);
|
||||
}
|
||||
|
||||
Block<DMatBase> XYStatData::y(const PlaceHolder ph1 __unused,
|
||||
const PlaceHolder ph2 __unused)
|
||||
Block<MatBase<double>> XYStatData::y(const PlaceHolder ph1 __unused,
|
||||
const PlaceHolder ph2 __unused)
|
||||
{
|
||||
return y_.block(0, 0, getNData(), getYDim());
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::y(const PlaceHolder ph1 __unused,
|
||||
const PlaceHolder ph2 __unused) const
|
||||
ConstBlock<MatBase<double>> XYStatData::y(const PlaceHolder ph1 __unused,
|
||||
const PlaceHolder ph2 __unused)
|
||||
const
|
||||
{
|
||||
return y_.block(0, 0, getNData(), getYDim());
|
||||
}
|
||||
|
||||
Block<DMatBase> XYStatData::y(const Index j, const PlaceHolder ph2 __unused)
|
||||
Block<MatBase<double>> XYStatData::y(const Index j,
|
||||
const PlaceHolder ph2 __unused)
|
||||
{
|
||||
return y_.block(0, j, getNData(), 1);
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::y(const Index j,
|
||||
const PlaceHolder ph2 __unused) const
|
||||
ConstBlock<MatBase<double>> XYStatData::y(const Index j,
|
||||
const PlaceHolder ph2 __unused)
|
||||
const
|
||||
{
|
||||
return y_.block(0, j, getNData(), 1);
|
||||
}
|
||||
|
||||
Block<DMatBase> XYStatData::y(const PlaceHolder ph1 __unused, const Index k)
|
||||
Block<MatBase<double>> XYStatData::y(const PlaceHolder ph1 __unused, const Index k)
|
||||
{
|
||||
return y_.block(k, 0, 1, getYDim());
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::y(const PlaceHolder ph1 __unused,
|
||||
const Index k) const
|
||||
ConstBlock<MatBase<double>> XYStatData::y(const PlaceHolder ph1 __unused,
|
||||
const Index k) const
|
||||
{
|
||||
return y_.block(k, 0, 1, getYDim());
|
||||
}
|
||||
@ -179,32 +186,35 @@ const double & XYStatData::y(const Index j, const Index k) const
|
||||
|
||||
#define FULL_BLOCK(m) (m).block(0, 0, (m).rows(), (m).cols())
|
||||
|
||||
Block<DMatBase> XYStatData::xxVar(const Index i1, const Index i2)
|
||||
Block<MatBase<double>> XYStatData::xxVar(const Index i1, const Index i2)
|
||||
{
|
||||
return FULL_BLOCK(var_[xx](i1, i2));
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::xxVar(const Index i1, const Index i2) const
|
||||
ConstBlock<MatBase<double>> XYStatData::xxVar(const Index i1,
|
||||
const Index i2) const
|
||||
{
|
||||
return FULL_BLOCK(var_[xx](i1, i2));
|
||||
}
|
||||
|
||||
Block<DMatBase> XYStatData::yyVar(const Index j1, const Index j2)
|
||||
Block<MatBase<double>> XYStatData::yyVar(const Index j1, const Index j2)
|
||||
{
|
||||
return FULL_BLOCK(var_[yy](j1, j2));
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::yyVar(const Index j1, const Index j2) const
|
||||
ConstBlock<MatBase<double>> XYStatData::yyVar(const Index j1,
|
||||
const Index j2) const
|
||||
{
|
||||
return FULL_BLOCK(var_[yy](j1, j2));
|
||||
}
|
||||
|
||||
Block<DMatBase> XYStatData::yxVar(const Index j, const Index i)
|
||||
Block<MatBase<double>> XYStatData::yxVar(const Index j, const Index i)
|
||||
{
|
||||
return FULL_BLOCK(var_[yx](j, i));
|
||||
}
|
||||
|
||||
ConstBlock<DMatBase> XYStatData::yxVar(const Index j, const Index i) const
|
||||
ConstBlock<MatBase<double>> XYStatData::yxVar(const Index j,
|
||||
const Index i) const
|
||||
{
|
||||
return FULL_BLOCK(var_[yx](j, i));
|
||||
}
|
||||
|
@ -76,32 +76,36 @@ public:
|
||||
void resize(const Index nData, const Index xDim,
|
||||
const Index yDim);
|
||||
void reinitChi2(const bool doReinit = true);
|
||||
Block<DMatBase> x(const PlaceHolder ph1 = _,
|
||||
const PlaceHolder ph2 = _);
|
||||
ConstBlock<DMatBase> x(const PlaceHolder ph1 = _,
|
||||
const PlaceHolder ph2 = _) const;
|
||||
Block<DMatBase> x(const Index i, const PlaceHolder ph2 = _);
|
||||
ConstBlock<DMatBase> x(const Index i, const PlaceHolder ph2 = _) const;
|
||||
Block<DMatBase> x(const PlaceHolder ph1, const Index k);
|
||||
ConstBlock<DMatBase> x(const PlaceHolder ph1, const Index k) const;
|
||||
double & x(const Index i, const Index k);
|
||||
const double & x(const Index i, const Index k) const;
|
||||
Block<DMatBase> y(const PlaceHolder ph1 = _,
|
||||
const PlaceHolder ph2 = _);
|
||||
ConstBlock<DMatBase> y(const PlaceHolder ph1 = _,
|
||||
const PlaceHolder ph2 = _) const;
|
||||
Block<DMatBase> y(const Index i, const PlaceHolder ph2 = _);
|
||||
ConstBlock<DMatBase> y(const Index i, const PlaceHolder ph2 = _) const;
|
||||
Block<DMatBase> y(const PlaceHolder ph1, const Index k);
|
||||
ConstBlock<DMatBase> y(const PlaceHolder ph1, const Index k) const;
|
||||
double & y(const Index i, const Index k);
|
||||
const double & y(const Index i, const Index k) const;
|
||||
Block<DMatBase> xxVar(const Index i1, const Index i2);
|
||||
ConstBlock<DMatBase> xxVar(const Index i1, const Index i2) const;
|
||||
Block<DMatBase> yyVar(const Index j1, const Index j2);
|
||||
ConstBlock<DMatBase> yyVar(const Index j1, const Index j2) const;
|
||||
Block<DMatBase> yxVar(const Index j, const Index i);
|
||||
ConstBlock<DMatBase> yxVar(const Index j, const Index i) const;
|
||||
Block<MatBase<double>> x(const PlaceHolder ph1 = _,
|
||||
const PlaceHolder ph2 = _);
|
||||
ConstBlock<MatBase<double>> x(const PlaceHolder ph1 = _,
|
||||
const PlaceHolder ph2 = _) const;
|
||||
Block<MatBase<double>> x(const Index i, const PlaceHolder ph2 = _);
|
||||
ConstBlock<MatBase<double>> x(const Index i,
|
||||
const PlaceHolder ph2 = _) const;
|
||||
Block<MatBase<double>> x(const PlaceHolder ph1, const Index k);
|
||||
ConstBlock<MatBase<double>> x(const PlaceHolder ph1,
|
||||
const Index k) const;
|
||||
double & x(const Index i, const Index k);
|
||||
const double & x(const Index i, const Index k) const;
|
||||
Block<MatBase<double>> y(const PlaceHolder ph1 = _,
|
||||
const PlaceHolder ph2 = _);
|
||||
ConstBlock<MatBase<double>> y(const PlaceHolder ph1 = _,
|
||||
const PlaceHolder ph2 = _) const;
|
||||
Block<MatBase<double>> y(const Index i, const PlaceHolder ph2 = _);
|
||||
ConstBlock<MatBase<double>> y(const Index i,
|
||||
const PlaceHolder ph2 = _) const;
|
||||
Block<MatBase<double>> y(const PlaceHolder ph1, const Index k);
|
||||
ConstBlock<MatBase<double>> y(const PlaceHolder ph1,
|
||||
const Index k) const;
|
||||
double & y(const Index i, const Index k);
|
||||
const double & y(const Index i, const Index k) const;
|
||||
Block<MatBase<double>> xxVar(const Index i1, const Index i2);
|
||||
ConstBlock<MatBase<double>> xxVar(const Index i1, const Index i2) const;
|
||||
Block<MatBase<double>> yyVar(const Index j1, const Index j2);
|
||||
ConstBlock<MatBase<double>> yyVar(const Index j1, const Index j2) const;
|
||||
Block<MatBase<double>> yxVar(const Index j, const Index i);
|
||||
ConstBlock<MatBase<double>> yxVar(const Index j, const Index i) const;
|
||||
// fit
|
||||
FitResult fit(Minimizer &minimizer, const DVec &init,
|
||||
const std::vector<const DoubleModel *> &modelVector);
|
||||
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* XmlReader.cpp, part of LatAnalyze 3
|
||||
*
|
||||
* Copyright (C) 2013 - 2014 Antonin Portelli
|
||||
*
|
||||
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <LatAnalyze/XmlReader.hpp>
|
||||
#include <LatAnalyze/includes.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace Latan;
|
||||
|
||||
/******************************************************************************
|
||||
* XmlReader implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
XmlReader::XmlReader(const string &fileName)
|
||||
{
|
||||
open(fileName);
|
||||
}
|
||||
|
||||
// IO //////////////////////////////////////////////////////////////////////////
|
||||
void XmlReader::open(const std::string &fileName)
|
||||
{
|
||||
name_ = fileName;
|
||||
doc_.LoadFile(name_.c_str());
|
||||
if (doc_.Error())
|
||||
{
|
||||
string errMsg1, errMsg2;
|
||||
|
||||
if (doc_.GetErrorStr1())
|
||||
{
|
||||
errMsg1 = doc_.GetErrorStr1();
|
||||
}
|
||||
if (doc_.GetErrorStr2())
|
||||
{
|
||||
errMsg2 = doc_.GetErrorStr2();
|
||||
}
|
||||
LATAN_ERROR(Io, "tinyxml2 code " + strFrom(doc_.ErrorID()) + ": " +
|
||||
errMsg1 + " - " + errMsg2);
|
||||
}
|
||||
root_ = doc_.RootElement();
|
||||
}
|
||||
|
||||
// XML structure access ////////////////////////////////////////////////////////
|
||||
const XmlNode * XmlReader::getNextNode(const XmlNode *node)
|
||||
{
|
||||
if (node)
|
||||
{
|
||||
return node->NextSiblingElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
/*
|
||||
* XmlReader.hpp, part of LatAnalyze 3
|
||||
*
|
||||
* Copyright (C) 2013 - 2014 Antonin Portelli
|
||||
*
|
||||
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef Latan_XmlReader_hpp_
|
||||
#define Latan_XmlReader_hpp_
|
||||
|
||||
#include <LatAnalyze/Global.hpp>
|
||||
#include <LatAnalyze/XML/tinyxml2.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
BEGIN_LATAN_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* XML parameter file reader *
|
||||
******************************************************************************/
|
||||
typedef tinyxml2::XMLElement XmlNode;
|
||||
|
||||
class XmlReader
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
XmlReader(void) = default;
|
||||
explicit XmlReader(const std::string &fileName);
|
||||
// destructor
|
||||
virtual ~XmlReader(void) = default;
|
||||
// IO
|
||||
void open(const std::string &fileName);
|
||||
// XML structure access
|
||||
template <typename... Strs>
|
||||
static const XmlNode * getFirstNode(const XmlNode *startNode,
|
||||
const std::string &nodeName,
|
||||
Strs... nodeNames);
|
||||
template <typename... Strs>
|
||||
const XmlNode * getFirstNode(const std::string &nodeName,
|
||||
Strs... nodeNames) const;
|
||||
static const XmlNode * getNextNode(const XmlNode *node);
|
||||
template <typename T>
|
||||
static T getValue(const XmlNode *node);
|
||||
template <typename T, typename... Strs>
|
||||
static T getFirstValue(const XmlNode *startNode,
|
||||
const std::string &nodeName, Strs... nodeNames);
|
||||
template <typename T, typename... Strs>
|
||||
T getFirstValue(const std::string &nodeName, Strs... nodeNames) const;
|
||||
template <typename T, typename... Strs>
|
||||
static std::vector<T> getAllValues(const XmlNode *startNode,
|
||||
const std::string &nodeName,
|
||||
Strs... nodeNames);
|
||||
template <typename T, typename... Strs>
|
||||
std::vector<T> getAllValues(const std::string &nodeName,
|
||||
Strs... nodeNames) const;
|
||||
private:
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
tinyxml2::XMLDocument doc_;
|
||||
XmlNode *root_{nullptr};
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* XmlReader template implementation *
|
||||
******************************************************************************/
|
||||
// XML structure access ////////////////////////////////////////////////////////
|
||||
template <typename... Strs>
|
||||
const XmlNode * XmlReader::getFirstNode(const XmlNode *startNode,
|
||||
const std::string &nodeName,
|
||||
Strs... nodeNames)
|
||||
{
|
||||
static_assert(static_or<std::is_assignable<std::string, Strs>::value...>::value,
|
||||
"getFirstValue arguments are not compatible with std::string");
|
||||
|
||||
const unsigned int nName = sizeof...(nodeNames) + 1;
|
||||
const std::string name[] = {nodeName, nodeNames...};
|
||||
const XmlNode *node = startNode;
|
||||
|
||||
if (!node)
|
||||
{
|
||||
LATAN_ERROR(Io, "root node is null, no XML file opened");
|
||||
}
|
||||
for (unsigned int i = 0; i < nName; ++i)
|
||||
{
|
||||
node = node->FirstChildElement(name[i].c_str());
|
||||
if (!node)
|
||||
{
|
||||
LATAN_ERROR(Parsing, "XML node " + name[i] + " not found");
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
template <typename... Strs>
|
||||
const XmlNode * XmlReader::getFirstNode(const std::string &nodeName,
|
||||
Strs... nodeNames) const
|
||||
{
|
||||
if (!root_)
|
||||
{
|
||||
LATAN_ERROR(Io, "root node is null, no XML file opened");
|
||||
}
|
||||
|
||||
return getFirstNode(root_, nodeName, nodeNames...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T XmlReader::getValue(const XmlNode *node)
|
||||
{
|
||||
if (node)
|
||||
{
|
||||
if (node->GetText())
|
||||
{
|
||||
return strTo<T>(node->GetText());
|
||||
}
|
||||
else
|
||||
{
|
||||
return T();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return T();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename... Strs>
|
||||
T XmlReader::getFirstValue(const XmlNode *startNode,
|
||||
const std::string &nodeName, Strs... nodeNames)
|
||||
{
|
||||
const XmlNode *node = getFirstNode(startNode, nodeName, nodeNames...);
|
||||
|
||||
return getValue<T>(node);
|
||||
}
|
||||
|
||||
template <typename T, typename... Strs>
|
||||
T XmlReader::getFirstValue(const std::string &nodeName, Strs... nodeNames) const
|
||||
{
|
||||
return getFirstValue<T>(root_, nodeName, nodeNames...);
|
||||
}
|
||||
|
||||
template <typename T, typename... Strs>
|
||||
std::vector<T> XmlReader::getAllValues(const XmlNode *startNode,
|
||||
const std::string &nodeName,
|
||||
Strs... nodeNames)
|
||||
{
|
||||
const XmlNode *node = getFirstNode(startNode, nodeName, nodeNames...);
|
||||
std::vector<T> value;
|
||||
|
||||
while (node)
|
||||
{
|
||||
value.push_back(getValue<T>(node));
|
||||
node = getNextNode(node);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename T, typename... Strs>
|
||||
std::vector<T> XmlReader::getAllValues(const std::string &nodeName,
|
||||
Strs... nodeNames) const
|
||||
{
|
||||
return getAllValues<T>(root_, nodeName, nodeNames...);
|
||||
}
|
||||
|
||||
END_LATAN_NAMESPACE
|
||||
|
||||
#endif // Latan_XmlReader_hpp_
|
Reference in New Issue
Block a user