Can't get object from root file

Hi all, this is probably a pretty simple one for most but I’m really struggling with this one. I suck at reading root file. Anyway here is the issue. I have data in a root file like so:

tree

I am trying to get the objects in PanelDIGI out. But I just cannot figure it out.

I have tried:

    TFile* f = get_file(1);
    TTreeReader* t=new TTreeReader("a2MC",f);
    std::cout << "Number of events: " << t->GetEntries() << "\n";
    TTreeReaderValue<a2mcPanelDIGI> panelDIGI(*t, "PanelDIGI");
    t->Next();

which results in Error in <TTreeReaderValueBase::CreateProxy()>: The branch PanelDIGI contains data of type TClonesArray. It cannot be accessed by a TTreeReaderValue<a2mcPanelDIGI>

and

    std::unique_ptr<TFile> myFile( TFile::Open("../root/a2MC-2023-01-30-09-33-25_0.root") );
    auto tree = myFile->Get<TTree>("a2MC");
    a2mcPanelDIGIvariable;
    tree->SetBranchAddress("PanelDIGI", &variable);
    tree->GetEntry(0);

which gives

Error in <TTree::SetBranchAddress>: The address for "PanelDIGI" should be the address of a pointer!
Error in <TTree::SetBranchAddress>: The pointer type given (a2mcPanelDIGI) does not correspond to the class needed (TClonesArray) by the branch: PanelDIGI

If anyone could help that would be great.

Cheers


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Actually I may have found a way forward but not quite:

    TFile* f = get_file(1);
    TTreeReader* t=new TTreeReader("a2MC",f);
    std::cout << "Number of events: " << t->GetEntries() << "\n";
    TTreeReaderValue<TClonesArray> array(*t, "PanelDIGI");
    t->Next();
    a2mcPanelDIGI* digi =     (a2mcPanelDIGI*)clonearray->At(0);

but then the digi is just a nullptr

Sorry for my slow response, @lgolino .

Can I get access to an example file that shows the problem? It could well be that you have found a deficiency in TTreeReader… but I’d like to verify that.

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