How to Check for meta-data availablity through RSampleInfo?

Hello,
I was wondering if there is a possibility to either get the RSample or RMetaData objects itself from the RSamplesInfo instance. Or if there is another way to circumvent the following issue.

The current issue I am facing is the following.
I need to define the cross-section for some samples, which I achieve as follows:

Double_t define_xsect(unsigned int slot, const ROOT::RDF::RSampleInfo &id)
{
    return std::stod(id.GetS("xsect"));
}

Under the circumstances that the SampleMeta data does not contain the xsect information, this leads to a run-time error. Ideally, the workaround would be to either get the RMetaData object itself to check if it has the underlying xsect information or have such a function for the RSampleInfo class itself to check if it has an xsect available?

Thanks in advance.

Hello,

you bring up a good point. Maybe we should provide some kind of test function, like e.g.
hasKey("xsect"), returning true or false.

In the mean time, you can still use the current API, but catch the std::logic_error. Given that this happens only once per sample, the runtime overhead of exception handling should be unnoticeable:

try {
  return id.GetD("xsect");
} catch (std::logic_error const &) {
  return -1.; // or some other magic value
}

Let us know what you think.

Hi,
Thank you.
Yes, I can use catch for now.

Thanks Again.

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