How to read unsigned long using TTreeReader

Dear experts,

I’m trying the TTreeReade and have problem to read an unsigned long leaf. I used

TTreeReaderValue<unsigned long> evt_event(myReader,"evt.event");

and get:

Error in <CreateProxy()>: Leaf of type ULong64_t cannot be read by TTreeReaderValue<unsigned long>.

Then I tried

TTreeReaderValue<ULong64_t> evt_event(myReader,"evt.event");
Error in <CreateProxy()>: Leaf of type ULong64_t cannot be read by TTreeReaderValue<unsigned long long>.

The “evt” branch in the input tree is created from an struct, of which “event” is a unsigned long member variable.

Thanks.

Can you try

TTreeReaderValue<unsigned long long> evt_event(myReader,"evt.event");

Cheers,
Philippe.

Hi Philippe,

I can not see your answer. I am getting same error and I would like to understand the solution.

Thanks!

Hi Dilia,
Philippe is currently travelling, he might reply when he’s back (in ~3 weeks).

In the meanwhile, can you post the output of tree->Print() for your TTree? As far as I know it’s not possible to create branches of type unsigned long in a TTree, i.e. you might want to actually read the branch as some other type, e.g. unsigned long long.

Cheers,
Enrico

I am also seeing the exact same behavior, and trying to use

TTreeReaderValue<unsigned long long> evt_event(myReader,"evt.event");

does not correct the issue for me.

I seem to be doing the same thing as DongLiang and Dilia_Maria_Portillo.

I make a branch using a struct in my analysis, and that struct contains items of type ULong64_t. When I run MakeSelector on the branch that is made, I get

TTreeReaderValue<ULong64_t> event = {fReader, "SelectOpHitBkgInfo.event"}; 
TTreeReaderValue<ULong64_t> run = {fReader, "SelectOpHitBkgInfo.run"}; 
TTreeReaderValue<ULong64_t> subRun = {fReader, "SelectOpHitBkgInfo.subRun"};

When I try to run the selector in ROOT (v6.18), I am presented with an error:

root [0] TChain* ch = new TChain("pduneMuonLifetime/OpHitBkgTree")
(TChain *) 0x55aa6129d3f0
root [1] ch->Add("~/PDune_ReproV28/pdune_reco_repro_opPatch_SMu_np04_raw_run005*.root")
(int) 14
root [2] ch->Process("BKGSelection.C+g")
slave begin
Hists made
Getting Entry from reader
Error in <TTreeReaderValueBase::CreateProxy()>: Leaf of type ULong64_t cannot be read by TTreeReaderValue<unsigned long long>.

I hate to resurrect a zombie, but it appears that this is the exact same issue, and a solution does not appear to have been found.

Here is a print() of my TTree.

root [4] OpHitBkgTree->Print()
******************************************************************************
*Tree    :OpHitBkgTree: Select Op Detector Hit info for backgrounds.           *
*Entries :   103099 : Total =         9106593 bytes  File  Size =    2408312 *
*        :          : Tree compression factor =   3.78                       *
******************************************************************************
*Br    0 :SelectOpHitBkgInfo : deltat0/D:deltat/D:t0/D:te/D:tabs/D:PEs/D:    *
*         | event/l:run/l:subRun/l:chan/l:bar/l                              *
*Entries :   103099 : Total  Size=    9106120 bytes  File Size  =    2405000 *
*Baskets :      285 : Basket Size=      32000 bytes  Compression=   3.78     *
*............................................................................*

The struct used to fill it uses the same types as listed in the documentation for TTree.```

    D : a 64 bit floating point (Double_t)
    l : a 64 bit unsigned integer (ULong64_t)

And the struct I use to fill.

167 struct ohitinfo
168 {
169   double  deltat0 = -999999999.9;
170   double  deltat  = -999999999.9;
171   double  t0      = -999999999.9;
172   double  te      = -999999999.9;
173   double  tabs    = -999999999.9;
174   double  pes     = -999999999.9;
175   uint64_t event   =  999999999;
176   uint64_t run     =  999999999;
177   uint64_t subrun  =  999999999;
178   uint64_t channel =  999999999;
179   uint64_t bar     =  999999999;
180 
181   void reset()
182   {
183     deltat0 = -999999999.9;
184     deltat  = -999999999.9;
185     t0      = -999999999.9;
186     te      = -999999999.9;
187     tabs    = -999999999.9;
188     pes     = -999999999.9;
189     event   =  999999999;
190     run     =  999999999;
191     subrun  =  999999999;
192     channel =  999999999;
193     bar     =  999999999;
194   }

I have created my own topic to follow up with this, as I feel it does merit it’s own discussion in a modern thread, but for anyone who ends up here by virtue of google and is in need of an answer, I want to link that topic here.

1 Like

See https://github.com/root-project/root/pull/4670