Hi rooters,
I tried to save several vector from a vector< vector> into a root TTree. It is nessesary to save each vector into this tree seperately, to be able to use the features from TTreeViewer. Here is the smallest (not) working macro:
[code]//macro to save vector in TTree
//std. c includes
#include <stdlib.h>
#include <stdio.h>
#include
//root includes
#include “TTree.h”
#include “TFile.h”
#include “TBranch.h”
void FillTTree() {
//init vectors
std::vector *time_signal = new std::vector();
std::vector <vector > *waveform_vector = new std::vector <vector >();
//open file
f = new TFile(“Data.root”, “RECREATE”);
//define TTree
waveforms = new TTree(“waveforms”, “Tree containing Acqiris waveforms”);
waveforms->Branch(“time”,“vector”, &time_signal,1000,0);
waveforms->Branch(“channel1”,“vector”, &waveform_vector->at(0),1000,0);
waveforms->Branch(“channel2”,“vector”, &waveform_vector->at(1),1000,0);
waveforms->Branch(“channel3”,“vector”, &waveform_vector->at(2),1000,0);
waveforms->Branch(“channel4”,“vector”, &waveform_vector->at(3),1000,0);
//fill TTree
for (int events=0; events<1000; events++)
{ for (int i=0; i<4; i++)
{ waveform_vector->push_back(vector ());
for (int j=0; j<1000; j++)
{ if (i==0) time_signal->push_back(j);
waveform_vector->at(i).push_back((i+1)*j);
}
}
waveform1_vector = &waveform_vector->at(0);
waveform2_vector = &waveform_vector->at(1);
waveform3_vector = &waveform_vector->at(2);
waveform4_vector = &waveform_vector->at(3);
waveforms->Fill();
time_signal->clear();
waveform_vector->clear();
}
waveforms->Write();
f->Close();
}
[/code]
The root interpreter returns:
Error: Symbol #include is not defined in current scope FillTTree.cpp:29:
Error: Symbol exception is not defined in current scope FillTTree.cpp:29:
Syntax Error: #include FillTTree.cpp:29:
Error: Symbol G__exception is not defined in current scope FillTTree.cpp:29:
Error: type G__exception not defined FILE: FillTTree.cpp LINE:29
*** Interpreter error recovered ***
If one pass the pointer of a vector element of this vector< vector> to another 1d vector and saves this into the root Tree, everything is fine.
Is it possible to define a TTree in that way and pass such an Element to a Branch, like it is shown in the posted code??
Cheers
Toni