ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
THStock.cxx
Go to the documentation of this file.
1 
8 #include "THStock.h"
9 /*
10 //#include "AbstractObjectStock.h"
11 #include "ObjectLine.h"
12 #include "ObjectStock.h"
13 */
14 
15 #include <utility>
16 // gPad used a lot in *cpp, like in TH1
17 //#include <TPad.h>
18 #include <TMath.h>
19 #include <TColor.h>
20 
21 //for ROOT dictionnary
23 
24 //Constructors and destructors
25 THStock::THStock() : TH1()
26 {
27  // set default size for array and init: fNcells = n;
28  // but no used by THstock, need list of StockData
29  SetBinsLength(3);
30  // needed ? not maybe later
31  //if (fgDefaultSumw2) Sumw2();
32 
33  fcommon_xaxis_th = 0 ;
34  //default value of FontSize, to check if used ??
35  fsize_title = 0;
36  //shoudl be done by constructor TH1 by default, to check
37  fMaximum = -1111;
38  fMinimum = -1111;
39 }
40 
41 THStock::THStock(const char* name, const char* title, int size_axis ) :
42 TH1(name,title, size_axis ,(Float_t *)0), fcommon_xaxis_th(0)
43 {
44 #ifdef DEBUG_OBJSTOCK
45  std::cout << "Constructor THStock name and title and size only " << size_axis << std::endl;
46 #endif
47  //set default size for array and init: fNcells = n; But no used by THstock, need list of StockData
48  SetBinsLength(3);
49  fsize_title = 0;
50  //shoudl be done by constructor TH1 by default, to check
51  fMaximum = -1111;
52  fMinimum = -1111;
53 }
54 
55 
56 //trick with TH1 constructor, do not provide *float, will create by default 0,1
57 // and will setup fNcells of TH1 according to nbins
58 THStock::THStock(const char* name, const char* title, ListDataStockBase * ldata) :
59 TH1(name,title,ldata->GetSize(),(Float_t *)0)
60 {
61 #ifdef DEBUG_OBJSTOCK
62  std::cout << "\n\tEntry constructor THStock with ldata argument " << std::endl;
63  std::cout << "name " << name << " title " << title << std::endl;
64 #endif
65  fDimension = 1;
66  //default zero, but could set the normal xaxis ?? not sure about common, so keep it like this
67  // will be set up after
68  fcommon_xaxis_th = 0;
69  std::cout << "In constructor get size xaxis " << GetXaxis()->GetNbins() << std::endl;
70  //will create with factory and store the corresponding ObjectStock
71  AddPairToVector ( ldata );
72 }
73 
74 // Copy constructor, why complaining, clone ?? used ??
75 THStock::THStock( const THStock& ht ) : TH1(), fcommon_xaxis_th(0),fsize_title(0)
76 {
77  ((THStock&)ht).Copy(*this);
78  // copy the list of Object ?? check with TH1, do not copy function,
79  // seems to need TObject::Clone, not clear ..certainly clone needed with polymorphic
80 }
81 
83 {
84 #ifdef DEBUG_OBJSTOCK
85  std::cout << "Destructeur THStock " << std::endl;
86 #endif
87  // Allocated by CanvasStock, just nullify
88  fcommon_xaxis_th = 0; // ?? here not goood certainly why not, allocated by CanvasStock
89 
90  // here 2 orders, need to delete objects of the pair, do not delete ListDataStock, done by StockManager
91  for ( it_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++ ) {
92  // first will be deleted by StockManager
93  delete (*it).second;
94  }
95  vect_pair_obj.clear();
96 }
97 
98 //used ?? yes where ??
99 void THStock::Copy(TObject &newht) const
100 {
101  std::cout << "\nEntry THStock::Copy\n" << std::endl;
102  TH1::Copy(newht);
103  //need copy of the pointeur to list data stock ?? certainly...
104 }
105 
106 //used ?? not yet ! certainly no need here ??
107 THStock* THStock::DrawCopy(Option_t *option) const
108 {
109  std::cout << "\n\t THStock::DrawCopy " << std::endl;
110  TString opt = option;
111 
112  opt.ToLower();
113  if (gPad && !opt.Contains("same")) gPad->Clear();
114 
115  THStock *newth = (THStock*)Clone();
116  newth->SetDirectory(0);
117  newth->SetBit(kCanDelete);
118  newth->AppendPad(option);
119  return newth;
120 }
121 
122 
124 {
125 #ifdef DEBUG_OBJSTOCK
126  std::cout << "\n\tTHStock SetCommonXAxis " << new_xaxis << std::endl;
127 #endif
128  fcommon_xaxis_th = new_xaxis;
129  return;
130 }
131 
133 {
134 #ifdef DEBUG_OBJSTOCK
135  std::cout << "Entry THStock::operator= " << std::endl;
136 #endif
137  if (this != &ht) ((THStock&)ht).Copy(*this);
138  return *this;
139 }
140 
145 ListDataStockBase * THStock::GetListDataStock ( std::string shortname ) const
146 {
147 #ifdef DEBUG_OBJSTOCK
148  std::cout << "Entry THStock::GetListDataStock fullname " << std::endl;
149 #endif
150  for ( cit_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++) {
151  std::cout << " name first " << (*it).first->GetName() << std::endl;
152  if ( (*it).first->GetName() == shortname ) {
153  std::cout << "Found shortname" << std::endl;
154  return (*it).first;
155  }
156  }
157  return nullptr;
158 }
159 
160 // enforce const, because called by many const member function in THStock
162 {
163  // need const iterator for the function to be const ?
164  cit_pair it1 = vect_pair_obj.begin();
165  cit_pair it2 = vect_pair_obj.end();
166 
167  for ( cit_pair it = it1; it != it2; ++it ) {
168  // need to clarify the names !
169  //std::cout << " name of Object at it " << (*it).second->GetNameObject() << std::endl;
170  if ( (*it).first != nullptr ) {
171  //std::cout << " FOUND name from listdata it " << (*it).first->GetName() << std::endl;
172  return (*it).first;
173  }
174  }
175  return nullptr;
176 }
177 
178 // with a few test on ldata could combine with Add ( ObjectLine* )
179 // story about CommonAxis may change this state, painting different as well
182 {
183 #ifdef DEBUG_OBJSTOCK
184  std::cout << "\n\tTHStock::AddPairToVector" << std::endl;
185  std::cout << " ldata name " << ldata->GetName() << std::endl;
186 #endif
187 
188  std::pair< ListDataStockBase*, IndicatorObjectStock* > tmp_pair;
189  IndicatorObjectStock * object;
190 
191  Indicator indic = Indicator::GetIndicator ( ldata->GetName() );
192  //UInt_t size = ldata->GetSize();
193  unsigned int size = 0;
194  size = ldata->GetSize();
195  std::cout << "size " << size << std::endl;
196 
197  // call factory method, delete all reference to listdatastock
198  // set parent when creating object ( need for STOCHF support ), not anymore !
199  // need the fullname as well for collection, and the indicator
200  // need this for Collection only ?? strange
201  object = FactoryObjectStock::CreateObjectStock ( indic, ldata->GetName(), size, this );
202 
203  if ( object == 0 ) {
204  std::cout << "object is null " << std::endl;
205  return;
206  }
207  //else {
208  // std::cout << "THStock::AddPairToVector object created " << std::endl;
209  //}
210 
211  // set as parent, extend to all now, if needed could extend to Candle or Bar but not needed interact through ListObject
212  // now extended to all, could get all dates from it !! no need to copy in ObjectStock !
213  // need to parent in constructiong object ( support in STOCHF ), to delete
214  object-> SetParent( this ); //keep for the other
215  //std::cout << "Setted up the parent AddPairToVector " << object->GetParent() << std::endl;
216 
217  tmp_pair = std::make_pair ( ldata, object );
218  // push Indicator AFTER the supports, problem in THisPainterStock !
219  // here insert first, or THisPainterStock loop until ldata is not null
220  // now inserted last : ex RSI, support first and then PStockLine
221  vect_pair_obj.push_back( tmp_pair );
222 #ifdef DEBUG_OBJSTOCK
223  std::cout << "AddPair ldata/object " << ldata << " " << object << std::endl;
224  std::cout << "After push_back size " << vect_pair_obj.size() << std::endl;
225 #endif
226 }
227 
228 // specify last commented, when commented for compilation, should be moved to ObjectSupportTendance
229 // cannot compile with Abstract ?? problem in make pair !
230 // void THStock::Add ( AbstractObjectStock *obj_stock )
231 void THStock::Add ( ObjectLine *obj_stock )
232 {
233 #ifdef DEBUG_OBJSTOCK
234  std::cout << "\n\tTHStock::Add (ObjectLine ) obj_stock " << obj_stock << std::endl;
235  std::cout << "this->GetName() " << this->GetName() << std::endl;
236  // need ObjectLine in parameter here
237  std::cout << "obj X0 X1 " << obj_stock->GetX0() << " " << obj_stock->GetX1() << std::endl;
238  std::cout << "obj Y0 Y1 " << obj_stock->GetY0() << " " << obj_stock->GetY1() << std::endl;
239 #endif
240 
241  // insert the object in the vector
242  //std::cout << "before push_back size " << vect_pair_obj.size() << std::endl;
243  vect_pair_obj.push_back( std::make_pair<ListDataStockBase*,AbstractObjectStock*>( nullptr,obj_stock) );
244 #ifdef DEBUG_OBJSTOCK
245  std::cout << "After push_back size " << vect_pair_obj.size() << std::endl;
246 #endif
247 }
248 
259 void THStock::AnchorToIndicator( const int & px, const int & py, ObjectLine * obj_line, FactoryObjectStock::EStageDraw kDraw )
260 {
261 #ifdef DEBUG_OBJSTOCK
262  std::cout << "Entry AnchorToIndicator with object " << std::endl;
263  std::cout << " enum EStageDraw " << kDraw << std::endl;
264  std::cout << "px/py " << px << " / " << py << std::endl;
265 #endif
266 
267  double y_anchor = -1;
268  double dist_y_anchor = 9999;
269 
270  // check if bin necessary ?? here can simply compute bin in DistancetoPoint
271  dist_y_anchor = DistancetoPoint ( px, py , y_anchor ); //bin_x0
272  std::cout << "dist_y_anchor " << dist_y_anchor << "y_anchor " << y_anchor << std::endl;
273 
274  if ( dist_y_anchor < DIST_ANCHOR ) {
275  //now just fixe Y0, X0 is correct (bin by default), coeff_d will be modified after, when repainting
276  if ( kDraw == FactoryObjectStock::kBeginDraw )
277  obj_line->SetY0( y_anchor );
278  // seems ok with support, keep the first point
279  else if ( kDraw == FactoryObjectStock::kEndDraw )
280  obj_line->SetY1( y_anchor );
281  }
282 }
283 
284 // called when update, need to increase the size of the objectstock, if needed
285 // no need of new_size if listdata stock has been updated
286 // just intermediate to force correct resize of ObjectStock, no need to check all the time
287 
288 // how to get if replace last ?? no probelm until now shoud use SetValues() all the time
289 // update is forced anyway a new message is given
290 
291 // maybe change name, make clear than only modifies the size
292 // AdaptSize ResizeObjectsStock
293 void THStock::UpdateObjectStock() // unsigned int new_size )
294 {
295 #ifdef DEBUG_OBJSTOCK
296  std::cout <<"Entry THStock::UpdateObjectStock() " << std::endl;
297 #endif
298  unsigned int size_ldata, size_object;
299  Int_t new_size;
300  //Indicator indic;
301 
302  it_pair it_p;
303  for ( it_pair it_p = vect_pair_obj.begin(); it_p != vect_pair_obj.end(); it_p++ ) {
304 
305 #ifdef DEBUG_OBJSTOCK
306  if ( ((*it_p).first) != nullptr ) {
307  std::cout << "ldata_name / size " << ((*it_p).first)->GetName() << " " << ((*it_p).first)->GetSize() << std::endl;
308  std::cout << "pointer to ldata " << (*it_p).first << std::endl;
309  }
310  std::cout << "size object "<< ((*it_p).second)->GetSize() << std::endl;
311 #endif
312 
313  // case of ObjectLine, 0 and 0
314  if ( ((*it_p).first) != nullptr ) {
315  size_ldata = ((*it_p).first)->GetSize();
316  std::cout << "sizeldata " << size_ldata << std::endl;
317  } else {
318  std::cout << "ObjectLine size = 0 " << std::endl;
319  size_ldata = 0;
320  }
321  size_object = ((*it_p).second)->GetSize();
322 
323  // before was using indicator and send to Factory. Now call directly
324  // Indicator indic = Indicator::GetIndicator ( ((*it_p).first)->GetName() );
325  // should work all time, send listdatastock to Factory to know the type
326  // new version, send only the size to add, always SetValues, so no problem with replace first
327  if ( size_ldata > size_object ) {
328 
329  std::cout << "need to resize ObjectStock to " << size_ldata << " Call Factory::Resize()" << std::endl;
330  new_size = size_ldata - size_object;
331  std::cout << " send to resize new_size " << new_size << std::endl;
332  // why factory ? could be specialized
333  //FactoryObjectStock::Resize( (*it_p).second, indic, new_size );
334  ((*it_p).second)->Resize( new_size );
335  }
336  }
337 
338 }
339 
340 unsigned int THStock::GetNTHStockToPaint () const
341 {
342  unsigned int nb_paint = 0;
343  for ( cit_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++ ) {
344  if ( ((*it).second )->ToPaint() ) {
345  nb_paint++;
346  }
347  }
348  return nb_paint;
349 }
350 
351 // delete wrong with RSI
352 void THStock::HideNameListData ( std::string fullname, bool toDelete )
353 {
354 #ifdef DEBUG_OBJSTOCK
355  std::cout << "Entry THStock::HideNameListData fullname " << fullname << " toDelete " << toDelete << std::endl;
356 #endif
357 
358  for ( it_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++ ) {
359 
360  // case RSI, all support must be deleted
361  // for now, SetToPaint false by default
362  if ( (*it).first == nullptr ) {
363  std::cout << "found nullptr THStock::HideNameListData in to solve later " << std::endl;
364  std::cout << "case RSI " << std::endl;
365  std::cout << "name object " << ( (*it).second )->GetNameObject() << std::endl;
366  // default
367  ( (*it).second )->SetToPaint( false );
368  ( (*it).second )->ClearObjectStock();
369  continue;
370  }
371 
372  if ( ( (*it).first )->GetFullName() == fullname ) {
373  //std::cout << "found set paint to false" << std::endl;
374  // hide ObjectStock if toDelete false
375  ( (*it).second )->SetToPaint( false );
376  // but will not be "Clear"
377  //std::cout << "THStock::HideNameListData need to clear the object here ??" << std::endl;
378  ((*it).second)->ClearObjectStock();
379 
380  //if need to delete
381  if ( toDelete ) {
382  std::cout << "THStock::HideNameListData option toDelete " << std::endl;
383  //delete explicitely the Object, listdata will be done by StockManager
384  delete ( (*it).second );
385  vect_pair_obj.erase ( it );
386  }
387  return;
388  }
389  }
390  std::cout << "THStock::HideNameListData not found" << std::endl;
391 }
392 
393 void THStock::ShowNameListData ( std::string fullname ) const
394 {
395 #ifdef DEBUG_OBJSTOCK
396  std::cout << "Entry THStock::ShowNameListData " << fullname << std::endl;
397 #endif
398  for ( cit_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++ ) {
399 
400  // Case RSI, support before in vector
401  if ( (*it).first == nullptr ) {
402  // needed to see the support again
403  ((*it).second)->SetToPaint( true );
404  std::cout << "nullptr case RSI " << std::endl;
405  continue;
406  }
407 
408  if ( ( (*it).first )->GetFullName() == fullname ) {
409  ((*it).second)->SetToPaint( true );
410 #ifdef DEBUG_OBJSTOCK
411  std::cout << "fund return true" << std::endl;
412 #endif
413  return;
414  }
415  }
416 }
417 
418 void THStock::SetColor( ListDataStockBase * ldata, Pixel_t color ) const
419 {
420 #ifdef DEBUG_OBJSTOCK
421  std::cout << "Entry THStock::SetColor " << color << std::endl;
422  std::cout << "ldata->GetName() " << ldata->GetName() << std::endl;
423 #endif
424 
425  for ( cit_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++ ) {
426 
427  std::cout << (*it).first << std::endl;
428  // case RSI, Support added, makes problem
429  if ( (*it).first == nullptr )
430  continue;
431 
432  if ( (*it).first == ldata ) {
433 
434  // need to check the pointer for all those function
435 
436  // equivalent to dynamic_cast ??
437  // THstock derive from ROOT, so better to use
438  if ( ((*it).second)->InheritsFrom("PStockLine") ) {
439  std::cout << "SetLineColor " << TColor::GetColor( color ) << std::endl;
440  ((*it).second)->SetLineColorObject( TColor::GetColor( color ) );
441  }
442  std::cout << "found return " << std::endl;
443  return;
444  }
445  }
446 }
447 
448 // new version send the fullname, hash table, map faster ??
449 // changed from ldata to name
450 void THStock::SetColor( std::string fname, Pixel_t color ) const
451 {
452 #ifdef DEBUG_OBJSTOCK
453  std::cout << "Entry THStock::SetColor " << color << std::endl;
454  std::cout << "TColor::GetColor( color ) " << TColor::GetColor( color ) << std::endl;
455  std::cout << "With fullname " << fname << std::endl;
456 #endif
457  //std::cout << "ldata->GetName() " << ldata->GetName() << std::endl;
458 
459  // could be a function GetItMap/VecByFName()
460  for ( cit_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++ ) {
461 
462  // case RSI, Support added, list = 0, makes problem
463  if ( (*it).first == nullptr )
464  continue;
465 
466  if ( (*it).first->GetFullName() == fname ) {
467 
468  //std::cout << ((*it).second)->ClassName() << std::endl;
469  // could be better, Be sure SetLineColorObject exists for all.. some crashes
470  if ( ((*it).second)->InheritsFrom("PStockLine") ) {
471  //std::cout << "SetLineColor " << TColor::GetColor( color ) << std::endl;
472  //((*it).second)->SetLineColorObject( TColor::GetColor( color ) );
473  ((PStockLine*) ((*it).second))->SetLineColorObject( TColor::GetColor( color ) );
474  }
475 #ifdef DEBUG_OBJSTOCK
476  std::cout << "found return " << std::endl;
477 #endif
478  return;
479  }
480  }
481 }
482 
483 //do not work for MACD, other THStock, need to refer to first THStock, not used anymore
484 // so need access CanvasStock, or throught fCommonAxis or directly from ListObjectStock !!
485 //maybe needed for ObjectLine, make sense in this case.
486 // here safe, no idea about the order ??
487 // easier with commonaxis
488 time_t THStock::GetDateFromBin ( Int_t bin ) const
489 {
490 #ifdef DEBUG_OBJSTOCK
491  std::cout << "Entry THStock::GetDateFromBin bin " << bin << std::endl;
492 #endif
493 
494  time_t date;
496  //std::cout << "ldata " << ldata << " " << ldata->GetName() << std::endl;
497 
498  date = ldata->ChronologicAt( bin ).GetDate();
499  //std::cout << "size_data " << size_data << " size_data-bin " << size_data-bin << " date " << date << std::endl;
500 #ifdef DEBUG_OBJSTOCK
501  std::cout << "ldata " << ldata << " " << ldata->GetName() << std::endl;
502  std::cout << "date " << date << " " << Utils::Time_tToString(date) << std::endl;
503 #endif
504  return date;
505 }
506 
507 //developped for MACD, for retriving date, problem because in another THStock
508 //used in PstockLine as well !!
509 Int_t THStock::GetBinFromPixel ( Int_t px, Int_t &bin2 ) const
510 {
511 #ifdef DEBUG_OBJSTOCK
512  std::cout << "Entry THStock::GetBinFromPixel px " << px << std::endl;
513 #endif
514  Int_t bin = fcommon_xaxis_th->GetXAxis()->FindBin( gPad->AbsPixeltoX( px ) );
515  //total_bin = fcommon_xaxis_th->GetNbins();
516  if ( bin2 > 0 ) {
517  //std::cout << "option bin2, check next or previous closest bin " << std::endl;
518  //std::cout << "bin center " << fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin ) << std::endl;
519  if ( gPad->AbsPixeltoX( px ) > fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin ) ) {
520  //std::cout << " gPad->AbsPixeltoX( px ) is > center " << std::endl;
521  bin2 = bin + 1;
522  } else {
523  bin2 = bin - 1;
524  }
525  }
526  return bin;
527 }
528 
529 //not used anyymore for MACD,
530 // used by ObjectLine
531 time_t THStock::GetDateBinFromPixel ( Int_t px, Int_t /*py*/, Int_t &bin, Int_t &bin2 ) const
532 {
533  //std::cout << "Entry THStock::GetDateBinFromPixel " << std::endl;
534  time_t date;
535 
536  bin = fcommon_xaxis_th->GetXAxis()->FindBin( gPad->AbsPixeltoX( px ) );
537  date = GetDateFromBin( bin );
538  //std::cout << "get bin " << bin << " get date " << date << std::endl;
539 
540  if ( bin2 > 0 ) {
541  //std::cout << "option bin2, check next or previous closest bin " << std::endl;
542  //std::cout << "bin center " << fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin ) << std::endl;
543  if ( gPad->AbsPixeltoX( px ) > fcommon_xaxis_th->GetXAxis()->GetBinCenter( bin ) ) {
544  //std::cout << " gPad->AbsPixeltoX( px ) is > center " << std::endl;
545  bin2 = bin + 1;
546  } else {
547  bin2 = bin - 1;
548  }
549  }
550  return date;
551 }
552 
553 void THStock::GetObjectExtrema( double & ymin, double & ymax ) const
554 {
555 #ifdef DEBUG_OBJSTOCK
556  std::cout << "\n\tEntry THStock::GetObjectExtrema " << std::endl;
557 #endif
558 
559  double min, max;
560  // shoul give default values !!
561  min = 10e6;
562  max = -10e6;
563 
564  // loop over object, here only ObjectStock
565  for ( cit_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++) {
566 
567  // try to call the appropriate function, ok
568  // important test, if hidden should not enter into account
569  if ( (*it).second->ToPaint() ) {
570  (*it).second->GetExtrema( min, max );
571 
572  if ( max > ymax ) ymax = max;
573  if ( min < ymin ) ymin = min;
574  }
575  }
576 #ifdef DEBUG_OBJSTOCK
577  std::cout << "will return ymin " << ymin << " ymax " << ymax << std::endl;
578 #endif
579 }
580 
581 Int_t THStock::DistancetoPrimitive(Int_t px, Int_t py, TObject** obj)
582 //Int_t THStock::DistancetoPrimitive(Int_t px, Int_t py, AbstractObjectStock** obj)
583 {
584 /*
585 #ifdef DEBUG_OBJSTOCK
586  std::cout << "THStock::DistancetoPrimitive size vect_pair_obj " << vect_pair_obj.size() << std::endl;
587 #endif
588 */
589  Int_t dist = 9999;
590  Int_t dist_objstock = 9999;
591 
592  //need a tmp_obj, cannot set and change in the same time
593  AbstractObjectStock * tmp_object;
594 
595  for ( it_pair it = vect_pair_obj.begin() ; it != vect_pair_obj.end(); it ++ ) {
596  // check if is painted
597  if ( !((*it).second)->ToPaint() ) {
598 #ifdef DEBUG_OBJSTOCK
599  std::cout <<"ToPaint false"<< std::endl;
600 #endif
601  continue;
602  }
603 
604  tmp_object = 0;
605  // will return a tmp_object anyway, accepted only if better or equal
606  dist_objstock = ((*it).second)->DistancetoPrimitive( px, py, &tmp_object ); //obj );
607  //std::cout << " dist_objstock after PLine " << dist_objstock << " value of dist " << dist << std::endl;
608  // test before ??
609  if ( tmp_object == 0 ) {
610 #ifdef DEBUG_OBJSTOCK
611  std::cout << "\nYES CALLED ! tmp_object is null, continue\n" << std::endl;
612 #endif
613  continue;
614  }
615  if ( dist_objstock <= dist ) {
616  //std::cout << "THStock new min dist " << dist_objstock << std::endl;
617  dist = dist_objstock;
618  //std::cout << "Set object in THStock " << tmp_object << (tmp_object)->ClassName() << std::endl;
619  *obj = tmp_object;
620  }
621  //std::cout << " THStock::DistancetoPrimitive dist " << dist << std::endl;
622  //std::cout << " obj?? " << *obj << std::endl;
623  }
624 
625  //std::cout << " THStock return obj " << *obj << " " << (*obj)->ClassName() << std::endl;
626  return dist;
627 }
628 
629 // inspired from DistancetoPrimitive, used by the anchor function when drawing ObjectLine
630 // called by
631 // After modification of ObjectStock, could change
632 Int_t THStock::DistancetoPoint(Int_t px, Int_t py, Double_t &yvalue ) const
633 {
634 #ifdef DEBUG_OBJSTOCK
635  std::cout << "Entry THStock::DistancetoPoint" << std::endl;
636 #endif
637  Int_t dist = 9999;
638  Int_t dist_objstock = 9999;
639  Double_t yvalue_tmp;
640 
641  // want to anchor to any IndicatorObjectStock, not other
642  IndicatorObjectStock *indic_anchor_obj;
643 
644  int bin_x0 = fcommon_xaxis_th->GetXAxis()->FindBin( gPad->AbsPixeltoX( px ) );
645  std::cout << "bin_x0 " << bin_x0 << std::endl;
646 
647  // should check for bin_x0,bin_x1 only, intermediate noisy
648  for ( cit_pair it = vect_pair_obj.begin() ; it != vect_pair_obj.end(); it ++ ) {
649  // check if is painted
650  if ( !((*it).second)->ToPaint() ) {
651  //std::cout << " Not paint !! continue " << std::endl;
652  continue;
653  }
654  //std::cout << "name associated " << GetNameListData( (*it).second ) << std::endl;
655  // return AbstractBase
656  //std::cout << "ClassName() " << ((*it).second )->ClassName() << std::endl;
657  indic_anchor_obj = dynamic_cast<IndicatorObjectStock *>( (*it).second );
658  if ( indic_anchor_obj != nullptr ) { //0 ) { //nullptr )
659  //std::cout << "name associated " << GetNameListData( (*it).second ) << std::endl;
660 
661  //may need an option, over all bin, bin not fixed ( but printed ) depend of bin loop over bin should be here
662  // if sure Indicator. distancetoPoint maybe limited to it...
663  dist_objstock = ((*it).second)->DistancetoPoint( px, py, yvalue_tmp, bin_x0 );
664  //dist_objstock = ((*it).second)->DistancetoPoint( gPad->AbsPixeltoX( px ), gPad->AbsPixeltoY( py ),
665  // bin_x0, yvalue_tmp );
666  if ( dist_objstock <= dist ) {
667  dist = dist_objstock;
668  yvalue = yvalue_tmp;
669  std::cout << "set new dist " << dist << " yvalue " << yvalue << std::endl;
670  }
671  }
672  // for test only
673  /*
674  else { std::cout << ((*it).second)->GetNameObject() << " not inheriting from IndicatorObjectStock " << std::endl; }
675  */
676  } // end loop over object
677 
678 #ifdef DEBUG_OBJSTOCK
679  std::cout << "Exit THStock::DistancetoPoint final dist " << dist << " yvalue " << yvalue << std::endl;
680 #endif
681  return dist;
682 }
683 
684 // only call method Paint on the object
685 // could use Paint default ?? argument not used
686 void THStock::PaintObjectStock( const Option_t* option ) // Hparam_stock_t &Hparam_stock )
687 {
688 #ifdef DEBUG_OBJSTOCK
689  std::cout << "\n\tEntry THStock::PaintObjectStock new version " << std::endl;
690  //std::cout << "Hparam_stock.xfirst " << Hparam_stock.xfirst << std::endl;
691  //std::cout << "Hparam_stock.xlast " << Hparam_stock.xlast << std::endl;
692 #endif
693 
694  //ListDataStockBase *ldata;
695  AbstractObjectStock *object;
696 
697  for ( it_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++ ) {
698 
699  //ldata = (*it).first; // can be nullptr
700  object = (*it).second;
701  //std::cout << "object name " << (*it).second->GetName() << std::endl;
702 
703  // forgot strange bug, in part because painted 2 times..
704  if ( object->ToPaint() )
705  object->Paint();
706  else {
707 #ifdef DEBUG_OBJSTOCK
708  std::cout << "ToPaint is False " << std::endl;
709 #endif
710  }
711  }
712 }
713 
721 {
722 #ifdef DEBUG_OBJSTOCK
723  std::cout << "\n\tEntry THStock::SetObjectStock new version " << std::endl;
724  std::cout << " size of vect_pair " << vect_pair_obj.size() << std::endl;
725  //std::cout << "Hparam_stock.xfirst " << Hparam_stock.xfirst << std::endl;
726  //std::cout << "Hparam_stock.xlast " << Hparam_stock.xlast << std::endl;
727 #endif
728 
729  ListDataStockBase *ldata;
730  AbstractObjectStock *object;
731 
732  for ( cit_pair it = vect_pair_obj.begin(); it != vect_pair_obj.end(); it ++ ) {
733 
734  ldata = (*it).first;
735  object = (*it).second;
736 
737  // can protect
738 
739 #ifdef DEBUG_OBJSTOCK
740  if ( ldata != nullptr ) {
741  std::cout << "Call ClearObjectStcok and SetObjectStock on " << ldata->GetName() << std::endl;
742  } else {
743  std::cout << "pointer ldata is nullptr, it is a line objectstock " << std::endl;
744  }
745 #endif
746 
747  // consider here than clear object and set to paint = false is already called when hide/delete is pressed
748  // so only Object to redraw here
749  if ( object->ToPaint() ) {
750  // - For ListObjectStock, really set ToPaint in Candle and Bar to false, ClearObject is used
751  // - For PStockLine, delete all values, will need to be recreated each time, or need to extend like ListObjectStock.
752  // ToPaint false, only by IndicatorFrame
753  // - Collection call ClearObjectStock on every items
754  // - ObjectLine, should always be draw ? will enforce in GetExtrema
755  // easy to modify, because in subclass
756  // for the moment do nothing
757  object->ClearObjectStock();
758 
759  // do not want to overwrite Paint(), paint different Set better
760  // original ROOT done in THistPainter ??
761  //if ( object->ToPaint() )
762  // here redondant, many of the property in common_axis in Hparam_stock
763  // in fact only Hparam_stock.shift_futur is used = fcommon_xaxis_th.GetShift()
764  //object->SetObjectStock( ldata, fcommon_xaxis_th ); //, Hparam_stock );
765  object->SetObjectStock( ldata, fcommon_xaxis_th, Hparam_stock );
766  }
767  }
768 }
void SetY0(double y0)
Definition: ObjectLine.h:102
virtual void Paint(const Option_t *="")=0
Paint the objet, to overide.
double GetY1() const
Definition: ObjectLine.h:98
Derive from TH1 will draw the graph.
Definition: THStock.h:59
"Clever" enumeration of the ListDataStock type : StockCSV, Volume, EMA, BOLL,...
Definition: Indicator.h:29
void SetObjectStock(Hparam_stock_t &Hparam_stock) const
set the object, need Hparam_stock here
Definition: THStock.cxx:720
ClassImp(THStock) THStock
Definition: THStock.cxx:22
unsigned int GetNTHStockToPaint() const
return the number of object to paint called by CanvasStock, but Why ?? want bool ??
Definition: THStock.cxx:340
static IndicatorObjectStock * CreateObjectStock(Indicator indic, std::string full_name_indic, unsigned int size, THStock *parent, std::string opt_string=std::string())
create indicator object
THStock()
Constructors.
void AnchorToIndicator(const int &px, const int &py, ObjectLine *obj_line, FactoryObjectStock::EStageDraw kDraw)
set px, py to the closest indicator point
Definition: THStock.cxx:259
virtual void Add(ObjectLine *obj_stock)
call by Factory, specific to drawable line
Definition: THStock.cxx:231
virtual bool ToPaint() const
Int_t DistancetoPoint(Int_t px, Int_t py, Double_t &yvalue) const
used by anchor to find a Yvalue is close and anchor to it
Definition: THStock.cxx:632
Use a policy PolicyChronologic, default VecNoChronologic.
void GetObjectExtrema(Double_t &ymin, Double_t &ymax) const
broadcast the call to all object
Definition: THStock.cxx:553
void PaintObjectStock(const Option_t *option="")
called from THisPainter when Hparam_sock has been completed
Definition: THStock.cxx:686
double GetX0() const
wrapper functions to fline, need public for all ??
Definition: ObjectLine.h:95
Hparam_stock_t Hparam_stock
std::vector< std::pair< ListDataStockBase *, AbstractObjectStock * > >::const_iterator cit_pair
Definition: THStock.h:65
static Indicator GetIndicator(const std::string &str_name)
Constructor with a string label.
Definition: Indicator.cpp:234
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
std::vector< std::pair< ListDataStockBase *, AbstractObjectStock * > > vect_pair_obj
for storing pair<ListDataStock,ObjectStock>
Definition: THStock.h:71
virtual void AddPairToVector(ListDataStockBase *ldata)
create a IndicatorStock and add a new pair
Definition: THStock.cxx:181
virtual THStock * DrawCopy(Option_t *option="") const
Definition: THStock.cxx:107
ListDataStockBase * GetFirstListData() const
Get the first inserted ListDataStock, by THistPainterStock, needeed for size should add check...
Definition: THStock.cxx:161
std::vector< std::pair< ListDataStockBase *, AbstractObjectStock * > >::iterator it_pair
typedef for iterators
Definition: THStock.h:64
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
void SetColor(ListDataStockBase *ldata, Pixel_t color) const
2 versions one with ldata or with fullname
Definition: THStock.cxx:418
time_t GetDateFromBin(Int_t bin) const
called by ObjectLine need the date from a bin
Definition: THStock.cxx:488
class for drawing graph
TAxis * GetXAxis()
Definition: CommonXAxis.h:54
virtual void Copy(TObject &hnew) const
Definition: THStock.cxx:99
double GetY0() const
Definition: ObjectLine.h:97
void SetCommonXAxis(CommonXAxis *new_xaxis)
called by CanvasStock to set a common axis for all thstock
Definition: THStock.cxx:123
CommonXAxis * fcommon_xaxis_th
pointer to the CommonXAxis Constructor and ownership done by CanvasStock
Definition: THStock.h:75
virtual unsigned int GetSize() const =0
Return the size of the vector.
static const int DIST_ANCHOR
maybe modifiable later
Definition: THStock.h:68
std::string GetName() const
Definition: ListDataStock.h:78
ListDataStockBase * GetListDataStock(std::string fullname) const
want to retrieve from which pad is the fullname, call by CanvasStock
Definition: THStock.cxx:145
virtual ~THStock()
Definition: THStock.cxx:82
Abstract base class for the ListDataStock, for storing base pointers in vectors.
Definition: ListDataStock.h:50
void SetY1(double y1)
Definition: ObjectLine.h:103
Int_t DistancetoPrimitive(Int_t px, Int_t py, TObject **obj)
call by THistPainterStock, broadcast call to all objects.
Definition: THStock.cxx:581
Int_t GetNbins()
Definition: CommonXAxis.h:77
void HideNameListData(std::string fullname, bool toDelete)
called by CanvasStock
Definition: THStock.cxx:352
Define an abstract base class for all objects to be painted in a THStock.
Float_t fsize_title
size depend on the layout, used by THsitPainterStock
Definition: THStock.h:78
double GetX1() const
Definition: ObjectLine.h:96
void ShowNameListData(std::string fullname) const
Definition: THStock.cxx:393
for all ObjectLines
Definition: ObjectLine.h:33
EStageDraw
define stages for drawing
virtual void UpdateObjectStock()
to redefine
Definition: THStock.cxx:293
time_t GetDateBinFromPixel(Int_t px, Int_t py, Int_t &bin, Int_t &bin2) const
return both the date and two bins called only ObjectLine::GetValues
Definition: THStock.cxx:531
const T & ChronologicAt(const unsigned int offset) const
Get the nth element in a chronological order.
THStock & operator=(const THStock &ht)
assignement operator tested ?? needed by dictionary ??
Definition: THStock.cxx:132