ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ListObjectStock.h
Go to the documentation of this file.
1 
8 #ifndef _LISTOBJECTSTOCK_H_
9 #define _LISTOBJECTSTOCK_H_
10 
11 #include <vector>
12 // need gPad for drawing, really needed only function SetObjectStock
13 // which can be combined in IndicatorObjectStock
14 // #include <TPad.h>
15 
16 #include "ObjectStock.h"
17 #include "../../src_cpp/ListDataStock.h"
18 #include "../CommonXAxis.h"
19 
33 template < class T >
35 {
36  private :
37  typedef T type_obj;
38  std::vector<type_obj> vec_object;
39 
40  public :
42  ListObjectStock( std::string name ) : IndicatorObjectStock( name ) {}
43  // really needed ??, will resize
44  //ListObjectStock ( Indicator indic, UInt_t size, const char * name_contained = "", bool ref0 = false );
45  ListObjectStock ( unsigned int size, std::string name_contained = std::string(), bool ref0 = false );
46  virtual ~ListObjectStock();
47 
48  virtual UInt_t GetSize() const { return vec_object.size(); }
49  virtual void Resize( unsigned int new_size );
50 
52  virtual void GetExtrema( double & min, double & max ) const;
53 
54  virtual void AddToVecObject ( T * obj) { vec_object.push_back( *obj );}
55 
56  // no function get values ??
57  virtual void SetValues( UInt_t bin, std::vector<type_value_data> values,
58  Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value = 0 );
59 
60  // specific implementation
61  virtual void ClearObjectStock();
62 
64  virtual int DistancetoPrimitive(int px, int py, AbstractObjectStock** obj);// const;
66  virtual int DistancetoPoint(int px, int py, double &yvalue, int bin = -1) const;
67  // try new method,, if work delete previous, not convenient distance dependent of the scale !
68  //virtual Int_t DistancetoPoint( double value_x, double value_y, unsigned int bin, double & y_value);
69 
70  //to be overloaded, event, px, py
71  // never moved, just need to be selected
72  //virtual void ExecuteEvent(Int_t, Int_t, Int_t ) {} /*std::cout << "ListObjectStock ExecuteEvent()" << std::endl;*/
73 
74  virtual void Paint( const Option_t* = "");
75  virtual void SetObjectStock( ListDataStockBase * ldata, CommonXAxis *fcommon_xaxis_th, Hparam_stock_t & Hparam_stock );
76  //virtual void SetObjectStock( ListDataStockBase * ldata, CommonXAxis *fcommon_xaxis_th );
77 };
78 
79 
81 
83 template < class T >
85 {
86 #ifdef DEBUG_OBJSTOCK
87  std::cout << "Entry default Constructor ListObjectStock" << std::endl;
88 #endif
89 }
90 
91 // default: name = "", ref0 = false
92 template< class T >
93 ListObjectStock<T>::ListObjectStock( unsigned int size, std::string name_contained, bool ref0 )
94  : IndicatorObjectStock ( name_contained )
95 {
96 #ifdef DEBUG_OBJSTOCK
97  std::cout << "Entry Constructor ListObjectStock size " << size << std::endl;
98  std::cout << "name_contained " << name_contained << std::endl;
99  //std::cout << "Indicator label " << indic.label() << std::endl;
100  std::cout << "ref0 " << ref0 << std::endl;
101 #endif
102 
103  for ( unsigned int i=0; i < size; i++ ) {
104  vec_object.push_back( type_obj() );
105  }
106 }
107 
108 template< class T >
110 {
111 #ifdef DEBUG_OBJSTOCK
112  std::cout << "Destructor ListObjectStock" << std::endl;
113 #endif
114  // crash in deleting the object, object is contained, properly destroyed when ListDataStock is deleted
115  // for ( unsigned int i=0; i< vec_object.size(); ++i ) {
116  // delete &(vec_object[i]);
117  // }
118  //vec_object.erase();
119 
120  // take out from the list, and destroy the object
121  vec_object.clear();
122 
123 #ifdef DEBUG_OBJSTOCK
124  std::cout << "size vec_object " << vec_object.size() << std::endl;
125 #endif
126 }
127 
128 
129 // could be in indicator object stock
130 // cannot simply loop over all, need a Hparam_stock for futur, and check for its own specificity ( shift_left )
136 template< class T >
137 void ListObjectStock<T>::GetExtrema( double & min, double & max ) const
138 {
139 #ifdef DEBUG_OBJSTOCK
140  std::cout << "Entry ListObjectStock::GetExtrema " << std::endl;
141 #endif
142 
143  // local and true min, max
144  double lmin, lmax;
145  double tmin, tmax;
146  tmin = 10e6;
147  tmax = -10e6;
148  lmin = tmin;
149  lmax = tmax;
150 
151  // use info painted, only the painted object are accounted
152  // save lots of code
153  for ( unsigned int i = 0; i < vec_object.size(); i++ ) {
154  //std::cout << "object i " << i << " ToPaint() " << vec_object[i].ToPaint() << std::endl;
155 
156  if ( vec_object[i].ToPaint() ) {
157  vec_object[i].GetExtrema( lmin, lmax );
158  if ( lmin < tmin ) tmin = lmin;
159  if ( lmax > tmax ) tmax = lmax;
160  }
161  }
162 
163  min = tmin;
164  max = tmax;
165 #ifdef DEBUG_OBJSTOCK
166  std::cout << "will return extrema min/max " << min << " " << max << std::endl;
167 #endif
168 }
169 
170 // send function to candle and bar
171 template < class T >
173 {
174 #ifdef DEBUG_OBJSTOCK
175  std::cout << " Entry ListObjectStock::ClearObjectStock(), clear all object size " << vec_object.size() << std::endl;
176 #endif
177 
178  for ( unsigned int i = 0; i < vec_object.size(); i++ ) {
179  // for Candle and Bars set kPaint to false, only
180  vec_object[i].ClearObjectStock();
181  }
182 }
183 
184 //come from update, new size is always more data, may need to extend later ( if want to delete data )
185 template < class T >
186 void ListObjectStock<T>::Resize( unsigned int new_size )
187 {
188 #ifdef DEBUG_OBJSTOCK
189  std::cout << "ListObjectStock::Resize new_size " << new_size << std::endl;
190 #endif
191  // seems to work !!
192  //const char * default_name = GetNameObject().c_str();
193  for ( unsigned int i = 0; i < new_size; ++i ) {
194  vec_object.push_back( type_obj() );
195  }
196 }
197 
198 template < class T >
200 {
201 #ifdef DEBUG_OBJSTOCK
202  std::cout << "Entry ListObjectStock::DistancetoPrimitive " << std::endl;
203  std::cout << "broadcast the function to all elements " << std::endl;
204 #endif
205  Int_t dist = 9999;
206  Int_t dist_objstock;
207  // added because of declaration. but not used
208  AbstractObjectStock *tmp_obj;
209 
210  //ListObjectStock always contains same kind of ObjectStock Bar or Candle (PStockLine ?? choice)
211  for ( unsigned int i = 0; i < vec_object.size(); ++i ) {
212  // candle or bar do not set the object in the function
213  dist_objstock = vec_object[i].DistancetoPrimitive( px, py, &(tmp_obj) );
214 
215  if ( dist_objstock <= dist ) {
216  dist = dist_objstock;
217  *obj = &(vec_object[i]);
218  // could stop if 0
219  //std::cout << "set obj_tmp " << *obj << " " << (*obj)->ClassName() << " dist " << dist << std::endl;
220  }
221  }
222  return dist;
223 }
224 
225 template < class T >
226 int ListObjectStock<T>::DistancetoPoint(int px, int py, double & yvalue, int bin ) const
227 {
228 #ifdef DEBUG_OBJSTOCK
229  std::cout << "Entry ListObjectStock::DistancetoPoint get bin_entry " << bin << std::endl;
230 #endif
231 
232  int dist = 9999;
233  // because always nochronologic order when painting
234  int bin_entry = vec_object.size() - bin;
235 
236  //std::cout << "ListObjectStock::DistancetoPoint bin_entry " << std::endl;
237  dist = (vec_object[ bin_entry ]).DistancetoPoint( px, py, yvalue );
238 
239  //std::cout << "return from ListObjectStock::DistancetoPoint dist " << dist_objstock << "yvalue " << yvalue << std::endl;
240  return dist;
241 }
242 
248 template < class T >
249 void ListObjectStock<T>::SetValues( UInt_t bin, std::vector<type_value_data> values,
250  Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value )
251 {
252 /*
253 #ifdef DEBUG_OBJSTOCK
254  std::cout << " Entry ListObjectStock SetValues bin " << bin << " opt_value " << opt_value << std::endl;
255 #endif
256 */
257  vec_object[bin].SetValues( bin, values, xmin, xmax, date, opt_value );
258 
259  // assumption: if set values, will be to paint
260  vec_object[bin].SetToPaint( true );
261 }
262 
268 template < class T >
269 void ListObjectStock<T>::Paint( const Option_t* option )
270 {
271 #ifdef DEBUG_OBJSTOCK
272  std::cout << "Entry ListObjectStock::Paint" << std::endl;
273 #endif
274 
275  for ( unsigned int i = 0; i < vec_object.size(); i++ ) {
276 
277  if ( vec_object[i].ToPaint() )
278  vec_object[i].Paint( option );
279  }
280 }
281 
288 template < class T >
290 {
291 /*
292 #ifdef DEBUG_OBJSTOCK
293  std::cout << "\n\tEntry ListObjectStock::SetObjectStock " << std::endl;
294  //std::cout << " Hparam_stock.xlast not modified here " << Hparam_stock.xlast << std::endl;
295  std::cout << " Always identical to fcommon_axis->GetLast() " << fcommon_xaxis_th->GetLast() << std::endl;
296  // std::cout << "gPad->GetName() " << gPad->GetName() << std::endl;
297  // ok this is the TPadStock 1 created
298  // std::cout << "gPad " << gPad << std::endl;
299 #endif
300 */
301  std::vector<type_value_data> values;
302  double xmin,xmax;
303 
304  unsigned int xfirst, xlast;
305  int shift_left;
306  unsigned int size_data = ldata->GetSize();
307 
308  ComputeBinRange( ldata, fcommon_xaxis_th, Hparam_stock, xfirst, xlast, shift_left );
309  //std::cout << "After ComputeBinRange xfirst/xlast " << xfirst << " " << xlast << std::endl;
310 
311  for ( unsigned int bin = xlast; bin >= xfirst; bin -- ) {
312  //std::cout << "bin " << bin << " " << size_data - bin + shift_left << std::endl;
313  values=ldata->NoChronologicAt( size_data - bin + shift_left ).GetValues();
314 
315  // x are the same !!
316  //xmin = gPad->XtoPad( fcommon_xaxis_th->GetXAxis()->GetBinLowEdge(bin) );
317  //xmax = gPad->XtoPad( fcommon_xaxis_th->GetXAxis()->GetBinUpEdge(bin) );
318  xmin = fcommon_xaxis_th->GetXAxis()->GetBinLowEdge(bin);
319  xmax = fcommon_xaxis_th->GetXAxis()->GetBinUpEdge(bin);
320  //std::cout << "xmin " << xmin << " " << fcommon_xaxis_th->GetXAxis()->GetBinLowEdge(bin) << std::endl;
321 
322  // modfiy slightly for candle and Bar
323  // should be in Candle and Bar !
324  xmin += (xmax-xmin)*0.1;
325  xmax -= (xmax-xmin)*0.1;
326 
327  // set values for each bin
328  SetValues ( size_data - bin + shift_left, values, xmin, xmax,
329  ldata->NoChronologicAt( size_data-bin+shift_left).GetDate() );
330  }
331 }
332 
333 
334 #endif /* _LISTOBJECTSTOCK_H_ */
virtual int DistancetoPrimitive(int px, int py, AbstractObjectStock **obj)
neeed for selection broadcast to the contained objects
virtual ~ListObjectStock()
virtual int DistancetoPoint(int px, int py, double &yvalue, int bin=-1) const
needed for anchoring, broadcast to the contained objects
virtual void SetValues(UInt_t bin, std::vector< type_value_data > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)
called by SetObjectStock.
virtual void AddToVecObject(T *obj)
return values
Definition: ObjectStock.cxx:37
Define concrete classes for ObjectStock.
Hparam_stock_t Hparam_stock
Define a base class for drawing indicator only, they are sorted in ListDataStock object.
virtual Int_t DistancetoPrimitive(int, int, AbstractObjectStock **)=0
used for selection of object, for const need attention to the pointer
virtual void Resize(unsigned int new_size)
virtual void ClearObjectStock()
general function called when drawing
virtual std::vector< type_value_data > GetValues() const =0
Return the value(s) in a vector.
virtual void Paint(const Option_t *="")
Simply paint the objects, if needed .
std::vector< type_obj > vec_object
TAxis * GetXAxis()
Definition: CommonXAxis.h:54
virtual UInt_t GetSize() const
virtual void GetExtrema(double &min, double &max) const
overid base class
virtual void SetObjectStock(ListDataStockBase *ldata, CommonXAxis *fcommon_xaxis_th, Hparam_stock_t &Hparam_stock)
Set the values of the objects .
Define a vector for all identical Object ( Candle, Bar...)
virtual unsigned int GetSize() const =0
Return the size of the vector.
ListObjectStock(std::string name)
Abstract base class for the ListDataStock, for storing base pointers in vectors.
Definition: ListDataStock.h:50
time_t GetDate() const
Get the date data member.
Definition: DataStock.h:126
virtual const DataStock & NoChronologicAt(const unsigned int offset) const =0
Get nth element in a non chronological order.
Define an abstract base class for all objects to be painted in a THStock.