TTree::Branch question

I am trying to make my own class and store objects of it on a tree.
My class looks like this:


#include <TObject.h>

class Point : public TObject
  float x;
  float y;
  float z;

  Point(float x, float y, float z);
  void SetPoint(float x, float y, float z);
  float GetPointX(void);
  float GetPointY(void);
  float GetPointZ(void);

  ClassDef(Point, 1);

Point::Point(float x, float y, float z)
{ this->x = x; this->y = y; this->z = z; }

void Point::SetPoint(float x, float y, float z)
{ this->x = x; this->y = y; this->z = z; }

float Point::GetPointX(void)
{ return this->x; }

float Point::GetPointY(void)
{ return this->y; }

float Point::GetPointZ(void)
{ return this->z; }

#if !defined(_CINT_)


My program is the following.

#include <stdio.h>
#include <TFile.h>
#include <TTree.h>
#include <TObject.h>
#include "Point.cpp"

int go(void)
  if (!TClass::GetDict("Point"))
    gROOT->ProcessLine(".L Point.cpp+");

  TFile *file = new TFile("foo.root","RECREATE","practice file");
  TTree *tree = new TTree("tree1","A glorious tree");

  Point *pnt = new Point(0,0,0);
  return 0;

When I literally type what is in my program directly into the interpreter, everything seems to work fine, but when I try to do it by loading treestuff.cpp, I get the following output.

root [0] .L treestuff.cpp
root [1] go()
Error in <TTree::Branch>: The actual class (TObject) of the object provided for the definition of the branch "PointBranch" does not inherit from Point

I don’t know what to make of this error. My object *pnt seems to be of class Point, not just TObject…

in your version of treestuff.cpp, you include Point.cpp before loading the compiled code, so CINT will create its own interpreted class and you will get a mismatch between the two. The solution is to do

root > .L Point.cpp+ root > .L treestuff.C or .L treestuff.C+ root > go()
with treetuff.C without the gROOT->ProcessLine statement


Thank you very much for the help. Everything seems to work now, but there is some output that I don’t understand when I compile:

root [1] .L treestuff.C+
Info in <TUnixSystem::ACLiC>: creating shared library /root/playground/./
Error in <TUnixSystem::DynamicPathName>: libvectorDict[.so | .sl | .dl | .a | .dll] does not exist in .:/root/software/root/lib::/root/software/root/lib:/root/software/root/lib:/root/software/root/lib:/root/software/root/cint/cint/stl

Is this something I should be concerned about?

Nothing to worry to run this simple example, but you may have a problem if you use std::vector.
I would need more info about your installation.