Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:18

0001 // -*- C++ -*-
0002 //
0003 // DataPointSetFactory.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef LWH_DataPointSetFactory_H
0010 #define LWH_DataPointSetFactory_H
0011 //
0012 // This is the declaration of the DataPointSetFactory class.
0013 //
0014 
0015 #include "AIDataPointSetFactory.h"
0016 #include "DataPointSet.h"
0017 #include "Histogram1D.h"
0018 #include "Tree.h"
0019 #include <string>
0020 #include <stdexcept>
0021 
0022 namespace LWH {
0023 
0024 using namespace AIDA;
0025 
0026 /**
0027  * Basic user-level interface for creating a factory
0028  * of IDataPointSet. The created objects are assumed to be
0029  * managed by the tree which is associated to the factory.
0030  */
0031 class DataPointSetFactory: public IDataPointSetFactory {
0032 
0033 public: 
0034 
0035   /**
0036    * Standard constructor.
0037    */
0038   DataPointSetFactory(Tree & t)
0039     : tree(&t) {}
0040 
0041   /**
0042    * Destructor.
0043    */
0044   virtual ~DataPointSetFactory() {}
0045 
0046   /**
0047    * Create an empty IDataPointSet.
0048    * @param path  The path of the IDataPointSet. The path can either
0049    *              be a relative or full path.
0050    *              ("/folder1/folder2/dataName" and "../folder/dataName"
0051    *              are valid paths). All the directories in the path
0052    *              must exist. The characther `/` cannot be used in
0053    *              names; it is only used to delimit directories within
0054    *            paths.
0055    * @param title The title of the IDataPointSet.
0056    * @param dim   The dimension of the IDataPoints that can be stored
0057    *              in the set.
0058    * @return      The newly created IDataPointSet.
0059    */
0060   virtual IDataPointSet *
0061   create(const std::string & path, const std::string & title, int dim) {
0062     DataPointSet * dset = new DataPointSet(dim);
0063     dset->setTitle(title);
0064     if ( !tree->insert(path, dset) ) {
0065       delete dset;
0066       dset = 0;
0067       throw std::runtime_error("LWH could not create DataPointSet '"
0068                    + title + "'." );
0069     }
0070     return dset;
0071   }
0072 
0073   /**
0074    * Create an empty IDataPointSet.
0075    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0076    *                     a relative or full path. The last part of the path is
0077    *                     used as the title. ("/folder1/folder2/dataTitle" and
0078    *                     "../folder/dataTitle" are valid paths).
0079    *                     All the directories in the path must exist. The
0080    *                     characther `/` cannot be used in names; it is only
0081    *                     used to delimit directories within paths.
0082    * @param dim          The dimension of the IDataPoints that can be stored
0083    *                     in the set.
0084    * @return             The newly created IDataPointSet.
0085    */
0086   virtual IDataPointSet * create(const std::string & pathAndTitle, int dim) {
0087     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0088     return create(pathAndTitle, title, dim);
0089   }
0090 
0091   /**
0092    * Create a two dimensional IDataPointSet providing the data along y (the x
0093    * value is the index of the y value in the array).
0094    * @param path  The path of the IDataPointSet. The path can either be a
0095    *              relative or full path. ("/folder1/folder2/dataTitle" and
0096    *              "../folder/dataTitle" are valid paths). All the directories
0097    *              in the path must exist. The characther `/` cannot be used
0098    *              in names; it is only used to delimit directories within paths.
0099    * @param title The title of the IDataPointSet.
0100    * @param y     The array of the y values
0101    * @param ey    The array with the symmetric errors on y
0102    * @return      The created IDataPointSet.
0103    */
0104   virtual IDataPointSet *
0105   createY(const std::string & path, const std::string & title,
0106       const std::vector<double> & y, const std::vector<double> & ey) {
0107     return createY(path, title, y, ey, ey);
0108   }
0109 
0110   /**
0111    * Create a two dimensional IDataPointSet providing the data along y (the x
0112    * value is the index of the y value in the array).
0113    * @param path  The path of the IDataPointSet. The path can either be a
0114    *              relative or full path. ("/folder1/folder2/dataTitle" and
0115    *              "../folder/dataTitle" are valid paths). All the directories
0116    *              in the path must exist. The characther `/` cannot be used
0117    *              in names; it is only used to delimit directories within paths.
0118    * @param title The title of the IDataPointSet.
0119    * @param y     The array of the y values
0120    * @param eyp   The array with the plus errors on y
0121    * @param eym   The array with the minus errors on y
0122    * @return      The created IDataPointSet.
0123    */
0124   virtual IDataPointSet *
0125   createY(const std::string & path, const std::string & title,
0126       const std::vector<double> & y, const std::vector<double> & eyp,
0127       const std::vector<double>  & eym) {
0128     IDataPointSet * dset = create(path, title, 2);
0129     std::vector<double> x, ex;
0130     for ( int i = 0, N = y.size(); i < N; ++i ) {
0131       dset->addPoint(DataPoint(2));
0132       x.push_back(i);
0133       ex.push_back(0);
0134     }
0135     if ( !dset->setCoordinate(0, x, ex, ex) ||
0136          !dset->setCoordinate(1, y, eyp, eym) )
0137       throw std::runtime_error("LWH could add points to DataPointSet '" +
0138                    title +  "'." );
0139     return dset;
0140   }
0141     
0142   /**
0143    * Create a two dimensional IDataPointSet providing the data along y (the x
0144    value is the index of the y value in the array).
0145    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0146    *                     a relative or full path. The last part of the path is
0147    *                     used as the title. ("/folder1/folder2/dataTitle" and
0148    *                     "../folder/dataTitle" are valid paths). All the
0149    *                     directories in the path must exist. The characther
0150    *                     `/` cannot be used in names; it is only used to
0151    *                     delimit directories within paths.
0152    * @param y            The array of the y values
0153    * @param ey           The array with the symmetric errors on y
0154    * @return             The created IDataPointSet.
0155    *
0156    */
0157   virtual IDataPointSet *
0158   createY(const std::string & pathAndTitle, const std::vector<double> & y,
0159       const std::vector<double> & ey) {
0160     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0161     return createY(pathAndTitle, title, y, ey);
0162   }
0163 
0164   /**
0165    * Create a two dimensional IDataPointSet providing the data along y (the x
0166    * value is the index of the y value in the array).
0167    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0168    *                     a relative or full path. The last part of the path is
0169    *                     used as the title. ("/folder1/folder2/dataTitle" and
0170    *                     "../folder/dataTitle" are valid paths). All the
0171    *                     directories in the path must exist. The characther
0172    *                     `/` cannot be used in names; it is only used to
0173    *                     delimit directories within paths.
0174    * @param y            The array of the y values
0175    * @param eyp          The array with the plus errors on y
0176    * @param eym          The array with the minus errors on y
0177    * @return             The created IDataPointSet.
0178    */
0179   virtual IDataPointSet *
0180   createY(const std::string & pathAndTitle,
0181       const std::vector<double>  & y, const std::vector<double>  & eyp,
0182       const std::vector<double>  & eym) {
0183     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0184     return createY(pathAndTitle, title, y, eyp, eym);
0185   }
0186 
0187   /**
0188    * Create a two dimensional IDataPointSet providing the data along x (the y
0189    * value is the index of the x value in the array).
0190    * @param path  The path of the IDataPointSet. The path can either be a
0191    *              relative or full path. ("/folder1/folder2/dataTitle" and
0192    *              "../folder/dataTitle" are valid paths). All the directories
0193    *              in the path must exist. The characther `/` cannot be used
0194    *              in names; it is only used to delimit directories within paths.
0195    * @param title The title of the IDataPointSet.
0196    * @param x     The array of the x values
0197    * @param ex    The array with the symmetric errors on x
0198    * @return      The created IDataPointSet.
0199    */
0200   virtual IDataPointSet *
0201   createX(const std::string & path, const std::string & title,
0202       const std::vector<double>  & x, const std::vector<double>  & ex) {
0203     return createX(path, title, x, ex, ex);
0204   }
0205 
0206   /**
0207    * Create a two dimensional IDataPointSet providing the data along x (the y
0208    * value is the index of the x value in the array).
0209    * @param path  The path of the IDataPointSet. The path can either be a
0210    *              relative or full path. ("/folder1/folder2/dataTitle" and
0211    *              "../folder/dataTitle" are valid paths). All the directories
0212    *              in the path must exist. The characther `/` cannot be used
0213    *              in names; it is only used to delimit directories within paths.
0214    * @param title The title of the IDataPointSet.
0215    * @param x     The array of the x values
0216    * @param exp   The array with the plus errors on x
0217    * @param exm   The array with the minus errors on x
0218    * @return      The created IDataPointSet.
0219    */
0220   virtual IDataPointSet *
0221   createX(const std::string & path, const std::string & title,
0222       const std::vector<double> & x, const std::vector<double> & exp,
0223       const std::vector<double>  & exm) {
0224     IDataPointSet * dset = create(path, title, 2);
0225     std::vector<double> y, ey;
0226     for ( int i = 0, N = x.size(); i < N; ++i ) {
0227       dset->addPoint(DataPoint(2));
0228       y.push_back(i);
0229       ey.push_back(0);
0230     }
0231     if ( !dset->setCoordinate(0, x, exp, exm) ||
0232          !dset->setCoordinate(1, y, ey, ey) )
0233       throw std::runtime_error("LWH could add points to DataPointSet '" +
0234                    title +  "'." );
0235     return dset;
0236   }
0237 
0238   /**
0239    * Create a two dimensional IDataPointSet providing the data along x (the y
0240    * value is the index of the x value in the array).
0241    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0242    *                     a relative or full path. The last part of the path is
0243    *                     used as the title. ("/folder1/folder2/dataTitle" and
0244    *                     "../folder/dataTitle" are valid paths). All the
0245    *                     directories in the path must exist. The characther
0246    *                     `/` cannot be used in names; it is only used to
0247    *                     delimit directories within paths.
0248    * @param x            The array of the x values
0249    * @param ex           The array with the symmetric errors on x
0250    * @return             The created IDataPointSet.
0251    */
0252   virtual IDataPointSet *
0253   createX(const std::string & pathAndTitle, const std::vector<double> & x,
0254       const std::vector<double> & ex) {
0255     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0256     return createX(pathAndTitle, title, x, ex, ex);
0257   }
0258 
0259   /**
0260    * Create a two dimensional IDataPointSet providing the data along x (the y
0261    * value is the index of the x value in the array).
0262    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0263    *                     a relative or full path. The last part of the path is
0264    *                     used as the title. ("/folder1/folder2/dataTitle" and
0265    *                     "../folder/dataTitle" are valid paths). All the
0266    *                     directories in the path must exist. The characther
0267    *                     `/` cannot be used in names; it is only used to
0268    *                     delimit directories within paths.
0269    * @param x            The array of the x values
0270    * @param exp          The array with the plus errors on x
0271    * @param exm          The array with the minus errors on x
0272    * @return             The created IDataPointSet.
0273    */
0274   virtual IDataPointSet *
0275   createX(const std::string & pathAndTitle, const std::vector<double> & x,
0276       const std::vector<double> & exp, const std::vector<double> & exm) {
0277     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0278     return createX(pathAndTitle, title, x, exp, exm);
0279   }
0280 
0281   /**
0282    * Create a two dimensional IDataPointSet providing the data.
0283    * @param path  The path of the IDataPointSet. The path can either be a
0284    *              relative or full path. ("/folder1/folder2/dataTitle" and
0285    *              "../folder/dataTitle" are valid paths). All the directories
0286    *              in the path must exist. The characther `/` cannot be used
0287    *              in names; it is only used to delimit directories within paths.
0288    * @param title The title of the IDataPointSet.
0289    * @param x     The array of the x values
0290    * @param y     The array of the y values
0291    * @param exp   The array with the plus errors on x
0292    * @param eyp   The array with the plus errors on y
0293    * @param exm   The array with the minus errors on x
0294    * @param eym   The array with the minus errors on y
0295    * @return      The created IDataPointSet.
0296    */
0297   virtual IDataPointSet *
0298   createXY(const std::string & path, const std::string & title,
0299        const std::vector<double> & x, const std::vector<double> & y,
0300        const std::vector<double> & exp, const std::vector<double> & eyp,
0301        const std::vector<double> & exm, const std::vector<double> & eym) {
0302     IDataPointSet * dset = create(path, title, 2);
0303     for ( int i = 0, N = y.size(); i < N; ++i ) dset->addPoint(DataPoint(2));
0304     if ( !dset->setCoordinate(0, x, exp, exm) ||
0305          !dset->setCoordinate(1, y, eyp, eym) )
0306       throw std::runtime_error("LWH could add points to DataPointSet '" +
0307                    title +  "'." );
0308     return dset;   
0309   }
0310 
0311   /**
0312    * Create a two dimensional IDataPointSet providing the data.
0313    * @param path  The path of the IDataPointSet. The path can either be a
0314    *              relative or full path. ("/folder1/folder2/dataTitle" and
0315    *              "../folder/dataTitle" are valid paths). All the directories
0316    *              in the path must exist. The characther `/` cannot be used
0317    *              in names; it is only used to delimit directories within paths.
0318    * @param title The title of the IDataPointSet.
0319    * @param x     The array of the x values
0320    * @param y     The array of the y values
0321    * @param ex    The array with the symmetric errors on x
0322    * @param ey    The array with the symmetric errors on y
0323    * @return      The created IDataPointSet.
0324    */
0325   virtual IDataPointSet *
0326   createXY(const std::string & path, const std::string & title,
0327        const std::vector<double> & x, const std::vector<double> & y,
0328        const std::vector<double> & ex, const std::vector<double> & ey) {
0329     return createXY(path, title, x, y, ex, ey, ex, ey);
0330   }
0331 
0332   /**
0333    * Create a two dimensional IDataPointSet providing the data.
0334    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0335    *                     a relative or full path. The last part of the path is
0336    *                     used as the title. ("/folder1/folder2/dataTitle" and
0337    *                     "../folder/dataTitle" are valid paths). All the
0338    *                     directories in the path must exist. The characther
0339    *                     `/` cannot be used in names; it is only used to
0340    *                     delimit directories within paths.
0341    * @param x            The array of the x values
0342    * @param y            The array of the y values
0343    * @param exp          The array with the plus errors on x
0344    * @param eyp          The array with the plus errors on y
0345    * @param exm          The array with the minus errors on x
0346    * @param eym          The array with the minus errors on y
0347    * @return             The created IDataPointSet.
0348    */
0349   virtual IDataPointSet *
0350   createXY(const std::string & pathAndTitle,
0351        const std::vector<double> & x, const std::vector<double> & y,
0352        const std::vector<double> & exp, const std::vector<double> & eyp,
0353        const std::vector<double> & exm, const std::vector<double> & eym) {
0354     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0355     return createXY(pathAndTitle, title, x, y, exp, eyp, exm, eym);
0356   }
0357 
0358   /**
0359    * Create a two dimensional IDataPointSet providing the data.
0360    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0361    *                     a relative or full path. The last part of the path is
0362    *                     used as the title. ("/folder1/folder2/dataTitle" and
0363    *                     "../folder/dataTitle" are valid paths). All the
0364    *                     directories in the path must exist. The characther
0365    *                     `/` cannot be used in names; it is only used to
0366    *                     delimit directories within paths.
0367    * @param x            The array of the x values
0368    * @param y            The array of the y values
0369    * @param ex           The array with the symmetric errors on x
0370    * @param ey           The array with the symmetric errors on y
0371    * @return             The created IDataPointSet.
0372    */
0373   virtual IDataPointSet *
0374   createXY(const std::string & pathAndTitle,
0375        const std::vector<double> & x, const std::vector<double> & y,
0376        const std::vector<double> & ex, const std::vector<double> & ey) {
0377     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0378     return createXY(pathAndTitle, title, x, y, ex, ey, ex, ey);
0379   }
0380 
0381   /**
0382    * Create a three dimensional IDataPointSet providing the data.
0383    * @param path  The path of the IDataPointSet. The path can either be a
0384    *              relative or full path. ("/folder1/folder2/dataTitle" and
0385    *              "../folder/dataTitle" are valid paths). All the directories
0386    *              in the path must exist. The characther `/` cannot be used
0387    *              in names; it is only used to delimit directories within paths.
0388    * @param title The title of the IDataPointSet.
0389    * @param x     The array of the x values
0390    * @param y     The array of the y values
0391    * @param z     The array of the z values
0392    * @param exp   The array with the plus errors on x
0393    * @param eyp   The array with the plus errors on y
0394    * @param ezp   The array with the plus errors on z
0395    * @param exm   The array with the minus errors on x
0396    * @param eym   The array with the minus errors on y
0397    * @param ezm   The array with the minus errors on z
0398    * @return      The created IDataPointSet.
0399    */
0400   virtual IDataPointSet *
0401   createXYZ(const std::string & path, const std::string & title,
0402         const std::vector<double> & x, const std::vector<double> & y,
0403         const std::vector<double> & z, const std::vector<double> & exp,
0404         const std::vector<double> & eyp, const std::vector<double> & ezp,
0405         const std::vector<double> & exm, const std::vector<double> & eym,
0406         const std::vector<double>  & ezm) {
0407     IDataPointSet * dset = create(path, title, 3);
0408     for ( int i = 0, N = y.size(); i < N; ++i ) dset->addPoint(DataPoint(3));
0409     if ( !dset->setCoordinate(0, x, exp, exm) ||
0410          !dset->setCoordinate(1, y, eyp, eym) ||
0411          !dset->setCoordinate(2, z, ezp, ezm) )
0412       throw std::runtime_error("LWH could add points to DataPointSet '" +
0413                    title +  "'." );
0414     return dset;   
0415   }
0416 
0417   /**
0418    * Create a three dimensional IDataPointSet providing the data.
0419    * @param path  The path of the IDataPointSet. The path can either be a
0420    *              relative or full path. ("/folder1/folder2/dataTitle" and
0421    *              "../folder/dataTitle" are valid paths). All the directories
0422    *              in the path must exist. The characther `/` cannot be used
0423    *              in names; it is only used to delimit directories within paths.
0424    * @param title The title of the IDataPointSet.
0425    * @param x     The array of the x values
0426    * @param y     The array of the y values
0427    * @param z     The array of the z values
0428    * @param ex    The array with the symmetric errors on x
0429    * @param ey    The array with the symmetric errors on y
0430    * @param ez    The array with the symmetric errors on z
0431    * @return      The created IDataPointSet.
0432    */
0433   virtual IDataPointSet *
0434   createXYZ(const std::string & path, const std::string & title,
0435         const std::vector<double> & x, const std::vector<double> & y,
0436         const std::vector<double> & z, const std::vector<double> & ex,
0437         const std::vector<double> & ey, const std::vector<double> & ez) {
0438     return createXYZ(path, title, x, y, z, ex, ey, ez, ex, ey, ez);
0439   }
0440 
0441   /**
0442    * Create a two dimensional IDataPointSet providing the data.
0443    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0444    *                     a relative or full path. The last part of the path is
0445    *                     used as the title. ("/folder1/folder2/dataTitle" and
0446    *                     "../folder/dataTitle" are valid paths). All the
0447    *                     directories in the path must exist. The characther
0448    *                     `/` cannot be used in names; it is only used to
0449    *                     delimit directories within paths.
0450    * @param x            The array of the x values
0451    * @param y            The array of the y values
0452    * @param z            The array of the z values
0453    * @param exp          The array with the plus errors on x
0454    * @param eyp          The array with the plus errors on y
0455    * @param ezp          The array with the plus errors on z
0456    * @param exm          The array with the minus errors on x
0457    * @param eym          The array with the minus errors on y
0458    * @param ezm          The array with the minus errors on z
0459    * @return             The created IDataPointSet.
0460    */
0461   virtual IDataPointSet *
0462   createXYZ(const std::string & pathAndTitle, const std::vector<double> & x,
0463         const std::vector<double> & y, const std::vector<double> & z,
0464         const std::vector<double> & exp, const std::vector<double> & eyp,
0465         const std::vector<double> & ezp, const std::vector<double> & exm,
0466         const std::vector<double> & eym, const std::vector<double> & ezm) {
0467     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0468     return createXYZ(pathAndTitle, title, x, y, z,
0469              exp, eyp, ezp, exm, eym, ezm);
0470   }
0471 
0472   /**
0473    * Create a two dimensional IDataPointSet providing the data.
0474    * @param pathAndTitle The path of the IDataPointSet. The path can either be
0475    *                     a relative or full path. The last part of the path is
0476    *                     used as the title. ("/folder1/folder2/dataTitle" and
0477    *                     "../folder/dataTitle" are valid paths). All the
0478    *                     directories in the path must exist. The characther
0479    *                     `/` cannot be used in names; it is only used to
0480    *                     delimit directories within paths.
0481    * @param x            The array of the x values
0482    * @param y            The array of the y values
0483    * @param z            The array of the z values
0484    * @param ex           The array with the symmetric errors on x
0485    * @param ey           The array with the symmetric errors on y
0486    * @param ez           The array with the symmetric errors on z
0487    * @return             The created IDataPointSet.
0488    */
0489   virtual IDataPointSet *
0490   createXYZ(const std::string & pathAndTitle, const std::vector<double> & x,
0491         const std::vector<double> & y, const std::vector<double> & z,
0492         const std::vector<double> & ex, const std::vector<double> & ey,
0493         const std::vector<double> & ez) {
0494     std::string title = pathAndTitle.substr(pathAndTitle.rfind('/') + 1);
0495     return createXYZ(pathAndTitle, title, x, y, z, ex, ey, ez, ex, ey, ez);
0496   }
0497 
0498   /**
0499    * Make a copy of a given IDataPointSet.
0500    * @param path  The path of the IDataPointSet. The path can either be a
0501    *              relative or full path. ("/folder1/folder2/dataTitle" and
0502    *              "../folder/dataTitle" are valid paths). All the directories
0503    *              in the path must exist. The characther `/` cannot be used
0504    *              in names; it is only used to delimit directories within paths.
0505    * @param dataPointSet The IDataPointSet to be copied.
0506    * @return             The copy of the given IDataPointSet.
0507    */
0508   virtual IDataPointSet *
0509   createCopy(const std::string & path, const IDataPointSet & dataPointSet) {
0510     IDataPointSet * dset =
0511       create(path, dataPointSet.title(), dataPointSet.dimension());
0512     for ( int i = 0, N = dataPointSet.size(); i < N; ++i )
0513       dset->addPoint(*dataPointSet.point(i));
0514     return dset;
0515   }
0516 
0517   /**
0518    * Destroy a given IDataPointSet.
0519    * @param dataPointSet  The IDataPointSet to be destroyed.
0520    * @return false If dataPointSet cannot be destroyed.
0521    */
0522   virtual bool destroy(IDataPointSet * dataPointSet) {
0523     IManagedObject * mo = dynamic_cast<IManagedObject *>(dataPointSet);
0524     if ( !mo ) return false;
0525     return tree->rm(tree->findPath(*mo));
0526   }
0527 
0528   /**
0529    * Create an IDataPointSet from an IHistogram1D.
0530    * @param path  The path of the IDataPointSet. The path can either
0531    *              be a relative or full path.
0532    *              ("/folder1/folder2/dataName" and "../folder/dataName"
0533    *              are valid paths). All the directories in the path
0534    *              must exist. The characther `/` cannot be used in
0535    *              names; it is only used to delimit directories within
0536    *            paths.
0537    * @param hist    The IHistogram1D from which the data is taken.
0538    * @return        The newly created IDataPointSet.
0539    */
0540   virtual IDataPointSet *
0541   create(const std::string & path, const IHistogram1D & hist,
0542      const std::string & = "") {
0543     IDataPointSet * dset = create(path, hist.title(), 2);
0544     std::vector<double> x, y, ex, ey;
0545     for ( int i = 2, N = hist.axis().bins() + 2; i < N; ++i ) {
0546       dset->addPoint(DataPoint(2));
0547       x.push_back(hist.binMean(i - 2));
0548       ex.push_back(hist.axis().binWidth(i - 2));
0549       y.push_back(hist.binHeight(i - 2));
0550       ey.push_back(hist.binError(i - 2));
0551     }
0552     if ( !dset->setCoordinate(0, x, ex, ex) ||
0553          !dset->setCoordinate(1, y, ey, ey) )
0554       throw std::runtime_error("LWH could add points to DataPointSet '" +
0555                    hist.title() +  "'." );
0556     return dset;
0557   }
0558 
0559   /**
0560    * Create an IDataPointSet from an IHistogram2D.
0561    * @param path  The path of the IDataPointSet. The path can either
0562    *              be a relative or full path.
0563    *              ("/folder1/folder2/dataName" and "../folder/dataName"
0564    *              are valid paths). All the directories in the path
0565    *              must exist. The characther `/` cannot be used in
0566    *              names; it is only used to delimit directories within
0567    *            paths.
0568    * @param hist    The IHistogram2D from which the data is taken.
0569    * @param options Options, currently not specified
0570    * @return        The newly created IDataPointSet.
0571    */
0572   virtual IDataPointSet *
0573   create(const std::string & path, const IHistogram2D & hist,
0574          const std::string & = "") {
0575     IDataPointSet * dset = create(path, hist.title(), 3);
0576     
0577     std::vector<double> x, y, z, ex, ey, ez;
0578     for ( int ix = 2, Nx = hist.xAxis().bins() + 2; ix < Nx; ++ix )
0579       for ( int iy = 2, Ny = hist.yAxis().bins() + 2; iy < Ny; ++iy ) {
0580     dset->addPoint(DataPoint(3));
0581     //x.push_back(hist.binMean(i - 2)); // < "Dynamic" version
0582     // Shouldn't IAxis have a binCentre(size_t binId) method?
0583     // (According to Java AIDA v3.3.0 API)
0584     x.push_back((hist.xAxis().binLowerEdge(ix - 2) +
0585              hist.xAxis().binUpperEdge(ix - 2))/2.0);
0586     ex.push_back(hist.xAxis().binWidth(ix - 2)/2.0);
0587     y.push_back((hist.yAxis().binLowerEdge(iy - 2) +
0588              hist.yAxis().binUpperEdge(iy - 2))/2.0);
0589     ey.push_back(hist.yAxis().binWidth(iy - 2)/2.0);
0590     const double binwidth = hist.xAxis().binWidth(ix - 2)*
0591       hist.yAxis().binWidth(iy - 2);
0592     z.push_back(hist.binHeight(ix - 2, iy - 2)/binwidth);
0593     ez.push_back(hist.binError(ix - 2, iy - 2)/binwidth);
0594       }
0595     if ( !dset->setCoordinate(0, x, ex, ex) ||
0596          !dset->setCoordinate(1, y, ey, ey) ||
0597          !dset->setCoordinate(2, z, ez, ez) )
0598       throw std::runtime_error("LWH could not add points to DataPointSet '" +
0599                    hist.title() +  "'." );
0600     return dset;
0601   }
0602 
0603 
0604   /**
0605    * LWH cannot handle a IHistogram3D.
0606    */
0607   virtual IDataPointSet * create(const std::string &, const IHistogram3D &,
0608                  const std::string & = "") {
0609     return error<IDataPointSet>("IHistogram3D");
0610   }
0611 
0612   /**
0613    * LWH cannot handle a ICloud1.
0614    */
0615   virtual IDataPointSet * create(const std::string &, const ICloud1D &,
0616                  const std::string & = "") {
0617     return error<IDataPointSet>("ICloud1D");
0618   }
0619 
0620   /**
0621    * LWH cannot handle a ICloud2D.
0622    */
0623   virtual IDataPointSet * create(const std::string &, const ICloud2D &,
0624                  const std::string & = "") {
0625     return error<IDataPointSet>("ICloud2D");
0626   }
0627 
0628   /**
0629    * LWH cannot handle a ICloud3D.
0630    */
0631   virtual IDataPointSet * create(const std::string &, const ICloud3D &,
0632                  const std::string & = "") {
0633     return error<IDataPointSet>("ICloud3D");
0634   }
0635 
0636   /**
0637    * LWH cannot handle a IProfile1D.
0638    */
0639   virtual IDataPointSet * create(const std::string &, const IProfile1D &,
0640                  const std::string & = "") {
0641     return error<IDataPointSet>("IProfile1D");
0642   }
0643 
0644   /**
0645    * LWH cannot handle a IProfile2D.
0646    */
0647   virtual IDataPointSet * create(const std::string &, const IProfile2D &,
0648                  const std::string & = "") {
0649     return error<IDataPointSet>("IProfile2D");
0650   }
0651 
0652   /**
0653    * LWH cannot handle the addition of data points.
0654    */
0655   virtual IDataPointSet * add(const std::string &,
0656                   const IDataPointSet &, const IDataPointSet &) {
0657     return error<IDataPointSet>("addition of data points");
0658   }
0659 
0660   /**
0661    * LWH cannot handle the subtraction of data points.
0662    */
0663   virtual IDataPointSet * subtract(const std::string &, const IDataPointSet &,
0664                    const IDataPointSet &) {
0665     return error<IDataPointSet>("subtraction of data points");
0666   }
0667 
0668   /**
0669    * LWH cannot handle the multiplication of data points.
0670    */
0671   virtual IDataPointSet * multiply(const std::string &, const IDataPointSet &,
0672                    const IDataPointSet &) {
0673     return error<IDataPointSet>("multiplication of data points");
0674   }
0675 
0676   /**
0677    * LWH cannot handle the division of data points.
0678    */
0679   virtual IDataPointSet * divide(const std::string &, const IDataPointSet &,
0680                  const IDataPointSet &) {
0681     return error<IDataPointSet>("division of data points");
0682   }
0683 
0684   /**
0685    * LWH cannot handle the weighted mean of data points.
0686    */
0687   virtual IDataPointSet *
0688   weightedMean(const std::string &, const IDataPointSet &,
0689            const IDataPointSet &) {
0690     return error<IDataPointSet>("weighted means of data points");
0691   }
0692   
0693 private:
0694 
0695   /** Throw a suitable error. */
0696   template <typename T>
0697   static T * error(std::string feature) {
0698     throw std::runtime_error("LWH cannot handle " + feature + ".");
0699   }
0700 
0701   /** The tree where the actual data sets are stored. */
0702   Tree * tree;
0703 
0704 };
0705 }
0706 
0707 #endif