CINT problem with TMath::Sort()

Dear ROOTers

The following function did work in root_v5.18/00 w/o the need to compile it:

Double_t Median(Int_t n, const Double_t *arr)
{
   if (n == 1) return arr[0];

// Create index and sort array
   Int_t *index = 0;
   if (!(index = new Int_t[n])) {return 1;}
   TMath::Sort(n, arr, index);

// Find median
   Int_t k;
   Double_t median = 0;
   if ((n % 2) == 0){
      k = (Int_t)TMath::Floor(n / 2.0) - 1;
      median = (arr[index[k]] + arr[index[k+1]])/2;
   } else {
      k = (Int_t)TMath::Floor(n / 2.0);
      median = arr[index[k]];
   }//if

   delete [] index;

   return median;
}//Median

However, in root_v15.20/00 I get the following error:

Error: Function Sort(n,arr,index) is not defined in current scope

Replacing index with:

   Long64_t *index = 0;
//or:
//   long long *index = 0;
   if (!(index = new Long64_t[n])) {return 1;}

results in the following error:

Error: Symbol TMath is not defined in current scope

The problem is clearly the change in the definition of TMath::Sort() between root_v5.18/00 and root_v15.20/00.

It would be great if CINT could handle the new definitions w/o the need to compile, or alternatively the
old definition of TMath::Sort() could be added to TMath.

Best regards
Christian

It should be sufficient to do:

since in the dictionary only the instantiation of TMath::Sort with Long64_t is present. With this change it works for me.

Best Regards
Lorenzo

Dear Lorenzo

You are right, when simply testing function Median() everything seems to be fine, however it seems that my example was too simple.

For this reason I am attaching macro “macroTestMedian.C”. Now I get the following output on MacOS X 10.4.11:

root [0] .L macroTestMedian.C
root [1] TestWeights()       
Error: Symbol TMath is not defined in current scope  macroTestMedian.C:46:
*** Interpreter error recovered ***
root [2] .L macroTestMedian.C+
Info in <ACLiC>: script has already been loaded in interpreted mode
Info in <ACLiC>: unloading /Volumes/CoreData/ROOT/rootcode/xps-x.x.x/./macroTestMedian.C and compiling it
Info in <TUnixSystem::ACLiC>: creating shared library /Volumes/CoreData/ROOT/rootcode/xps-x.x.x/./macroTestMedian_C.so
root [3] TestWeights()        
w: - 0.0421298 - 0.0433799 - 0.0479173 - 0.0436661 - 0.043845 - 0.037824 - 0 - 0.0438016 - 0.0451288 - 0.0411797 - 0.049073 - 0.00238643 - 0.0370189 - 0.0496886 - 0.0496012 - 0.0497087 - 0.0432122 - 0.0438448 - 0.0424522 - 0.0497087 - 0.0496401 - 0.0485132 - 0.046909 - 0.0493705
root [4] .q

As you see, running the macro with CINT results in an error, while compiling it with ACLiC everything is ok!

As a second point I have a severe problem with the inconsistencies in TMath, see my new thread in “ROOT Discussion”.

Best regards
Christian
macroTestMedian.C (2.39 KB)

The problem is with this valid C++ code probably mis-interpreted by CINT
(nothing to do with TMath)

 max  = (TMath::Abs(x[i]) > max) ? TMath::Abs(x[i]) : max;

Anyway in this case, I think it is peferable to write the code as

 if  (TMath::Abs(x[i]) > max) max =  TMath::Abs(x[i]);

The other problem is in the doc (THTML) not TMath.

Regards

Lorenzo

Dear Lorenzo

Thank you for your suggestion.

Testing the code I realized that simply replacing

max  = (TMath::Abs(x[i]) > max) ? TMath::Abs(x[i]) : max;

with

max  = (TMath::Abs(x[i]) > max) ? (TMath::Abs(x[i])) : max;

did also solve the problem.

Nevertheless I hope that this CINT problem will be solved.

Best regards
Christian