g4tools  5.4.0
xy2plot
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_xy2plot
5 #define tools_sg_xy2plot
6 
7 #include "plottables"
8 
9 #include "../words"
10 #include "../num2s"
11 #include "../vmanip"
12 #include "../mnmx"
13 #include "../forit"
14 
15 #ifdef TOOLS_MEM
16 #include "../mem"
17 #endif
18 
19 namespace tools {
20 namespace sg {
21 
22 template <class T>
23 class xy2plot : public virtual points2D {
24  static const std::string& s_empty() {
25  static const std::string s_v("");
26  return s_v;
27  }
28 public: //plottable
29  virtual plottable* copy() const {return new xy2plot(*this);}
30  virtual bool is_valid() const {return true;}
31  virtual const std::string& name() const {return m_name;}
32  virtual void set_name(const std::string& a_s) {m_name = a_s;}
33  virtual const std::string& title() const {return s_empty();}
34  virtual const std::string& legend() const {return m_legend;}
35  virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
36 
37  virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
38  a_sinfos.clear();
39  std::string f_lf("\n");
40  std::vector<std::string> ws;
41  words(a_opts," ",false,ws);
42  tools_vforcit(std::string,ws,it) {
43  if(((*it)=="name") && m_name.size()) {
44  if(a_sinfos.size()) a_sinfos += f_lf;
45  a_sinfos += "Name\n";
46  a_sinfos += m_name;
47 
48  } else if((*it)=="entries") {
49  if(a_sinfos.size()) a_sinfos += f_lf;
50  a_sinfos += "Entries\n";
51  if(!numas<unsigned int>(mn<unsigned int>(m_x.size(),m_y.size()),a_sinfos)){}
52 
53  }
54  }
55  }
56 public: //points2D
57  virtual float x_axis_min() const {return float(m_x_min);}
58  virtual float x_axis_max() const {return float(m_x_max);}
59  virtual float y_axis_min() const {return float(m_y_min);}
60  virtual float y_axis_max() const {return float(m_y_max);}
61 
62  virtual unsigned int points() const {
63  return mn<unsigned int>(m_x.size(),m_y.size());
64  }
65  virtual bool ith_point(unsigned int a_index,float& a_x,float& a_y) const {
66  if(a_index>=m_x.size()) {a_x = T();a_y = T();return false;}
67  if(a_index>=m_y.size()) {a_x = T();a_y = T();return false;}
68  a_x = m_x[a_index];
69  a_y = m_y[a_index];
70  return true;
71  }
72 public:
73  typedef typename std::vector<T> data_t;
74 public:
75  xy2plot(const data_t& a_x,const data_t& a_y)
76  :m_x(a_x)
77  ,m_y(a_y)
78  {
79 #ifdef TOOLS_MEM
80  mem::increment(s_class().c_str());
81 #endif
82  minimum<T>(a_x,m_x_min);
83  maximum<T>(a_x,m_x_max);
84 
85  minimum<T>(a_y,m_y_min);
86  maximum<T>(a_y,m_y_max);
87  }
88  virtual ~xy2plot(){
89 #ifdef TOOLS_MEM
90  mem::decrement(s_class().c_str());
91 #endif
92  }
93 public:
94  xy2plot(const xy2plot& a_from)
95  :plottable(a_from),points2D(a_from)
96  ,m_x(a_from.m_x)
97  ,m_y(a_from.m_y)
98  ,m_name(a_from.m_name)
99  ,m_legend(a_from.m_legend)
100  ,m_x_min(a_from.m_x_min)
101  ,m_x_max(a_from.m_x_max)
102  ,m_y_min(a_from.m_y_min)
103  ,m_y_max(a_from.m_y_max)
104  {
105 #ifdef TOOLS_MEM
106  mem::increment(s_class().c_str());
107 #endif
108  }
109  xy2plot& operator=(const xy2plot& a_from){
110  m_name = a_from.m_name;
111  m_legend = a_from.m_legend;
112  m_x_min = a_from.m_x_min;
113  m_x_max = a_from.m_x_max;
114  m_y_min = a_from.m_y_min;
115  m_y_max = a_from.m_y_max;
116  return *this;
117  }
118 protected:
119  const data_t& m_x;
120  const data_t& m_y;
121  std::string m_name;
122  std::string m_legend;
127 
128 private: static void check_instantiation() {
129  std::vector<float> data;
130  xy2plot<float> dummy(data,data);
131  }
132 };
133 
134 }}
135 
136 #endif
tools::sg::xy2plot::m_y_min
T m_y_min
Definition: xy2plot:125
tools::sg::xy2plot::y_axis_min
virtual float y_axis_min() const
Definition: xy2plot:59
tools::sg::xy2plot::copy
virtual plottable * copy() const
Definition: xy2plot:29
tools::sg::xy2plot::m_x_min
T m_x_min
Definition: xy2plot:123
tools::sg::xy2plot::m_y
const data_t & m_y
Definition: xy2plot:120
tools::sg::xy2plot::name
virtual const std::string & name() const
Definition: xy2plot:31
tools::sg::plottable
Definition: plottable:15
tools::sg::xy2plot::data_t
std::vector< T > data_t
Definition: xy2plot:73
tools::sg::xy2plot::m_legend
std::string m_legend
Definition: xy2plot:122
tools::sg::xy2plot::ith_point
virtual bool ith_point(unsigned int a_index, float &a_x, float &a_y) const
Definition: xy2plot:65
tools::sg::xy2plot::set_legend
virtual void set_legend(const std::string &a_s)
Definition: xy2plot:35
tools::sg::xy2plot::title
virtual const std::string & title() const
Definition: xy2plot:33
tools::sg::xy2plot::x_axis_min
virtual float x_axis_min() const
Definition: xy2plot:57
tools::sg::xy2plot::m_y_max
T m_y_max
Definition: xy2plot:126
tools::sg::xy2plot::y_axis_max
virtual float y_axis_max() const
Definition: xy2plot:60
plottables
tools::sg::xy2plot::m_x
const data_t & m_x
Definition: xy2plot:119
tools::sg::xy2plot::m_x_max
T m_x_max
Definition: xy2plot:124
tools::sg::xy2plot::x_axis_max
virtual float x_axis_max() const
Definition: xy2plot:58
tools::sg::xy2plot
Definition: xy2plot:23
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::xy2plot::xy2plot
xy2plot(const data_t &a_x, const data_t &a_y)
Definition: xy2plot:75
tools::words
void words(const std::string &a_string, const std::string &a_sep, bool a_take_empty, std::vector< std::string > &a_words, bool a_clear=true)
Definition: words:12
tools::sg::xy2plot::operator=
xy2plot & operator=(const xy2plot &a_from)
Definition: xy2plot:109
tools::sg::xy2plot::legend
virtual const std::string & legend() const
Definition: xy2plot:34
tools::sg::xy2plot::~xy2plot
virtual ~xy2plot()
Definition: xy2plot:88
tools::sg::xy2plot::infos
virtual void infos(const std::string &a_opts, std::string &a_sinfos) const
Definition: xy2plot:37
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::sg::xy2plot::m_name
std::string m_name
Definition: xy2plot:121
tools::sg::xy2plot::points
virtual unsigned int points() const
Definition: xy2plot:62
tools::sg::points2D
Definition: plottables:120
tools::sg::xy2plot::set_name
virtual void set_name(const std::string &a_s)
Definition: xy2plot:32
tools::sg::xy2plot::is_valid
virtual bool is_valid() const
Definition: xy2plot:30
tools::sg::xy2plot::xy2plot
xy2plot(const xy2plot &a_from)
Definition: xy2plot:94