Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/xy2plot 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_xy2plot
0005 #define tools_sg_xy2plot
0006 
0007 #include "plottables"
0008 
0009 #include "../words"
0010 #include "../num2s"
0011 #include "../vmanip"
0012 #include "../mnmx"
0013 #include "../forit"
0014 
0015 #ifdef TOOLS_MEM
0016 #include "../mem"
0017 #endif
0018 
0019 namespace tools {
0020 namespace sg {
0021 
0022 template <class T>
0023 class xy2plot : public virtual points2D {
0024   static const std::string& s_empty() {
0025     static const std::string s_v("");
0026     return s_v;
0027   }
0028 public: //plottable
0029   virtual plottable* copy() const {return new xy2plot(*this);}
0030   virtual bool is_valid() const {return true;}
0031   virtual const std::string& name() const {return m_name;}
0032   virtual void set_name(const std::string& a_s) {m_name = a_s;}
0033   virtual const std::string& title() const {return s_empty();}
0034   virtual const std::string& legend() const {return m_legend;}
0035   virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0036 
0037   virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0038     a_sinfos.clear();
0039     std::string f_lf("\n");
0040     std::vector<std::string> ws;
0041     words(a_opts," ",false,ws);
0042     tools_vforcit(std::string,ws,it) {
0043       if(((*it)=="name") && m_name.size()) {
0044         if(a_sinfos.size()) a_sinfos += f_lf;
0045         a_sinfos += "Name\n";
0046         a_sinfos += m_name;
0047 
0048       } else if((*it)=="entries") {
0049         if(a_sinfos.size()) a_sinfos += f_lf;
0050         a_sinfos += "Entries\n";
0051         if(!numas<unsigned int>(mn<unsigned int>(m_x.size(),m_y.size()),a_sinfos)){}
0052 
0053       }
0054     }
0055   }
0056 public: //points2D
0057   virtual float x_axis_min() const {return float(m_x_min);}
0058   virtual float x_axis_max() const {return float(m_x_max);}
0059   virtual float y_axis_min() const {return float(m_y_min);}
0060   virtual float y_axis_max() const {return float(m_y_max);}
0061 
0062   virtual unsigned int points() const {
0063     return mn<unsigned int>(m_x.size(),m_y.size());
0064   }
0065   virtual bool ith_point(unsigned int a_index,float& a_x,float& a_y) const {
0066     if(a_index>=m_x.size()) {a_x = T();a_y = T();return false;}
0067     if(a_index>=m_y.size()) {a_x = T();a_y = T();return false;}
0068     a_x = m_x[a_index];
0069     a_y = m_y[a_index];
0070     return true;
0071   }
0072 public:
0073   typedef typename std::vector<T> data_t;
0074 public:
0075   xy2plot(const data_t& a_x,const data_t& a_y)
0076   :m_x(a_x)
0077   ,m_y(a_y)
0078   {
0079 #ifdef TOOLS_MEM
0080     mem::increment(s_class().c_str());
0081 #endif
0082     minimum<T>(a_x,m_x_min);
0083     maximum<T>(a_x,m_x_max);
0084 
0085     minimum<T>(a_y,m_y_min);
0086     maximum<T>(a_y,m_y_max);
0087   }
0088   virtual ~xy2plot(){
0089 #ifdef TOOLS_MEM
0090     mem::decrement(s_class().c_str());
0091 #endif
0092   }
0093 public:
0094   xy2plot(const xy2plot& a_from)
0095   :plottable(a_from),points2D(a_from)
0096   ,m_x(a_from.m_x)
0097   ,m_y(a_from.m_y)
0098   ,m_name(a_from.m_name)
0099   ,m_legend(a_from.m_legend)
0100   ,m_x_min(a_from.m_x_min)
0101   ,m_x_max(a_from.m_x_max)
0102   ,m_y_min(a_from.m_y_min)
0103   ,m_y_max(a_from.m_y_max)
0104   {
0105 #ifdef TOOLS_MEM
0106     mem::increment(s_class().c_str());
0107 #endif
0108   }
0109   xy2plot& operator=(const xy2plot& a_from){
0110     m_name = a_from.m_name;
0111     m_legend = a_from.m_legend;
0112     m_x_min = a_from.m_x_min;
0113     m_x_max = a_from.m_x_max;
0114     m_y_min = a_from.m_y_min;
0115     m_y_max = a_from.m_y_max;
0116     return *this;
0117   }
0118 protected:
0119   const data_t& m_x;
0120   const data_t& m_y;
0121   std::string m_name;
0122   std::string m_legend;
0123   T m_x_min;
0124   T m_x_max;
0125   T m_y_min;
0126   T m_y_max;
0127 
0128 private: static void check_instantiation() {
0129     std::vector<float> data;
0130     xy2plot<float> dummy(data,data);
0131   }
0132 };
0133 
0134 }}
0135 
0136 #endif