See examples in tutorials (eg tree2.C) or $ROOTSYS/test/Event.h (cxx)
See also simple example below
Rene Brun
int boldt ()
{
TFile f("filea.root", "RECREATE");
TTree *ta = new TTree("t", "tree");
cerr << "branch" << endl;
int nf = 3; //or any dynamic value
float *flovec = new float[nf];
ta->Branch("nf",&nf,"nf/I");
ta->Branch("vdc",flovec,"flovec[nf]/F");
flovec[0] = 1.1; flovec[1] = 2.2; flovec[2] = 3.3;
f.Write(); delete ta; f.Close();
}
On
Fri, 18 Nov 2005, Tomasz Bold wrote:
> Thanks,
> Is there any other way of saving variable size array in TTree?
> Preferably the one which can be later on easily turned to STL syntax.
>
>
> Regards,
> Tomasz Bold
>
> Rene Brun wrote:
>> Tomasz,
>>
>> This problem reproducible with 4.04 has been fixed a few weeks ago
>> in version 5.06
>>
>> Rene Brun
>>
>> On Thu, 17 Nov 2005, Tomasz Bold wrote:
>>
>>> Hello ROOTers,
>>> What is wrong in clode below. It crashes.
>>> I am using ROOT 4.04.02f/slc3_ia32_gcc323
>>>
>>> Regards,
>>> Tomasz Bold
>>>
>>> // code
>>> #include <TFile.h>
>>> #include <TTree.h>
>>> #include <iostream>
>>> #include <string>
>>> #include <vector>
>>>
>>>
>>> using namespace std;
>>>
>>> int main ()
>>> {
>>>
>>> TFile f("filea.root", "RECREATE");
>>> TTree ta("t", "tree");
>>>
>>> cerr << "branch" << endl;
>>> std::vector<float> *flovec = new std::vector<float>;
>>> ta.Branch("vdc","vector<float>",&flovec);
>>> // another try ta.Branch("vdc", &flovec);
>>>
>>> flovec->push_back(0.1);
>>> flovec->push_back(0.2);
>>> flovec->push_back(0.3);
>>> cerr << "fill" << endl;
>>> ta.Fill();
>>> cerr << "write" << endl;
>>> f.Write();
>>> f.Close();
>>>
>>> }
>>>
>
Received on Fri Nov 18 2005 - 10:27:09 MET
This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET