# ROOT7 TDirectory::Find upcast fix

**URL:** <https://root-forum.cern.ch/t/root7-tdirectory-find-upcast-fix/21508>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [July 11, 2016, 10:31pm UTC](https://root-forum.cern.ch/t/root7-tdirectory-find-upcast-fix/21508 "2016-07-11T22:31:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![berserker](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/berserker/32/17693_2.png) [@berserker](https://root-forum.cern.ch/u/berserker)\
**Post date:** [July 11, 2016, 10:31pm UTC](https://root-forum.cern.ch/t/root7-tdirectory-find-upcast-fix/21508/1 "2016-07-11T22:31:19Z")

</div>

UPDATE  
Ok, I’ve had old clone of ROOT repository and this patch is relative to [this version of TDirectoryEntry.h](https://github.com/root-mirror/root/blob/51a8464657b17e42e72665be4ff5782d9d4b64fa/core/base/v7/inc/ROOT/TDirectoryEntry.h). Now developers added TClass\* member to track original type. So, my more general solution is redundant now. But I’ll leave original message for the history.

ORIGINAL MESSAGE  
Inspired by [drdobbs.com/cpp/twisting-the … /229401004](http://www.drdobbs.com/cpp/twisting-the-rtti-system-for-safe-dynami/229401004), propose I this patch.

TDirectory uses different type erasure scheme than KeyValue (the first link), but I managed to fit that method into it. I intentionally didn’t touch TDirectory::Get, which also cries “FIXME: implement upcast!”, because currently it seem to me that it might require bit more changes, which I’ll left to the original author.

I didn’t test this code in ROOT (even whether it compiles or not, lol).  
But I’ve created excerpt with shortened TDirectoryEntryPtr[Base] implementation and some testing code, which is attached here and uploaded to [ideone](https://ideone.com/uDSzWU). Despite the fact that excerpt’s tests coverage is not exhaustive, for me it seem to prove the idea. Feel free to write your own tests!

Hope it’ll be helpful.  
[excerpt.cpp](https://root-forum.cern.ch/uploads/default/original/2X/d/d26141d92ab1ea4bebcbef0a126f1bf82e851517.cpp) (5.53 KB)  
[tdirectory\_find\_upcast.diff](https://root-forum.cern.ch/uploads/default/original/2X/7/7fa63b65774ab8c16c2c489b494510074dc63f92.diff) (1.58 KB)

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [July 18, 2016, 10:14am UTC](https://root-forum.cern.ch/t/root7-tdirectory-find-upcast-fix/21508/2 "2016-07-18T10:14:47Z")

</div>

For the record, that’s [github.com/root-mirror/root/pull/200](https://github.com/root-mirror/root/pull/200)

Thanks!

Axel.
