gviz3d.C

Go to the documentation of this file.
00001 // Simple TStructViewer tutorial 
00002 
00003 #include <TRandom.h>
00004 #include <TList.h>
00005 #include <TROOT.h>
00006 
00007 // Function creating elements of lists
00008 void MakeCrazy(TList *list, Int_t maxDepth, Int_t maxObjects, Float_t pList) {
00009    const Int_t ncl =12;
00010    const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
00011       "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
00012       Int_t nobj = gRandom->Uniform(0,maxObjects);
00013       for (Int_t i=0;i<nobj;i++) {
00014          if (maxDepth && gRandom->Rndm() < pList) {
00015             TList *slist = new TList();
00016             slist->SetName(Form("list_%d_%d",maxDepth,i));
00017             list->Add(slist);
00018             MakeCrazy(slist,maxDepth-1,maxObjects,pList);
00019          } else {
00020             Int_t icl = (Int_t)gRandom->Uniform(0,ncl);
00021             TNamed *named = (TNamed*)gROOT->ProcessLine(Form("new %s;",clnames[icl]));
00022             named->SetName(Form("%s_%d_%d",clnames[icl],maxDepth,i));
00023             list->Add(named);
00024          }
00025       }
00026 }
00027 
00028 // function creating a hierachy of objects to test the TStructViewer
00029 TList *crazy(Int_t maxDepth=5, Int_t maxObjects=20, Float_t pList=0.2) {
00030    TList *list = new TList();
00031    list->SetName("SuperList");
00032    MakeCrazy(list,maxDepth,maxObjects,pList);
00033    gROOT->GetListOfTasks()->Add(list);
00034    return list;
00035 }
00036 // function adding colors to viewer
00037 void FillColorsMap(TStructViewer* sv)
00038 {
00039    // Fills list fColors with TStructNodeProperty
00040   const Int_t ncl =12;
00041   const char *clnames[ncl] = {"TH1F","TGraph","TGraphErrors","TF1","TPaveText",
00042     "TAxis","TF2","TH2D","TLatex","TText","TCutG","THnSparseF"};
00043 
00044   for (int i = 0; i < ncl ; i++) {
00045     sv->SetColor(clnames[i], (Int_t)gRandom->Integer(8)+2);
00046   }
00047 }
00048 
00049 
00050 void gviz3d()
00051 {
00052    // Loading library needed by TStructViewer
00053    gSystem->Load("libGviz3d");
00054    // Creating a pointer to list
00055    TList* pointer = crazy(2,10);
00056    // Creating a viewer
00057    TStructViewer* sv = new TStructViewer(pointer);
00058    // adding colors
00059    FillColorsMap(sv);
00060    sv->Draw();
00061 }

Generated on Tue Jul 5 15:44:19 2011 for ROOT_528-00b_version by  doxygen 1.5.1