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