g4tools  5.4.0
f2plot
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_f2plot
5 #define tools_sg_f2plot
6 
7 // Connexion inlib/func to sg/plotter.
8 
9 #include "plottables"
10 
11 //#include "../func"
12 
13 #include "../words"
14 #include "../S_STRING"
15 #include "../forit"
16 
17 #ifdef TOOLS_MEM
18 #include "../mem"
19 #endif
20 
21 namespace tools {
22 namespace sg {
23 
24 template <class T>
25 class f1d2plot : public virtual func1D {
26 public:
28  virtual void* cast(const std::string& a_class) const {
29  if(void* p = cmp_cast<f1d2plot>(this,a_class)) {return p;}
30  return func1D::cast(a_class);
31  }
32 public: //plottable
33  virtual plottable* copy() const {return new f1d2plot(*this);}
34  virtual bool is_valid() const {return true;}
35  virtual const std::string& name() const {return m_name;}
36  virtual void set_name(const std::string& a_s) {m_name = a_s;}
37  virtual const std::string& title() const {return m_title;}
38  virtual const std::string& legend() const {return m_legend;}
39  virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
40 
41  virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
42  a_sinfos.clear();
43  std::string f_lf("\n");
44  std::vector<std::string> _words;
45  words(a_opts," ",false,_words);
46  tools_vforcit(std::string,_words,it) {
47  if(((*it)=="name") && m_name.size()) {
48  if(a_sinfos.size()) a_sinfos += f_lf;
49  a_sinfos += "Name\n";
50  a_sinfos += m_name;
51  }
52  }
53  }
54 public: //func1D
55  virtual bool value(float a_x,float& a_v) const {
56  if(!m_data.in_domain(a_x)) {a_v = 0;return false;}
57  a_v = (float)m_data.value(a_x);
58  return true;
59  }
60 
61  virtual unsigned int x_steps() const {return m_data.xdomain_number_of_steps();}
62  virtual float x_min() const {return (float)m_data.xdomain_min();}
63  virtual float x_max() const {return (float)m_data.xdomain_max();}
64 
65 public:
66  f1d2plot(const T& a_data):m_data(a_data){
67 #ifdef TOOLS_MEM
68  mem::increment(s_class().c_str());
69 #endif
70  }
71  virtual ~f1d2plot(){
72 #ifdef TOOLS_MEM
73  mem::decrement(s_class().c_str());
74 #endif
75  }
76 public:
77  f1d2plot(const f1d2plot& a_from)
78  :plottable(a_from),func1D(a_from)
79  ,m_data(a_from.m_data)
80  ,m_name(a_from.m_name)
81  ,m_legend(a_from.m_legend)
82  ,m_title(a_from.m_title)
83  {
84 #ifdef TOOLS_MEM
85  mem::increment(s_class().c_str());
86 #endif
87  }
88  f1d2plot& operator=(const f1d2plot& a_from){
89  m_name = a_from.m_name;
90  m_legend = a_from.m_legend;
91  m_title = a_from.m_title;
92  return *this;
93  }
94 public:
95  void set_title(const std::string& a_s) {m_title = a_s;} //for gopaw.
96 protected:
97  const T& m_data;
98  std::string m_name;
99  std::string m_legend;
100  std::string m_title;
101 };
102 
103 template <class T>
104 class f1d2plot_cp : public f1d2plot<T> {
105 public:
107  virtual void* cast(const std::string& a_class) const {
108  if(void* p = cmp_cast<f1d2plot_cp>(this,a_class)) {return p;}
109  return f1d2plot<T>::cast(a_class);
110  }
111 public:
112  f1d2plot_cp(const T& a_data)
113  :f1d2plot<T>(m_cp)
114  ,m_cp(a_data)
115  {}
116  virtual ~f1d2plot_cp(){}
117 public:
118  f1d2plot_cp(const f1d2plot_cp& a_from)
119  :plottable(a_from)
120  ,func1D(a_from)
121  ,f1d2plot<T>(m_cp)
122  ,m_cp(a_from.m_cp)
123  {}
125  f1d2plot<T>::operator=(a_from);
126  m_cp = a_from.m_cp;
127  return *this;
128  }
129 protected:
130  T m_cp;
131 };
132 
133 template <class T>
134 class f2d2plot : public virtual func2D {
135 public:
137  virtual void* cast(const std::string& a_class) const {
138  if(void* p = cmp_cast<f2d2plot>(this,a_class)) {return p;}
139  return func2D::cast(a_class);
140  }
141 public: //plottable
142  virtual plottable* copy() const {return new f2d2plot(*this);}
143  virtual bool is_valid() const {return true;}
144  virtual const std::string& name() const {return m_name;}
145  virtual void set_name(const std::string& a_s) {m_name = a_s;}
146  virtual const std::string& title() const {return m_title;}
147  virtual const std::string& legend() const {return m_legend;}
148  virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
149 
150  virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
151  a_sinfos.clear();
152  std::string f_lf("\n");
153  std::vector<std::string> _words;
154  words(a_opts," ",false,_words);
155  tools_vforcit(std::string,_words,it) {
156  if(((*it)=="name") && m_name.size()) {
157  if(a_sinfos.size()) a_sinfos += f_lf;
158  a_sinfos += "Name\n";
159  a_sinfos += m_name;
160  }
161  }
162  }
163 public: //func2D
164  virtual bool value(float a_x,float a_y,float& a_v) const {
165  if(!m_data.in_domain(a_x,a_y)) {a_v = 0;return false;}
166  a_v = (float)m_data.value(a_x,a_y);
167  return true;
168  }
169 
170  virtual unsigned int x_steps() const {return m_data.xdomain_number_of_steps();}
171  virtual float x_min() const {return m_data.xdomain_min();}
172  virtual float x_max() const {return m_data.xdomain_max();}
173  virtual unsigned int y_steps() const {return m_data.ydomain_number_of_steps();}
174  virtual float y_min() const {return m_data.ydomain_min();}
175  virtual float y_max() const {return m_data.ydomain_max();}
176 public:
177  f2d2plot(const T& a_data):m_data(a_data){
178 #ifdef TOOLS_MEM
179  mem::increment(s_class().c_str());
180 #endif
181  }
182  virtual ~f2d2plot(){
183 #ifdef TOOLS_MEM
184  mem::decrement(s_class().c_str());
185 #endif
186  }
187 public:
188  f2d2plot(const f2d2plot& a_from)
189  :plottable(a_from),func2D(a_from)
190  ,m_data(a_from.m_data)
191  ,m_name(a_from.m_name)
192  ,m_legend(a_from.m_legend)
193  ,m_title(a_from.m_title)
194  {
195 #ifdef TOOLS_MEM
196  mem::increment(s_class().c_str());
197 #endif
198  }
199  f2d2plot& operator=(const f2d2plot& a_from){
200  m_name = a_from.m_name;
201  m_legend = a_from.m_legend;
202  m_title = a_from.m_title;
203  return *this;
204  }
205 public:
206  void set_title(const std::string& a_s) {m_title = a_s;} //for gopaw.
207 protected:
208  const T& m_data;
209  std::string m_name;
210  std::string m_legend;
211  std::string m_title;
212 };
213 
214 template <class T>
215 class f2d2plot_cp : public f2d2plot<T> {
216 public:
218  virtual void* cast(const std::string& a_class) const {
219  if(void* p = cmp_cast<f2d2plot_cp>(this,a_class)) {return p;}
220  return f2d2plot<T>::cast(a_class);
221  }
222 public:
223  f2d2plot_cp(const T& a_data)
224  :f2d2plot<T>(m_cp)
225  ,m_cp(a_data)
226  {}
227  virtual ~f2d2plot_cp(){}
228 public:
229  f2d2plot_cp(const f2d2plot_cp& a_from)
230  :plottable(a_from)
231  ,func2D(a_from)
232  ,f2d2plot<T>(m_cp)
233  ,m_cp(a_from.m_cp)
234  {}
236  f2d2plot<T>::operator=(a_from);
237  m_cp = a_from.m_cp;
238  return *this;
239  }
240 protected:
241  T m_cp;
242 };
243 
244 }}
245 
246 #endif
tools::sg::f1d2plot::infos
virtual void infos(const std::string &a_opts, std::string &a_sinfos) const
Definition: f2plot:41
tools::sg::func1D::cast
virtual void * cast(const std::string &a_class) const
Definition: plottables:80
tools::sg::f2d2plot_cp::f2d2plot_cp
f2d2plot_cp(const f2d2plot_cp &a_from)
Definition: f2plot:229
tools::sg::f1d2plot::x_steps
virtual unsigned int x_steps() const
Definition: f2plot:61
tools::sg::f2d2plot::set_legend
virtual void set_legend(const std::string &a_s)
Definition: f2plot:148
tools::sg::f2d2plot_cp::operator=
f2d2plot_cp & operator=(const f2d2plot_cp &a_from)
Definition: f2plot:235
tools::sg::f1d2plot_cp
Definition: f2plot:104
tools::sg::f1d2plot::m_name
std::string m_name
Definition: f2plot:98
tools::sg::f1d2plot::set_title
void set_title(const std::string &a_s)
Definition: f2plot:95
tools::sg::f2d2plot::x_steps
virtual unsigned int x_steps() const
Definition: f2plot:170
tools::sg::f2d2plot_cp::~f2d2plot_cp
virtual ~f2d2plot_cp()
Definition: f2plot:227
tools::sg::f2d2plot::y_max
virtual float y_max() const
Definition: f2plot:175
tools::sg::f2d2plot::f2d2plot
f2d2plot(const f2d2plot &a_from)
Definition: f2plot:188
tools::sg::f2d2plot::y_min
virtual float y_min() const
Definition: f2plot:174
tools::sg::plottable
Definition: plottable:15
tools::sg::func1D
Definition: plottables:76
tools::sg::func2D
Definition: plottables:93
tools::sg::f1d2plot_cp::m_cp
T m_cp
Definition: f2plot:130
tools::sg::f2d2plot_cp::m_cp
T m_cp
Definition: f2plot:241
tools::sg::f2d2plot::operator=
f2d2plot & operator=(const f2d2plot &a_from)
Definition: f2plot:199
tools::sg::f2d2plot_cp::f2d2plot_cp
f2d2plot_cp(const T &a_data)
Definition: f2plot:223
tools::sg::f2d2plot::legend
virtual const std::string & legend() const
Definition: f2plot:147
tools::sg::f2d2plot::~f2d2plot
virtual ~f2d2plot()
Definition: f2plot:182
tools::sg::f1d2plot::f1d2plot
f1d2plot(const T &a_data)
Definition: f2plot:66
tools::sg::f2d2plot::set_title
void set_title(const std::string &a_s)
Definition: f2plot:206
tools::sg::f2d2plot_cp
Definition: f2plot:215
plottables
tools::sg::f2d2plot::cast
virtual void * cast(const std::string &a_class) const
Definition: f2plot:137
tools::sg::f2d2plot::is_valid
virtual bool is_valid() const
Definition: f2plot:143
tools::sg::f1d2plot_cp::f1d2plot_cp
f1d2plot_cp(const T &a_data)
Definition: f2plot:112
tools::sg::f2d2plot::m_legend
std::string m_legend
Definition: f2plot:210
tools::sg::f1d2plot::copy
virtual plottable * copy() const
Definition: f2plot:33
tools::sg::f1d2plot::x_min
virtual float x_min() const
Definition: f2plot:62
tools::sg::f1d2plot::value
virtual bool value(float a_x, float &a_v) const
Definition: f2plot:55
tools::sg::f1d2plot::legend
virtual const std::string & legend() const
Definition: f2plot:38
tools::sg::f1d2plot_cp::cast
virtual void * cast(const std::string &a_class) const
Definition: f2plot:107
tools::sg::f1d2plot::operator=
f1d2plot & operator=(const f1d2plot &a_from)
Definition: f2plot:88
tools::sg::f2d2plot::copy
virtual plottable * copy() const
Definition: f2plot:142
tools::sg::f1d2plot_cp::operator=
f1d2plot_cp & operator=(const f1d2plot_cp &a_from)
Definition: f2plot:124
tools::sg::f2d2plot::y_steps
virtual unsigned int y_steps() const
Definition: f2plot:173
tools::sg::f1d2plot::x_max
virtual float x_max() const
Definition: f2plot:63
tools::sg::f2d2plot::x_max
virtual float x_max() const
Definition: f2plot:172
tools::sg::f2d2plot_cp::cast
virtual void * cast(const std::string &a_class) const
Definition: f2plot:218
tools::sg::f1d2plot::cast
virtual void * cast(const std::string &a_class) const
Definition: f2plot:28
tools::sg::f1d2plot::f1d2plot
f1d2plot(const f1d2plot &a_from)
Definition: f2plot:77
tools::sg::f2d2plot::m_data
const T & m_data
Definition: f2plot:208
tools::sg::f2d2plot::value
virtual bool value(float a_x, float a_y, float &a_v) const
Definition: f2plot:164
tools::sg::f1d2plot::set_legend
virtual void set_legend(const std::string &a_s)
Definition: f2plot:39
tools::sg::func2D::cast
virtual void * cast(const std::string &a_class) const
Definition: plottables:97
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
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::f2d2plot
Definition: f2plot:134
tools::sg::f2d2plot::infos
virtual void infos(const std::string &a_opts, std::string &a_sinfos) const
Definition: f2plot:150
tools::sg::f1d2plot::is_valid
virtual bool is_valid() const
Definition: f2plot:34
tools::sg::f1d2plot::title
virtual const std::string & title() const
Definition: f2plot:37
tools::sg::f1d2plot::name
virtual const std::string & name() const
Definition: f2plot:35
tools::sg::f2d2plot::m_title
std::string m_title
Definition: f2plot:211
tools::sg::f1d2plot::set_name
virtual void set_name(const std::string &a_s)
Definition: f2plot:36
TOOLS_T_SCLASS
#define TOOLS_T_SCLASS(a_T, a_name)
Definition: S_STRING:48
tools::sg::f2d2plot::m_name
std::string m_name
Definition: f2plot:209
tools::sg::f1d2plot_cp::f1d2plot_cp
f1d2plot_cp(const f1d2plot_cp &a_from)
Definition: f2plot:118
tools::sg::f1d2plot::m_data
const T & m_data
Definition: f2plot:97
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::sg::f2d2plot::f2d2plot
f2d2plot(const T &a_data)
Definition: f2plot:177
tools::sg::f1d2plot_cp::~f1d2plot_cp
virtual ~f1d2plot_cp()
Definition: f2plot:116
tools::sg::f1d2plot
Definition: f2plot:25
tools::sg::f2d2plot::set_name
virtual void set_name(const std::string &a_s)
Definition: f2plot:145
tools::sg::f2d2plot::x_min
virtual float x_min() const
Definition: f2plot:171
tools::sg::f2d2plot::title
virtual const std::string & title() const
Definition: f2plot:146
tools::sg::f2d2plot::name
virtual const std::string & name() const
Definition: f2plot:144
tools::sg::f1d2plot::~f1d2plot
virtual ~f1d2plot()
Definition: f2plot:71
tools::sg::f1d2plot::m_title
std::string m_title
Definition: f2plot:100
tools::sg::f1d2plot::m_legend
std::string m_legend
Definition: f2plot:99