RDataFrame error: expected '(' for function-style cast or type construction

Hi,

I am trying to read through a root file in a RDataFrame inside python. The tree has elements belonging to a template class (template class TStoreGEMData) but i can’t figure out how to access them inside the data frame.

lyA_Power_data=ROOT.RDataFrame("feGEM/121_Laser\\PMT_integral","../2022_Laser_cooling_ROOT_files/output65661.root")
lyA_Power_data= lyA_Power_data.Define("runnumber", "TStoreGEMData<double>.GetRunNumber()")

AbortSignal                               Traceback (most recent call last)
Cell In [2], line 2
      1 lyA_Power_data=ROOT.RDataFrame("feGEM/121_Laser\\PMT_integral","../2022_Laser_cooling_ROOT_files/output65661.root")
----> 2 lyA_Power_data= lyA_Power_data.Define("runnumber", "TStoreGEMData<double>.GetRunNumber()")

AbortSignal: Template method resolution failed:
  ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void>::Define(basic_string_view<char,char_traits<char> > name, basic_string_view<char,char_traits<char> > expression) =>
    AbortSignal: abort from C++; program state was reset

input_line_135:2:49: error: expected '(' for function-style cast or type construction
auto lambda0 = [](){return TStoreGEMData<double>.GetRunNumber()
                           ~~~~~~~~~~~~~~~~~~~~~^
libc++abi: terminating with uncaught exception of type std::runtime_error: 
RDataFrame: An error occurred during just-in-time compilation. The lines above might indicate the cause of the crash
 All RDF objects that have not run an event loop yet should be considered in an invalid state.

 *** Break *** abort

The root tree has the following elements:

print(lyA_Power_data.GetColumnNames() )
{ "DataEndianness", "MIDASTime", "RawLabVIEWAsUNIXTime", "RawLabVIEWtimestamp", "RawLabVIEWtimestamp.Seconds", "RawLabVIEWtimestamp.SubSecondFraction", "RawLabVIEWtimestamp.TObject", "RawLabVIEWtimestamp.fBits", "RawLabVIEWtimestamp.fUniqueID", "RunTime", "TObject", "TStoreGEMData<double>", "TStoreGEMData<double>.DataEndianness", "TStoreGEMData<double>.MIDASTime", "TStoreGEMData<double>.RawLabVIEWAsUNIXTime", "TStoreGEMData<double>.RawLabVIEWtimestamp", "TStoreGEMData<double>.RawLabVIEWtimestamp.Seconds", "TStoreGEMData<double>.RawLabVIEWtimestamp.SubSecondFraction", "TStoreGEMData<double>.RawLabVIEWtimestamp.TObject", "TStoreGEMData<double>.RawLabVIEWtimestamp.fBits", "TStoreGEMData<double>.RawLabVIEWtimestamp.fUniqueID", "TStoreGEMData<double>.RunTime", "TStoreGEMData<double>.TObject", "TStoreGEMData<double>.TimestampEndianness", "TStoreGEMData<double>.data", "TStoreGEMData<double>.fBits", "TStoreGEMData<double>.fUniqueID", "TStoreGEMData<double>.runNumber", "TimestampEndianness", "data", "fBits", "fUniqueID", "runNumber" }

_ROOT Version: JupyROOT 6.26/06
_Platform:
_Compiler: Apple clang version 13.1.6 (clang-1316.0.21.2.5)


Hi @anevans ,

and welcome to the ROOT forum!

When passing expressions as strings to Defines or Filters, you use the column names as variable names. The very weird thing in your schema is that some of the column names seem to be C++ type names!

So when you write:

that of course confuses the interpreter because there is a type where there should be a variable name.
You might be able to work around this by aliasing the column name: df.Alias("gemdata", "TStoreGEMData<double>").Define("runnumber", "gemdata.GetRunNumber()") – but I would suggest to change the schema so that column names look like variable names and do not correspond with the value type, if possible.

Cheers,
Enrico

Enrico,

Thank you so much for your advice. using the Alias method did resolve the problem. Could you please explain how this method is different than Define?

Andrew

Hi Andrew,

See the docs :smiley: The important detail here is that Alias does not calculate anything, so it doesn’t care whether the second argument is valid code or not, while Define needs the second argument to be valid C++ code (still, it’s quite weird to use C++ types as TTree branch names, I would suggest to change the scheme if possible).

Cheers,
Enrico

Enrico,

The TStoreGEMData class is some template that has a bunch of other members. Long story, but I don’t think we want to change it at this point.

Anyway, thanks again for your help.

Andrew

To clarify, I’m just suggesting to change the name of the TTree branch, not the implementation of the class.

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