Newbye: can't load root file in standalone program

Hi,

I’d like to access data in a ROOT file from a standalone application.
I’m basically doing what’s in the test code below which I compile with :

g++ -g -Wall -o test test.cpp -I$HOME_WAT/include" -L$HOME_WAT/lib -Wl,-static -lwavelet -Wl,-Bdynamic root-config --cflags --glibs

I receive a segmentation violation. See full transcript at the end of the message.
inputfile.Get(“V1:4”) returns NULL but the data is there! When I run test() in
interactive mode, everything goes fine.

Any help would be greatly appreciated!
Eric

# include <iostream>
#include "TFile.h"
#include "wseries.hh"

using namespace std;

void test()
{
    TFile inputfile("file.root");
    inputfile.ls();
    WSeries<double>* wavelet_transform = (WSeries<double>*)inputfile.Get("V1:4");
  cout << wavelet_transform->size() << endl;
}

# ifndef __CINT__
int main()
{
  test();
  return 0;
}
# endif

ecm@titan1:~/graph$ ./test
Warning in TUnixSystem::SetDisplay: DISPLAY not set, setting it to XXXXX:0.0
Warning in TClass::TClass: no dictionary for class slice is available
Warning in TClass::TClass: no dictionary for class WDM is available
Warning in TClass::TClass: no dictionary for class Wavelet is available
Warning in TClass::TClass: no dictionary for class SymmObjArray<SymmArraySSE > is available
Warning in TClass::TClass: no dictionary for class SymmArraySSE is available
TFile** file.root
TFile* file.root
KEY: WSeries L1:8;1
KEY: WSeries H1:8;1
KEY: WSeries V1:8;1
KEY: WSeries L1:7;1
KEY: WSeries H1:7;1
KEY: WSeries V1:7;1
KEY: WSeries L1:6;1
KEY: WSeries H1:6;1
KEY: WSeries V1:6;1
KEY: WSeries L1:5;1
KEY: WSeries H1:5;1
KEY: WSeries V1:5;1
KEY: WSeries L1:4;1
KEY: WSeries H1:4;1
KEY: WSeries V1:4;1
KEY: WSeries L1:3;1
KEY: WSeries H1:3;1
KEY: WSeries V1:3;1
Error in TKey::ReadObj: Unknown class WSeries

*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

stat_loc=0x7fff48dcda5c, options=<value optimized out>)
at ../sysdeps/unix/sysv/linux/waitpid.c:32

#0 0x00007f6ac216083e in __libc_waitpid (pid=,
stat_loc=0x7fff48dcda5c, options=)
at …/sysdeps/unix/sysv/linux/waitpid.c:32
#1 0x00007f6ac20fe2c9 in do_system (line=)
at …/sysdeps/posix/system.c:149
#2 0x00007f6ac69c3668 in TUnixSystem::StackTrace() ()
from /home/waveburst/SOFT/ROOT/root-v5-32-04.patched/lib/libCore.so
#3 0x00007f6ac69c2163 in TUnixSystem::DispatchSignals(ESignals) ()
from /home/waveburst/SOFT/ROOT/root-v5-32-04.patched/lib/libCore.so
#4
#5 0x0000000000400e36 in test () at test.cpp:12
#6 0x0000000000400ead in main () at test.cpp:18

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x0000000000400e36 in test () at test.cpp:12
#6 0x0000000000400ead in main () at test.cpp:18

Hi,

as the error message says, you miss the dictionaries for reading back your WSeries objects. What is the library which they reside? How was the file written?
First of all, you should load them before attempting to read the file.

Danilo

Thanks Danilo for your message.

I have the C++ source where WSeries object is defined. To generate the dictionary,
I understand that I need to use rootcint. Is that correct?

Once it is generated, how do I load the dictionary from my standalone application?

Eric

Hi Eric,

to generate the dictionary you need rootcint or genreflex (root5 supports these two “flavours” - in the end they are 2 equivalent ways of filling the root’s internal typesystem).
The chain of steps to be followed is the following:

  1. generate the dictionary for the class. The output is a cpp autogenerated file
  2. compile this file into a shared library.
  3. load the library using something like “gSystem->Load(“libMylib.so”)” (alternatively root can load on demand automatically the library provided that you write out a rootmap file like those in the $ROOTSYS/lib directory or let genreflex build one for you automatically)

Cheers,
Danilo