Keep track of missing DCS points in DDL maps (flagged by 'x')
[u/mrichter/AliRoot.git] / STAT / TKDInterpolator.cxx
index 2abe0d1..31d846a 100644 (file)
@@ -1,6 +1,7 @@
 #include "TKDInterpolator.h"
 #include "TKDNodeInfo.h"
 
+#include "TError.h"
 #include "TClonesArray.h"
 
 ClassImp(TKDInterpolator)
@@ -9,7 +10,7 @@ ClassImp(TKDInterpolator)
 
 //_________________________________________________________________
 TKDInterpolator::TKDInterpolator() :
-       TKDInterpolatorBase()
+  TKDInterpolatorBase()
 {
 // Default constructor. To be used with care since in this case building
 // of data structure is completly left to the user responsability.
@@ -17,11 +18,11 @@ TKDInterpolator::TKDInterpolator() :
 
 //_________________________________________________________________
 TKDInterpolator::TKDInterpolator(Int_t ndim, Int_t npoints) :
-       TKDInterpolatorBase(ndim)
+  TKDInterpolatorBase(ndim)
 {
 // Wrapper constructor for the TKDTree.
 
-       if(npoints) TKDInterpolatorBase::Build(npoints);
+  if(npoints) TKDInterpolatorBase::Build(npoints);
 }
 
 
@@ -33,51 +34,53 @@ TKDInterpolator::~TKDInterpolator()
 //_________________________________________________________________
 void TKDInterpolator::AddNode(const TKDNodeInfo &node)
 {
-       if(!fTNodes){
-               printf("W - TKDInterpolator::SetNode() : Node array not defined.\n");
-               return;
-       }
+  if(!fNodes){
+    Warning("TKDInterpolator::SetNode()", "Node array not defined.");
+    return;
+  }
 
-       new((*fTNodes)[fNTNodes++]) TKDNodeInfo(node);
+  Int_t n(GetNTNodes());
+  new((*fNodes)[n++]) TKDNodeInfo(node);
 }
 
 //_________________________________________________________________
-void TKDInterpolator::Build(Int_t npoints, Int_t ndim)
+Bool_t TKDInterpolator::Build(Int_t npoints, Int_t ndim)
 {
-       fNSize = ndim;
-       TKDInterpolatorBase::Build(npoints);
+  fNSize = ndim;
+  return TKDInterpolatorBase::Build(npoints);
 }
 
 //_________________________________________________________________
 Int_t TKDInterpolator::GetNodeIndex(const Float_t *p)
 {
-/*     printf("TKDInterpolator::GetNodeIndex() ...\n");
-       printf("Looking for p[");
-       for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
-       printf("] ...\n");*/
-       TKDNodeInfo *node;
-       for(int inode=0; inode<fNTNodes; inode++){
-               node = (TKDNodeInfo*)(*fTNodes)[inode];
-               //node->Print();
-               if(node->Has(p)) return inode;
-       }
-       return -1;
+//     printf("TKDInterpolator::GetNodeIndex() ...\n");
+//   printf("Looking for p[");
+//   for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
+//   printf("] ...\n");
+
+  for(Int_t i=GetNTNodes(); i--;)
+    if(((TKDNodeInfo*)(*fNodes)[i])->Has(p)) return i;
+  
+  printf("Point p[");
+  for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
+  printf("] outside range.\n");
+  return -1;
 }
 
 
 //_________________________________________________________________
 Bool_t TKDInterpolator::SetNode(Int_t inode, const TKDNodeInfo &ref)
 {
-       if(!fTNodes){
-               printf("W - TKDInterpolator::SetNode() : Node array not defined.\n");
-               return kFALSE;
-       }
-       if(inode >= fNTNodes){
-               printf("W - TKDInterpolator::SetNode() : Node array defined up to %d.\n", fNTNodes);
-               return kFALSE;
-       }
-       TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[inode];
-       (*node) = ref;
-       return kTRUE;
+  if(!fNodes){
+    Warning("TKDInterpolator::SetNode()", "Node array not defined.");
+    return kFALSE;
+  }
+  if(inode >= GetNTNodes()){
+    Warning("TKDInterpolator::SetNode()", Form("Node array defined up to %d.", GetNTNodes()));
+    return kFALSE;
+  }
+  TKDNodeInfo *node = (TKDNodeInfo*)(*fNodes)[inode];
+  (*node) = ref;
+  return kTRUE;
 }