Convert ROOT._Bit_reference

Hello everyone,

I have a problem with the datatype _Bit_reference. In a first step I save in c++ a vector< bool > in a TTree, and now I want to read single entries of the vector in in python and fill a histogram.
What I do is:

entry = vector[index]

And entry has the datatype <class ‘ROOT._Bit_reference’>.

I’ve seen code, where this was done:

entry = ord(vector[index])

But than this error occurs:
TypeError: ord() expected string of length 1, but _Bit_reference found

So why are entries in vector< bool > in TTree sometimes a char or string, and why are mine entries _Bit_reference datatype? And most importantly, how can I convert them in python in a float or so?

ROOT Version: 6.18/00

Hi @eneb,

vector<bool>, in order to be space efficient, can store the true/false values as bits. That is why you get this _Bit_references. You can get their python boolean value by doing bool(vector[index]).

If the type is a vector<bool>, you should not get back strings or chars. Are you sure the type of the branch is always vector<bool>?

Hi @etejedor

Thanks for your answer. You’re right, the other code I checked got bool values in the c++ script but stored them in a vector<char> so that’s why there was used the ord() command.

My solution was now the same, I changed my vector<bool> to vector <char> in the script before but I think I will test your solution, too.

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