TTreeReaderArray with branch of variable size array

Hello,

I’m currently trying to use a TTreeReaderArray with a TChain. The branch I’m examining (called time_truth) is a variable size array. However, I get an error (I think it results when I declare the TTreeReaderArray) because the branch that the array’s size is linked to has elements of type long.

Here’s my code:

    TChain *ch = new TChain("events/events");
    TChain *fax_truth = new TChain("fax_truth_sort");
    // chain files

    TH2D *h = new TH2D("h","Fax_truth vs Fax_t", 350, -500, 3000, 7000, 0, 7000);
    TTreeReader r1(ch);
    TTreeReaderValue<vector<float>> Fax_t(r1, "Fax_t");
    TTreeReader r2(fax_truth);
    TTreeReaderArray<double> Fax_truth(r2, "time_truth"); // error occurs here
    //TTreeReaderValue<long> pl(r2, "peaks_length");
    
    while(r1.Next() && r2.Next()){
        vector<float> fax_t_data = *Fax_t;
        for(int i = 0; i < fax_t_data.size(); i++){
            if(Fax_truth.GetSize() == 4){
                Double_t s1_dt = Fax_truth[2] - Fax_truth[0];
                int bin = h->GetBin(s1_dt, fax_t_data.at(i));
                h->AddBinContent(bin);
            }
        }
    }

This branch that the size of time_truth is linked to is called peaks_length. Here’s the error I get:

Error in <CreateProxy()>: The branch peaks_length contains data of type long long. It cannot be accessed by a TTreeReaderValue<int>

I’m not sure why ROOT is giving me this error. I’ve changed the type of Fax_truth to Double_t but I get the same error. I appreciate any feedback! Thanks!

Hi,
what happens if you follow the error message’s suggestion and define "peaks_length" as long long? I.e.

TTreeReaderValue<long long> pl(r2, "peaks_length");

(I don’t understand why you changed Fax_truth to Double_t, the error is due to branch peaks_length as the error message says)

I think I understand (@eguiraud - the TTreeReaderArray currently sets up a TTreeReaderValue to read the branch / leaf count, and it got its underlying type wrong):

In principle, only int is supported as array size. But in reality we never really enforced that, so now TTreeReader needs to handle this case.

I’m (I was, actually) working on changing the way TTreeReaderArray reads its data; let me resume that - soon - and I’ll check this case. I have created https://sft.its.cern.ch/jira/browse/ROOT-8952 for me to remember this.

Would you be able to share a file with that tree, even if it’s just one tree entry? I need a test case to make sure that the new code (once I have it) is actually solving this!

Cheers, Axel.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.