# TLeaf implementation for truncated datatypes (Float16\_t and Double32\_t)

**URL:** <https://root-forum.cern.ch/t/tleaf-implementation-for-truncated-datatypes-float16-t-and-double32-t/32872>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [February 22, 2019, 7:04pm UTC](https://root-forum.cern.ch/t/tleaf-implementation-for-truncated-datatypes-float16-t-and-double32-t/32872 "2019-02-22T19:04:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Triple\_S](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/triple_s/32/17129_2.png) [@Triple\_S](https://root-forum.cern.ch/u/Triple_S)\
**Post date:** [February 22, 2019, 7:04pm UTC](https://root-forum.cern.ch/t/tleaf-implementation-for-truncated-datatypes-float16-t-and-double32-t/32872/1 "2019-02-22T19:04:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Triple\_S](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/triple_s/32/17129_2.png) [@Triple\_S](https://root-forum.cern.ch/u/Triple_S)\
**Post date:** [February 23, 2019, 2:43pm UTC](https://root-forum.cern.ch/t/tleaf-implementation-for-truncated-datatypes-float16-t-and-double32-t/32872/2 "2019-02-23T14:43:08Z")

</div>

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

In my tests the new classes reduced the filesize significantly.

---

<div class="post-metadata">

**Author:** ![amete](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/amete/32/22968_2.png) [@amete](https://root-forum.cern.ch/u/amete)\
**Post date:** [August 28, 2019, 10:18am UTC](https://root-forum.cern.ch/t/tleaf-implementation-for-truncated-datatypes-float16-t-and-double32-t/32872/3 "2019-08-28T10:18:43Z")

</div>

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](https://root.cern/doc/v618/release-notes.html#tleaff16-and-tleafd32) 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](https://root-forum.cern.ch/t/branch-of-type-float16-t/34809) but it seems to be closed w/o a conclusion.

---

<div class="post-metadata">

**Author:** ![Triple\_S](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/triple_s/32/17129_2.png) [@Triple\_S](https://root-forum.cern.ch/u/Triple_S)\
**Post date:** [August 28, 2019, 11:03am UTC](https://root-forum.cern.ch/t/tleaf-implementation-for-truncated-datatypes-float16-t-and-double32-t/32872/4 "2019-08-28T11:03:51Z")

</div>

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](https://root.cern.ch/doc/master/classTBufferFile.html#ac4e06e123e79c792a481bd430644c767), [TBufferFile::WriteDouble32](https://root.cern/doc/v608/classTBufferFile.html#a44c2adb6fb1194ec999b84aed259e5bc) and [TStreamerElement::GetRange](https://root.cern/doc/v608/TStreamerElement_8cxx.html#a4d6c86845bee19cf28c93a531ec50f29)). For the simple branches I impelemnted this by additional specifiers behind the type character in the leaflist (As explained in [TTree::Branch](https://root.cern.ch/doc/master/classTTree.html#ac1fa9466ce018d4aa739b357f981c615)).  
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.

---

<div class="post-metadata">

**Author:** ![amete](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/amete/32/22968_2.png) [@amete](https://root-forum.cern.ch/u/amete)\
**Post date:** [August 30, 2019, 9:01am UTC](https://root-forum.cern.ch/t/tleaf-implementation-for-truncated-datatypes-float16-t-and-double32-t/32872/5 "2019-08-30T09:01:22Z")

</div>

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
