9 #ifndef LWH_DataPointSetFactory_H
10 #define LWH_DataPointSetFactory_H
15 #include "AIDataPointSetFactory.h"
16 #include "DataPointSet.h"
17 #include "Histogram1D.h"
60 virtual IDataPointSet *
61 create(
const std::string & path,
const std::string & title,
int dim) {
64 if ( !tree->insert(path, dset) ) {
67 throw std::runtime_error(
"LWH could not create DataPointSet '"
86 virtual IDataPointSet *
create(
const std::string & pathAndTitle,
int dim) {
87 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
88 return create(pathAndTitle, title, dim);
104 virtual IDataPointSet *
105 createY(
const std::string & path,
const std::string & title,
106 const std::vector<double> & y,
const std::vector<double> & ey) {
107 return createY(path, title, y, ey, ey);
124 virtual IDataPointSet *
125 createY(
const std::string & path,
const std::string & title,
126 const std::vector<double> & y,
const std::vector<double> & eyp,
127 const std::vector<double> & eym) {
128 IDataPointSet * dset = create(path, title, 2);
129 std::vector<double> x, ex;
130 for (
int i = 0, N = y.size(); i < N; ++i ) {
135 if ( !dset->setCoordinate(0, x, ex, ex) ||
136 !dset->setCoordinate(1, y, eyp, eym) )
137 throw std::runtime_error(
"LWH could add points to DataPointSet '" +
157 virtual IDataPointSet *
158 createY(
const std::string & pathAndTitle,
const std::vector<double> & y,
159 const std::vector<double> & ey) {
160 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
161 return createY(pathAndTitle, title, y, ey);
179 virtual IDataPointSet *
181 const std::vector<double> & y,
const std::vector<double> & eyp,
182 const std::vector<double> & eym) {
183 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
184 return createY(pathAndTitle, title, y, eyp, eym);
200 virtual IDataPointSet *
201 createX(
const std::string & path,
const std::string & title,
202 const std::vector<double> & x,
const std::vector<double> & ex) {
203 return createX(path, title, x, ex, ex);
220 virtual IDataPointSet *
221 createX(
const std::string & path,
const std::string & title,
222 const std::vector<double> & x,
const std::vector<double> & exp,
223 const std::vector<double> & exm) {
224 IDataPointSet * dset = create(path, title, 2);
225 std::vector<double> y, ey;
226 for (
int i = 0, N = x.size(); i < N; ++i ) {
231 if ( !dset->setCoordinate(0, x, exp, exm) ||
232 !dset->setCoordinate(1, y, ey, ey) )
233 throw std::runtime_error(
"LWH could add points to DataPointSet '" +
252 virtual IDataPointSet *
253 createX(
const std::string & pathAndTitle,
const std::vector<double> & x,
254 const std::vector<double> & ex) {
255 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
256 return createX(pathAndTitle, title, x, ex, ex);
274 virtual IDataPointSet *
275 createX(
const std::string & pathAndTitle,
const std::vector<double> & x,
276 const std::vector<double> & exp,
const std::vector<double> & exm) {
277 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
278 return createX(pathAndTitle, title, x, exp, exm);
297 virtual IDataPointSet *
298 createXY(
const std::string & path,
const std::string & title,
299 const std::vector<double> & x,
const std::vector<double> & y,
300 const std::vector<double> & exp,
const std::vector<double> & eyp,
301 const std::vector<double> & exm,
const std::vector<double> & eym) {
302 IDataPointSet * dset = create(path, title, 2);
303 for (
int i = 0, N = y.size(); i < N; ++i ) dset->addPoint(
DataPoint(2));
304 if ( !dset->setCoordinate(0, x, exp, exm) ||
305 !dset->setCoordinate(1, y, eyp, eym) )
306 throw std::runtime_error(
"LWH could add points to DataPointSet '" +
325 virtual IDataPointSet *
326 createXY(
const std::string & path,
const std::string & title,
327 const std::vector<double> & x,
const std::vector<double> & y,
328 const std::vector<double> & ex,
const std::vector<double> & ey) {
329 return createXY(path, title, x, y, ex, ey, ex, ey);
349 virtual IDataPointSet *
351 const std::vector<double> & x,
const std::vector<double> & y,
352 const std::vector<double> & exp,
const std::vector<double> & eyp,
353 const std::vector<double> & exm,
const std::vector<double> & eym) {
354 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
355 return createXY(pathAndTitle, title, x, y, exp, eyp, exm, eym);
373 virtual IDataPointSet *
375 const std::vector<double> & x,
const std::vector<double> & y,
376 const std::vector<double> & ex,
const std::vector<double> & ey) {
377 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
378 return createXY(pathAndTitle, title, x, y, ex, ey, ex, ey);
400 virtual IDataPointSet *
401 createXYZ(
const std::string & path,
const std::string & title,
402 const std::vector<double> & x,
const std::vector<double> & y,
403 const std::vector<double> & z,
const std::vector<double> & exp,
404 const std::vector<double> & eyp,
const std::vector<double> & ezp,
405 const std::vector<double> & exm,
const std::vector<double> & eym,
406 const std::vector<double> & ezm) {
407 IDataPointSet * dset = create(path, title, 3);
408 for (
int i = 0, N = y.size(); i < N; ++i ) dset->addPoint(
DataPoint(3));
409 if ( !dset->setCoordinate(0, x, exp, exm) ||
410 !dset->setCoordinate(1, y, eyp, eym) ||
411 !dset->setCoordinate(2, z, ezp, ezm) )
412 throw std::runtime_error(
"LWH could add points to DataPointSet '" +
433 virtual IDataPointSet *
434 createXYZ(
const std::string & path,
const std::string & title,
435 const std::vector<double> & x,
const std::vector<double> & y,
436 const std::vector<double> & z,
const std::vector<double> & ex,
437 const std::vector<double> & ey,
const std::vector<double> & ez) {
438 return createXYZ(path, title, x, y, z, ex, ey, ez, ex, ey, ez);
461 virtual IDataPointSet *
462 createXYZ(
const std::string & pathAndTitle,
const std::vector<double> & x,
463 const std::vector<double> & y,
const std::vector<double> & z,
464 const std::vector<double> & exp,
const std::vector<double> & eyp,
465 const std::vector<double> & ezp,
const std::vector<double> & exm,
466 const std::vector<double> & eym,
const std::vector<double> & ezm) {
467 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
468 return createXYZ(pathAndTitle, title, x, y, z,
469 exp, eyp, ezp, exm, eym, ezm);
489 virtual IDataPointSet *
490 createXYZ(
const std::string & pathAndTitle,
const std::vector<double> & x,
491 const std::vector<double> & y,
const std::vector<double> & z,
492 const std::vector<double> & ex,
const std::vector<double> & ey,
493 const std::vector<double> & ez) {
494 std::string title = pathAndTitle.substr(pathAndTitle.rfind(
'/') + 1);
495 return createXYZ(pathAndTitle, title, x, y, z, ex, ey, ez, ex, ey, ez);
508 virtual IDataPointSet *
509 createCopy(
const std::string & path,
const IDataPointSet & dataPointSet) {
510 IDataPointSet * dset =
511 create(path, dataPointSet.title(), dataPointSet.dimension());
512 for (
int i = 0, N = dataPointSet.size(); i < N; ++i )
513 dset->addPoint(*dataPointSet.point(i));
522 virtual bool destroy(IDataPointSet * dataPointSet) {
523 IManagedObject * mo =
dynamic_cast<IManagedObject *
>(dataPointSet);
524 if ( !mo )
return false;
525 return tree->rm(tree->findPath(*mo));
540 virtual IDataPointSet *
541 create(
const std::string & path,
const IHistogram1D & hist,
542 const std::string & =
"") {
543 IDataPointSet * dset = create(path, hist.title(), 2);
544 std::vector<double> x, y, ex, ey;
545 for (
int i = 2, N = hist.axis().bins() + 2; i < N; ++i ) {
547 x.push_back(hist.binMean(i - 2));
548 ex.push_back(hist.axis().binWidth(i - 2));
549 y.push_back(hist.binHeight(i - 2));
550 ey.push_back(hist.binError(i - 2));
552 if ( !dset->setCoordinate(0, x, ex, ex) ||
553 !dset->setCoordinate(1, y, ey, ey) )
554 throw std::runtime_error(
"LWH could add points to DataPointSet '" +
555 hist.title() +
"'." );
572 virtual IDataPointSet *
573 create(
const std::string & path,
const IHistogram2D & hist,
574 const std::string & =
"") {
575 IDataPointSet * dset = create(path, hist.title(), 3);
577 std::vector<double> x, y, z, ex, ey, ez;
578 for (
int ix = 2, Nx = hist.xAxis().bins() + 2; ix < Nx; ++ix )
579 for (
int iy = 2, Ny = hist.yAxis().bins() + 2; iy < Ny; ++iy ) {
584 x.push_back((hist.xAxis().binLowerEdge(ix - 2) +
585 hist.xAxis().binUpperEdge(ix - 2))/2.0);
586 ex.push_back(hist.xAxis().binWidth(ix - 2)/2.0);
587 y.push_back((hist.yAxis().binLowerEdge(iy - 2) +
588 hist.yAxis().binUpperEdge(iy - 2))/2.0);
589 ey.push_back(hist.yAxis().binWidth(iy - 2)/2.0);
590 const double binwidth = hist.xAxis().binWidth(ix - 2)*
591 hist.yAxis().binWidth(iy - 2);
592 z.push_back(hist.binHeight(ix - 2, iy - 2)/binwidth);
593 ez.push_back(hist.binError(ix - 2, iy - 2)/binwidth);
595 if ( !dset->setCoordinate(0, x, ex, ex) ||
596 !dset->setCoordinate(1, y, ey, ey) ||
597 !dset->setCoordinate(2, z, ez, ez) )
598 throw std::runtime_error(
"LWH could not add points to DataPointSet '" +
599 hist.title() +
"'." );
607 virtual IDataPointSet *
create(
const std::string &,
const IHistogram3D &,
608 const std::string & =
"") {
609 return error<IDataPointSet>(
"IHistogram3D");
615 virtual IDataPointSet *
create(
const std::string &,
const ICloud1D &,
616 const std::string & =
"") {
617 return error<IDataPointSet>(
"ICloud1D");
623 virtual IDataPointSet *
create(
const std::string &,
const ICloud2D &,
624 const std::string & =
"") {
625 return error<IDataPointSet>(
"ICloud2D");
631 virtual IDataPointSet *
create(
const std::string &,
const ICloud3D &,
632 const std::string & =
"") {
633 return error<IDataPointSet>(
"ICloud3D");
639 virtual IDataPointSet *
create(
const std::string &,
const IProfile1D &,
640 const std::string & =
"") {
641 return error<IDataPointSet>(
"IProfile1D");
647 virtual IDataPointSet *
create(
const std::string &,
const IProfile2D &,
648 const std::string & =
"") {
649 return error<IDataPointSet>(
"IProfile2D");
655 virtual IDataPointSet *
add(
const std::string &,
656 const IDataPointSet &,
const IDataPointSet &) {
657 return error<IDataPointSet>(
"addition of data points");
663 virtual IDataPointSet *
subtract(
const std::string &,
const IDataPointSet &,
664 const IDataPointSet &) {
665 return error<IDataPointSet>(
"subtraction of data points");
671 virtual IDataPointSet *
multiply(
const std::string &,
const IDataPointSet &,
672 const IDataPointSet &) {
673 return error<IDataPointSet>(
"multiplication of data points");
679 virtual IDataPointSet *
divide(
const std::string &,
const IDataPointSet &,
680 const IDataPointSet &) {
681 return error<IDataPointSet>(
"division of data points");
687 virtual IDataPointSet *
689 const IDataPointSet &) {
690 return error<IDataPointSet>(
"weighted means of data points");
696 template <
typename T>
697 static T *
error(std::string feature) {
698 throw std::runtime_error(
"LWH cannot handle " + feature +
".");
virtual IDataPointSet * weightedMean(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the weighted mean of data points.
static T * error(std::string feature)
Throw a suitable error.
Tree * tree
The tree where the actual data sets are stored.
virtual IDataPointSet * createY(const std::string &pathAndTitle, const std::vector< double > &y, const std::vector< double > &eyp, const std::vector< double > &eym)
Create a two dimensional IDataPointSet providing the data along y (the x value is the index of the y ...
virtual IDataPointSet * subtract(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the subtraction of data points.
virtual ~DataPointSetFactory()
Destructor.
virtual IDataPointSet * createY(const std::string &path, const std::string &title, const std::vector< double > &y, const std::vector< double > &ey)
Create a two dimensional IDataPointSet providing the data along y (the x value is the index of the y ...
virtual IDataPointSet * createCopy(const std::string &path, const IDataPointSet &dataPointSet)
Make a copy of a given IDataPointSet.
virtual IDataPointSet * createXY(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &ex, const std::vector< double > &ey)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * createX(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &ex)
Create a two dimensional IDataPointSet providing the data along x (the y value is the index of the x ...
Basic user-level interface for creating a factory of IDataPointSet.
virtual IDataPointSet * createXYZ(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &exp, const std::vector< double > &eyp, const std::vector< double > &ezp, const std::vector< double > &exm, const std::vector< double > &eym, const std::vector< double > &ezm)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * create(const std::string &path, const std::string &title, int dim)
Create an empty IDataPointSet.
virtual IDataPointSet * createXY(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &exp, const std::vector< double > &eyp, const std::vector< double > &exm, const std::vector< double > &eym)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * create(const std::string &pathAndTitle, int dim)
Create an empty IDataPointSet.
virtual IDataPointSet * create(const std::string &, const IHistogram3D &, const std::string &="")
LWH cannot handle a IHistogram3D.
virtual IDataPointSet * createXYZ(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &ex, const std::vector< double > &ey, const std::vector< double > &ez)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * create(const std::string &, const ICloud2D &, const std::string &="")
LWH cannot handle a ICloud2D.
An DataPointSet represents a binned histogram axis.
virtual IDataPointSet * multiply(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the multiplication of data points.
virtual IDataPointSet * createXY(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &ex, const std::vector< double > &ey)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * createXYZ(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &exp, const std::vector< double > &eyp, const std::vector< double > &ezp, const std::vector< double > &exm, const std::vector< double > &eym, const std::vector< double > &ezm)
Create a three dimensional IDataPointSet providing the data.
virtual IDataPointSet * create(const std::string &, const ICloud1D &, const std::string &="")
LWH cannot handle a ICloud1.
virtual IDataPointSet * createX(const std::string &pathAndTitle, const std::vector< double > &x, const std::vector< double > &exp, const std::vector< double > &exm)
Create a two dimensional IDataPointSet providing the data along x (the y value is the index of the x ...
virtual IDataPointSet * create(const std::string &path, const IHistogram2D &hist, const std::string &="")
Create an IDataPointSet from an IHistogram2D.
virtual IDataPointSet * create(const std::string &path, const IHistogram1D &hist, const std::string &="")
Create an IDataPointSet from an IHistogram1D.
virtual IDataPointSet * createY(const std::string &path, const std::string &title, const std::vector< double > &y, const std::vector< double > &eyp, const std::vector< double > &eym)
Create a two dimensional IDataPointSet providing the data along y (the x value is the index of the y ...
bool setTitle(const std::string &title)
Set the data set's title.
DataPointSetFactory(Tree &t)
Standard constructor.
The LWH namespace contains a Light-Weight Histogram package which implements the most rudimentary his...
virtual IDataPointSet * add(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the addition of data points.
An DataPoint represents a binned histogram axis.
virtual IDataPointSet * createXY(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &exp, const std::vector< double > &eyp, const std::vector< double > &exm, const std::vector< double > &eym)
Create a two dimensional IDataPointSet providing the data.
virtual IDataPointSet * divide(const std::string &, const IDataPointSet &, const IDataPointSet &)
LWH cannot handle the division of data points.
virtual IDataPointSet * create(const std::string &, const IProfile2D &, const std::string &="")
LWH cannot handle a IProfile2D.
virtual IDataPointSet * create(const std::string &, const ICloud3D &, const std::string &="")
LWH cannot handle a ICloud3D.
The Tree class is a simple implementation of the AIDA::ITree interface.
virtual IDataPointSet * createXYZ(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &ex, const std::vector< double > &ey, const std::vector< double > &ez)
Create a three dimensional IDataPointSet providing the data.
virtual IDataPointSet * createY(const std::string &pathAndTitle, const std::vector< double > &y, const std::vector< double > &ey)
Create a two dimensional IDataPointSet providing the data along y (the x value is the index of the y ...
virtual IDataPointSet * createX(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &exp, const std::vector< double > &exm)
Create a two dimensional IDataPointSet providing the data along x (the y value is the index of the x ...
virtual bool destroy(IDataPointSet *dataPointSet)
Destroy a given IDataPointSet.
virtual IDataPointSet * create(const std::string &, const IProfile1D &, const std::string &="")
LWH cannot handle a IProfile1D.
virtual IDataPointSet * createX(const std::string &path, const std::string &title, const std::vector< double > &x, const std::vector< double > &ex)
Create a two dimensional IDataPointSet providing the data along x (the y value is the index of the x ...