Hello ROOTers
One of the neat things about ROOT is to be able to fetch objects by name after they have been drawn on a canvas. Using scripts, this is easily done by
I am working in my C++ program and I would like to get access to this pointer. Any ideas how I could do that? Would this pointer be global, in the same way as gPad, where it can be accessed by any object I instantiate in run time (I think the answer is yes… I am only double checking)?
Thanks,
You can store any named object in gROOT->GetListOfSpecials() with
gROOT->GetListOfSpecials()->Add(myobject);
and retrive it later with gROOT->FindObject.
I found my problem. I was accessing the gROOT pointer through one of my objects that gets indirectly created in the main function. Because of the way how I declare my header files, my objects was not seeing the declaraition of the TROOT header file. I solved my problem including
#include "TROOT.h"
#include "TRint.h"
in my object’s header file.
Thanks for your help!
Cristian
[quote=“brun”]You can store any named object in gROOT->GetListOfSpecials() with
gROOT->GetListOfSpecials()->Add(myobject);
and retrive it later with gROOT->FindObject.
Rene[/quote]
Rene,
I have a list of graphs in a Canvas with multiples pads. I have assigned a unique ID (via TGraph::SetuniqueID(int) ) and then I have added these graphs to the list of specials as you suggested. If I want to retrieve a gr based on its uniqueID, how can I retrieve the list of specials so to iterate through this list to find such ID (hence the gr of interest)???
[quote] If I want to retrieve a gr based on its uniqueID, how can I retrieve the list of specials so to iterate through this list to find such ID (hence the gr of interest)??? [/quote]The only way is to iterate through the list; for example: TIter next(gROOT->GetListOfSpecials);
TGraph *graph;
while ( ( graph = (TGraph*) next() ) ) {
if ( graph->GetUniqueID() == what_we_are_looking_for ) {
break; // exit the loop, leave graph pointing to the desired result
}
}
if (graph) {
// Use the correct graph
}