Skip to content

Commit

Permalink
Merge pull request cms-sw#10 from adavidzh/master
Browse files Browse the repository at this point in the history
Constructor directly from file
  • Loading branch information
adavidzh committed Jul 21, 2013
2 parents a4149df + 0af4e69 commit adce8fc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions interface/RooSpline1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RooSpline1D : public RooAbsReal {

public:
RooSpline1D() : interp_(0) {}
RooSpline1D(const char *name, const char *title, RooAbsReal &xvar, const char *path, const unsigned short xcol, const unsigned short ycol, const unsigned short skipLines=0, const char *algo="CSPLINE") ;
RooSpline1D(const char *name, const char *title, RooAbsReal &xvar, unsigned int npoints, const double *xvals, const double *yvals, const char *algo="CSPLINE") ;
RooSpline1D(const char *name, const char *title, RooAbsReal &xar, unsigned int npoints, const float *xvals, const float *yvals, const char *algo="CSPLINE") ;
~RooSpline1D() ;
Expand Down
28 changes: 28 additions & 0 deletions src/RooSpline1D.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

#include <stdexcept>

#include <fstream>
#include <sstream>

RooSpline1D::RooSpline1D(const char *name, const char *title, RooAbsReal &xvar, const char *path, const unsigned short xcol, const unsigned short ycol, const unsigned short skipLines, const char *algo) :
RooAbsReal(name,title),
xvar_("xvar","Variable", this, xvar),
x_(), y_(), type_(algo),
interp_(0)
{
std::ifstream file( path, std::ios::in);
std::string line;

for(int lineno=0; std::getline(file, line); lineno++){
if(lineno<skipLines) continue;
std::istringstream ss(line);
std::istream_iterator<std::string > begin(ss), end;
std::vector<std::string> tokens(begin, end);

x_.push_back(atof(tokens[xcol].c_str()));
y_.push_back(atof(tokens[ycol].c_str()));

// std::cout << lineno << ": " << line << std::endl;
}

file.close();
}


RooSpline1D::RooSpline1D(const char *name, const char *title, RooAbsReal &xvar, unsigned int npoints, const double *xvals, const double *yvals, const char *algo) :
RooAbsReal(name,title),
xvar_("xvar","Variable", this, xvar),
Expand Down

0 comments on commit adce8fc

Please sign in to comment.