Retrieve added variables in ROOT prompt

We usually test c++ codes in ROOT prompt before we write them to a file and compile it. After we write many lines, we may forget what we did previously. It would be nice to have a way to view all the added variables in the prompt.

For example, after we execute those codes in ROOT prompt:

root [0] double A = 16
root [1] vector<double> B = {1,2,3,4}
root [2] string filename = "myfile.txt"
root [3] patient_t patient(...)
...

We type some command, and ROOT will print a list of those variables. Something like Matlab “Workspace”:

image

Is there any way to do that?

Hello,

If these variables are in the global scope (as in your example), you can use:

gROOT->GetListOfGlobals()->ls()

which prints your variables plus ROOT-related globals.

Thanks for your reply. But that doen’t work.

root [0] double A = 16
(double) 16.000000
root [1] vector<double> B = {1,2,3,4}
(std::vector<double> &) { 1.0000000, 2.0000000, 3.0000000, 4.0000000 }
root [2] gROOT->GetListOfGlobals()->ls()
OBJ: TListOfDataMembers TListOfDataMembers      List of TDataMembers for a class : 0
 OBJ: TGlobal   gROOT   TROOT* : 0 at: 0x1fee220
 OBJ: TGlobal   gPad    TVirtualPad* : 0 at: 0x1ff5880
 OBJ: TGlobal   gVirtualX       TVirtualX* : 0 at: 0x20308c0
 OBJ: TGlobal   gDirectory      TDirectory* : 0 at: 0x1f1f500
 OBJ: TGlobal   gGLManager      TVirtualGL* : 0 at: 0x6c0900
 OBJ: TGlobal   gInterpreter    TInterpreter* : 0 at: 0x6c53b0
 OBJ: TGlobal   gFile   TFile* : 0 at: 0x6d9610
 OBJ: TGlobal   kTRUE    : 0 at: 0x6d96c0
 OBJ: TGlobal   kIterForward     : 0 at: 0x2024790
root [3]

Looks like GetListOfGlobals() only lists ROOT global variables, not all the c++ objects defined from command line. My ROOT version is 6.20/00

That’s strange, for me it showed a couple of variables a and b that I defined, together with a bunch of ROOT globals:

...
 OBJ: TGlobal	a	 : 0 at: 0x5617c52fffb0
 OBJ: TGlobal	b	 : 0 at: 0x5617c5300730
 OBJ: TGlobal	kMaxCuts	 : 0 at: 0x5617c530bbc0
 OBJ: TGlobal	gHelpSMTopLevel	 : 0 at: 0x5617c532ec90
 OBJ: TGlobal	gHelpSMGeneral	 : 0 at: 0x5617c4f1a330
 OBJ: TGlobal	gHelpSMCanvas	 : 0 at: 0x5617c53016a0
...

Perhaps @pcanal knows how to get the user-defined ones too?

ROOT::GetListOfGlobals is an “on-demand” collection. By default it is populated only with the symbols explicitly searched for. To get the full list, you need to request explicit a full loading:

gROOT->GetListOfGlobals( true )->ls()

Cheers,
Philippe.

Thank you very much! That works now!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.