Beispiel #1
0
def test_stl():
    generate('map<int,vector<float> >', '<vector>;<map>')
    generate('map<int,vector<int> >', '<vector>;<map>')
    generate('vector<TLorentzVector>', '<vector>;TLorentzVector.h')

    ROOT.std.map('int,vector<float>')
    ROOT.std.map('int,vector<int>')
    ROOT.std.vector('TLorentzVector')

    temp = CPPType.from_string('vector<vector<vector<int> > >')
    temp.ensure_built()

    stl.vector('vector<map<int, string> >')
    stl.vector(stl.string)()
    stl.vector('string')()
    stl.vector(int)

    stl.map("string", "string")
    stl.map(stl.string, stl.string)
    stl.map(int, stl.string)
    stl.map(stl.string, int)
    stl.map("string", ROOT.TLorentzVector)

    histmap = stl.map("string", ROOT.TH1D)()
    a = ROOT.TH1D("a", "a", 10, -1, 1)
    histmap["a"] = a

    StrHist = stl.pair(stl.string, "TH1*")

    generate('pair<map<string,TH1*>::iterator,bool>', '<map>;<TH1.h>')
    histptrmap = stl.map(stl.string, "TH1*")()
    histptrmap.insert(StrHist("test", a))

    assert histptrmap["test"] is a
Beispiel #2
0
def load_event_class(filename, force_recompile=False):
    """Read a C++ root class definition from filename, generating dictionaries for vectors of classes
    Or, if the library hass been compiled before, load it.
    """
    # Load , or if necessary compile, the file in ROOT
    # Unfortunately this must happen in the current directory.
    # I tried rootpy.register_file, but it is very weird: compilation is triggered only when you make an object
    # I then tried to make a object right after, but get a weird segfault later... don't we all just love C++...
    libname = get_libname(filename)
    if os.path.exists(libname) and not force_recompile:
        if ROOT.gSystem.Load(libname) not in (0, 1):
            raise RuntimeError("failed to load the library '{0}'".format(libname))
    else:
        ROOT.gROOT.ProcessLine('.L %s+' % filename)

    # Generate dictionaries for vectors of custom classes
    # If you don't do this, the vectors will actually be useless sterile root objects
    for name in find_class_names(filename):
        stl.generate("std::vector<%s>" % name, ['<vector>', "%s" % filename], True)