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