Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/f2plot is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_f2plot
0005 #define tools_sg_f2plot
0006 
0007 // Connexion tools/func to sg/plotter.
0008 
0009 #include "plottables"
0010 
0011 #include "../tokenize"
0012 #include "../S_STRING"
0013 #include "../forit"
0014 
0015 namespace tools {
0016 namespace sg {
0017 
0018 template <class T>
0019 class f1d2plot : public virtual func1D {
0020 public:
0021   TOOLS_T_SCLASS(T,tools::sg::f1d2plot)
0022   virtual void* cast(const std::string& a_class) const {
0023     if(void* p = cmp_cast<f1d2plot>(this,a_class)) {return p;}
0024     return func1D::cast(a_class);
0025   }
0026 public: //plottable
0027   virtual plottable* copy() const {return new f1d2plot(*this);}
0028   virtual bool is_valid() const {return true;}
0029   virtual const std::string& name() const {return m_name;}
0030   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0031   virtual const std::string& title() const {return m_title;}
0032   virtual const std::string& legend() const {return m_legend;}
0033   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0034 
0035   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0036     a_sinfos.clear();
0037     std::string f_lf("\n");
0038     std::vector<std::string> _words;
0039     words(a_opts," ",false,_words);
0040     tools_vforcit(std::string,_words,it) {
0041       if(((*it)=="name") && m_name.size()) {
0042         if(a_sinfos.size()) a_sinfos += f_lf;
0043         a_sinfos += "Name\n";
0044         a_sinfos += m_name;
0045       }
0046     }
0047   }
0048 public: //func1D
0049   virtual bool value(float a_x,float& a_v) const {
0050     if(!m_data.in_domain(a_x)) {a_v = 0;return false;}
0051     a_v = (float)m_data.value(a_x);
0052     return true;
0053   }
0054 
0055   virtual unsigned int x_steps() const {return m_data.xdomain_number_of_steps();}
0056   virtual float x_min() const {return (float)m_data.xdomain_min();}
0057   virtual float x_max() const {return (float)m_data.xdomain_max();}
0058 
0059 public:
0060   f1d2plot(const T& a_data):m_data(a_data){
0061   }
0062   virtual ~f1d2plot(){
0063   }
0064 public:
0065   f1d2plot(const f1d2plot& a_from)
0066   :plottable(a_from),func1D(a_from)
0067   ,m_data(a_from.m_data)
0068   ,m_name(a_from.m_name)
0069   ,m_legend(a_from.m_legend)
0070   ,m_title(a_from.m_title)
0071   {
0072   }
0073   f1d2plot& operator=(const f1d2plot& a_from){
0074     m_name = a_from.m_name;
0075     m_legend = a_from.m_legend;
0076     m_title = a_from.m_title;
0077     return *this;
0078   }
0079 public:
0080   void set_title(const std::string& a_s) {m_title = a_s;} //for gopaw.
0081 protected:
0082   const T& m_data;
0083   std::string m_name;
0084   std::string m_legend;
0085   std::string m_title;
0086 };
0087 
0088 template <class T>
0089 class f1d2plot_cp : public f1d2plot<T> {
0090 public:
0091   TOOLS_T_SCLASS(T,tools::sg::f1d2plot_cp)
0092   virtual void* cast(const std::string& a_class) const {
0093     if(void* p = cmp_cast<f1d2plot_cp>(this,a_class)) {return p;}
0094     return f1d2plot<T>::cast(a_class);
0095   }
0096 public:
0097   f1d2plot_cp(const T& a_data)
0098   :f1d2plot<T>(m_cp)
0099   ,m_cp(a_data)
0100   {}
0101   virtual ~f1d2plot_cp(){}
0102 public:
0103   f1d2plot_cp(const f1d2plot_cp& a_from)
0104   :plottable(a_from)
0105   ,func1D(a_from)
0106   ,f1d2plot<T>(m_cp)
0107   ,m_cp(a_from.m_cp)
0108   {}
0109   f1d2plot_cp& operator=(const f1d2plot_cp& a_from){
0110     f1d2plot<T>::operator=(a_from);
0111     m_cp = a_from.m_cp;
0112     return *this;
0113   }
0114 protected:
0115   T m_cp;
0116 };
0117 
0118 template <class T>
0119 class f2d2plot : public virtual func2D {
0120 public:
0121   TOOLS_T_SCLASS(T,tools::sg::f2d2plot)
0122   virtual void* cast(const std::string& a_class) const {
0123     if(void* p = cmp_cast<f2d2plot>(this,a_class)) {return p;}
0124     return func2D::cast(a_class);
0125   }
0126 public: //plottable
0127   virtual plottable* copy() const {return new f2d2plot(*this);}
0128   virtual bool is_valid() const {return true;}
0129   virtual const std::string& name() const {return m_name;}
0130   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0131   virtual const std::string& title() const {return m_title;}
0132   virtual const std::string& legend() const {return m_legend;}
0133   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0134 
0135   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0136     a_sinfos.clear();
0137     std::string f_lf("\n");
0138     std::vector<std::string> _words;
0139     words(a_opts," ",false,_words);
0140     tools_vforcit(std::string,_words,it) {
0141       if(((*it)=="name") && m_name.size()) {
0142         if(a_sinfos.size()) a_sinfos += f_lf;
0143         a_sinfos += "Name\n";
0144         a_sinfos += m_name;
0145       }
0146     }
0147   }
0148 public: //func2D
0149   virtual bool value(float a_x,float a_y,float& a_v) const {
0150     if(!m_data.in_domain(a_x,a_y)) {a_v = 0;return false;}
0151     a_v = (float)m_data.value(a_x,a_y);
0152     return true;
0153   }
0154 
0155   virtual unsigned int x_steps() const {return m_data.xdomain_number_of_steps();}
0156   virtual float x_min() const {return m_data.xdomain_min();}
0157   virtual float x_max() const {return m_data.xdomain_max();}
0158   virtual unsigned int y_steps() const {return m_data.ydomain_number_of_steps();}
0159   virtual float y_min() const {return m_data.ydomain_min();}
0160   virtual float y_max() const {return m_data.ydomain_max();}
0161 public:
0162   f2d2plot(const T& a_data):m_data(a_data){
0163   }
0164   virtual ~f2d2plot(){
0165   }
0166 public:
0167   f2d2plot(const f2d2plot& a_from)
0168   :plottable(a_from),func2D(a_from)
0169   ,m_data(a_from.m_data)
0170   ,m_name(a_from.m_name)
0171   ,m_legend(a_from.m_legend)
0172   ,m_title(a_from.m_title)
0173   {
0174   }
0175   f2d2plot& operator=(const f2d2plot& a_from){
0176     m_name = a_from.m_name;
0177     m_legend = a_from.m_legend;
0178     m_title = a_from.m_title;
0179     return *this;
0180   }
0181 public:
0182   void set_title(const std::string& a_s) {m_title = a_s;} //for gopaw.
0183 protected:
0184   const T& m_data;
0185   std::string m_name;
0186   std::string m_legend;
0187   std::string m_title;
0188 };
0189 
0190 template <class T>
0191 class f2d2plot_cp : public f2d2plot<T> {
0192 public:
0193   TOOLS_T_SCLASS(T,tools::sg::f2d2plot_cp)
0194   virtual void* cast(const std::string& a_class) const {
0195     if(void* p = cmp_cast<f2d2plot_cp>(this,a_class)) {return p;}
0196     return f2d2plot<T>::cast(a_class);
0197   }
0198 public:
0199   f2d2plot_cp(const T& a_data)
0200   :f2d2plot<T>(m_cp)
0201   ,m_cp(a_data)
0202   {}
0203   virtual ~f2d2plot_cp(){}
0204 public:
0205   f2d2plot_cp(const f2d2plot_cp& a_from)
0206   :plottable(a_from)
0207   ,func2D(a_from)
0208   ,f2d2plot<T>(m_cp)
0209   ,m_cp(a_from.m_cp)
0210   {}
0211   f2d2plot_cp& operator=(const f2d2plot_cp& a_from){
0212     f2d2plot<T>::operator=(a_from);
0213     m_cp = a_from.m_cp;
0214     return *this;
0215   }
0216 protected:
0217   T m_cp;
0218 };
0219 
0220 }}
0221 
0222 #endif