Logo ROOT  
Reference Guide
gviz3d.C File Reference

Detailed Description

Simple TStructViewer tutorial

#include <TRandom.h>
#include <TList.h>
#include <TROOT.h>
// Function creating elements of lists
void MakeCrazy(TList *list, Int_t maxDepth, Int_t maxObjects, Float_t pList) {
const Int_t ncl =12;
const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
"TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
Int_t nobj = gRandom->Uniform(0,maxObjects);
for (Int_t i=0;i<nobj;i++) {
if (maxDepth && gRandom->Rndm() < pList) {
TList *slist = new TList();
slist->SetName(Form("list_%d_%d",maxDepth,i));
list->Add(slist);
MakeCrazy(slist,maxDepth-1,maxObjects,pList);
} else {
Int_t icl = (Int_t)gRandom->Uniform(0,ncl);
TNamed *named = (TNamed*)gROOT->ProcessLine(Form("new %s;",clnames[icl]));
named->SetName(Form("%s_%d_%d",clnames[icl],maxDepth,i));
list->Add(named);
}
}
}
// function creating a hierachy of objects to test the TStructViewer
TList *crazy(Int_t maxDepth=5, Int_t maxObjects=20, Float_t pList=0.2) {
TList *list = new TList();
list->SetName("SuperList");
MakeCrazy(list,maxDepth,maxObjects,pList);
gROOT->GetListOfTasks()->Add(list);
return list;
}
// function adding colors to viewer
void FillColorsMap(TStructViewer* sv)
{
// Fills list fColors with TStructNodeProperty
const Int_t ncl =12;
const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
"TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
for (int i = 0; i < ncl ; i++) {
sv->SetColor(clnames[i], (Int_t)gRandom->Integer(8)+2);
}
}
void gviz3d()
{
// Creating a pointer to list
TList* pointer = crazy(2,10);
// Creating a viewer
TStructViewer* sv = new TStructViewer(pointer);
// adding colors
FillColorsMap(sv);
sv->Draw();
}
Author
Timur Pocheptsov

Definition in file gviz3d.C.

TStructViewer
Definition: TStructViewer.h:26
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
Form
char * Form(const char *fmt,...)
TRandom.h
Float_t
float Float_t
Definition: RtypesCore.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
TRandom::Uniform
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:635
TList.h
TROOT.h
TStructViewer::SetColor
void SetColor(TString name, Int_t color)
Sets color for the class "name" to color "color".
Definition: TStructViewer.cxx:450
TNamed
Definition: TNamed.h:29
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TRandom::Rndm
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:541
TRandom::Integer
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition: TRandom.cxx:349
TStructViewer::Draw
void Draw(Option_t *option="")
Draw object if there is valid pointer.
Definition: TStructViewer.cxx:342
TCollection::SetName
void SetName(const char *name)
Definition: TCollection.h:204
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TList
Definition: TList.h:44
gROOT
#define gROOT
Definition: TROOT.h:406