AttributeError: 'TTree' object has no attribute 'AsMatrix'

I am trying to execute the example mentioned here: https://root.cern.ch/doc/master/pyroot002__TTreeAsMatrix_8py.html

It converts the data in TTree’s to a numpy array.
However, I am receiving the error:
AttributeError: ‘TTree’ object has no attribute ‘AsMatrix’

What am I missing in the code?

This is a new interface in ROOT, what version of ROOT are you using?

I am using the 6.10/09 ROOT version. This is in my university cluster. I also tried in lxplus where the version is 6.12/07.

Those versions of ROOT do not have the interface you want to use. I don’t remember which version of ROOT it first became available, but it’s no earlier than 6.14. Please try to load from CVMFS a newer version of ROOT, e.g. 6.16/00.

I switched to Root 6.16.00 with the following command:
source /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.16.00/x86_64-centos7-gcc48-opt/bin/thisroot.sh

However, this has unset several paths.

Initially, python is not running. Once I added python to my path, then numpy cannot be imported.

I think this is a bug, is it?

Note that the binary release that you try to use expects the standard default CentOS 7 operating system provided Python 2.7.5 (and I get no problems with it on my system).

I think lcg/app/releases only contains ROOT. If you want a full environment you can try lcg/views/LCG_94/x86_64-centos7-gcc8-opt/setup.sh

I tried your command and I get the following error:

cling::DynamicLibraryManager::loadLibrary(): /cvmfs/cms.cern.ch/slc6_amd64_gcc630/cms/cmssw/CMSSW_9_4_9/lib/slc6_amd64_gcc630/libDataFormatsStdDictionaries.so: undefined symbol: ZN5TROOT14RegisterModuleEPKcPS1_S2_S1_S1_PFvvERKSt6vectorISt4pairINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiESaISD_EES2

Error in <TInterpreter::TCling::AutoLoad>: failure loading library libDataFormatsStdDictionaries.so for allocator<double>

Fatal in <TClass::SetUnloaded>: The TClass for allocator<double> is being unloaded when in state 3

Could you report what steps are needed to reproduce this failure?
This works for me on lxplus7 (i.e. centos7, similarly on lxplus and slc6):

~ ssh eguiraud@lxplus7.cern.ch
Password: 
Last login: Tue Feb 12 19:40:17 2019 from cern762.dyndns.cern.ch
[eguiraud@lxplus031 ~]$ source /cvmfs/sft.cern.ch/lcg/views/LCG_94/x86_64-centos7-gcc8-opt/setup.sh
[eguiraud@lxplus031 ~]$ root -b
   ------------------------------------------------------------
  | Welcome to ROOT 6.14/04                http://root.cern.ch |
  |                               (c) 1995-2018, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tags/v6-14-04@v6-14-04, Aug 23 2018, 17:00:44         |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] TH1F h
(TH1F &) Name:  Title:  NbinsX: 1
root [1] .q
[eguiraud@lxplus031 ~]$ python
Python 2.7.15 (default, Jul 30 2018, 09:42:34) 
[GCC 8.1.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> ^D
[eguiraud@lxplus031 ~]$ 

I wrote the previous comment in a confusing manner. The error was not from the command you gave but from running the file afterwards.

So, with the command you provided, I was able to change the ROOT version from 6.12/07 to 6.14/04.

The error came when I tried to run the file mentioned here:

https://root.cern.ch/doc/master/pyroot002__TTreeAsMatrix_8py.html

I am getting the following error when I run the file:

Error in <TInterpreter::TCling::AutoLoad>: failure loading library libDataFormatsStdDictionaries.so for allocator<double>

Fatal in <TClass::SetUnloaded>: The TClass for allocator<double> is being unloaded when in state 3

This works for me:

~ ssh eguiraud@lxplus7.cern.ch
Password: 
[eguiraud@lxplus054 ~]$ source /cvmfs/sft.cern.ch/lcg/views/LCG_94/x86_64-centos7-gcc8-opt/setup.sh
[eguiraud@lxplus054 ~]$ python "$ROOTSYS/tutorials/pyroot/pyroot002_TTreeAsMatrix.py"
Tree content:
[[ 0.  0.]
 [ 1. -1.]
 [ 2. -2.]
 [ 3. -3.]]
...
Tree converted to a pandas.DataFrame:
     x    y
0  0.0  0.0
1  1.0 -1.0
2  2.0 -2.0
3  3.0 -3.0
[eguiraud@lxplus054 ~]$ 

What are we doing differently?

You are comparing apples and oranges:
x86_64-centos7-gcc48-opt is for CentOS 7
slc6_amd64_gcc630 is for SLC 6

I found out what was going wrong.
When I try your command without “cmsenv” then it is working fine.

If I do “cmsenv” followed by your command then it is giving the error.

I think by doing “cmsenv” followed by “source /cvmfs/sft.cern.ch/lcg/views/LCG_94/x86_64-centos7-gcc8-opt/setup.sh” I am messing with the shared libraries.

Yes this is highly probable

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