Failing tokenizing expression in RDataFrame's Take

Dear all,
I am having some issues with the option Take in RDataFrame.
I have an action (two filters and a Take) to repeat on multiple columns with similar names of the same dataframe, so I implemented some for loops:

auto d1 = ROOT::RDataFrame("Events", "./../trees/tree_general_cut.root");
for (int k = -120; k <= 120; k += 20)
   {
      if (k == 0)
         continue;
      std::string_view data_name = "nominal_z==" + std::to_string(k);
      for (int j = 0; j < 20; j++)
      {
         std::string_view filter_name = "rdfentry_ % 20 ==" + std::to_string(j);
         auto data = new Double_t[n];
         for (int i = 1; i < 27; i++)
         {
            std::string_view column_name = "numclusterod" + std::to_string(i);
            auto v1 = Mean(d1.Filter(data_name)
                          .Filter(filter_name)
                          .Take<double, ROOT::VecOps::RVec<double>>(column_name)
                          .GetValue());
          }
       }
    }

Executing the macro, it seems that the method Take has some problems with the string I passed to it.

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Failed to tokenize expression:
numclusterod1

It seems strange that I don’t have problem passing a filter defining a string, but I cannot make the same operation with the action Take().

Does anyone have an idea of what this might be?
Thanks a lot.


_ROOT Version: 6.26/06
_Platform: macOS 10.15.7
_Compiler: clang-1200.0.32.29


Hi @zenith378 ,

here you are building a string_view that will point to the storage of the temporary std::string that is destroyed right after this line. I think this might be the problem (RDF likely ends up reading garbage from those strings).

Try making those string_view actual std::strings, that might help.

Otherwise please share a small self-contained reproducer that we can run on our side to debug what is happening.

Cheers,
Enrico

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.