root icon indicating copy to clipboard operation
root copied to clipboard

Name normalization problem with some boost::histogram functions

Open bendavid opened this issue 1 year ago • 2 comments

Some boost histogram utility functions have trouble being called from PyROOT. I've traced this back to what looks like a name normalization problem. Unfortunately I did not manage to put together a standalone example without the boost histogram dependency.

Consider the following test case:

test.c

#include "TInterpreter.h"
#include "TClass.h"
#include "TMethod.h"
#include <iostream>
#include <boost/histogram.hpp>

int test() {
  auto ns = TClass::GetClass("boost::histogram");
  auto meth = ns->GetMethodWithPrototype("make_histogram", "boost::histogram::axis::regular<>&&");

  std::cout << "meth->GetReturnTypeName(): " << meth->GetReturnTypeName() << std::endl;
  std::cout << "meth->GetReturnTypeNormalizedName(): " << meth->GetReturnTypeNormalizedName() << std::endl;

  auto cl = TClass::GetClass(meth->GetReturnTypeNormalizedName().c_str());
  std::cout << "cl: " << cl << std::endl;

  return 0;
}

output:

meth->GetReturnTypeName(): boost::histogram::histogram<tuple<boost::histogram::axis::regular<double,boost::use_default,boost::use_default,boost::use_default> >,boost::histogram::unlimited_storage<allocator<char> > >
meth->GetReturnTypeNormalizedName(): boost::histogram::histogram<tuple<regular<double,use_default,use_default,use_default> >,unlimited_storage<allocator<char> > >
cl: 0
(int) 0

So note that the normalized return type is missing the boost::histogram namespace for the template arguments of the std::tuple. (and then obviously trying to lookup the type again fails)

This prevents properly calling this function and other similar ones from PyROOT because the normalized return type is used e.g. here https://github.com/root-project/root/blob/4483b01b7f4bad47332f98d773dbd9b8c7f36b9d/bindings/pyroot/cppyy/cppyy-backend/clingwrapper/src/clingwrapper.cxx#L1515

bendavid avatar Mar 26 '23 16:03 bendavid