Home | News | Documentation | Download

TLeaf implementation for truncated datatypes (Float16_t and Double32_t)

I was wondering whether there is already an implementation that allows to save Float16_t or Double32_t values to a TTree.
I know that these are internally the same as Float_t or Double_t values and only differ when being written to the Buffer, but according to the implementations of TLeafF or TLeafD these classes have no ability to write the truncated types.

I’m asking whether there is a way I don’t see at the moment before I start to write an implementation myself. I think it would be quite useful cause it saves memory and in many cases you don’t need the full precision of Float_t or Double_t.

I added a pull request for this: https://github.com/root-project/root/pull/3463

In my tests the new classes reduced the filesize significantly.

1 Like

Hi @Triple_S,

That’s indeed a neat feature, thanks a lot. I’ve been experimenting with this in v6.18. From the release notes I see that values/arrays are supported but is there any support for STL containers, i.e. storing std::vector< Float16_t> with bit-truncation? Many thanks.

Best,
Serhan

PS: I just now see a similar discussion/request at Branch of Type Float16_t but it seems to be closed w/o a conclusion.

Hi @amete and welcome to the forum,

Actually I have to admit I was not even thinking of the STL containers when I wrote this feature so it is definitly not implemented yet.
I just took a short look and I already see a maybe critical problem: The way the truncated datatypes are streamed can be influenced by additional range and bit specifiers (See TBufferFile::WriteFloat16, TBufferFile::WriteDouble32 and TStreamerElement::GetRange). For the simple branches I impelemnted this by additional specifiers behind the type character in the leaflist (As explained in TTree::Branch).
Since the branching of STL containers does not allow to specify a leaflist, one would ne a differnt way to implement this which I don’t see at the moment. Unfortunatly I do not have time time to look more deeply into this at the moment.

Hi @Triple_S,

Thank you very much. In a real life use case, for us (ATLAS) for example, we would like to store std::vector<Float16_t>, std::vector<std::vector<Float16_t> >, and even variables of this type that are data members of more complex classes. I understand this is out of the scope of your particular development but I wonder if there is a general ROOT plan to support at least the former use cases (i.e. vectors, and vectors of vectors). I should admit I don’t really know how complicated this would be (if at all possible). We’re currently investigating different possibilities for the future and it would be great to have a better understanding of the plans.

Many thanks.

Best,
Serhan