Hello
I’m using a union to have a single interface to my data disregarding their nature. Once I try to teach root to read it, I failed (from the message I got while running). Here is a mininmal working example of a class UEntry, starting with the .h, .cxx and Linkdef file
[code]#ifndef UENTRY_H
#define UENTRY_H
//std
#include
using namespace std;
//ROOT
#include “TObject.h”
class UEntry : public TObject
{
public:
enum TAG {Double, String, Vector};
TAG tag;
string name;
union pouet {
double dou;
string *str;
vector *vec;
} val;
UEntry();
UEntry(UEntry::TAG atag, string aname="[default]");
~UEntry();
ClassDef(UEntry, 200);
};
#endif[/code]
[code]#define UENTRY_CXX
#include “UEntry.h”
ClassImp (UEntry)
UEntry::UEntry():
TObject(), tag(UEntry::Double), name("[default_const]")
{
val.dou=0;
}
UEntry::UEntry(UEntry::TAG atag, string aname):
TObject(), tag(atag), name(aname)
{
switch(tag)
{
case UEntry::Double: val.dou = -1; break;
case UEntry::String: val.str = new string(""); break;
case UEntry::Vector: val.vec = new vector(); break;
}
}
UEntry::~UEntry()
{
switch(tag)
{
case UEntry::String: delete val.str; break;
case UEntry::Vector: delete val.vec; break;
}
}[/code]
[code]#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;
#pragma link C++ union UEntry::pouet+;
#pragma link C++ class UEntry+;
#endif[/code]
I’m producing a library with a dummy makefile:
all:
rootcint -f UEntryDict.cxx -c UEntry.h UEntryLinkDef.h
g++ -fPIC `root-config --cflags --libs` -c UEntryDict.cxx
g++ -fPIC `root-config --cflags --libs` -c UEntry.cxx
g++ -shared -o UEntry.so UEntry.o UEntryDict.o
and once I execute it gives:
[quote]root [1] gSystem->Load(“UEntry.so”);
root [2] gROOT->GetClass(“UEntry”)->GetStreamerInfo()->ls()
Error in TStreamerInfo::Build: UEntry, unknown type: UEntry::pouet val
StreamerInfo for class: UEntry, version=200, checksum=0x38b15c0c
TObject BASE offset= 0 type=66 Basic ROOT object
UEntry::TAG tag offset= 16 type= 3
string name offset= 24 type=300 ,stl=365, ctype=365,
i= 0, TObject type= 66, offset= 0, len=1, method=0
i= 1, tag type= 3, offset= 16, len=1, method=0
i= 2, name type=300, offset= 24, len=1, method=0
[/quote]
Can anyone point me to what I’m doing wrong ?
For simplicity, I’m joining the three files in case someone wants to try
Thanks in advance
jb
UEntry.cxx (600 Bytes)
UEntry.h (436 Bytes)
UEntryLinkDef.h (221 Bytes)