rootpy.stl
: STL Dictionary Generation¶
This module allows C++ template types to be generated on demand with ease,
automatically building dictionaries with ROOT’s ACLiC as necessary. Unlike
vanilla ACLiC, rootpy’s stl module generates and compiles dictionaries without
creating a mess of temporary files in your current working directory.
Dictionaries are also cached in ~/.cache/rootpy/
and used by any future
request for the same dictionary instead of compiling from scratch again.
Templates can be arbitrarily nested, limited only by what ACLiC and CINT can
handle.
Examples¶
import rootpy.stl as stl, ROOT
# Create a vector type
StrVector = stl.vector(stl.string)
# Instantiate
strvector = StrVector()
strvector.push_back("Hello")
MapStrRoot = stl.map(stl.string, ROOT.TH1D)
MapStrRootPtr = stl.map(stl.string, "TH1D*")
Dictionary generation type inference is flexible and can be nested:
>>> import rootpy.stl as stl
>>> import ROOT
>>> from rootpy.plotting import Hist
>>> stl.vector('int')
<class 'ROOT.vector<int,allocator<int> >'>
>>> stl.vector(int)
<class 'ROOT.vector<int,allocator<int> >'>
>>> stl.vector(long)
<class 'ROOT.vector<long,allocator<long> >'>
>>> stl.vector('vector<int>')
<class 'ROOT.vector<vector<int,allocator<int> >,allocator<vector<int,allocator<int> > > >'>
>>> stl.vector(stl.vector('int'))
<class 'ROOT.vector<vector<int,allocator<int> >,allocator<vector<int,allocator<int> > > >'>
>>> stl.vector(stl.vector(stl.vector(int)))
<class 'ROOT.vector<vector<vector<int,allocator<int> >,allocator<vector<int,allocator<int> > > > >'>
>>> stl.map('string,int')
<class 'ROOT.map<string,int,less<string>,allocator<pair<const string,int> > >'>
>>> stl.map('string', 'int')
<class 'ROOT.map<string,int,less<string>,allocator<pair<const string,int> > >'>
>>> stl.map(stl.string, int)
<class 'ROOT.map<string,int,less<string>,allocator<pair<const string,int> > >'>
>>> stl.map(str, int)
<class 'ROOT.map<string,int,less<string>,allocator<pair<const string,int> > >'>
>>> stl.map(str, stl.map(int, stl.vector(float)))
<class 'ROOT.map<string,map<int,vector<float,allocator<float> > > >'>
>>> stl.map(str, Hist)
<class 'ROOT.map<string,TH1,less<string>,allocator<pair<const string,TH1> > >'>
>>> stl.map(str, ROOT.TH1)
<class 'ROOT.map<string,TH1,less<string>,allocator<pair<const string,TH1> > >'>
>>> stl.map(str, 'TH1*')
<class 'ROOT.map<string,TH1*,less<string>,allocator<pair<const string,TH1*> > >'>
Functions¶
stl.generate (declaration[, headers, …]) |
Compile and load the reflection dictionary for a type. |