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