Hi,
probably, but you’re posting in the PyROOT forum, so I’m giving you python answers. 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