ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CanvasStock.cxx
Go to the documentation of this file.
1 
8 #include "CanvasStock.h"
9 
10 #include "ObjectStock/THStock.h"
11 #include "../utils/FullName.h"
12 //#include <TPad.h>
13 
14 //ClassDef ?? Signal Selected from TCanvas
16 
17 //Constructor for embedded Canvas
18 CanvasStock::CanvasStock ( const char *name, Int_t ww, Int_t wh, Int_t winid ):
19 TCanvas( name, ww, wh, winid ), fcommon_xaxis_cs(0)
20 {
21 #ifdef DEBUG_CONT_FRAME
22  std::cout << " Entry Constructor CanvasStock name " << name << " winid " << winid << std::endl;
23 #endif
24 
25  //Create the instance of CommomXAxis, maybe not good,
26  // use 0 by default and will be setup later ( cannot test a wrong axis )
27  //or send the size of the object !! 0 better with size apart
28  fcommon_xaxis_cs = new CommonXAxis();
29 #ifdef DEBUG_CONT_FRAME
30  std::cout << "just created axis, size " << fcommon_xaxis_cs->GetNbins() << std::endl;
31 #endif
32 
33  // Set the specific painter class of CanvasStock and THStock
34  //std::cout << " SetPainter(THistPainterStock) " << std::endl;
35  TVirtualHistPainter::SetPainter("THistPainterStock");
36 }
37 
38 // constructor for ...
39 CanvasStock::CanvasStock ( const char *name, const char *title, Int_t ww, Int_t wh ):
40 TCanvas( name, title, ww, wh ), fcommon_xaxis_cs(0)
41 {
42 #ifdef DEBUG_CONT_FRAME
43  std::cout << " Entry Constructor Not Embedded CanvasStock name " << name << std::endl;
44 #endif
45 
46  //Create the instance of CommomXAxis, maybe not good,
48  //std::cout << "just created axis, size " << fcommon_xaxis_cs->GetNbins() << std::endl;
49 
50  // Set the specific painter class of CanvasStock and THStock
51  //std::cout << " SetPainter(THistPainterStock) " << std::endl;
52  TVirtualHistPainter::SetPainter("THistPainterStock");
53 }
54 
55 // Copy Constructor, not used
56 // use keyword explicit or something to avoid
57 // missing CommonXAxis copy
58 /*
59 CanvasStock::CanvasStock( const CanvasStock & rhs ):
60 TCanvas( rhs.GetName(), rhs.GetName() ),
61 vecTHStock ( rhs.vecTHStock )
62 {
63 #ifdef DEBUG
64  std::cout << "Copy Constructor CanvasStock" << std::endl;
65 #endif
66 }
67 */
68 
70 {
71 #ifdef DEBUG_CONT_FRAME
72  std::cout << "Destructor default CanvasStock" << std::endl;
73 #endif
74  delete fcommon_xaxis_cs;
75  fcommon_xaxis_cs = 0;
76  // call destructor of all THStock
77  std::vector<THStock*>::iterator it;
78  for ( it= vecTHStock.begin(); it != vecTHStock.end(); it++ ) {
79  delete ( *it );
80  }
81  vecTHStock.clear();
82  //std::cout << "size of vecTHStock " << vecTHStock.size() << std::endl;
83 }
84 
86 
87 // may keep, no to delete, moved to controller in a way
88 // need more than shortname to be sure ( SMA on Volume ) listdata would be better
89 /*
90 THStock * CanvasStock::GetTHStock ( UInt_t npad, std::string shortname )
91 {
92  std::cout << "Entry CanvasStock::GetTHStock " << npad << " " << shortname << std::endl;
93 
94  //to develop
95  //return vecTHStock[ npad-1 ]->GetTHStock( name );
96  return 0;
97 }
98 */
99 
100 // new version, to keep
101 // oneTHStock by pad, could loop over the pads ??
103 {
104 #ifdef DEBUG_CONT_FRAME
105  std::cout << "Entry CanvasStock::GetNPadToPaint() vecTHStock size " << vecTHStock.size() << std::endl;
106 #endif
107  UInt_t nbpad_topaint = 0;
108  //THStock *ths = 0;
109 
110  for ( unsigned int i=0; i < vecTHStock.size(); i++ ) {
111  //std::cout << "CanvasStock::GetNPadToPaint() i "<< i << std::endl;
112  //ths = vecTHStock[i];
113  //if ( ths->GetNTHStockToPaint() > 0 ) {
114  if ( vecTHStock[i]->GetNTHStockToPaint() > 0 ) {
115  nbpad_topaint++;
116  //std::cout << " increment nbpad_topaint " << nbpad_topaint << std::endl;
117  }
118  }
119 #ifdef DEBUG_CONT_FRAME
120  std::cout << " CanvasStock::GetNPadToPaint nbpad_topaint " << nbpad_topaint << std::endl;
121 #endif
122  return nbpad_topaint;
123 }
124 
127 {
128  //delete the thstock
129  //std::vector<THStock *>::iterator it_vec;
130  it_vthstock it_vec;
131  Int_t counter = 0;
132 
133  for ( it_vec = vecTHStock.begin(); it_vec != vecTHStock.end(); it_vec++ ) {
134  //if ( (*it_vec) == ths ) {
135  if ( counter == npad ) {
136  std::cout << "will delete thstock " << (*it_vec)->GetName() << std::endl;
137  delete ( *it_vec );
138  // pointer so object is not destroyed
139  vecTHStock.erase ( it_vec );
140  return;
141  }
142  counter++;
143  }
144  std::cout << "CanvasStock::DeleteOneTHStock nbpad not found" << std::endl;
145 }
146 
147 // Copied to CommonXAxis, keep this version for tests
148 // Update after an UpdateCSV in GUI
149 // with new version needed ?? to do in CommonXAxis but need intermediate
150 
160 {
161 #ifdef DEBUG_CONT_FRAME
162  std::cout << "\n\tEntry CanvasStock:UpdateTHStock " << std::endl;
163 #endif
164 
165  // developed for update,
166  // check the size of the first ListDataStock first
167  int new_size = vecTHStock[0]-> GetFirstListData()->GetSize();
168 #ifdef DEBUG_CONT_FRAME
169  std::cout << "new_size of the first ldata " << new_size << std::endl;
170  std::cout << "size of common_axis " << fcommon_xaxis_cs->GetNbins() << std::endl;
171 #endif
172 
173  // here need to resize !
174  // need to be done before UpdateObjectStock
175  //if new_size != old_size, update CommonAxis and Size ObjectStock
176 
177  // test done in UpdateCommon. to choose only one to call
178  if ( new_size > fcommon_xaxis_cs->GetNbins() ) {
179  //std::cout << "new size is larger " << std::endl;
180 
181  // increase size and update the range view if modified
182  UpdateCommonAxis( new_size );
183 
184  // need to resize the Object in THStock
185  for ( unsigned int i = 0; i < vecTHStock.size(); i++ ) {
186  vecTHStock[i]->UpdateObjectStock();
187  }
188  }
189  // 3. setup all pad as Modified, needed ?
190  // if axis extended, as well
191  UpdateAllPad();
192  // 4. call Paint, PaintInit & THStock::PaintObjectStock
193  Update();
194 
195 #ifdef DEBUG_CONT_FRAME
196  std::cout << "\n\tEnd CanvasStock::UpdateTHStock() " << std::endl;
197 #endif
198 
199  return;
200 }
201 
202 // could slider directly bound to axis by Signal. better ?
203 void CanvasStock::SetRangeCommonAxis( Double_t MinPos, Double_t MaxPos )
204 {
205 #ifdef DEBUG_CONT_FRAME
206  std::cout << " Entry CanvasStock::SetRangeCommonAxis MinPosd " << MinPos << " MaxPos " << MaxPos << std::endl;
207 #endif
208 
209  if ( !fcommon_xaxis_cs ) {
210  std::cout << " fcommon_xaxis_cs is not found, return " << std::endl;
211  return;
212  }
213 
214  Int_t nbbin = fcommon_xaxis_cs->GetNbins();
215 
216 
217  // fXaxis->GetNbins() is not not modified
218 #ifdef DEBUG_CONT_FRAME
219  std::cout << "set integer min " << (Int_t) (MinPos * ( ((Double_t)nbbin) /100. )) <<
220  " max " << (Int_t)(MaxPos * ( ((Double_t)nbbin) /100. )) << std::endl;
221 #endif
222 
223  //SetRange expect Int_t, Set the view in modifying fFirst and fLast
224  fcommon_xaxis_cs->GetXAxis()->SetRange ( (Int_t) (MinPos * ( ((Double_t)nbbin) /100. )), (Int_t)(MaxPos * ( ((Double_t)nbbin) /100. )) );
225  //fcommon_xaxis_cs->GetXAxis()->SetRange ( min, (Int_t)(MaxPos * ( ((Double_t)nbbin) /100. )) );
226 
227 #ifdef DEBUG_CONT_FRAME
228  std::cout << "Now com. Xaxis is correctly setup ??" << std::endl;// yes !!
229  std::cout << "fcommom->GetFirst/Last " << fcommon_xaxis_cs->GetXAxis()->GetFirst() << " " << fcommon_xaxis_cs->GetXAxis()->GetLast() << std::endl;
230 #endif
231 }
232 
233 // new version need to called again for sure
234 void CanvasStock::UpdateCommonAxis( int new_size)
235 {
236 
237 #ifdef DEBUG_CONT_FRAME
238  std::cout << "CanvasStock::UpdateCommonAxis" << std::endl;
239  std::cout << "prev size " << fcommon_xaxis_cs->GetNbins() << std::endl;
240  std::cout << "new_size " << new_size << std::endl;
241  std::cout << "previous last " << fcommon_xaxis_cs->GetLast() << std::endl;
242 #endif
243 
244  // previous range values
245  Int_t max = fcommon_xaxis_cs->GetLast();
246  Int_t min = fcommon_xaxis_cs->GetFirst();
247 
248  int old_size = fcommon_xaxis_cs->GetNbins();
249 
250  // test done before in update THStock?? not needed ??
251  // increase the size of the axis, default range always 0 to 1
252  if ( old_size != new_size ) {
253  //std::cout << "size Has Changed set new size " << new_size << std::endl;
254  fcommon_xaxis_cs->GetXAxis()->Set( new_size, (Double_t)0.0, (Double_t)1.0 );
255 
256  // previous slider was at the maximum, need to reset fLast with SetRange
257  if ( max == old_size )
258  fcommon_xaxis_cs->GetXAxis()->SetRange ( min, new_size );
259  // not needed if not changed
260  //else
261  // fcommon_xaxis_cs->GetXAxis()->SetRange ( min, max );
262  }
263  return;
264 }
265 
266 
267 void CanvasStock::ShowListData ( std::string fullname, Int_t npad )
268 {
269 #ifdef DEBUG_CONT_FRAME
270  std::cout << "CanvasStock::ShowListData" << fullname << std::endl;
271 #endif
272  THStock *ths = 0;
273  bool toRecreate = false;
274  //std::cout << " Entry ShowListData " << p_listdata->GetName() << " " << npad << std::endl;
275 
276  ths = vecTHStock[ npad - 1 ];
277  //std::cout << " ths " << ths << std::endl;
278 
279  // if 0, need to recreate the pad
280  if ( ths->GetNTHStockToPaint() == 0 ) {
281  toRecreate = true;
282  }
283 
284  ths->ShowNameListData( fullname );
285 
286  if ( toRecreate ) {
287  std::cout << "GetNTHStockToPaint nb_topaint == 0 recreate pad" << std::endl;
288  CreateNPad();
289  } else {
290  GetPad( npad )->Modified();
291  }
292 }
293 
294 void CanvasStock::HideListData ( std::string fullname, Int_t npad, bool toDelete )
295 {
296 #ifdef DEBUG_CONT_FRAME
297  //std::cout << " Entry CanvasStock::HideListData " << p_listdata->GetName() << " " << npad << " bAll " << bAll << " toDelete " << toDelete << std::endl;
298  //std::cout << " Entry CanvasStock::HideListData " << p_listdata->GetFullName() << std::endl;
299  std::cout << " Entry CanvasStock::HideListData " << fullname << " npad " << npad << " toDelete " << toDelete << std::endl;
300 #endif
301  THStock *ths = 0;
302  // need to be sure here
303  ths = vecTHStock[ npad - 1 ];
304 
305  // delete done in THStock
306  ths->HideNameListData( fullname, toDelete );
307 
308  //if hide Volume need to delete the pad but keep the canvas
309  // could make the same with first...
310  UInt_t nb_topaint = ths->GetNTHStockToPaint();
311 #ifdef DEBUG_CONT_FRAME
312  std::cout << " nb_topaint " << nb_topaint << std::endl;
313 #endif
314 
315  //if ( ( nb_topaint == 0 ) || toDelete ) {
316  if ( nb_topaint == 0) {
317 #ifdef DEBUG_CONT_FRAME
318  std::cout << "nb_topaint == 0 or to delete " << std::endl;
319 #endif
320 
321  // force deleting all, delete the THStock and all data
322  if ( toDelete ) {
323  //delete the thstock
324  DeleteOneTHStock ( npad - 1 );
325  }
326  //both case need to recreate the pad, because geometric changes
327 #ifdef DEBUG_CONT_FRAME
328  // more a work from the controller, but more convenient here ??
329  std::cout << "Need to recreate the pad " << std::endl;
330 #endif
331  CreateNPad();
332  }
333 
334  else {
335  //works
336 #ifdef DEBUG_CONT_FRAME
337  std::cout << "nothing to delete and nb_topaint > 0, just call pad->Modified() " << std::endl;
338 #endif
339  GetPad( npad )->Modified();
340  }
341 
342 }
343 
344 Int_t CanvasStock::AddListDataStockToMap( ListDataStockBase *p_listdata, Int_t forcepad )
345 {
346 #ifdef DEBUG_CONT_FRAME
347  std::cout << "\n\tCanvasStock::AddListDataStockToMap" << std::endl;
348 #endif
349  std::string name_listdata = p_listdata->GetName();
350  // tricky to deal if it is the first pad for the common axis
351  bool first_pad = false;
352  bool create_ths = false;
353 
354 #ifdef DEBUG_CONT_FRAME
355  std::cout << "name list_data " << name_listdata << std::endl;
356  std::cout << "name canvas stock " << GetName() << std::endl; //name CanvasStock CStock_CAC40_DAY
357 #endif
358 
359  // default set up nb_pad to original for incrementing
360  // get the number of pad in the canvas stock, before adding, for first ( no THStock) it is 0
361  Int_t nb_pad = vecTHStock.size();
362 #ifdef DEBUG_CONT_FRAME
363  std::cout << "original GetNbPad() nb_pad " << nb_pad << std::endl;
364 #endif
365 
366  // will extract namestock and indicator from canvas stock name
367  std::vector <std::string> split_string;
368  std::string title_canvas;
369 
370  THStock *ths = 0;
371 
373  // better use shortname namespace
374  // framename to use
375  // to check if still needed, now with controller nb_pad = 0 may not be anymore
376  // if it is the first pad, set up first pad
377  if ( nb_pad == 0 ) {
378  Utils::splitline ( GetName(), "_", split_string );
379  // delete the "CStock_" then namestock, timescale
380  title_canvas = split_string[1] + " " + split_string[2];
381 #ifdef DEBUG_CONT_FRAME
382  std::cout << " nb_pad==0 title_canvas " << title_canvas << std::endl;
383 #endif
384  // first_pad is true in this case, will use this axis as common axis
385  first_pad = true;
386  create_ths = true;
387  }
388  // if SMA compute title even if not needed, maybe title to do after
389  // SMA studpid ?? no title ?? not used !! for Volume ok...
390  // can use ShortName now
391  else {
392  Utils::splitline ( name_listdata, "_", split_string );
393  // cut the name of the indicator, or of the StockCSV... need better
394  title_canvas = split_string[0];
395  if ( title_canvas.size() > 4 ) {
396 
397  title_canvas.erase( 4, title_canvas.size()-4 );
398  title_canvas.replace( 3, 1, "." );
399 #ifdef DEBUG_CONT_FRAME
400  std::cout << " size " << title_canvas.size() << std::endl;
401  std::cout << " nb_pad >= 1, title_canvas " << title_canvas << std::endl;
402 #endif
403  }
404  }
406 
407  // default force pad 0, no need 0 not a canvas
408  // used only for SHOW at the moment
409  if ( forcepad !=0 ) {
410 #ifdef DEBUG_CONT_FRAME
411  std::cout << "forcepad to pad " << forcepad << std::endl;
412 #endif
413  nb_pad = forcepad;
414  }
415  // default, send by Validation
416  // else decide which nb_pad to add
417  else {
418  // get the selected pad
419  // really need better
420  std::string indic_str = ShortName::GetIndicator ( p_listdata->GetName() ).label();
421  //std::cout << "Indicator string " << indic_str << std::endl;
422 
423  //here test is working, should copy to Stock.cpp ComputeTA
424  if ( (indic_str.compare(1,2,"MA",0,2)==0) || ( indic_str.compare("BOLL")==0) ) {
425 #ifdef DEBUG_CONT_FRAME
426  std::cout << "Will add *MA/BOLL to selected pad" << std::endl;
427 #endif
428  // why in fact
429  SetSelectedPad( ( (TPad*) gPad ) ) ;
430  //std::cout << " After SetSelectedPad " << std::endl;
431  // set the pad to draw
432  nb_pad = gPad->GetSelectedPad()->GetNumber();
433 #ifdef DEBUG_CONT_FRAME
434  std::cout << " gPad name " << gPad->GetName() << std::endl;
435  std::cout << " selcted name " << gPad->GetSelectedPad()->GetName() << std::endl;
436  std::cout << " gPad number " << gPad->GetNumber() << std::endl;
437  std::cout << " selected number " << gPad->GetSelectedPad()->GetNumber() << std::endl;
438 #endif
439  }
440 
441  // will create a new Pad in Canvas, by default add one to map
442  else {
443  // here increment nb_pad, never draw in pad 0, first is always the first subpad one
444  nb_pad += 1;
445 #ifdef DEBUG_CONT_FRAME
446  std::cout << "nbpad default New nb_pad " << nb_pad << std::endl;
447 #endif
448  // here need to create a new THSock
449  create_ths = true;
450  }
451  }
452 
453  // whatever before, create a new THstock, why to force ListDataStock ??? to test !!!
454  //std::cout << "Will create a new THStock " << std::endl;
455  // to be replaced, Add ( ObjectStock,..option); depending first or not
456  //ths = new THStock( name_listdata.c_str(), title_canvas.c_str(), (ListDataStock<DataCSV> *)p_listdata );
457  //
458  if ( create_ths ) {
459 #ifdef DEBUG_CONT_FRAME
460  std::cout << "Will create a new THStock " << std::endl;
461  std::cout << "fcommon_xaxis_cs " << fcommon_xaxis_cs << std::endl;
462  std::cout << "name THStock " << name_listdata << std::endl;
463 #endif
464  // add all in once, need to set up the commmon_xaxis
465 
466  // problem with name, only StockCSV or Volume
467  //std::string name_thstock = "THStock" + nb_pad + name_listdata +
468  // can use full name, really strange output !! delete some letters !
469  //std::string name_thstock = "THStock" + nb_pad + p_listdata->GetFullName();
470  //std::cout << "new name_thstock " << name_thstock << std::endl;
471 
472  // here create empty object, but need the size for Axis, which may become common
473  ths = new THStock( name_listdata.c_str(), title_canvas.c_str(), p_listdata->GetSize() );
474  //ths = new THStock( name_thstock.c_str(), title_canvas.c_str(), p_listdata->GetSize() );
475  //std::cout << "THStock created " << std::endl;
476  if ( nb_pad > 1 ) {
477 #ifdef DEBUG_CONT_FRAME
478  std::cout << "\nnot the first pad, set commonaxis right now!\n " << std::endl;
479 #endif
481  }
482  // not clear what i mean here
483  //else { //may here set up the common_xaxis
484  // std::cout << "Achtung some indicator may work or not "<< std::endl;
485  //}
486  //once ceated, can add object and will be created
487  ths->Add ( p_listdata );
488 
489  // bug CommonAxis, not needed before ?? but why , should be set up at a point !!
490  // to do in THStock creation
491  // should be done in CanvasStock when created, maybe later and does not exist yet ...
492  ths->GetXaxis()->Set ( p_listdata->GetSize(), (Double_t)0.0, (Double_t)1.0 );
493 
494 #ifdef DEBUG_CONT_FRAME
495  std::cout << "p_lisdata size " << p_listdata->GetSize() << std::endl;
496  std::cout << "ths get axis size " << ths->GetXaxis()->GetNbins() << std::endl;
497 #endif
498  //
499  //already done before maybe a trick somewhere..., yes trick problem with STOCHF which has ObjectLine
500  //ths = new THStock ( name_listdata.c_str(), title_canvas.c_str(), p_listdata );
501 
502  vecTHStock.push_back( ths );
503 
504  if ( first_pad ) {
505  ths->SetSizeTitle ( 0. );
506  ths->GetYaxis()->SetLabelSize(0.05);
507  ths->GetXaxis()->SetLabelSize(0.06);
508  //std::cout << " first pad axis of canvas " << fcommon_xaxis_cs << " size " << fcommon_xaxis_cs->GetNbins() << std::endl;
509  //std::cout << " first pad axis of ths " << ths->GetXaxis() << " size " << ths->GetXaxis()->GetNbins() << std::endl;
510  fcommon_xaxis_cs->SetCommonXAxis( ths->GetXaxis() );
511  //std::cout << "first_pad, get common_axis from ths " << ths->GetXaxis() << " size " << ths->GetXaxis()->GetNbins() << std::endl;
512  //std::cout << "first_pad, new common_axis of canvas " << fcommon_xaxis_cs << " fcom->GetXasis() " << fcommon_xaxis_cs->GetXAxis() << " size " << fcommon_xaxis_cs->GetNbins() << std::endl;
513  //std::cout << "first_pad, get common_axis from ths " << ths->GetXaxis() << std::endl;
514  }
515  else {
516 #ifdef DEBUG_CONT_FRAME
517  std::cout << "not a new first pad " << std::endl;
518 #endif
519  ths->SetSizeTitle ( 0.1 );
520  ths->GetYaxis()->SetLabelSize ( 0.12 );
522  //before deleted, make it again
523  //fcommon_xaxis_cs->SetCommonXAxis( ths->GetXaxis() );
524  }
525  }
526 
527  else {
528 #ifdef DEBUG_CONT_FRAME
529  std::cout << "Add to existing THStock" << std::endl;
530 #endif
531  //see later do not want to modify nb_pad
532  int nb_pad2 = gPad->GetSelectedPad()->GetNumber();
533 #ifdef DEBUG_CONT_FRAME
534  std::cout << "Add nb_pad2 " << nb_pad2 << std::endl;
535 #endif
536  ths = vecTHStock [ nb_pad2-1 ];
537 #ifdef DEBUG_CONT_FRAME
538  std::cout << "ths GetName() " << ths->GetName() << std::endl;
539 #endif
540  ths->Add ( p_listdata );
541  }
542 
543  // if new or old should set the CommonAxis of THStock, in all case need to point of the new CommonXaxis
544  // cannot keep the original axis as reference, but always refer to CommonAxis
545  //std::cout << "fcommon_xaxis_cs " << fcommon_xaxis_cs << std::endl;
546  if ( ths ) {
547  //set axis of ths to the commonaxis
548 #ifdef DEBUG_CONT_FRAME
549  std::cout << "SetAxis of ths " << std::endl;
550 #endif
552  } else {
553 #ifdef DEBUG_CONT_FRAME
554  std::cout << "ths false, no axis to assign " << std::endl;
555 #endif
556  }
557  // anyway, call CreateNPad, certainly not the best..for sure now
558  //no need if add SMA
559  CreateNPad();
560 #ifdef DEBUG_CONT_FRAME
561  std::cout << "Return CreateNPad and CanvasStock::AddListDataStokpMap nb_pad " << nb_pad << std::endl;
562 #endif
563  return nb_pad;
564 }
573 // similar function has been implemented in ControllerIndicTHStock, certainly a better one
574 // here it is a work done done by a view
575 /*
576 unsigned int CanvasStock::GetPadNumber( std::string fullname)
577 {
578  unsigned int nb_pad = 0;
579  //nb_pad = FindPadNb( fullname );
580  std::string shortname = FullName::GetShortName( fullname );
581  ListDataStockBase *ldata;
582 
583 #ifdef DEBUG_CONT_FRAME
584  std::cout << "shortname " << shortname << std::endl;
585  std::cout << "frame_name " << FullName::GetFrameName( fullname ) << std::endl;
586 #endif
587 
588  for ( it_vthstock it = vecTHStock.begin(); it != vecTHStock.end(); it++ ) {
589  nb_pad += 1;
590  std::cout << "Name of THStock " << (*it)->GetName() << std::endl;
591  ldata = (*it)->GetListDataStock( shortname );
592  // even do not check name, but only if return value is not zero !
593  // controller version is much better
594  if ( !ldata ) {
595  //if ( ldata->GetName() == shortname ) {
596  std::cout << "Found it" << std::endl;
597  //}
598  }
599  //nb_pad += 1;
600  }
601  return nb_pad;
602 }
603 */
604 
605 // new version
607 #ifdef DEBUG_CONT_FRAME
608  std::cout << "Entry CanvasStock::CreateNPad" << std::endl;
609  std::cout << " name " << gPad->GetName() << std::endl;
610  std::cout << " classname " << gPad->ClassName() << std::endl;
611  std::cout << " nbpad " << vecTHStock.size() << std::endl;
612  std::cout << " nb_padtopaint " << GetNPadToPaint() << std::endl;
613 #endif
614 
615  TPadStock *pad;
616 
617  Int_t nchname = strlen(GetName())+6;
618  char *name = new char [nchname];
619 
620  UInt_t nbpad = vecTHStock.size();
621  UInt_t nb_padtopaint = GetNPadToPaint();
622 
623 
624  Double_t x1,y1,x2,y2;
625  Double_t dy=0;
626  Double_t rest=0;
627  Double_t margin = 0.001;
628  x1 = margin;
629  x2 = 1 - margin;
630  y1 = 0; y2 = 0;
631 
632  //std::cout << " nbpad " << nbpad << std::endl;
633  nb_padtopaint = GetNPadToPaint();
634 #ifdef DEBUG_CONT_FRAME
635  std::cout << " nbpad (vecTHStock.size()) " << nbpad << std::endl;
636  std::cout << " nb_padtopaint " << nb_padtopaint << std::endl;
637  PrintVector();
638 #endif
639 
640  THStock * ths = 0;
641  // updated only if drawn
642  UInt_t count = 0;
643 
644  //Clear everything and redraw
645  //needed if add or remove a pad
646  //Is THStock deleted ?? seems not...almost sure
647  // All pad correclty deleted ?
648  Clear();
649 
650  //std::cout << "CreateNPad " << nb_pad << std::endl;
651  // loop over the subpad
652  // only if they must be printed
653  for ( UInt_t i = 1; i <= nbpad; i++ ) {
654 
655  ths = vecTHStock [ i-1 ];
656 
657  //nb_topaint = ths->GetNTHStockToPaint();
658  //std::cout << "nb_topaint " << nb_topaint << std::endl;
659  if ( ths->GetNTHStockToPaint () == 0 ) {
660 #ifdef DEBUG_CONT_FRAME
661  std::cout << " GetNTHStockToPaint == 0, continue " << std::endl;
662 #endif
663  continue;
664  }
665  //std::cout << "normal " << std::endl;
666  count++;
667 
668  // if nbpad=1, StockCSV 100%
669  //if ( (i==1) && (nb_padtopaint == 1) ) {
670  if ( (count==1) && (nb_padtopaint == 1) ) {
671  y2 = 1. - margin;
672  y1 = margin;
673  rest=0.;
674  dy = 0.;
675  }
676  // if nbpad=2, StockCSV 75%
677  //if ( (i==1) && (nbpad==2) ) {
678  //need else ??
679  //else if ( (i==1) && (nb_padtopaint==2) ) {
680  else if ( (count==1) && (nb_padtopaint==2) ) {
681  //else if ( (i==1) && (nbpad==2) ) {
682  y2 = 1. - margin;
683  y1 = 0.25 + margin;
684  rest=0.25;
685  dy = 0.25;
686  }
687  //if nbpad=3, StockCSV 60%
688  //else if ( (i==1) && (nbpad==3) ) {
689  //else if ( (i==1) && (nb_padtopaint==3) ) {
690  else if ( (count==1) && (nb_padtopaint==3) ) {
691  y2 = 1. - margin;
692  y1 = 0.40 + margin;
693  rest=0.40;
694  dy = rest / 2.;
695  }
696  //else keep 50 %
697  //else if ( (i==1) && (nbpad>3)) {
698  //else if ( (i==1) && (nb_padtopaint >3)) {
699  else if ( (count==1) && (nb_padtopaint >3)) {
700  y2 = 1. - margin;
701  y1 = 0.50 + margin;
702  rest = 0.50;
703  // may be changed, try
704  //dy = rest / (nbpad-1);
705  dy = rest / ( nb_padtopaint - 1 );
706  }
707  // other than 0 and more than 3
708  // could be else
709  //else if ( i > 1 ) {
710  else if ( count > 1 ) {
711  //y2 = rest - (i-2)*dy - margin;
712  y2 = rest - (count-2)*dy - margin;
713  y1 = y2 - dy + 2*margin;
714  }
715 
716  //Always placed at origin before creating a pad
717  this ->cd( 0 );
718  //std::cout << "cd(0) gPad " << gPad << std::endl;
719 
720  //create name for pad, will need to extend if more than 1 CanvasStock
721  //snprintf(name,nchname,"%s_%d",GetName(),i);
722  snprintf(name,nchname,"%s_%d",GetName(),count);
723  //std::cout << "Will create new pad with name " << name << std::endl;
724  //std::cout << "x1,y1 " << x1 << " " << y1 << std::endl;
725  pad = new TPadStock( name, name, x1, y1, x2, y2, -1);
726 
727  // necessary ??
728  //pad->SetNumber(i);
729  pad->SetNumber(count);
730  //ok, apply for all pads, could be done in a Style
731  pad->SetRightMargin(0.02);
732  // Draw, do not paint, necessary
733  pad->Draw();
734  //this->cd(i);
735  this->cd(count);
736  //std::cout << "cd(i) gPad " << i << " " << gPad << std::endl;
737 
738  //std::cout << "loop " << i << std::endl;
739  //std::cout << " NbTHStock " << GetNbTHStock(i+1) << std::endl;
740 
741  // setup style for a THSTock, can be in Style
742  // done when created
743  //ths = vecTHStock [ i-1 ];
744  //std::cout << " Get ths " << ths << std::endl;
745  //std::cout << " Before Draw " << std::endl;
746  ths->Draw();
747 
748  }//end loop for nbpad
749 
750  //reset gpad to main, seem more flexible, ...but lose gPad to a Pad...
751  //cd(0);
752  cd(1);
753 
754 #ifdef DEBUG_CONT_FRAME
755  std::cout << "Exit CanvasStock::CreateNPad() count " << count << std::endl;
756 #endif
757  return;
758 }
759 
760 // npad stored in controller
761 void CanvasStock::SetColor ( UInt_t npad, std::string fullname, unsigned long color )
762 {
763 #ifdef DEBUG_CONT_FRAME
764  std::cout << "npad " << npad << std::endl;
765  std::cout << "fullname " << fullname << std::endl;
766  std::cout << "color " << color << std::endl;
767  std::cout << "(Pixel_t)color " << (Pixel_t)color << std::endl;
768 #endif
769 
770  THStock *ths = 0;
771 
772  ths = vecTHStock[ npad - 1 ];
773  //std::cout << " ths " << ths << " will call THStock::SetColor " << std::endl;
774  //ths->SetColor ( listdata, (Pixel_t)color );
775  ths->SetColor ( fullname, (Pixel_t)color );
776 
777  // important for direct update
778  GetPad( npad )->Modified();
779 }
780 
781 // Should update all Stock, belong to class TPad and the common axis
782 // Possible Stock change(last candle) but not the Common_axis
783 // used ?? not !! but idea of fPrimitvies not bad
784 // used yes keep output, necessary ?? to check
785 // to change to ModifiedAllPad
787 {
788 #ifdef DEBUG_CONT_FRAME
789  std::cout << " CanvasStock::UpdateAllPad(), marked as modified only, but do not update anything" << std::endl;
790 #endif
791 
792  TObject *obj;
793  if (!fPrimitives) return ;
794  //std::cout << "fPrimitives is not empty " << std::endl;
795 
796  //try second method, ok compile and work
797  TObjOptLink *lnk = 0;
798  lnk = (TObjOptLink*)fPrimitives->FirstLink();
799  while (lnk) {
800  obj = lnk->GetObject();
801  //if (obj->InheritsFrom(TPad::Class()))
802  //
803  //std::cout << "name modified " << ((TPad*)obj)->GetName() << std::endl;
804  //modified only is enough, will be redraw after
805  ((TPad*)obj)->Modified();
806  //try after, works here even if not redraw
807  // not needed if CanvasStock::Update is called just after
808  //((TPad*)obj)->Update();
809  lnk = (TObjOptLink*)lnk->Next();
810  }
811 /*
812 #ifdef DEBUG_CONT_FRAME
813  std::cout << " Exit CanvasStock::UpdateAllPad " << std::endl;
814 #endif
815 */
816 }
817 
818 // look at TPad::ExcetueEvent ( overriden by TPadStock )
819 // and TCanvas::ExecuteEvent, do only a few
820 /* do nothing to delete
821 void CanvasStock::ExecuteEvent(Int_t, Int_t, Int_t ) //event, px, py
822 {
823  std::cout << " Entry CanvasStock::ExecuteEvent,do nothing " << std::endl;
824 }
825 */
826 
827 // Print info on vector THStock
829 {
830  std::cout << "===================\nShowMap CanvasStock" << std::endl;
831  std::cout << "Size " << vecTHStock.size() << std::endl;
832 
833  for ( UInt_t nb_th = 0; nb_th < vecTHStock.size(); nb_th++ ) {
834  std::cout << "Name " << vecTHStock[nb_th]->GetName() << std::endl;
835  }
836  return;
837 }
CanvasStock()
used this constructor ?? may be usefull for test code ?? I/ O need default constructor anyway ...
Definition: CanvasStock.h:78
void SetColor(UInt_t npad, std::string fullname, unsigned long color)
new version with fname, really Needed ?? GetPad ( nb_pad ) from Controller not so good...
Owns a vector of THStock.
Definition: CanvasStock.h:53
Derive from TH1 will draw the graph.
Definition: THStock.h:59
std::vector< THStock * >::iterator it_vthstock
define typedef for the vector
Definition: CanvasStock.h:57
unsigned int GetNTHStockToPaint() const
return the number of object to paint called by CanvasStock, but Why ?? want bool ??
Definition: THStock.cxx:340
void DeleteOneTHStock(Int_t npad)
delete a complete Pad
ClassImp(CanvasStock) CanvasStock
Definition: CanvasStock.cxx:15
void UpdateAllPad()
group function to update all thstock
virtual void Add(ObjectLine *obj_stock)
call by Factory, specific to drawable line
Definition: THStock.cxx:231
virtual ~CanvasStock()
destructor
Definition: CanvasStock.cxx:69
Int_t GetLast()
Definition: CommonXAxis.h:79
void PrintVector()
for info
CanvasStock used to represent THStock.
Indicator GetIndicator(const std::string &sname)
Extract the indicator from a frame name.
Definition: FullName.cpp:103
Int_t AddListDataStockToMap(ListDataStockBase *, Int_t npad=0)
Add a ListDataStock, decide if new pad is created Add a pointeur to the new ListDataStock now decides...
Overload TPad Because ExecuteEvent not overloaded by CanvasStock.
Definition: TPadStock.h:31
CommonXAxis * fcommon_xaxis_cs
owns a common axis
Definition: CanvasStock.h:61
class for drawing graph
void SetRangeCommonAxis(Double_t MinPos, Double_t MaxPos)
interface to CommonXaxis.
void SetSizeTitle(Float_t new_size)
Definition: THStock.h:103
TAxis * GetXAxis()
Definition: CommonXAxis.h:54
void SetCommonXAxis(TAxis *xaxis)
Definition: CommonXAxis.h:55
void SetCommonXAxis(CommonXAxis *new_xaxis)
called by CanvasStock to set a common axis for all thstock
Definition: THStock.cxx:123
virtual unsigned int GetSize() const =0
Return the size of the vector.
std::string GetName() const
Definition: ListDataStock.h:78
Abstract base class for the ListDataStock, for storing base pointers in vectors.
Definition: ListDataStock.h:50
UInt_t GetNPadToPaint() const
function to return the number of pad needed
std::vector< THStock * > vecTHStock
store the THStocks.
Definition: CanvasStock.h:67
void CreateNPad()
clean all and recreate all pads, can improve
Int_t GetNbins()
Definition: CommonXAxis.h:77
void HideNameListData(std::string fullname, bool toDelete)
called by CanvasStock
Definition: THStock.cxx:352
void HideListData(std::string fullname, Int_t npad, bool toDelete=false)
Used for showing listdatastock indicator.
void ShowNameListData(std::string fullname) const
Definition: THStock.cxx:393
void splitline(const std::string &str, const std::string &delimiters, std::vector< std::string > &tokens)
splitline
Definition: Utils.cpp:56
Int_t GetFirst()
Definition: CommonXAxis.h:78
void UpdateCommonAxis(int new_size)
Resize CommonXaxis, increase size of the axis Update the range (bins) of the Axis (fFirst...
void UpdateTHStock()
to redefine
void ShowListData(std::string fullname, Int_t npad)
Used for Hide and Delete, with option.