I run the attached code in my Xcode project and I get the following error message at runtime:
[ul]Error in TTree::Branch: The pointer specified for mystring is not of a class or type known to ROOT[/ul]
The output file is written and contains myfloat but not mystring.
It is obviously a problem with dictionaries. I tried various incantations suggested in other posts about generating my own dictionary without success. I guess Root must have already dictionaries for such common types as , so the problem must be where those dictionaries are and how do I tell Xcode to get at them.
I’d be grateful for any help you could offer.
Thanks
Luciano
I am running Xcode Version 4.6.2 (4H1003)
Mac OS X 10.8.5
Here is my code:
//
// Adapted from https://root-forum.cern.ch/t/problem-in-getting-the-vector-vector-string-branch/14608/1
//
#include <string>
#include <vector>
#include "TFile.h"
#include "TTree.h"
void write_tree(const char *file_name = "trial.root")
{
if (!file_name || !(*file_name)) return; // just a precaution
TFile *f = new TFile(file_name, "RECREATE");
TTree *tree = new TTree("tree", "tree");
float myfloat;
tree->Branch("myfloat", &myfloat);
std::string mystring;
tree->Branch("mystring", &mystring);
tree->Fill();
tree->Write();
delete f;
}
void trial(const char *file_name = "trial.root")
{
if (!file_name || !(*file_name)) return; // just a precaution
write_tree(file_name);
}
int main(int argc, char **)
{
trial("trial.root"); // just call the "ROOT Script"
return 0;
}