Change the intendation (Marian)
authormarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 16 Jul 2008 22:57:14 +0000 (22:57 +0000)
committermarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 16 Jul 2008 22:57:14 +0000 (22:57 +0000)
STAT/Macros/kDTreeTest.C

index 80d8532..9ca1efa 100644 (file)
@@ -1,17 +1,31 @@
+/*
+  Test macro for TKDTree
+  
+  //Initialization:
+
+  gSystem->AddIncludePath("-I$ALICE_ROOT/STAT")
+  gSystem->Load("$ALICE_ROOT/lib/tgt_linux/libSTAT.so");
+  .L $ALICE_ROOT/STAT/Macros/kDTreeTest.C+ 
+
+  //TestBuild
+
+*/
+
 #include <malloc.h>
+#include "TSystem.h"
 #include "TMatrixD.h"
 #include "TRandom.h"
 #include "TGraph.h"
 #include "TStopwatch.h"
-#include "../src/TKDTree.h"
+#include "TKDTree.h"
 
 
 Float_t Mem()
 {
-  // size in KB
-  static struct mallinfo memdebug; 
-  memdebug = mallinfo();
-  return memdebug.uordblks/1024.;
+  // get mem info
+  ProcInfo_t procInfo;
+  gSystem->GetProcInfo(&procInfo);
+  return procInfo.fMemVirtual;
 }
 
 
@@ -34,6 +48,9 @@ void kDTreeTest()
 
 //______________________________________________________________________
 void TestBuild(const Int_t npoints, const Int_t bsize){  
+  //
+  // Test memory consumption
+  //
   Float_t *data0 =  new Float_t[npoints*2];
   Float_t *data[2];
   data[0] = &data0[0];
@@ -55,13 +72,13 @@ void TestBuild(const Int_t npoints, const Int_t bsize){
 //______________________________________________________________________
 void TestSpeed(const Int_t npower2, const Int_t bsize)
 {
-       if(npower2 < 10){
-               printf("Please specify a power of 2 greater than 10\n");
-               return;
-       }
-       
-       Int_t npoints = Int_t(pow(2., npower2))*bsize;
-       Float_t *data0 =  new Float_t[npoints*2];
+  if(npower2 < 10){
+    printf("Please specify a power of 2 greater than 10\n");
+    return;
+  }
+  
+  Int_t npoints = Int_t(pow(2., npower2))*bsize;
+  Float_t *data0 =  new Float_t[npoints*2];
   Float_t *data[2];
   data[0] = &data0[0];
   data[1] = &data0[npoints];
@@ -69,24 +86,24 @@ void TestSpeed(const Int_t npower2, const Int_t bsize)
     data[1][i]= gRandom->Rndm();
     data[0][i]= gRandom->Rndm();
   }
-
-       TGraph *g = new TGraph(npower2-10);
-       g->SetMarkerStyle(7);
-       TStopwatch timer;
-       Int_t tpoints;
+  
+  TGraph *g = new TGraph(npower2-10);
+  g->SetMarkerStyle(7);
+  TStopwatch timer;
+  Int_t tpoints;
   TKDTreeIF *kdtree = 0x0;
-       for(int i=10; i<npower2; i++){
-               tpoints = Int_t(pow(2., i))*bsize;
-               timer.Start(kTRUE);
-               kdtree = new TKDTreeIF(tpoints, 2, bsize, data);
-               timer.Stop();
-               g->SetPoint(i-10, i, timer.CpuTime());
-               printf("npoints [%d] nodes [%d] cpu time %f [s]\n", tpoints, kdtree->GetNNodes(), timer.CpuTime());
-               //timer.Print("u");
-               delete kdtree;
-       }
-       g->Draw("apl");
-       return;
+  for(int i=10; i<npower2; i++){
+    tpoints = Int_t(pow(2., i))*bsize;
+    timer.Start(kTRUE);
+    kdtree = new TKDTreeIF(tpoints, 2, bsize, data);
+    timer.Stop();
+    g->SetPoint(i-10, i, timer.CpuTime());
+    printf("npoints [%d] nodes [%d] cpu time %f [s]\n", tpoints, kdtree->GetNNodes(), timer.CpuTime());
+    //timer.Print("u");
+    delete kdtree;
+  }
+  g->Draw("apl");
+  return;
 }
 
 //______________________________________________________________________
@@ -172,58 +189,58 @@ void  testkdtreeIF(Int_t npoints, Int_t bsize, Int_t nloop, Int_t mode)
   TKDTreeIF *kdtree = new TKDTreeIF(npoints, 2, bsize, data);
   timer.Stop();
   timer.Print();
-       if(mode == 0) return;
-       
-
-
-       Float_t countern=0;
-       Float_t counteriter  = 0;
-       Float_t counterfound = 0;
-
-
-       if (mode ==2){
-               if (nloop) timer.Start(kTRUE);
-               Int_t res[npoints];
-               Int_t nfound = 0;
-               for (Int_t kloop = 0;kloop<nloop;kloop++){
-                       if (kloop==0){
-                               counteriter = 0;
-                               counterfound= 0;
-                               countern    = 0;
-                       }
-                       for (Int_t i=0;i<npoints;i++){
-                               Float_t point[2]={data[0][i],data[1][i]};
-                               Float_t delta[2]={drangey,drangez};
-                               Int_t iter  =0;
-                               nfound =0;
-                               Int_t bnode =0;
-                               //kdtree->FindBNode(point,delta, bnode);
-                               //continue;
-                               kdtree->FindInRangeA(point,delta,res,nfound,iter,bnode);
-                               if (kloop==0){
-                                       //Bool_t isOK = kTRUE;
-                                       Bool_t isOK = kFALSE;
-                                       for (Int_t ipoint=0;ipoint<nfound;ipoint++)
-                                               if (res[ipoint]==i) isOK =kTRUE;
-                                       counteriter+=iter;
-                                       counterfound+=nfound;
-                                       if (isOK) {
-                                               countern++;
-                                       }else{
-                                               printf("Bug\n");
-                                       }
-                               }
-                       }
-               }
-               
-               if (nloop){
-                       timer.Stop();
-                       timer.Print();
-               }
+  if(mode == 0) return;
+  
+  
+  
+  Float_t countern=0;
+  Float_t counteriter  = 0;
+  Float_t counterfound = 0;
+  
+  
+  if (mode ==2){
+    if (nloop) timer.Start(kTRUE);
+    Int_t res[npoints];
+    Int_t nfound = 0;
+    for (Int_t kloop = 0;kloop<nloop;kloop++){
+      if (kloop==0){
+       counteriter = 0;
+       counterfound= 0;
+       countern    = 0;
+      }
+      for (Int_t i=0;i<npoints;i++){
+       Float_t point[2]={data[0][i],data[1][i]};
+       Float_t delta[2]={drangey,drangez};
+       Int_t iter  =0;
+       nfound =0;
+       Int_t bnode =0;
+       //kdtree->FindBNode(point,delta, bnode);
+       //continue;
+       kdtree->FindInRangeA(point,delta,res,nfound,iter,bnode);
+       if (kloop==0){
+         //Bool_t isOK = kTRUE;
+         Bool_t isOK = kFALSE;
+         for (Int_t ipoint=0;ipoint<nfound;ipoint++)
+           if (res[ipoint]==i) isOK =kTRUE;
+         counteriter+=iter;
+         counterfound+=nfound;
+         if (isOK) {
+           countern++;
+         }else{
+           printf("Bug\n");
+         }
        }
-       delete [] data0;
-
-       counteriter/=npoints;
-       counterfound/=npoints;
-       if (nloop) printf("Find nearest point:\t%f\t%f\t%f\n",countern, counteriter, counterfound);
+      }
+    }
+    
+    if (nloop){
+      timer.Stop();
+      timer.Print();
+    }
+  }
+  delete [] data0;
+  
+  counteriter/=npoints;
+  counterfound/=npoints;
+  if (nloop) printf("Find nearest point:\t%f\t%f\t%f\n",countern, counteriter, counterfound);
 }