Hello,
I would like to add multidimensional vector of simple type to a TTree as an array of known size. It theory it should work, since casting of vector to arrays works. However, I get bad values stored in TTree. Here is an example code:
#include <iostream>
#include "TFile.h"
#include "TTree.h"
#include <vector>
using namespace std;
int main()
{
TFile *f = new TFile("test.root", "RECREATE");
TTree *t = new TTree("t", "t");
int arr[2][2];
vector<vector<int> > v;
t->Branch("one", arr, "one[2][2]/I");
arr[0][0]=1;arr[0][1]=2;arr[1][0]=3;arr[1][1]=4;
v.resize(2,vector<int>(2));
// v = arr;
v[0][0]=1;v[0][1]=2;v[1][0]=3;v[1][1]=4;
cout << v[0][0] << " " << v[0][1] << " " << v[1][0] << " " << v[1][1] << endl;
t->Branch("two", &v[0], "two[2][2]/I");
t->Fill();
t->Write();
f->Close();
return 9;
}