Generating a dictionary for a vector of a custom structure

Hello,

I’d like to store vectors of a custom structure, FatJetStruct. I managed to create a dictionary and a library for the class using .L /path/FatJetStruct.h+ (header attached). Could anyone explain how to create a dictionary for vector<FatJetStruct>? Preferably by calling the ROOT interpreter directly from python. Thanks.

Cheers,
Matej

FatJetStruct.h (4.1 KB)


ROOT Version: 6.24/07
Platform: CentOS 7.8.2003
Compiler: g++ (GCC) 10.3.0


Hi @mroguljic ,
one way to do it is by calling GenerateDictionary as I do here: Generate dictionary for dinamically created custom STL collections - #2 by eguiraud .

Otherwise I think adding the right #pragma link C++ class (inside a #ifdef __CLING__ guard) in FatJetStruct.h should do the job.

Cheers,
Enrico

one way to do it is by calling GenerateDictionary as I do here: Generate dictionary for dinamically created custom STL collections - #2 by eguiraud .

Sorry for omitting this in the original question, but an error occurs once the std::vector<FatJetStruct> is added to the GenerateDictionary call.

import ROOT

#ROOT.gInterpreter.GenerateDictionary("FatJetStruct","FatJetStruct.h")#Runs fine
ROOT.gInterpreter.GenerateDictionary("FatJetStruct;std::vector<FatJetStruct>","FatJetStruct.h")#Returns an error

The error starts with

In file included from /users/mrogul/Work/py3TIMBER/Zbb_SF/test/AutoDict_FatJetStruct_2404355643_cxx_ACLiC_dict.cxx:32:
/cvmfs/cms.cern.ch/slc7_amd64_gcc10/lcg/root/6.24.07-911656c6946166b2b8b55eaa4b517565/include/TCollectionProxyInfo.h: In instantiation of 'static void* ROOT::Detail::TCollectionProxyInfo::Type<T>::construct(void*, size_t) [with T = std::vector<FatJetStruct>; size_t = long unsigned int]':
/cvmfs/cms.cern.ch/slc7_amd64_gcc10/lcg/root/6.24.07-911656c6946166b2b8b55eaa4b517565/include/TCollectionProxyInfo.h:582:51:   required from 'static ROOT::Detail::TCollectionProxyInfo* ROOT::Detail::TCollectionProxyInfo::Generate(const T&) [with T = ROOT::Detail::TCollectionProxyInfo::Pushback<std::vector<FatJetStruct> >]'
/users/mrogul/Work/py3TIMBER/Zbb_SF/test/AutoDict_FatJetStruct_2404355643_cxx_ACLiC_dict.cxx:124:128:   required from here
/cvmfs/cms.cern.ch/slc7_amd64_gcc10/lcg/root/6.24.07-911656c6946166b2b8b55eaa4b517565/include/TCollectionProxyInfo.h:339:13: error: no matching function for call to 'FatJetStruct::FatJetStruct()'
  339 |             ::new(m) Value_t();
      |             ^~~~~~~~~~~~~~~~~~

Otherwise I think adding the right #pragma link C++ class (inside a #ifdef __CLING__ guard) in FatJetStruct.h should do the job.

I’m not sure what would be the proper usage of #pragma link... here. If it’s something simple, could you point me to which line should added where in the header file?

Does FatJetStruct have a default constructor? I think that’s a requirement.

I just tested this on a reduced structure and that was it. Thanks.