BOOST smart pointer in CINT

Hi,

I tried to use CINT to generate a dictionary for a library that uses BOOST library. I got the following error message

I found the following discussion seems relevant to my situation.


root.cern.ch/phpBB2/viewtopic.ph … ight=boost

However, it is discussed in 2003. I am wondering whether CIINT can deal with smart pointer now. If so, how can we do it? Thank you very much.

regards,

gma

Hi,

The 2003 date there is when Philippe joined the forum; the relevant date is actually above the post and is last Friday. So, no, nothing much changed yet. :slight_smile:

You may be able to get something to work using Reflex+Cintex. Care to post the snippet of code that you are trying to bind?

Cheers,
Wim

Hi,
Thanks a lot. Too bad root cannot deal with smart pointer now. :open_mouth: Good catch for my mistake :blush:

Here is the code I am using, I did not attach the source file which may be too big.

#ifdef __CINT__
class pthread_cond_t;
class pthread_mutex_t;
#endif

#include "ql/quantlib.hpp"

#ifdef __MAKECINT__
#pragma link off class _FTCOMSTAT-;
#pragma link off class _FTDCB-;
#endif

gma

Hi,

that’s not what I meant with a code snippet … what are you actually trying to achieve? E.g. QuantLib has (according to their docs) SWIG bindings? Also, the header that you include there is just the whole kit and kaboodle in QuantLib, not something that you would be after?

Anyway, here’s a sample to show you have things work with Reflex:[code] cat selection.xml <lcgdict> <class name="QuantLib::Payoff" /> <class name="boost::shared_ptr<QuantLib::Payoff>" /> </lcgdict> cat gma.h
#include “ql/quantlib.hpp”
genreflex gma.h -s selection.xml g++ -I$ROOTSYS/include gma_rflx.cpp -shared -o libgma.so -lQuantLib
$ python

import PyCintex
PyCintex.loadDictionary( “gma.so” )
a = PyCintex.gbl.boost.shared_ptr(‘QuantLib::Payoff’ )()
print a
<ROOT.boost::shared_ptrQuantLib::Payoff object at 0x84e5b30>
[/code]

HTH,
Wim

Wlav,
Sorry for my late response. Totally distracted by other stuffs. Thank for your solution. :smiley: I will give them a try this week.

cheers,

gma

Wim,
You are right. I hope I can use all Quantlib classes in CINT. So it requires some reflex for the classes. Thank for your Python solution. I did not do any investigation along this line. A quick question is whether I can save this payoff class into tree? Thank you again.

cheers,

gma

Hi,

probably, but you’re posting in the PyROOT forum, so I’m giving you python answers. :slight_smile: For use with CINT, add these two lines to your script:ROOT::Cintex::Cintex::Enable(); gSystem->Load( "libgma" );

Quick? Don’t think so: Payoff is an abstract class, so no, that can not be stored, as it can’t be instantiated. Also, you’re going to have trouble with most other Payoff classes since they do not have default ctors, which are necessary for the persistency layer to be able to create “blank” objects.

But here’s a simplistic example:[code] cat selection.xml <lcgdict> <class pattern="QuantLib::*Payoff" /> <class name="QuantLib::Option" /> <class name="std::unary_function<double,double>" /> </lcgdict> cat gma.h
#include “ql/quantlib.hpp”
genreflex gma.h -s selection.xml g++ -I$ROOTSYS/include gma_rflx.cpp -shared -o libgma.so -lQuantLib
$ cat fixup.cxx
#include “ql/quantlib.hpp”
#include “TClass.h”

void* newPlainVanillaPayoff( void* ) {
return new QuantLib::PlainVanillaPayoff( QuantLib::Option::Put, 0. );
}

static struct initPlainVanillaPayoffCtor {
initPlainVanillaPayoffCtor() {
TClass* cl = TClass::GetClass( “QuantLib::PlainVanillaPayoff” );
cl->SetNew( newPlainVanillaPayoff );
}
} initPlainVanillaPayoffCtor_;
$ g++ -shared -I$ROOTSYS/include fixup.cxx -o fixup.so
$ cat writetree.py
import PyCintex, ROOT

PyCintex.loadDictionary( ‘gma.so’ )
ql = PyCintex.gbl.QuantLib

f = ROOT.TFile( ‘gma.root’, ‘recreate’ )
t = ROOT.TTree( ‘gma’, ‘my payoff’ )

b = ql.PlainVanillaPayoff( ql.Option.Call, 10. )

t.Branch( ‘payoff1’, b )

t.Fill()
t.Write()
f.Close()
$ cat readtree.py
import PyCintex, ROOT

PyCintex.loadDictionary( ‘gma.so’ )
ROOT.gSystem.Load( “fixup” )

f = ROOT.TFile( ‘gma.root’, ‘read’ )
gma = f.gma

gma.GetEntry(0)
print gma.payoff1.strike()
python writetree.py python readtree.py
10.0[/code]

HTH,
Wim