# Trouble with 'same key double TTree' in root-file

**URL:** <https://root-forum.cern.ch/t/trouble-with-same-key-double-ttree-in-root-file/25399>\
**Category:** ROOT\
**Tags:** tree\
**Created:** [July 4, 2017, 8:42am UTC](https://root-forum.cern.ch/t/trouble-with-same-key-double-ttree-in-root-file/25399 "2017-07-04T08:42:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hviemann](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/8e8cbc/32.png) [@hviemann](https://root-forum.cern.ch/u/hviemann)\
**Post date:** [July 4, 2017, 8:42am UTC](https://root-forum.cern.ch/t/trouble-with-same-key-double-ttree-in-root-file/25399/1 "2017-07-04T08:42:26Z")

</div>

Hi,  
I’m not sure if this topic is an old one, however I did not find a similar one.  
My problem is that I have a root file containing two TTree-objects with the same key-name. To be clear I only created one TTree and the file somehow wrote two into my root-file. (My foregoing algorithm opens the TFile with the option ‘recreate’, so it should not include the TTree from a previous run…)

```auto
root [1] _file0->ls()
TFile** DATA_Xib2LK_12aLL_MagDown.root  
 TFile* DATA_Xib2LK_12aLL_MagDown.root  
  KEY: TTree DATA_Xib2LK_12aLL_MagDown;4 DATA_Xib2LK_12aLL_MagDown
  KEY: TTree DATA_Xib2LK_12aLL_MagDown;3 DATA_Xib2LK_12aLL_MagDown
root [2] TTree* tree = (TTree*)_file0->Get("DATA_Xib2LK_12aLL_MagDown")
(TTree *) 0x34961f0
root [3] tree->GetEntries()
(Long64_t) 933494

```

In the TBrowser I can access and draw the key;4 and key;3. They have a different amount of entries:  
Entries key;4 -\> 933494  
Entries key;3 -\> 717840

So my question is, if the TTree is corrupted and has not been created incorrectly in the fist place, if accessing only the TTree with key;4 already includes the key;3 or if I have to access this in another way.

Cheers  
Harald

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [July 4, 2017, 8:51am UTC](https://root-forum.cern.ch/t/trouble-with-same-key-double-ttree-in-root-file/25399/2 "2017-07-04T08:51:55Z")

</div>

> [@Aux;1 aux;2 aux3;](https://root-forum.cern.ch/t/aux-1-aux-2-aux3/13345/2):
>
> Search for “cycle” and/or “namecycle”, for example in: In a Nutshell: [Input and Output](https://root.cern.ch/d/input-and-output) . ROOT User’s Guide: [Input/Output](https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#inputoutput) : [Retrieving Objects from Disk](https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#retrieving-objects-from-disk) , [Subdirectories and Navigation](https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#subdirectories-and-navigation) . Just for reference: [some additional notes about GetObject, Get, FindObjectAny, FindKeyAny, ReadObj, ReadObjAny](https://root-forum.cern.ch/t/broken-tdirectoryfile-findobjectany-and-tdirectoryfile-findkeyany/20943/16) .

---

<div class="post-metadata">

**Author:** ![hviemann](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/8e8cbc/32.png) [@hviemann](https://root-forum.cern.ch/u/hviemann)\
**Post date:** [July 4, 2017, 11:03am UTC](https://root-forum.cern.ch/t/trouble-with-same-key-double-ttree-in-root-file/25399/3 "2017-07-04T11:03:29Z")

</div>

Thanks for your link to the ‘cycle’ topics! I got the point with the cycle-number and how I can access the TTree.  
However, for me, one part of my question isn’t clear yet. Is it possible that a single call of the Write() method produces split TTree’s or is it just an iteration? On the one hand under the premise that my TTree objects are iterations, it is save to use the Object with the higher cycle-number I get by calling the Get()-method. On the other hand, when the TTree is split, things get complicated.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 18, 2017, 11:03am UTC](https://root-forum.cern.ch/t/trouble-with-same-key-double-ttree-in-root-file/25399/4 "2017-07-18T11:03:40Z")

</div>

Closed on July 18, 2017, 11:03am UTC

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