Reading and writing ttrees

I have a program that reads a tree from a file and writes the tree to another file based on a selection. The initialization takes place in one routine, selection and fill in another, and writing in a third. The problem is this: if I look at the tree after CloneTree(0) at initialization I see all the branches of the tree. If I look at the tree in the selection routine, I see the header, but not the branches. Clearly, there is something I am missing. Code and output follow.

The initialization of the write tree looks like this:

  if(writeTreeEvent==0){
    std::cout << "writeTreeEvent not found - creating" << std::endl;
    fsel->cd();
    writeTreeEvent=new TTree("myEvent","Selected Events");
    writeTreeEvent=myEvent->CloneTree(0);
    writeTreeEvent->Write();
    writeTreeEvent->Print("all");
    std::cout << "writeTreeEvent - created" << std::endl;
  }

and the write after the selection looks like this:

    if(deltaT>100.e-9){
      //                                                                                                                                
      // Write selected event                                                                                                           
      //                                                                                                                                
      std::cout << "Fill selected event" << std::endl;
      TTree* writeTreeEvent=(TTree*) cB->fsel->Get("myEvent");
      cB->fsel->cd();
      writeTreeEvent->Print("all");
      writeTreeEvent->Fill();
}

the final write looks like this

  TFile* fsel=cB->fsel;
  fsel->cd();
  TTree* wt=(TTree*) fsel->Get("myEvent");
  std::cout << "wt " << wt->GetEntries() << std::endl;
  wt->Write();

Print"all") of the tree at initialization,

writeTreeEvent not found - creating
******************************************************************************
*Tree    :myEvent   : event data                                             *
*Entries :        1 : Total =          165104 bytes  File  Size =      35137 *
*        :          : Tree compression factor =   4.69                       *
******************************************************************************
*Br    0 :nChan     : nChan/I                                                *
*Entries :        1 : Total  Size=        561 bytes  File Size  =         79 *
*Baskets :        1 : Basket Size=      51200 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :trace1V   : trace1V[nChan]/F                                       *
*Entries :        1 : Total  Size=      40678 bytes  File Size  =      10030 *
*Baskets :        1 : Basket Size=    6394368 bytes  Compression=   4.00     *
*............................................................................*
*Br    2 :trace2V   : trace2V[nChan]/F                                       *
*Entries :        1 : Total  Size=      40678 bytes  File Size  =       8280 *
*Baskets :        1 : Basket Size=    6394368 bytes  Compression=   4.84     *
*............................................................................*
*Br    3 :trace3V   : trace3V[nChan]/F                                       *
*Entries :        1 : Total  Size=      40678 bytes  File Size  =       8023 *
*Baskets :        1 : Basket Size=    6394368 bytes  Compression=   5.00     *
*............................................................................*
*Br    4 :trace4V   : trace4V[nChan]/F                                       *
*Entries :        1 : Total  Size=      40678 bytes  File Size  =       7569 *
*Baskets :        1 : Basket Size=    6394368 bytes  Compression=   5.30     *
*............................................................................*
*Br    5 :eventNumber : eventNumber/I                                        *
*Entries :        1 : Total  Size=        591 bytes  File Size  =         85 *
*Baskets :        1 : Basket Size=      51200 bytes  Compression=   1.00     *
*............................................................................*
*Br    6 :eventTime : eventTime/I                                            *
*Entries :        1 : Total  Size=        581 bytes  File Size  =         83 *
*Baskets :        1 : Basket Size=      51200 bytes  Compression=   1.00     *
*............................................................................*
*Br    7 :eventDate : eventDate/I                                            *
*Entries :        1 : Total  Size=        581 bytes  File Size  =         83 *
*Baskets :        1 : Basket Size=      51200 bytes  Compression=   1.00     *
*............................................................................*

In selection reoutine,

Fill selected event
******************************************************************************
*Tree    :myEvent   : Selected Events                                        *
*Entries :        0 : Total =             329 bytes  File  Size =        905 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************

Peter

_

__
Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Linux, Devuan GNU/Linux, ascii/ceres \n \l
Compiler: gcc version 7.2.0 (Debian 7.2.0-11)


Hi @fisherp,
sorry for the late reply, @pcanal can probably help here.
It’s not clear to me how the different routines interact. Could you put together a simple ROOT macro/C++ program that reproduces the issue, and specify what is the output you would expect from it?

Cheers,
Enrico

Were you able to resolve this problem?

From your description it is unclear why you ‘re-read’ the output TTree rather than re-using the pointer value that was returned by CloneTree. From the code snippet, I also can not tell whether the output TTree get attached to the proper/intended (output) TFile.