ClassDefInline: How do I use it (non-interactive mode)?

Hello,

Although the title of this post is similar to a previous post of mine (How to use ClassDefInline?), I still can’t seem to get ClassDefInline to work as expected in non-interactive mode (interactive mode works fine).

foo.h

#include <Rtypes.h>

class Foo {
 public:
  Foo() {}
  Foo(int foo) : foo_(foo) {}
  int GetFoo() { return foo_; }

 private:
  int foo_ = 42;
  ClassDefInlineNV(Foo, 1);
};

main.cc

#include "foo.h"

#include <iostream>
#include <TFile.h>

int main() {
  Foo foo(123);
  TFile f("foo.root", "RECREATE");
  f.WriteObject(&foo, "foo_object");
  f.Close();

  TFile f2("foo.root");
  Foo* foo2 = nullptr;
  f2.GetObject("foo_object", foo2);

  std::cout << foo2->GetFoo() << std::endl;
  return 0;
}

Output

Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::RegisterStreamerInfo>: Register StreamerInfo for Foo on non-empty slot (-1).
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
Error in <TClass::LoadClassInfo>: no interpreter information for class Foo is available even though it has a TClass initialization routine.
42

Running the code in main.cc in the interpreter works just fine. How should I be passing the interpreter information in non-interactive mode?

Cheers,
Ahmad


ROOT Version: v6.18/04
Platform: Ubuntu 16.04
Compiler: Not Provided


If you do not generate a dictionary for the class you will need to load the interpreter information by hand. For example:

gInterpreter->Declare("#include \"foo.h\");

Thanks @pcanal, that works :slight_smile: Any idea why I get the following warning though?

Warning in TClassTable::Add: class Foo already in TClassTable

I added the include statement as the first line of my main function.

Hi,

I had not paid attention that you are trying to do I/O on that object. Currently we do not fully support I/O for interpreted classes (mostly because we are missing support for the I/O collection but also because we are missing the suppression and/or handling of a few warning messages … include the TClassTable::Add …).

If you can not generate a dictionary for Foo, it might be good enough to suppress the warning message (and/or ignore it).

Cheers,
Philippe.

1 Like

Ah okay. In reality we are not trying to do I/O with the ClassDefInline. In this reproducer I just used I/O because it reproduced the same type of errors. But in our library, we wish to generate class information required by ROOT’s plugin manager to load our own own classes as part of a plugin.

I just tested; in that case we do not get the warning :slight_smile:

Many thanks for your help!

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