Simple function working with 6.28/04 but not with 6.30/04

Hello,
I’ve been using a very simple function to check the value (zero or one) of a digit in an int variable. I just discovered that my code which worked in the past few years doesn’t work anymore with root 6.30/04 while it worked with several previous root version (for example you can check with 6.28/04).

The code is the following:

//====================================================
bool checkBit(int value, int posFromRight) {
  int val = abs(value);
  posFromRight++;
  while (--posFromRight)
    val /= 10;
  val %= 10;
  //cout << "aCHECKBIT " << val << endl;
  if( val == 1 ) return true;
  else return false;
}
//====================================================

int val[5] = {100,101,1,10,11};

void testCheckBit() {

  Int_t  muo0id;
  TFile *out_all_TreeFile = new TFile("out.root","RECREATE");
  TTree * fTree = new TTree ("ana", "CMSSW anaFind tree");
  fTree->Branch("muo0id", &muo0id, "muo0id/I");
  for(int n=0;n<5; n++) {
    muo0id=val[n];
    out_all_TreeFile->cd();
    fTree->Fill();
  }
  out_all_TreeFile->Write();
  out_all_TreeFile->Close();

  TFile *f = TFile::Open("out.root");
  TTree *ana = (TTree*)f->Get("ana");
  ana->Scan("muo0id:checkBit(muo0id,0)");
  f->Close();
}

If I run this code with ROOT version 6.28/04 this is what I get:

   ------------------------------------------------------------------
  | Welcome to ROOT 6.28/04                        https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on May 08 2023, 02:44:07                 |
  | From tags/v6-28-04@v6-28-04                                      |
  | With g++ (GCC) 11.3.0                                            |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------


Processing testCheckBit.cpp...
************************************
*    Row   *    muo0id * checkBit( *
************************************
*        0 *       100 *         0 *
*        1 *       101 *         1 *
*        2 *         1 *         1 *
*        3 *        10 *         0 *
*        4 *        11 *         1 *
************************************

And everything looks ok… while if I run it with ROOT 6.30/04 all bits are zero:

   ------------------------------------------------------------------
  | Welcome to ROOT 6.30/04                        https://root.cern |
  | (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosxarm64 on Jan 31 2024, 08:17:06                   |
  | From heads/master@tags/v6-30-04                                  |
  | With Apple clang version 15.0.0 (clang-1500.3.9.4)               |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0]
Processing testCheckBit.cpp...
************************************
*    Row   *    muo0id * checkBit( *
************************************
*        0 *       100 *         0 *
*        1 *       101 *         0 *
*        2 *         1 *         0 *
*        3 *        10 *         0 *
*        4 *        11 *         0 *
************************************

Could someone explain to me what’s going on ?
Thanks

Attilio

Hi Attilio,

How are you running the code? As a macro or compiled? What platform?

Cheers,
Danilo

Hello, I run it as a macro…

6.28/04 is run on a Linus machine where I use the CERN script:
source /cvmfs/sft.cern.ch/lcg/views/LCG_104/x86_64-centos7-gcc11-opt/setup.sh
uname -a:
Linux ui02.recas.ba.infn.it 3.10.0-1160.80.1.el7.x86_64 #1 SMP Tue Nov 8 15:48:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

While the 6.30/04 is run on MAC with root installed using homebrew:
uname -a:
Darwin Mac-mini-di-attilio.local 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:44:06 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T8103 arm64

Best

Attilio

Dear @as5365 ,

Thanks for reaching out to the forum!

I have just tried your example on lxplus, with ROOT 6.30.02 (LCG_105) and the latest nightly build (dev3). With the former, I reproduce the error you are seeing. With the latter, the error is not there and the checkBit column reports the correct values. Could you maybe also try yourself and confirm?

My suspect is that we are missing a backport of this fix Readjust the representation of CallFunc arguments to match the callee signature by vgvassilev · Pull Request #14888 · root-project/root · GitHub to ROOT 6.30 patch series.

Cheers,
Vincenzo

I confirm that the problem is solved by Readjust the representation of CallFunc arguments to match the callee signature by vgvassilev · Pull Request #14888 · root-project/root · GitHub.
Currently this patch is only present in the master branch and the pre-release branch for v6.32.00

Hello,
thanks for the explanation… what would you suggest to have a working function on my mac? As far as I know homebrew doesn’t offer a simple way to switch to a previous version… I tried to install root 6.28.12 from binaries from the repository but they didint work [0]. Before to install from source (which always take a lot of time) is there any other option? And in case source is the only option is it better to go for root 6.28.12 or download from git the last buid?

Thanks

Attilio

[0] My mac is using Sonoma 14.4.1 (23E224) and the last version of XCode 15 so I tried to use https://root.cern/download/root_v6.28.12.macos-14.3-arm64-clang150.pkg but I got a lot of errors when I run root

The master is your best choice if you are going to build from source.

Note that you can probably work around the problem using

The relevant patch has been backported to 6.30, so you will get it via home-brew when the next 6.30 patch release will be published. The published binaries refer to the correct MacOS version so I believe that it should match (it doesn’t in the case of the binary you link). In the meanwhile, building from source is probably the only option if you want to run it on Mac (otherwise you can always use the LCG releases on lxplus).

Cheers,
Vincenzo

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