Add enum class in namespace to Root

I have a hh file


#ifndef _Definitions_hh_
#define _Definitions_hh_
namespace Definitions
{
  enum class WorkEnum_t {RECO, GEN};
  ClassDef(WorkEnum_t, 1)
}
#endif

and a LinkDef file

#ifdef __MAKECINT__
#pragma link off all class;
#pragma link off all function;

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ enum class Definitions::WorkEnum_t;
#endif

My goal is to add Definitions::WorkEnum_t to Root, but not the whole namespace Definitions (other members are defines in other .hh files).

rootcint generators errors:

rootcint -f src/WorkEnum_tDict.cc -rmf lib/WorkEnum_t.rootmap -c interface/WorkEnum_t.hh linkdef/WorkEnum_tLinkDef.h
In file included from input_line_11:6:
./interface/WorkEnum_t.hh:6:3: error: expected unqualified-id
  ClassDef(WorkEnum_t, 1)
...

Could you please help?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Just remove the ClassDef from your header [It is only for classes].

Some ingredients are still missing

In cling I do:

root [0] gSystem -> Load("/path/to/libexternal.so")

Definitions::WorkEnum_t k
ROOT_prompt_1:1:1: error: 'Definitions' is not a class, namespace, or enumeration
Definitions::WorkEnum_t k
^
ROOT_prompt_1:1:1: note: 'Definitions' declared here

What here is the above error message refering to?

What is wrong and what could I check?

Are the .hh files and linkdef files correct?


#ifndef _Definitions_WorkEnum_t_hh_
#define _Definitions_WorkEnum_t_hh_
//ClassDef(Definitions::WorkEnum_t, 1) https://root-forum.cern.ch/t/add-enum-class-in-namespace-to-root/47925/2                                                                  
namespace Definitions
{
  enum class WorkEnum_t {RECO, GEN};
}
#endif
// some C++ header definition                                                                                                                                                    
#ifdef __MAKECINT__
// turns off dictionary generation for all                                                                                                                                       
#pragma link off all class;
#pragma link off all function;

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
//#pragma link C++ enum class Definitions::WorkEnum_t;                                                                                                                           
#pragma link C++ namespace Definitions;
#endif

Did you include src/WorkEnum_tDict.cc object file inside /path/to/libexternal.so ?

yes. But Definitions::WorkEnum_t is still completely invisible to Root. Is it sufficient to just call gSystem → Load()?

I advanced a bit further (by loading other prerequisite libraries). Now Definitions is visible in cling, but ROOT says “I see it but I don’t know what it is”.

root [0] Def
DefAplGivens
DefGivens
DefHouseHolder
DefaultErrorHandler
Definitions
root [0] Definitions::Error in <TClass::LoadClassInfo>: no interpreter information for class Definitions is available even though it has a TClass initialization routine.

Definitions::WorkEnum_t k
ROOT_prompt_0:1:1: error: 'Definitions' is not a class, namespace, or enumeration
Definitions::WorkEnum_t k
^
ROOT_prompt_0:1:1: note: 'Definitions' declared here

From this specific error message can you suggest what to check/fix?

Would it help if I gave you the contents of WorkEnum_t.rootmap, WorkEnum_tDict.o WorkEnum_tDict_rdict.pcm and WorkEnum_tDict.cc or can you suggest specific things what to look at in these files?

There is another error from compilation with CMSSW scram that could suggest the root of this problem. WorkEnum_tDict_rdict.pcm is placed in the lib directory of the external directory.


Error in <TCling::RegisterModule>: cannot find dictionary module WorkEnum_tDict_rdict.pcm
*** Error in `python': corrupted size vs. prev_size: 0x000000000533fba0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x80c37)[0x7f83d1c31c37]
/lib64/libc.so.6(+0x82135)[0x7f83d1c33135]
/lib64/libc.so.6(__libc_malloc+0x4c)[0x7f83d1c3678c]
/cvmfs/cms.cern.ch/slc7_amd64_gcc630/external/gcc/6.3.0/lib64/libstdc++.so.6(_Znwm+0x18)[0x7f83d0d958c8]
/cvmfs/cms.cern.ch/slc7_amd64_gcc630/cms/cmssw/CMSSW_9_4_11/external/slc7_amd64_gcc630/lib/libCling.so(_ZN5cling17IncrementalParser18getAllTransactionsEv+0x94)[0x7f83cc27f804]
/cvmfs/cms.cern.ch/slc7_amd64_gcc630/cms/cmssw/CMSSW_9_4_11/external/slc7_amd64_gcc630/lib/libCling.so(_ZN5cling11Interpreter29runAndRemoveStaticDestructorsEv+0x22)[0x7f83cc22cf32]

This is strange. Can you try to add the directory that contains the library and the pcm file to the LD_LIBRARY_PATH shell environment variable?

Note; not finding this file might explain the error messages about not knowing the namespace.

I have now progressed further and with a testfunc I manage to wake up Definitions:

root [1] Definitions::WorkEnum_t k
ROOT_prompt_1:1:1: error: 'Definitions' is not a class, namespace, or enumeration
Definitions::WorkEnum_t k
^
ROOT_prompt_1:1:1: note: 'Definitions' declared here
root [2] testfunc()
testfunc
root [3] Definitions::WorkEnum_t k
(Definitions::WorkEnum_t) (Definitions::WorkEnum_t::RECO) : (int) 0

This magic is described here Bug in invocation of namespace in Root - #2 by Viesturs

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