Dear All,
I came across a curious issue just now. While trying to make some tests from the command line on the Python prompt, I was trying to execute the following:
Python 2.7.15 (default, Jan 6 2020, 03:17:10)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> from xAODDataSource.Helpers import MakexAODDataFrame
>>> ROOT.xAOD.Init().ignore()
xAOD::Init INFO Environment initialised for data access
>>> df = MakexAODDataFrame( '${ASG_TEST_FILE_DATA}' )
>>> df2 = df.Define( 'run_number', 'return EventInfo.runNumber();' )
input_line_309:2:8: error: expected expression
return return EventInfo.runNumber();
^
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: 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) =>
Cannot interpret the following expression:
return EventInfo.runNumber();
Make sure it is valid C++. (C++ exception of type runtime_error)
>>>
This confused me a lot, so I wrote it up into a small shell script. And I found that the following works just fine:
import ROOT
from xAODDataSource.Helpers import MakexAODDataFrame
ROOT.xAOD.Init().ignore()
df = MakexAODDataFrame( '${ASG_TEST_FILE_DATA}' )
df2 = df.Define( 'run_number',
'''
return EventInfo.runNumber();
''' )
hist = df2.Histo1D( 'run_number' )
hist.Print()
Singularity> python test.py
xAOD::Init INFO Environment initialised for data access
TH1.Print Name = run_number, Entries= 2157, Total sum= 2157
Singularity>
But the formalism that I tried on the command line as well, doesn’t.
import ROOT
from xAODDataSource.Helpers import MakexAODDataFrame
ROOT.xAOD.Init().ignore()
df = MakexAODDataFrame( '${ASG_TEST_FILE_DATA}' )
df2 = df.Define( 'run_number',
'return EventInfo.runNumber();' )
hist = df2.Histo1D( 'run_number' )
hist.Print()
Singularity> python test.py
xAOD::Init INFO Environment initialised for data access
input_line_308:2:8: error: expected expression
return return EventInfo.runNumber();
^
Traceback (most recent call last):
File "test.py", line 9, in <module>
'return EventInfo.runNumber();' )
Exception: 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) =>
Cannot interpret the following expression:
return EventInfo.runNumber();
Make sure it is valid C++. (C++ exception of type runtime_error)
xAOD::TFileAccessTracer INFO Sending file access statistics to http://rucio-lb-prod.cern.ch:18762/traces/
Singularity>
Is this by design? Should one really not be able to use single-line short expressions like that in the Define(...)
function?
Cheers,
Attila
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.16/00
Platform: x86_64-centos7-gcc8-opt
Compiler: GCC 8