Problem using Long64_t and "L" type with TBranch

Hello,

I’m trying to fill a TBranch with Long64_t variables. If the values are greater than 2147483646 they are converted to 0.
I checked that the max value of Long64_t is
kMaxLong64 = 9223372036854775807.

It seems like Long64_t is an Int_t.

Do you have any idea why I am getting such a result?
Is there any way to solve this problem?

I am using root/v6.14.04-el7-gcc71-py37.
Please find attached a very simple macro reproducing the observed results.

Thank you a lot for your help!

// root [0] .x ttreeCreate.C

void ttreeCreate(){
      
      TString fROOTSeedsFileName = "ttree_seeds.root";
      TFile * fROOTSeedsFile = new TFile (fROOTSeedsFileName,"RECREATE");
      
      Int_t fThreadsNb;
      Long64_t fSeeds;
      TTree * fGeneralInfo = new TTree("GeneralInfo", "General information");
      // General information
      fGeneralInfo->Branch("fThreadsNb",&fThreadsNb,"fThreadsNb/I");
      fGeneralInfo->Branch("fSeeds",&fSeeds,"fSeeds/L");
      
      for (int i=0; i<10; i++){
        fThreadsNb=2147483646;
        fSeeds=3711308690032; // cannot be put into fSeeds branch
        //fSeeds=2147483646;
        fGeneralInfo->Fill();
      }

      std::cout << " kMaxLong64 = " << kMaxLong64 << std::endl; 
      std::cout << " kMinLong64 = " << kMinLong64 << std::endl; 
      
      fROOTSeedsFile->Write();
      delete fROOTSeedsFile;
}

I guess @pcanal might help you.

This works properly for me:

root [6] GeneralInfo->Scan("fSeeds","","colsize=32")
***********************************************
*    Row   *                           fSeeds *
***********************************************
*        0 *                    3711308690032 *
*        1 *                    3711308690032 *
*        2 *                    3711308690032 *
*        3 *                    3711308690032 *
*        4 *                    3711308690032 *
*        5 *                    3711308690032 *
*        6 *                    3711308690032 *
*        7 *                    3711308690032 *
*        8 *                    3711308690032 *
*        9 *                    3711308690032 *
***********************************************

How did you assert that “they are converted to 0.” ?

Thank you a lot !!!
When I use Scan() or Show() I can also see the values.

@couet I first tested with TBrowser, clicking on the variable name to obtain the corresponding histogram. The fSeeds histogram was empty, on the stat box was Mean=0, so I thought all the values were converted to 0.

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

With the ROOT file ttree_seeds.root (5.7 KB) created by your script, I can see that GeneralInfo->Draw("fSeeds") creates a broken histogram. Its x-axis range is -2.14748e+09…-2.14748e+09 which isn’t helpful.

This should be fixed by [hist] THLimitsFinder: survive long long axis ranges. by Axel-Naumann · Pull Request #7098 · root-project/root · GitHub - thanks for reporting!

Note that this fix may still not work for branches with 64 bit unsigned integers (ULong64_t). Well, maybe it’s not a real problem as I guess another places there, which use “double” variables, will anyhow fail for values which are outside of the ±2^53 range (so e.g. also for some Long64_t values).