ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectStock.cxx
Go to the documentation of this file.
1 
9 #include "ObjectStock.h"
10 
11 #include <iostream>
12 #include <TPad.h>
13 #include <TLine.h>
14 #include <TBox.h>
15 #include <TPolyLine.h>
16 
17 #include "ListObjectStock.h"
18 #include "THStock.h"
19 #include "../CommonXAxis.h"
20 
21 //for ROOT dicionnary
26 
27 
29 
30 std::vector<float> CandleStock::GetValues() const
31 {
32 #ifdef DEBUG_OBJSTOCK
33  std::cout << "Entry CandleStock::GetValues()" << std::endl;
34 #endif
35  std::vector<float> values;
36  values.push_back( fopen ); values.push_back( fhigh ); values.push_back( flow ); values.push_back( fclose );
37  return values;
38 }
39 
40 std::vector<std::string> CandleStock::MakeStringForStatusBar( int /*px*/, int /*py*/) const
41 {
42 /* called when mouse moves
43 #ifdef DEBUG_OBJSTOCK
44  std::cout << "CandleStock::MakeStringForStatusBar " << std::endl;
45 #endif
46 */
47  std::vector < std::string > vec_str_text;
48  std::string text_str0, text_str1, indic_str;
49  std::vector<float> values;
50  time_t date;
51 
52  values = GetValues();
53  indic_str = GetNameObject();
54  text_str1 = indic_str + " open="+ Utils::toString<float>(values[0]) + " high="+ Utils::toString<float>(values[1])+
55  " low="+Utils::toString<float>(values[2])+" close="+ Utils::toString<float>(values[3]);
56  date = GetDate();
57  text_str0 = Utils::Time_tToString( date );
58 
59  vec_str_text.push_back( text_str0 );
60  vec_str_text.push_back( text_str1 );
61  return vec_str_text;
62 }
63 
64 
65 //bin and opt never used, only for polymorphisme
67 void CandleStock::SetValues( unsigned int /*bin*/, std::vector<double> values, double xmin, double xmax, time_t date, unsigned int /*opt_value*/ )
68 {
69 /*
70 #ifdef DEBUG_OBJSTOCK
71  std::cout << "Entry CandleStock::SetValues" << std::endl;
72  std::cout << "size values " << values.size() << std::endl;
73 #endif
74 */
75  fxmin = xmin;
76  fxmax = xmax;
77  fopen = values[0]; fhigh = values[1]; flow = values[2]; fclose = values[3];
78  //add update of date, may do better...
79  fdate = date;
80 }
81 
82 /*
83 void CandleStock::ClearObject()
84 {
85 #ifdef DEBUG_OBJSTOCK
86  std::cout << "CandleStock::ClearObject " << std::endl;
87 #endif
88 }
89 */
90 
91 void CandleStock::GetExtrema( double & min, double & max ) const
92 {
93 /*
94 #ifdef DEBUG_OBJSTOCK
95  std::cout << "entry CandleStock::GetExtrema " << std::endl;
96 #endif
97 */
98  std::vector<float> values;
99  values = GetValues();
100 
101  // extract high and low
102  max = values[1];
103  min = values[2];
104 }
105 
106 // to rewrite, look at THistPainter Stock
107 int CandleStock::DistancetoPrimitive(int px, int py, AbstractObjectStock** /*obj*/ ) //const
108 {
109 /*
110 #ifdef DEBUG_OBJSTOCK
111  std::cout << "Entry CandleStock::DistancetoPrimitive " << std::endl;
112 #endif
113 */
114  //std::cout << "CandleStock::DistancetoPrimitive " << std::endl;
115  Int_t pxl, pyl, pxt, pyt;
116 
117  Int_t px1 = gPad->XtoAbsPixel(fxmin);
118  Int_t py1 = gPad->YtoAbsPixel(fopen);
119  Int_t px2 = gPad->XtoAbsPixel(fxmax);
120  Int_t py2 = gPad->YtoAbsPixel(fclose);
121 
122  //std::cout << px1 << " " << py1 << " " << px2 << " " << py2 << std::endl;
123  //std::cout << px << " " << py << std::endl;
124 
125  //not necessary here flow shoud be < fhigh !!
126  if (px1 < px2) {pxl = px1; pxt = px2;}
127  else {pxl = px2; pxt = px1;}
128  if (py1 < py2) {pyl = py1; pyt = py2;}
129  else {pyl = py2; pyt = py1;}
130 
131  // Are we inside the box?
132  if ( (px >= pxl && px <= pxt) && (py >= pyl && py <= pyt) ) {
133  //std::cout << " return 0 " << std::endl;
134  return 0;
135  }
136  //test delete other test later;
137  else return 9999;
138 
139  // // }
140  // Inside enought ?? maybe not, extend for more, picked point...
141  // never executed after, need to find closer
142 
143  // test not necessary normally, to check
144 
145  /* make return 9999 in other case
146  Int_t dxl = TMath::Abs(px - pxl);
147  // ???
148  if (py < pyl) dxl += pyl - py; if (py > pyt) dxl += py - pyt;
149  Int_t dxt = TMath::Abs(px - pxt);
150  if (py < pyl) dxt += pyl - py; if (py > pyt) dxt += py - pyt;
151  Int_t dyl = TMath::Abs(py - pyl);
152  if (px < pxl) dyl += pxl - px; if (px > pxt) dyl += px - pxt;
153  Int_t dyt = TMath::Abs(py - pyt);
154  if (px < pxl) dyt += pxl - px; if (px > pxt) dyt += px - pxt;
155 
156  Int_t distance = dxl;
157  if (dxt < distance) distance = dxt;
158  if (dyl < distance) distance = dyl;
159  if (dyt < distance) distance = dyt;
160 
161  //return distance - Int_t(0.5*fLineWidth);
162  //std::cout << "distance " << distance << std::endl;
163  return distance; // - Int_t(1);
164  */
165 }
166 
167 
175 int CandleStock::DistancetoPoint( int /*px*/, int py, double & yvalue, int /*bin*/ ) const
176 {
177 #ifdef DEBUG_OBJSTOCK
178  std::cout << "Entry CandleStock::distancetoPoint " << std::endl;
179 #endif
180  int dist = 9999;
181  int distance;
182  double dtab_py[4] = { fopen, fclose, fhigh, flow };
183 
184  for ( unsigned int y = 0; y<4; y++ ) {
185  //distance = TMath::Abs( value_y - dtab_py[y] );
186  distance = TMath::Abs( py - gPad->YtoAbsPixel( dtab_py[y] ));
187  if ( distance < dist ) {
188  //std::cout << "min dist tab_py[y] " << tab_py[y] << " min distance " << distance << std::endl;
189  dist = distance;
190  //assign the correct value
191  yvalue = dtab_py[y];
192  }
193  }
194  std::cout << "Exit CandleStock::distancetoPoint dist py " << dist << " " << yvalue << std::endl;
195  return dist;
196 }
197 
198 
200 void CandleStock::Paint( const Option_t* )
201 {
202  //std::cout << "Entry Paint CandleStock " << std::endl;
203  TBox box;
204  TLine line;
205  //recompute on the fly
206  Double_t xmiddle = ( fxmin + fxmax ) / 2.;
207 
208  // test on kPaint done in ListDataStock
209  if ( fclose >= fopen ) {
210  box.SetFillColor(3); //green
211  line.SetLineColor(3);
212  }
213  else {
214  box.SetFillColor(2); //red
215  line.SetLineColor(2);
216  }
217  //std::cout << fxmin << " " << fopen << " " << fxmax << " " << fclose << std::endl;
218  //std::cout << xmiddle << " " << flow << " " << fhigh << " " << std::endl;
219  box.PaintBox ( fxmin, fopen, fxmax, fclose );
220  line.PaintLine ( xmiddle, flow, xmiddle, fhigh );
221 }
222 
224 
225 //all constructor to move into class def
227  //std::cout << "Constructor BarStock default" << std::endl;
228  fdate = 0; fvalue = 0;
229  fref0_value = false;
230  fxmax = fxmin = 0;
231 }
232 
233 //could extend with option, will be more general
235  //std::cout << "Constructor BarStock with ref0 " << ref0 << std::endl;
236  fdate = 0; fvalue = 0;
237  fxmin = fxmax = 0;
238  fref0_value = ref0;
239 }
240 
241 //ref0 default 0
242 /*
243 BarStock::BarStock ( const char * name, bool ref0 ) : AbstractObjectStock(){
244  //std::cout << "Constructor BarStock with name and ref0 " << ref0 <<std::endl;
245  //std::cout << "name " << name << " name_str " << name_str << std::endl;
246  fref0_value = ref0;
247 }
248 */
249 std::vector<float> BarStock::GetValues() const
250 {
251  //std::cout << "Entry CandleStock::GetValues()" << std::endl;
252  std::vector<float> values;
253  values.push_back( fvalue );
254  return values;
255 }
256 
257 std::vector<std::string> BarStock::MakeStringForStatusBar( int /*px*/, int /*py*/ ) const
258 {
259 #ifdef DEBUG_OBJSTOCK
260  std::cout << "BarStock::MakeStringForStatusBar " << std::endl;
261 #endif
262  std::vector < std::string > vec_str_text;
263  std::string text_str0, text_str1, indic_str;
264  std::vector<float> values;
265  time_t date;
266 
267  values = GetValues();
268  indic_str = GetNameObject();
269  text_str1 = indic_str + " ="+ Utils::toString<float>(values[0]);
270  date = GetDate();
271  text_str0 = Utils::Time_tToString( date );
272 
273  vec_str_text.push_back( text_str0 );
274  vec_str_text.push_back( text_str1 );
275  return vec_str_text;
276 }
277 
279 void BarStock::GetExtrema( double & min, double & max ) const
280 {
281 /*
282 #ifdef DEBUG_OBJSTOCK
283  std::cout << " Entry BarStock::GetExtrema " << std::endl;
284 #endif
285 */
286  std::vector<float> values;
287  values = GetValues();
288  //std::cout << "values[0] " << values[0] << " " << values[1] << std::endl;
289  max = values[0];
290  min = values[0];
291 }
292 
293 //default opt_value= 0
294 void BarStock::SetValues( unsigned int /*bin*/, std::vector<double> values,
295  double xmin, double xmax, time_t date, unsigned int opt_value )
296 {
297 /*
298 #ifdef DEBUG_OBJSTOCK
299  std::cout << "Entry BarStock::SetValues" << std::endl;
300  //std::cout << "size values " << values.size() << std::endl;
301  //std::cout << "values[opt_value ] " << opt_value << " " << values[opt_value] << std::endl;
302 #endif
303 */
304 
305  fvalue = (Double_t) values[opt_value];
306  fxmin = xmin;
307  fxmax = xmax;
308  fdate = date;
309 }
310 
311 int BarStock::DistancetoPrimitive(int px, int py, AbstractObjectStock** /*obj*/ ) //const
312 {
313 /*
314 #ifdef DEBUG_OBJSTOCK
315  std::cout << "BarStock::DistancetoPrimitive" << std::endl;
316  std::cout << "px " << px << " py " << py << std::endl;
317 #endif
318 */
319  Int_t pxl, pyl, pxt, pyt;
320  Int_t py1;
321 
322  Int_t px1 = gPad->XtoAbsPixel(fxmin);
323 
324  //strange work for both, in fact 0. in both case,
325  //because Yymin and ymax in THistPainterStock certainly ?? to understand
326  /*
327  if ( fref0_value ) {
328  py1 = gPad->YtoAbsPixel(0.);
329  std::cout << "use fref0 " << py1 << std::endl;
330  } else {
331  py1 = gPad->YtoAbsPixel(0.); //original
332  }*/
333 
334  py1 = gPad->YtoAbsPixel(0.);
335  //Int_t py1 = gPad->YtoAbsPixel( fvalue_min ); //keep 0 difficult to get small value with gPad, TFrame min.Hparam..??
336  //or force to 0. easier certainly and better
337  Int_t px2 = gPad->XtoAbsPixel( fxmax );
338  Int_t py2 = gPad->YtoAbsPixel( fvalue );
339  /*
340  std::cout << " fvalues " << fvalue << std::endl;
341  std::cout << "px1 " << px1 << " px2 " << px2 << std::endl;
342  std::cout << "py1 " << py1 << " py2 " << py2 << std::endl;
343  */
344 
345  //should not be necessary, consider all positive ?? problem ??
346  //necessary if fref0_value is true
347  if (px1 < px2) {pxl = px1; pxt = px2;}
348  else {pxl = px2; pxt = px1;}
349  if (py1 < py2) {pyl = py1; pyt = py2;}
350  else {pyl = py2; pyt = py1;}
351  //std::cout << "py " << py << " pyl " << pyl << " pyt " << pyt << std::endl;
352 
353  // Are we inside the box?
354  // // if (GetFillStyle()) {
355  if ( (px >= pxl && px <= pxt) && (py >= pyl && py <= pyt) ) {
356  //std::cout << "py " << py << " pyl " << pyl << " pyt " << pyt << std::endl;
357  std::cout << " BarStock::DtP return 0 " << std::endl;
358  return 0;
359  }
360  //std::cout << "BarStock return 9999 " << std::endl;
361  return 9999;
362 }
363 
364 int BarStock::DistancetoPoint(Int_t /*px*/, Int_t py, Double_t &yvalue, int /*bin*/) const
365 {
366 #ifdef DEBUG_OBJSTOCK
367  std::cout << "Entry Bar::DistancetoPoint " << std::endl;
368  std::cout << "py " << py << std::endl;
369 #endif
370 
371  yvalue = fvalue;
372  return TMath::Abs ( py - gPad->YtoAbsPixel(fvalue) );
373 }
374 
375 // all paint could be const
377 void BarStock::Paint( const Option_t* /*option*/ )
378 {
379  //std::cout << "BarStock::Paint option ref " << fref0_value << std::endl;//option << std::endl;
380  Double_t ymin;
381  //default fvalue, modified internally if needed, not the member fvalue !!
382  Double_t fvalue2 = fvalue;
383 
384  if ( fref0_value ) {
385  ymin = 0.;
386  //std::cout << "use fref0 " << ymin << std::endl;
387  } else {
388  //std::cout << "use original " << std::endl;
389  ymin = gPad->GetUymin(); //original use min of the pad
390  }
391 
392  //should checked ymin and fvalue if ref0
393  if ( ymin > fvalue ) {
394  Double_t tmp = ymin;
395  ymin = fvalue;
396  fvalue2 = tmp; // ==ymin and do not erase member fvalue
397  }
398  TBox box;
399  box.SetFillColor(2); //red
400  box.PaintBox ( fxmin, ymin, fxmax, fvalue2 );
401 }
402 
403 
405 
406 //no need indic name will be set by Factory or Collection
407 // do not need indic, just a name, deal name and properties by calling function (Factory or Collection)
408 // even size is not needed, should be resized before drawing
410 {
411 #ifdef DEBUG_OBJSTOCK
412  std::cout << "Entry Constructor PStockLine size " << size << std::endl;
413 #endif
414 
415  plvalues.reserve( size );
416  fx.reserve ( size );
417  //std::cout << "fx.size() " << fx.size() << std::endl;
418  for ( UInt_t i = 0; i < size; i++ ) {
419  fx.push_back (0.);
420  plvalues.push_back (0.);
421  }
422 }
423 
424 PStockLine::PStockLine( std::string name, unsigned int size ) : IndicatorObjectStock( name )
425 {
426 #ifdef DEBUG_OBJSTOCK
427  std::cout << "Entry Constructor PStockLine size " << size << std::endl;
428 #endif
429 
430  plvalues.reserve( size );
431  fx.reserve ( size );
432  //std::cout << "fx.size() " << fx.size() << std::endl;
433  for ( UInt_t i = 0; i < size; i++ ) {
434  fx.push_back (0.);
435  plvalues.push_back (0.);
436  }
437 }
438 
439 float PStockLine::ExtrapolateYPad ( int px, int bin0, int bin1, float y0, float y1 ) const
440 {
441  //std::cout << "Entry PStockLine::ExtrapolateYPad " << std::endl;
442  //need coeff and origin
443  float coeff, origin, extra_y;
444 
445  //get x value in Pad coordinate
446  float x0 = fParentTHStock->GetXPadFromBin ( bin0 );
447  float x1 = fParentTHStock->GetXPadFromBin ( bin1 );
448  //compute temporary coeff and origin
449  coeff = ( y1 - y0 ) / ( x1 - x0 );
450  origin = y0 - coeff * x0;
451  //std::cout << "coeff " << coeff << " origin " << origin << std::endl;
452  //extrapolate to px
453  extra_y = coeff * gPad->AbsPixeltoX( px ) + origin;
454  //std::cout << "extrapolateY Pstock " << extra_y << std::endl;
455  return extra_y;
456 }
457 
458 std::vector<float> PStockLine::GetValues( int px, int py, time_t & date ) const
459 {
460 #ifdef DEBUG_OBJSTOCK
461  std::cout << "Entry PStockLine::GetValues px/py, &date " << px << " " << py << std::endl;
462  //std::cout << " fParentTHStock " << fParentTHStock << std::endl;
463 #endif
464 
465  std::vector<float> values;
466  Int_t bin;
467  //option for extrapolating, considered if > 0, cannot use reference and default, test pointer * ??
468  Int_t bin2 = 1;
469 
470  // why 2 bins ??
471  //bin send as reference
472  bin = fParentTHStock->GetBinFromPixel(px, bin2);
473  std::cout << "date " << date << " bin " << bin << " bin2 " << bin2 << std::endl;
474 
475  // recompute shift
476  int shift_futur = fParentTHStock->GetCommonXAxis()->GetShift();
477  //std::cout << "shift_futur " << shift_futur << std::endl;
478  // correct calculation of shift_left by the shift_futur of the axis
479  int shift_left = fParentTHStock->GetCommonXAxis()->GetNbins() - shift_futur - plvalues.size();
480  //std::cout << "shift_left " << shift_left << std::endl;
481  //std::cout << "size - ( bin - shift_left )" << plvalues.size() - ( bin -shift_left ) << std::endl;
482  //std::cout << "shift axis " << fParentTHStock->GetCommonXAxis()->GetShift() << std::endl;
483 
484  //get value at bin, and closer bin
485  float value_pt0 = plvalues[ plvalues.size() - ( bin - shift_left ) ];
486  float value_pt1 = plvalues[ plvalues.size() - ( bin2 - shift_left ) ];
487  //std::cout << "date " << dates[ plvalues.size() - ( bin - shift_left ) ] << std::endl;
488  //now uses store vector<dates>
489  date = dates[ plvalues.size() - ( bin - shift_left ) ];
490 
491  //Extrapolate, need function ?? if reused later yes !!
492  float value_pt = ExtrapolateYPad ( px, bin, bin2, value_pt0, value_pt1 );
493  //std::cout << "return extrapolate " << value_pt << std::endl;
494 
495  values.push_back ( value_pt );
496  return values;
497 }
498 
499 
500 std::vector<std::string> PStockLine::MakeStringForStatusBar( int px, int py ) const
501 {
502 
503 #ifdef DEBUG_OBJSTOCK
504  std::cout << " PStockLine::MakeStringForStatusBar " << std::endl;
505  std::cout << " px, py" << px << " " << py << std::endl;
506  std::cout << "Name " << GetNameObject() << std::endl;
507 #endif
508 
509  std::string text_str0, text_str1;
510  std::vector<std::string> vec_string;
511  time_t date;
512  std::vector<float> values;
513 
514  values = GetValues( px, py, date );
515  //assign the date
516  text_str0 = Utils::Time_tToString( date, true );
517  //assign the unique value
518  text_str1 = GetNameObject() + " = " + Utils::toString<float>( values[0] );
519 
520  vec_string.push_back( text_str0 );
521  vec_string.push_back( text_str1 );
522  //std::cout << " return from PStockLine::MakeStringForStatusBar text " << text_str0 << " " << text_str1 << std::endl;
523  return vec_string;
524 }
525 
526 void PStockLine::GetExtrema( double & min, double & max ) const
527 {
528 #ifdef DEBUG_OBJSTOCK
529  std::cout << "\n\tPStockLine::GetExtrema size plvalues " << plvalues.size() << std::endl;
530 #endif
531  std::vector<Double_t>::const_iterator it, it2;
532  it2 = plvalues.end();
533  Double_t value, value_min, value_max;
534  value_min = 10.0e6;
535  value_max = 0.;
536 
537  for ( it = plvalues.begin(); it != it2; ++it ) {
538  value = (*it);
539 
540  if ( value < value_min ) value_min = value;
541  if ( value > value_max ) value_max = value;
542  }
543 
544  min = value_min;
545  max = value_max;
546 
547 }
548 
549 // with time follow standard and polymorphisme
555 void PStockLine::SetValues ( UInt_t, std::vector<double> values,
556  Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value )
557 {
558 #ifdef DEBUG_OBJSTOCK
559  std::cout << "Entry PStockLine::SetValues opt_value " << opt_value << " values[opt] " << values[opt_value] << std::endl;
560 #endif
561 
562  plvalues.push_back( values[ opt_value ]);
563  // now compute the middle point from min and max here
564  fx.push_back ( ( xmin + xmax ) / 2.0f );
565  //std::cout << "( xmin + xmax ) / 2.0f " << ( xmin + xmax ) / 2.0f << std::endl;
566  //add date
567  dates.push_back ( date );
568 }
569 
570 void PStockLine::Resize( unsigned int new_size )
571 {
572 #ifdef DEBUG_OBJSTOCK
573  std::cout << "PStockLine::Resize add_data new size " << new_size << std::endl;
574  std::cout << "old size " << plvalues.size() << std::endl;
575 #endif
576  plvalues.resize ( new_size );
577  fx.resize ( new_size );
578 }
579 
580 // used ?? yes, necessary ?? not for Candle
581 // sould clarify the role, kPaint = false for Object it is an Object, not an object Stock...
582 // PStock Line, kind of mix....may simulate a kpaint ??
583 // not independent point, kPaint apply to all / nothing here
584 // object need to be deleted / reset completely, easier
585 // or improve with intermediate in memory / draw on graph ( sort of copy )
587 {
588 #ifdef DEBUG_OBJSTOCK
589  std::cout << "PStockLine::ClearObjectStock()" << std::endl;
590 #endif
591  plvalues.clear();
592  fx.clear();
593  // Should set kPaint to false ?? certainly yes
594  // Not the fame function here, cannot specify if not want to draw or size is 0
595  // SetToPaint( false );
596 #ifdef DEBUG_OBJSTOCK
597  std::cout << "after clear plvalues.size() " << plvalues.size() << std::endl;
598  std::cout << "fx.size() " << fx.size() << std::endl;
599  //std::cout << "Set to Paint set to false " << std::endl;
600 #endif
601 }
602 
603 // keep this version, used if Collection or normal
604 int PStockLine::DistancetoPrimitive(int px, int py, AbstractObjectStock** obj ) //const
605 {
606 #ifdef DEBUG_OBJSTOCK
607  std::cout << "Entry PStockLine::DistancetoPrimitive" << std::endl;
608 #endif
609 
610  //set object by default, problem if want const function
611  *obj = this;
612 
613  int pxp, pyp, d;
614  unsigned int i;
615  d = 9999;
616  int distance = 9999;
617 
618  // really needed ??
619  for (i = 0; i < fx.size(); i++) {
620  pxp = gPad->XtoAbsPixel(gPad->XtoPad(fx[i]));
621  pyp = gPad->YtoAbsPixel(gPad->YtoPad(plvalues[i]));
622  d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
623  if (d < distance) distance = d;
624  }
625 
626  // check if point is near one of the connecting lines, ok works
627  for (i=0;i< fx.size()-1;i++) {
628  // d = DistancetoLine(px, py, gPad->XtoPad(fx[i]), gPad->YtoPad(plvalues[i]),
629  // gPad->XtoPad(fx[i+1]), gPad->YtoPad(plvalues[i+1]));
630  d = DistancetoLine(px, py, fx[i], gPad->YtoPad(plvalues[i]),
631  fx[i+1], gPad->YtoPad(plvalues[i+1]));
632  if (d < distance) distance = d;
633  }
634  //std::cout << "PStockLine::DistancetoPrimitive return " << distance << std::endl;
635  return distance;
636 }
637 
638 // Similar to ListObjectStock
639 int PStockLine::DistancetoPoint( int /*px*/, int py, double & yvalue, int bin ) const
640 {
641 #ifdef DEBUG_OBJSTOCK
642  std::cout << "Entry PStockLine::distancetoPoint " << std::endl;
643  std::cout << "Get input bin " << bin << "value at bin " << plvalues[bin] << std::endl;
644 #endif
645  yvalue = plvalues[bin];
646  return TMath::Abs( gPad->YtoAbsPixel( plvalues[bin] ) - py );
647 }
648 
658 void PStockLine::Paint( const Option_t* )
659 {
660 #ifdef DEBUG_OBJSTOCK
661  std::cout << "Entry PStockLine::Paint() " << std::endl;
662  std::cout << "fx.size() " << fx.size() << std::endl;
663  std::cout << "GetLineColor " << GetLineColor() << std::endl;
664  std::cout << "kPaint" << ToPaint() << std::endl;
665 #endif
666 
667  TPolyLine TPLine (fx.size());
668  TPLine.SetLineColor ( GetLineColor() );
669 
670  for ( UInt_t i=0; i< fx.size(); i++ ) {
671  TPLine.SetPoint( i, fx[i], plvalues[i] );
672  }
673  // test if size=< 1 no line to draw
674  if ( TPLine.GetN() >= 2 ) {
675  TPLine.Paint();
676  }
677 #ifdef DEBUG_OBJSTOCK
678  else {
679  std::cout << "TPLine too short do not Paint it" << std::endl;
680  }
681 #endif
682 }
683 
684 // use for SMA...
685 // exactly the same than ListObjectStock, only the SetValues is specific
686 // small difference in use of xmin/xmax
688 {
689 #ifdef DEBUG_OBJSTOCK
690  std::cout << " PStockLine::SetObjectStock " << std::endl;
691  //std::cout << "gPad->GetName() " << gPad->GetName() << std::endl;
692  // ok this is the TPadStock 1 created
693  // std::cout << "gPad " << gPad << std::endl;
694  //std::cout << " Hparam_stock.xlast not modified here " << Hparam_stock.xlast << std::endl;
695 #endif
696 
697  std::vector<type_value_data> values;
698  std::vector<double> values_intern;
699  Double_t xmin,xmax;
700 
701  unsigned int xfirst, xlast;
702  int shift_left;
703  unsigned int size_data = ldata->GetSize();
704 
705  ComputeBinRange( ldata, fcommon_xaxis_th, Hparam_stock, xfirst, xlast, shift_left );
706  //std::cout << "After ComputeBinRange xfirst/xlast " << xfirst << " " << xlast << std::endl;
707 
708  // MUST allocate space before std::copy, seems correct.
709  // Again a function GetNbValues would be useful
710  values_intern.resize( ldata->NoChronologicAt(0).GetValues().size() );
711  //std::cout << "Size of values_intern " << values_intern.size() << std::endl;
712 
713  for ( unsigned int bin = xlast ;bin >= xfirst; bin --) {
714  //std::cout << "size_data - bin + shift_left " << size_data - bin + shift_left << std::endl;
715  // call GetValues of DataStock
716  values = ldata->NoChronologicAt( size_data - bin + shift_left ).GetValues();
717  // no need of gPad for x values, identical
718  xmin = fcommon_xaxis_th->GetXAxis()->GetBinLowEdge(bin);
719  xmax = fcommon_xaxis_th->GetXAxis()->GetBinUpEdge(bin);
720 
721  // not present with EMA, change something ? get extrema separate, ok like this
722  //xmin += (xmax-xmin)*0.1;
723  //xmax -= (xmax-xmin)*0.1;
724 
725  std::copy ( values.begin(), values.end(), values_intern.begin() );
726 
727  // set values for each bin, here transform to its own type, could be float
728  //SetValues ( size_data - bin + shift_left, values_intern, xmin, xmax,
729  SetValues ( size_data - bin + shift_left, values, xmin, xmax,
730  ldata->NoChronologicAt( size_data-bin+shift_left).GetDate() );
731  }
732  // std::cout << "After ObjectPaint PstockLine " << std::endl;
733  }
734 
736 CollectionObjectStock::CollectionObjectStock( unsigned int size, std::string name_contained, bool ref0 )
737  : IndicatorObjectStock( name_contained )
738 {
739 #ifdef DEBUG_OBJSTOCK
740  std::cout << "Entry Constructor CollectionObjectStock size " << size << std::endl;
741  std::cout << "name_contained " << name_contained << std::endl;
742  //std::cout << "Indicator label " << indic.label() << std::endl;
743  std::cout << "ref0 " << ref0 << std::endl;
744 #endif
745 }
746 
748 {
749 #ifdef DEBUG_OBJSTOCK
750  std::cout << "Destructor CollectionObjectStock" << std::endl;
751 #endif
752 
753  for ( unsigned int i = 0; i < vec_object.size(); i ++ ) {
754  delete vec_object[i];
755  vec_object[i] = 0;
756  }
757  vec_object.clear();
758  // take out from the list, but do not destry object, to check
759  //ArrayObject.Delete();
760  //std::cout << "size ArrayObject " << ArrayObject.GetEntriesFast() << std::endl;
761 }
762 
764 {
765 #ifdef DEBUG_OBJSTOCK
766  std::cout << "Entry CollectionObjectStock::SetParent " << std::endl;
767 #endif
768  for ( unsigned i=0; i < vec_object.size(); ++i )
769  vec_object[i]->SetParent( thstock );
770 }
771 
772 /*
773 std::vector<std::string> CollectionObjectStock::MakeStringForStatusBar( int px, int py ) const
774 {
775 #ifdef DEBUG_OBJSTOCK
776  std::cout << "CollectionObject::MakeStringForStatusBar " << std::endl;
777 #endif
778 
779 }
780 */
781 
782 
783 // need a function for the factory to add a new object
784 //void CollectionObjectStock::AddObject( AbstractObjectStock * obj )
786 {
787 #ifdef DEBUG_OBJSTOCK
788  std::cout << " Entry CollectionObjectStock::AddToVecObject " << std::endl;
789 #endif
790  vec_object.push_back( obj );
791 
792 }
793 
794 void CollectionObjectStock::Resize( unsigned int new_size)
795 {
796 #ifdef DEBUG_OBJSTOCK
797  std::cout << " Entry CollectionObjectStock::Resize " << std::endl;
798 #endif
799  for ( unsigned int i = 0; i < vec_object.size(); i++ )
800  vec_object[i]->Resize( new_size );
801 }
802 
803 void CollectionObjectStock::GetExtrema( double & min, double & max ) const
804 {
805 #ifdef DEBUG_OBJSTOCK
806  std::cout << " Entry CollectionObjectStock::GetExtrema " << std::endl;
807 #endif
808  // local and true min, max
809  double lmin, lmax;
810  double tmin, tmax;
811 
812  tmin = 10e6;
813  tmax = 0;
814 
815  for ( unsigned int i = 0; i < vec_object.size(); i++ ) {
816  vec_object[i]->GetExtrema( lmin, lmax );
817  if ( lmin < tmin ) tmin = lmin;
818  if ( lmax > tmax ) tmax = lmax;
819  }
820  min = tmin;
821  max = tmax;
822 }
823 
824 void CollectionObjectStock::SetValues( unsigned int bin, std::vector<double> values,
825  double xmin, double xmax, time_t date, unsigned int /*opt_value*/ )
826 {
827 #ifdef DEBUG_OBJSTOCK
828  std::cout << "CollectionObjectStock::SetValues " << std::endl;
829  std::cout << "vec_object.size() " << vec_object.size() << std::endl;
830  std::cout << "values[0] " << values[0] << std::endl;
831 #endif
832 
833  std::vector<double> single_value(1);
834 
835  for ( unsigned int i= 0; i < vec_object.size(); i++ ) {
836  // extract values, one by one
837  single_value[0] = values[i];
838  std::cout << "single_value " << single_value[0] << std::endl;
839  // assign to the corresponding object
840  vec_object[i]->SetValues( bin, single_value, xmin, xmax, date );
841  }
842 }
843 
846 {
847 #ifdef DEBUG_OBJSTOCK
848  std::cout << " Entry CollectionObjectStock::ClearObjectStock vec_object.size() " << vec_object.size() << std::endl;
849 #endif
850  for ( unsigned int i = 0; i < vec_object.size(); i++ ) {
851  // call the base class, never contains candle or bar directly for the moment, only ListObjectStock and PstcokLine
852  vec_object[i]->ClearObjectStock();
853  }
854 }
855 // can be in IndicatorObjectStock !
857 {
858 #ifdef DEBUG_OBJSTOCK
859  std::cout << " Entry CollectionObjectStock::DistancetoPrimitive " << std::endl;
860 #endif
861  //std::cout << "CollectionObjectStock::DistancetoPrimitive() " << std::endl;
862  Int_t dist = 9999;
863  Int_t dist_objstock = 9999;
864 
865  //All collection needa tmp_object ??
866  AbstractObjectStock *tmp_object;
867 
868  for ( unsigned int i = 0; i < vec_object.size(); i++ ) {
869  tmp_object = 0;
870 
871  dist_objstock = vec_object[i]->DistancetoPrimitive( px, py, &tmp_object );
872  // here call TObject function ?? nothing happens !
873  //dist_objstock = vec_object[i]->DistancetoPrimitive( px, py );
874  if ( dist_objstock <= dist ) {
875  dist = dist_objstock;
876  *obj = tmp_object;
877  // make same as ListObjectStock, DistancetoPrimitive only px, py or TObject *
878  // sufficient, if List cannot get the candle, will get only The list !!
879  // certainly need previous version with tmp_object
880  //*obj = (vec_object[i]);
881  //std::cout << "set to collection obj_tmp " << *obj << " " << (*obj)->ClassName() << std::endl;
882  }
883  }
884 #ifdef DEBUG_OBJSTOCK
885  std::cout << " aggregate return dist " << dist << std::endl;
886  std::cout << " aggregate obj " << *obj << std::endl;
887 #endif
888  //std::cout << " retrun aggregate obj " << *obj << " " << (*obj)->ClassName() << std::endl;
889  return dist;
890 }
891 
892 void CollectionObjectStock::Paint( const Option_t* option )
893 {
894 #ifdef DEBUG_OBJSTOCK
895  std::cout << "Entry CollectionObjectStock::Paint size " << vec_object.size() << std::endl;
896 #endif
897  for ( unsigned int i = 0; i < vec_object.size(); i++ ) {
898  // why this test ?
899  //if ( dynamic_cast<AbstractObjectStock *>(ArrayObject[i])->ToPaint() )
900  //std::cout << "Paint i= " << i << std::endl;
901  //ArrayObject[i]->Paint( option );
902  if ( vec_object[i]->ToPaint() )
903  vec_object[i]->Paint( option );
904  }
905 }
906 
909 // work for MACD, one indicator, but miss loop over all the ldata ( BOLL forinstance )
910 //void CollectionObjectStock::SetObjectStock( ListDataStockBase * ldata, CommonXAxis *fcommon_xaxis_th ) //, Hparam_stock_t & Hparam_stock )
912 {
913 #ifdef DEBUG_OBJSTOCK
914  std::cout << "Entry CollectionObjectStock::SetObjectStock vec_object.size() " << vec_object.size() << std::endl;
915  //std::cout << "Is really called !!" << std::endl;
916 #endif
917 
918  // here problem if Object return float
919  std::vector<type_value_data> values;
920  // internally double is used
921  std::vector<double> values_intern;
922  double xmin,xmax;
923 
924  // part common to many object, should use an abstract base function SetParamStock
925  // should check redondance with THistPainterStock
926 /*
927 #ifdef DEBUG_OBJSTOCK
928  std::cout << "list size_data " << size_data << std::endl;
929  std::cout << "list size_candle " << size_candle << std::endl;
930  std::cout << "new internal shift_left " << shift_left << std::endl;
931  std::cout << "Hparam.shift_future /fcommon_xaxis " << Hparam_stock.shift_futur << " " << fcommon_xaxis_th->GetShift() << std::endl;
932 #endif
933 */
934  unsigned int xfirst, xlast;
935  int shift_left;
936  unsigned int size_data = ldata->GetSize();
937 
938  // MUST allocate space before std::copy, seems correct.
939  // Again a function GetNbValues would be useful
940  values_intern.resize( ldata->NoChronologicAt(0).GetValues().size() );
941  //std::cout << "Size of values_intern " << values_intern.size() << std::endl;
942 
943  ComputeBinRange( ldata, fcommon_xaxis_th, Hparam_stock, xfirst, xlast, shift_left );
944  //std::cout << "After ComputeBinRange xfirst/xlast " << xfirst << " " << xlast << std::endl;
945 
946  for ( unsigned int bin = xlast ;bin >= xfirst; bin-- ) {
947  //std::cout << "bin " << bin << std::endl;
948  values=ldata->NoChronologicAt( size_data - bin + shift_left ).GetValues();
949  //std::cout << "Get values " << values[0] << " " << values[1] << " " << values[2] << std::endl;
950  //std::cout << "GetSize values " << values.size() << std::endl;
951 
952  // no need of gPad to get x, identical
953  xmin = fcommon_xaxis_th->GetXAxis()->GetBinLowEdge(bin);
954  xmax = fcommon_xaxis_th->GetXAxis()->GetBinUpEdge(bin);
955 
956  // should be done in Candle or Bar if needed
957  xmin += (xmax-xmin)*0.1;
958  xmax -= (xmax-xmin)*0.1;
959 
960  // copy from DataStock type to internal type (always double)
961  std::copy ( values.begin(), values.end(), values_intern.begin() );
962 
963  SetValues( size_data - bin + shift_left, values_intern, xmin, xmax,
964  ldata->NoChronologicAt( size_data-bin+shift_left).GetDate() );
965 
966  // put support to THStock, seems easier
967  /* to be before ?? if add resistance
968  for ( unsigned int i= 0; i < vec_object.size(); i++ ) {
969  std::vector<float> single_value(1);
970  single_value[0] = values[i];
971  std::cout << "single_value " << single_value[0] << std::endl;
972  vec_object[i]->SetValues( size_data - bin + shift_left,
973  single_value, xmin, xmax,
974  ldata->NoChronologicAt( size_data-bin+shift_left).GetDate() );
975  }
976  */
977  }
978 }
double GetXPadFromBin(int bin)
Xvalue of the bin center, called by PStockLine to Extrapolate values.
Definition: THStock.h:136
int DistancetoPoint(int, int py, double &yvalue, int) const
called by THStock for anchoring.
virtual int DistancetoPoint(int, int, double &yvalue, int bin=-1) const
called by THStock for anchoring.
virtual time_t GetDate() const
Definition: ObjectStock.h:124
virtual void GetExtrema(double &min, double &max) const
Definition: ObjectStock.cxx:91
double fvalue
Definition: ObjectStock.h:106
virtual void ClearObjectStock()
Call ClearObject on every objects contained in the collection.
virtual void GetExtrema(double &min, double &max) const
override abstract base function
double fxmax
Definition: ObjectStock.h:41
virtual ~CollectionObjectStock()
virtual void ClearObjectStock()
different from Candle/Bar, delete the PstockLine.
virtual void Paint(const Option_t *="")
Paint the object.
time_t fdate
Definition: ObjectStock.h:99
Derive from TH1 will draw the graph.
Definition: THStock.h:59
virtual void Paint(const Option_t *="")
Paint the objet, to overide.
std::vector< float > GetValues(int px, int py, time_t &date) const
protected version, used by MakeStringForStatusBar difficult to extrapolate..., need optional bin2 ...
virtual void AddToVecObject(AbstractObjectStock *obj)
for all indicators, size and if update need to resize
virtual void SetObjectStock(ListDataStockBase *ldata, CommonXAxis *fcommon_xaxis_th, Hparam_stock_t &Hparam_stock)
called by , here need to send the correct ldata, but cannot split ldata so need to set up manually ...
ClassImp(CanvasStock) CanvasStock
Definition: CanvasStock.cxx:15
float fopen
Definition: ObjectStock.h:40
float fclose
Definition: ObjectStock.h:40
time_t fdate
Definition: ObjectStock.h:38
virtual bool ToPaint() const
virtual std::string GetNameObject() const
pure-virtual access
Definition: ObjectStock.h:118
CommonXAxis * GetCommonXAxis()
Definition: THStock.h:101
virtual void GetExtrema(double &min, double &max) const
overide base class
return values
Definition: ObjectStock.cxx:37
std::vector< time_t > dates
easy if date is here, still extrapolate data
Definition: ObjectStock.h:147
float fhigh
Definition: ObjectStock.h:40
std::vector< AbstractObjectStock * > vec_object
slight difference with ListObjectStock, here pointer to object, not object
Definition: ObjectStock.h:202
Define concrete classes for ObjectStock.
Hparam_stock_t Hparam_stock
virtual std::string GetNameObject() const
virtual std::string GetNameObject() const
pure-virtual access
Definition: ObjectStock.h:57
Define a base class for drawing indicator only, they are sorted in ListDataStock object.
Int_t GetBinFromPixel(Int_t px, Int_t &total_bin) const
called by ObjectStock, for StatusBar
Definition: THStock.cxx:509
void ComputeBinRange(ListDataStockBase *ldata, CommonXAxis *fcommon_xaxis_th, Hparam_stock_t &Hparam_stock, unsigned int &xfirst, unsigned int &xlast, int &shift_left)
set up bin first/ last.
virtual void GetExtrema(double &min, double &max) const
override the Abstract base class
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py, AbstractObjectStock **obj)
Define the template ListObjectStock<T> in a separate header.
virtual void SetObjectStock(ListDataStockBase *ldata, CommonXAxis *fcommon_xaxis_th, Hparam_stock_t &Hparam_stock)
used for from the listdata
virtual void Paint(const Option_t *="")
realize the painting, not setting the values
bool fref0_value
Definition: ObjectStock.h:104
virtual std::vector< type_value_data > GetValues() const =0
Return the value(s) in a vector.
double fxmax
Definition: ObjectStock.h:107
double fxmin
Definition: ObjectStock.h:41
virtual Int_t DistancetoPoint(int px, int py, double &yvalue, int bin=-1) const
specific, called only by ListDataStock do not use bin, but follow the hierarchy pixel better return a...
std::string Time_tToString(const time_t &time, const bool b_hour)
Return a string representing the date All times are expressed in the localtime.
Definition: Utils.cpp:157
virtual time_t GetDate() const
Definition: ObjectStock.h:60
virtual std::vector< std::string > MakeStringForStatusBar(int px, int py) const
create the string for the StatusBar
Definition: ObjectStock.cxx:40
float ExtrapolateYPad(int px, int bin0, int bin1, float x0, float x1) const
class for drawing graph
std::vector< float > GetValues() const
return the 4 values of a candle use fby MakeStringForStatus and GetExtrema
TAxis * GetXAxis()
Definition: CommonXAxis.h:54
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py, AbstractObjectStock **)
always called from ListObjectStock, aadd **pointer to overide abstract base, but not used ...
virtual int DistancetoPrimitive(int px, int py, AbstractObjectStock **obj)
used for selection of object, for const need attention to the pointer
virtual void SetValues(UInt_t, std::vector< double > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)
implementeation of pure virtual in Abstract, need double here
Definition: ObjectStock.cxx:67
virtual int DistancetoPrimitive(int px, int py, AbstractObjectStock **)
used for selection of object, for const need attention to the pointer
virtual std::vector< std::string > MakeStringForStatusBar(int px, int py) const
create the string for the StatusBar
float flow
Definition: ObjectStock.h:40
virtual void SetParent(THStock *thstock)
different from AbstractObjectStock, broadcast to all, needed ? could set to himself as well ...
virtual unsigned int GetSize() const =0
Return the size of the vector.
virtual std::vector< std::string > MakeStringForStatusBar(int px, int py) const
create the string for the StatusBar
Abstract base class for the ListDataStock, for storing base pointers in vectors.
Definition: ListDataStock.h:50
std::vector< double > fx
x coordinates, middle of the bin for painting
Definition: ObjectStock.h:145
double fxmin
Definition: ObjectStock.h:107
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.
Int_t GetNbins()
Definition: CommonXAxis.h:77
virtual void Paint(const Option_t *="")
Paint one candle.
Int_t GetShift() const
Definition: CommonXAxis.h:71
virtual void SetValues(UInt_t bin, std::vector< double > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)
Set the values .
Define an abstract base class for all objects to be painted in a THStock.
std::vector< double > plvalues
Definition: ObjectStock.h:143
virtual void Resize(unsigned int new_size)
std::vector< float > GetValues() const
return 1 one value in a vector used by MakeStringForStatus and GetExtrema
virtual void SetValues(UInt_t bin, std::vector< double > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)
virtual void Resize(unsigned int new_size)
Draw Jap.
Definition: ObjectStock.h:34
virtual void SetValues(UInt_t bin, std::vector< double > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)