# Lazy Primitive

**URL:** <https://root-forum.cern.ch/t/lazy-primitive/60403>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [August 2, 2024, 1:22pm UTC](https://root-forum.cern.ch/t/lazy-primitive/60403 "2024-08-02T13:22:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlalik](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rlalik/32/25117_2.png) [@rlalik](https://root-forum.cern.ch/u/rlalik)\
**Post date:** [August 2, 2024, 1:22pm UTC](https://root-forum.cern.ch/t/lazy-primitive/60403/1 "2024-08-02T13:22:50Z")

</div>

Hi,

Once I had an idea of a kind of class which would provide code executed at the `Draw()` call. The idea come from another idea to create a merge-able canvas.

When `hadd`ing files with canvases, new cycles are created, which make sense as the canvas may contain objects (like fits or lines) which are not merge-able. But what about if we can create just one canvas, with histograms which are merged, and then call a code which redo fitting and all other magic?

So what do you think? I have already a some simple demo here: [GitHub - rlalik/tlazyprimitive: A demo of TLazyPrimitive for CERN ROOT](https://github.com/rlalik/tlazyprimitive) with simple implementation of `TLazyPrimitive`.

Regards,  
Rafał

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 2, 2024, 1:28pm UTC](https://root-forum.cern.ch/t/lazy-primitive/60403/2 "2024-08-02T13:28:34Z")

</div>

Hi Rafal,

Thanks for the suggestion! I’m sure @couet will be interested to take a look when back from vacation

Cheers, Bertrand.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 14, 2024, 12:37pm UTC](https://root-forum.cern.ch/t/lazy-primitive/60403/3 "2024-08-14T12:37:43Z")

</div>

I cloned your repository and ran your example. I noticed that you’re manipulating the list of primitives, but I’m not entirely clear on the purpose of the `TLazyPrimitive` class. Could you explain why this class is necessary and what additional value it provides compared to directly accessing the list of primitives? I feel like I might be missing something important here.

---

<div class="post-metadata">

**Author:** ![rlalik](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rlalik/32/25117_2.png) [@rlalik](https://root-forum.cern.ch/u/rlalik)\
**Post date:** [August 25, 2024, 7:23am UTC](https://root-forum.cern.ch/t/lazy-primitive/60403/4 "2024-08-25T07:23:41Z")

</div>

Hi @couet. My idea with `TLazyPrimitive` is to delay the canvas manipulation to the time when is drawn next time. Like, I want to have timestamp on when the canvas was last drawn. Maybe stupid example but I’m sure there will be other use case. Thus the object must store a functor object which will be executed on the `Draw()` time.

I was thinking about a such object in the context of perhaps extending functionality of `hadd`. As per current default behaviour, if the N files contain a histogram and a canvas, all histograms will be add together, but all canvases will have its own copy in the output file.

With `TLazyPrimitive` it would be technically possible to end up with only one canvas which will redraw it contents (using summed up histograms) an the next use (thus TLazy… like lazy evaluation concept…).

There could be a decision branch for `hadd` which would be completely backward compatible that, if (and there are some but not all of propositions for triggers):

- the canvas contains at least on `TLazyPrimitive` object, or
- the canvas contains only `TLazyPrimitive` object, or
- the canvas contains only one primitive and it is a `TLazyPrimitive` object, then

There is only one canvas object in the output file. I think many people could be happy with a such feature.

About the implementation, it is just prototype. If you think it would be worth working on it, we could just use this repository to develop final product which later could be integrated into root.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 27, 2024, 12:47pm UTC](https://root-forum.cern.ch/t/lazy-primitive/60403/5 "2024-08-27T12:47:45Z")

</div>

> [@rlalik](#):
>
> Thus the object must store a functor object which will be executed on the `Draw()` time.

Is in not what TExec is doing ?

---

<div class="post-metadata">

**Author:** ![rlalik](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rlalik/32/25117_2.png) [@rlalik](https://root-forum.cern.ch/u/rlalik)\
**Post date:** [August 28, 2024, 7:06am UTC](https://root-forum.cern.ch/t/lazy-primitive/60403/6 "2024-08-28T07:06:08Z")

</div>

Oh, I wasn’t aware of `TExec` and it seems being similar. However it only accepts strings with macros. My proposition accept functors objects. I’m not sure whether macro in `TExec` allows for all the same what native code allows.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 28, 2024, 8:22am UTC](https://root-forum.cern.ch/t/lazy-primitive/60403/7 "2024-08-28T08:22:24Z")

</div>

It accept also functions, see “Case 2” here: [ROOT: TExec Class Reference](https://root.cern/doc/v632/classTExec.html)
