Home | News | Documentation | Download

Problem build/load std::vector<double> in ROOT when using Python

Hi,

I am trying to read a std::vector object using ROOT in Python but I am getting an error as std::vector is not supported. I tried to create a file mydict.h

#ifndef __MYDICT_H_
#define __MYDICT_H_
#if defined(__ROOTCLING__)
#pragma link C++ class std::vector <double>+;
#endif
#endif // __MYDICT_H_

and load ROOT and mydict.h as follows to the python file to be executed

from ROOT import gROOT
gROOT.LoadMacro('$ROOTCOREDIR/scripts/load_packages.C')
gROOT.ProcessLine(".L LinkDef.h");

However, I am still getting an ERROR that std::vector is not supported. I suspect that I am not building mydict.h with ROOT correctly but I am unsure how to solve the problem.
ROOT Version:6.16

Thanks you for your time and help!

@etejedor might be able to help

Hello,

I understand you would like to read an std::vector stored in a ROOT file? Or stored as a branch of a TTree in a ROOT file?

Hi @etejedor,

It is stored as metadata.

Do you mean stored as user info in a TTree?

How would you retrieve that std::vector in C++?

With xAOD.MakeTransientMetaTree(infile)

Ok, then it’s stored in a TTree. You should not need your own dictionaries to read std::vectors from a TTree, right @Axel ?

that is correct (all the dictionary and/or setup needed for std::vector of numerical types is already provided)

I expected it to be loaded as well. However, when calling xAOD.MakeTransientMetaTree(infile) I get the following error

Preformatted text` TClass::BuildRealData     ERROR   Inspection for allocator<double> not supported!
TStreamerInfo::Build      WARNING _Vector_base<double,allocator<double> >: _Vector_base<double,allocator<double> >::_Vector_impl has no streamer or dictionary, data member "_M_impl" will not be saved
TStreamerInfo::Build      WARNING allocator<double>: base class __gnu_cxx::new_allocator<double> has no streamer or dictionary it will not be saved
TStreamerInfo::Build      WARNING _Vector_base<double,allocator<double> >::_Vector_impl: base class allocator<double> has no streamer or dictionary it will not be saved
TStreamerInfo::Build      ERROR   _Vector_base<double,allocator<double> >::_Vector_impl, discarding: double* _M_start, no [dimension]

TStreamerInfo::Build      ERROR   _Vector_base<double,allocator<double> >::_Vector_impl, discarding: double* _M_finish, no [dimension]

TStreamerInfo::Build      ERROR   _Vector_base<double,allocator<double> >::_Vector_impl, discarding: double* _M_end_of_storage, no [dimension]

humm … Most of TStreamerInfo::Build is not even supposed to be executed for STL collections.
So something is likely unusual in your setup.

ROOT Version:6.16

This is quite old. Can you try v6.22/06?

A few more question on your installation?

  • How did you build and/or install and/or access this version of ROOT
  • Which compiler and operating system do you use?
  • Is the version of ROOT matching the compiler and OS?
  • What is the exact trigger of the error message (i.e. which line of code inside calling xAOD.MakeTransientMetaTree(infile) )?
  • What is the shortest piece of code that triggers the message?
  • Is there any other warnings or messages?

Cheers,
Philippe.

PS. Side notes:

gROOT.ProcessLine(".L LinkDef.h");

LinkDef.h are not meant to be loaded during a ROOT sessions. Instead they are supposed to be passed to rootcling which generate a source file which then needs to be compiled and then linked into a shared library.

To generate a dictionary on the fly one of the simplest options is:

gInterpreter->GenerateDictionary("svector<vector<int> >", "vector");
gInterpreter->GenerateDictionary("vector<vector<float> >;list<vector<float> >","list;vector");

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