I want to handle trees like this:
******************************************************************************
*Tree :Expcvadc : Event "Expcvadc", ID 3 *
*Entries : 398 : Total = 27171 bytes File Size = 27187 *
* : : Tree compression factor = 1.00 *
******************************************************************************
*Br 0 :ADC0 : nADC0/I:ADC0[nADC0]/s *
*Entries : 398 : Total Size= 16572 bytes File Size = 16003 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
*Br 1 :TIME : nTIME/I:TIME[nTIME]/D *
*Entries : 398 : Total Size= 10216 bytes File Size = 9635 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 *
*............................................................................*
These trees contain branches with arrays. I want to dump some values into text
file, e.g.,
0 3958 0 1.00 1.00
...
3 1926 3522 3.00 0.00
4 3958 0 4.00 1.00
...
9 3960 0 14.00 0.00
If only to handle branches with int arrays (e.g., “nADC0/I:ADC0[nADC0]/s”), the
following code works fine:
typedef struct MY_ADC_STRUCT {
Int_t m_nADC;
Short_t m_ADC[16];
} MY_ADC;
ofstream fout("treedump.txt");
MY_ADC rADC0;
TFile* f=new TFile("mydata.root");
TTree* T=(TTree*) f->Get("Expcvadc");
T->SetBranchAddress("ADC0", &rADC0);
for(Long64_t i=0;i<T->GetEntries(); i++) {
fout << i << " " << rADC0.m_ADC[0] << std::endl;
}
But if the branches contain double arrays (e.g., “nTIME/I:TIME[nTIME]/D”), the following code works
quite unexpectedly. I got only zeros.
typedef struct MY_TIME_STRUCT {
Int_t m_nTIME;
Double_t m_TIME[2];
} MY_TIME;
ofstream fout("treedump.txt");
MY_TIME rTIME;
TFile* f=new TFile("mydata.root");
TTree* T=(TTree*) f->Get("Expcvadc");
T->SetBranchAddress("TIME", &rTIME);
for(Long64_t i=0;i<T->GetEntries(); i++) {
fout << i << " " << rTIME.m_TIME[0] << std::endl;
}
I checked the ROOT manual, and searched the web. I didn’t find the reason. I
also tried the “T->MakeClass(…)” and “T->MakeSelector(…)”. At last, only the
generated selector works expectedly. All the test files including root data are
attached here.
I want to know, why the similar code works only with int arrays.
dump_test.tgz (15.4 KB)