00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef LWH_DataPointSetFactory_H
00010 #define LWH_DataPointSetFactory_H
00011
00012
00013
00014
00015 #include "AIDataPointSetFactory.h"
00016 #include "DataPointSet.h"
00017 #include "Histogram1D.h"
00018 #include "Tree.h"
00019 #include <string>
00020 #include <stdexcept>
00021
00022 namespace LWH {
00023
00024 using namespace AIDA;
00025
00031 class DataPointSetFactory: public IDataPointSetFactory {
00032
00033 public:
00034
00038 DataPointSetFactory(Tree & t)
00039 : tree(&t) {}
00040
00044 virtual ~DataPointSetFactory() {}
00045
00060 virtual IDataPointSet *
00061 create(const std::string & path, const std::string & title, int dim) {
00062 DataPointSet * dset = new DataPointSet(dim);
00063 dset->setTitle(title);
00064 if ( !tree->insert(path, dset) ) {
00065 delete dset;
00066 dset = 0;
00067 throw std::runtime_error("LWH could not create DataPointSet '"
00068 + title + "'." );
00069 }
00070 return dset;
00071 }
00072
00086 virtual IDataPointSet * create(const std::string & pathAndTitle, int dim) {
00087 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00088 return create(pathAndTitle, title, dim);
00089 }
00090
00104 virtual IDataPointSet *
00105 createY(const std::string & path, const std::string & title,
00106 const std::vector<double> & y, const std::vector<double> & ey) {
00107 return createY(path, title, y, ey, ey);
00108 }
00109
00124 virtual IDataPointSet *
00125 createY(const std::string & path, const std::string & title,
00126 const std::vector<double> & y, const std::vector<double> & eyp,
00127 const std::vector<double> & eym) {
00128 IDataPointSet * dset = create(path, title, 2);
00129 std::vector<double> x, ex;
00130 for ( int i = 0, N = y.size(); i < N; ++i ) {
00131 dset->addPoint(DataPoint(2));
00132 x.push_back(i);
00133 ex.push_back(0);
00134 }
00135 if ( !dset->setCoordinate(0, x, ex, ex) ||
00136 !dset->setCoordinate(1, y, eyp, eym) )
00137 throw std::runtime_error("LWH could add points to DataPointSet '" +
00138 title + "'." );
00139 return dset;
00140 }
00141
00157 virtual IDataPointSet *
00158 createY(const std::string & pathAndTitle, const std::vector<double> & y,
00159 const std::vector<double> & ey) {
00160 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00161 return createY(pathAndTitle, title, y, ey);
00162 }
00163
00179 virtual IDataPointSet *
00180 createY(const std::string & pathAndTitle,
00181 const std::vector<double> & y, const std::vector<double> & eyp,
00182 const std::vector<double> & eym) {
00183 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00184 return createY(pathAndTitle, title, y, eyp, eym);
00185 }
00186
00200 virtual IDataPointSet *
00201 createX(const std::string & path, const std::string & title,
00202 const std::vector<double> & x, const std::vector<double> & ex) {
00203 return createX(path, title, x, ex, ex);
00204 }
00205
00220 virtual IDataPointSet *
00221 createX(const std::string & path, const std::string & title,
00222 const std::vector<double> & x, const std::vector<double> & exp,
00223 const std::vector<double> & exm) {
00224 IDataPointSet * dset = create(path, title, 2);
00225 std::vector<double> y, ey;
00226 for ( int i = 0, N = x.size(); i < N; ++i ) {
00227 dset->addPoint(DataPoint(2));
00228 y.push_back(i);
00229 ey.push_back(0);
00230 }
00231 if ( !dset->setCoordinate(0, x, exp, exm) ||
00232 !dset->setCoordinate(1, y, ey, ey) )
00233 throw std::runtime_error("LWH could add points to DataPointSet '" +
00234 title + "'." );
00235 return dset;
00236 }
00237
00252 virtual IDataPointSet *
00253 createX(const std::string & pathAndTitle, const std::vector<double> & x,
00254 const std::vector<double> & ex) {
00255 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00256 return createX(pathAndTitle, title, x, ex, ex);
00257 }
00258
00274 virtual IDataPointSet *
00275 createX(const std::string & pathAndTitle, const std::vector<double> & x,
00276 const std::vector<double> & exp, const std::vector<double> & exm) {
00277 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00278 return createX(pathAndTitle, title, x, exp, exm);
00279 }
00280
00297 virtual IDataPointSet *
00298 createXY(const std::string & path, const std::string & title,
00299 const std::vector<double> & x, const std::vector<double> & y,
00300 const std::vector<double> & exp, const std::vector<double> & eyp,
00301 const std::vector<double> & exm, const std::vector<double> & eym) {
00302 IDataPointSet * dset = create(path, title, 2);
00303 for ( int i = 0, N = y.size(); i < N; ++i ) dset->addPoint(DataPoint(2));
00304 if ( !dset->setCoordinate(0, x, exp, exm) ||
00305 !dset->setCoordinate(1, y, eyp, eym) )
00306 throw std::runtime_error("LWH could add points to DataPointSet '" +
00307 title + "'." );
00308 return dset;
00309 }
00310
00325 virtual IDataPointSet *
00326 createXY(const std::string & path, const std::string & title,
00327 const std::vector<double> & x, const std::vector<double> & y,
00328 const std::vector<double> & ex, const std::vector<double> & ey) {
00329 return createXY(path, title, x, y, ex, ey, ex, ey);
00330 }
00331
00349 virtual IDataPointSet *
00350 createXY(const std::string & pathAndTitle,
00351 const std::vector<double> & x, const std::vector<double> & y,
00352 const std::vector<double> & exp, const std::vector<double> & eyp,
00353 const std::vector<double> & exm, const std::vector<double> & eym) {
00354 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00355 return createXY(pathAndTitle, title, x, y, exp, eyp, exm, eym);
00356 }
00357
00373 virtual IDataPointSet *
00374 createXY(const std::string & pathAndTitle,
00375 const std::vector<double> & x, const std::vector<double> & y,
00376 const std::vector<double> & ex, const std::vector<double> & ey) {
00377 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00378 return createXY(pathAndTitle, title, x, y, ex, ey, ex, ey);
00379 }
00380
00400 virtual IDataPointSet *
00401 createXYZ(const std::string & path, const std::string & title,
00402 const std::vector<double> & x, const std::vector<double> & y,
00403 const std::vector<double> & z, const std::vector<double> & exp,
00404 const std::vector<double> & eyp, const std::vector<double> & ezp,
00405 const std::vector<double> & exm, const std::vector<double> & eym,
00406 const std::vector<double> & ezm) {
00407 IDataPointSet * dset = create(path, title, 3);
00408 for ( int i = 0, N = y.size(); i < N; ++i ) dset->addPoint(DataPoint(3));
00409 if ( !dset->setCoordinate(0, x, exp, exm) ||
00410 !dset->setCoordinate(1, y, eyp, eym) ||
00411 !dset->setCoordinate(2, z, ezp, ezm) )
00412 throw std::runtime_error("LWH could add points to DataPointSet '" +
00413 title + "'." );
00414 return dset;
00415 }
00416
00433 virtual IDataPointSet *
00434 createXYZ(const std::string & path, const std::string & title,
00435 const std::vector<double> & x, const std::vector<double> & y,
00436 const std::vector<double> & z, const std::vector<double> & ex,
00437 const std::vector<double> & ey, const std::vector<double> & ez) {
00438 return createXYZ(path, title, x, y, z, ex, ey, ez, ex, ey, ez);
00439 }
00440
00461 virtual IDataPointSet *
00462 createXYZ(const std::string & pathAndTitle, const std::vector<double> & x,
00463 const std::vector<double> & y, const std::vector<double> & z,
00464 const std::vector<double> & exp, const std::vector<double> & eyp,
00465 const std::vector<double> & ezp, const std::vector<double> & exm,
00466 const std::vector<double> & eym, const std::vector<double> & ezm) {
00467 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00468 return createXYZ(pathAndTitle, title, x, y, z,
00469 exp, eyp, ezp, exm, eym, ezm);
00470 }
00471
00489 virtual IDataPointSet *
00490 createXYZ(const std::string & pathAndTitle, const std::vector<double> & x,
00491 const std::vector<double> & y, const std::vector<double> & z,
00492 const std::vector<double> & ex, const std::vector<double> & ey,
00493 const std::vector<double> & ez) {
00494 std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
00495 return createXYZ(pathAndTitle, title, x, y, z, ex, ey, ez, ex, ey, ez);
00496 }
00497
00508 virtual IDataPointSet *
00509 createCopy(const std::string & path, const IDataPointSet & dataPointSet) {
00510 IDataPointSet * dset =
00511 create(path, dataPointSet.title(), dataPointSet.dimension());
00512 for ( int i = 0, N = dataPointSet.size(); i < N; ++i )
00513 dset->addPoint(*dataPointSet.point(i));
00514 return dset;
00515 }
00516
00522 virtual bool destroy(IDataPointSet * dataPointSet) {
00523 IManagedObject * mo = dynamic_cast<IManagedObject *>(dataPointSet);
00524 if ( !mo ) return false;
00525 return tree->rm(tree->findPath(*mo));
00526 }
00527
00540 virtual IDataPointSet *
00541 create(const std::string & path, const IHistogram1D & hist,
00542 const std::string & = "") {
00543 IDataPointSet * dset = create(path, hist.title(), 2);
00544 std::vector<double> x, y, ex, ey;
00545 for ( int i = 2, N = hist.axis().bins() + 2; i < N; ++i ) {
00546 dset->addPoint(DataPoint(2));
00547 x.push_back(hist.binMean(i - 2));
00548 ex.push_back(hist.axis().binWidth(i - 2));
00549 y.push_back(hist.binHeight(i - 2));
00550 ey.push_back(hist.binError(i - 2));
00551 }
00552 if ( !dset->setCoordinate(0, x, ex, ex) ||
00553 !dset->setCoordinate(1, y, ey, ey) )
00554 throw std::runtime_error("LWH could add points to DataPointSet '" +
00555 hist.title() + "'." );
00556 return dset;
00557 }
00558
00562 virtual IDataPointSet * create(const std::string &, const IHistogram2D &,
00563 const std::string & = "") {
00564 return error<IDataPointSet>("IHistogram2D");
00565 }
00566
00570 virtual IDataPointSet * create(const std::string &, const IHistogram3D &,
00571 const std::string & = "") {
00572 return error<IDataPointSet>("IHistogram3D");
00573 }
00574
00578 virtual IDataPointSet * create(const std::string &, const ICloud1D &,
00579 const std::string & = "") {
00580 return error<IDataPointSet>("ICloud1D");
00581 }
00582
00586 virtual IDataPointSet * create(const std::string &, const ICloud2D &,
00587 const std::string & = "") {
00588 return error<IDataPointSet>("ICloud2D");
00589 }
00590
00594 virtual IDataPointSet * create(const std::string &, const ICloud3D &,
00595 const std::string & = "") {
00596 return error<IDataPointSet>("ICloud3D");
00597 }
00598
00602 virtual IDataPointSet * create(const std::string &, const IProfile1D &,
00603 const std::string & = "") {
00604 return error<IDataPointSet>("IProfile1D");
00605 }
00606
00610 virtual IDataPointSet * create(const std::string &, const IProfile2D &,
00611 const std::string & = "") {
00612 return error<IDataPointSet>("IProfile2D");
00613 }
00614
00618 virtual IDataPointSet * add(const std::string &,
00619 const IDataPointSet &, const IDataPointSet &) {
00620 return error<IDataPointSet>("addition of data points");
00621 }
00622
00626 virtual IDataPointSet * subtract(const std::string &, const IDataPointSet &,
00627 const IDataPointSet &) {
00628 return error<IDataPointSet>("subtraction of data points");
00629 }
00630
00634 virtual IDataPointSet * multiply(const std::string &, const IDataPointSet &,
00635 const IDataPointSet &) {
00636 return error<IDataPointSet>("multiplication of data points");
00637 }
00638
00642 virtual IDataPointSet * divide(const std::string &, const IDataPointSet &,
00643 const IDataPointSet &) {
00644 return error<IDataPointSet>("division of data points");
00645 }
00646
00650 virtual IDataPointSet *
00651 weightedMean(const std::string &, const IDataPointSet &,
00652 const IDataPointSet &) {
00653 return error<IDataPointSet>("weighted means of data points");
00654 }
00655
00656 private:
00657
00659 template <typename T>
00660 static T * error(std::string feature) {
00661 throw std::runtime_error("LWH cannot handle " + feature + ".");
00662 }
00663
00665 Tree * tree;
00666
00667 };
00668 }
00669
00670 #endif