# Quiet writing failure when applying schema evolution while slow cloning

**URL:** <https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350>\
**Category:** ROOT\
**Tags:** tree, io, root\
**Created:** [October 22, 2025, 1:45pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350 "2025-10-22T13:45:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomeichlersmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tomeichlersmith/32/39455_2.png) [@tomeichlersmith](https://root-forum.cern.ch/u/tomeichlersmith)\
**Post date:** [October 22, 2025, 1:45pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/1 "2025-10-22T13:45:03Z")

</div>

* * *

_ROOT Version_: 6.34.04  
_Platform_: linuxx8664gcc  
_Compiler_: GCC 13.3.0

Specifically, I am using the container image [ldmx/pro:v4.4.0 on DockerHub](https://hub.docker.com/layers/ldmx/pro/v4.4.0/images/sha256-3e2c25c7430441b5871d334b13a0ed93bcfa58cfe2fd6d88503040df7a1ae01f).

* * *

> **Boilerplate Intro Copied from Previous Post**
>
> Previous Forum Post: [Schema Evolution: Renaming a `std::map` Member Variable](https://root-forum.cern.ch/t/schema-evolution-renaming-a-std-map-member-variable/64310)
> 
> I am working in a project where we recently adopted some naming guidelines for our member variables and have now applied them to classes that are serialized by ROOT into output TTrees. However, unsurprisingly, we still have data files with the old schema (old names for member variables) floating around and so I am interested in having some schema rules that rename the member variables when reading the old format.
> 
> The full project [ldmx-sw](https://github.com/LDMX-Software/ldmx-sw) is large and takes quite some time to compile, but I’ve been able to partially replicate the issue with a smaller example.

The source code for this example is available on GitHub: [tomeichlersmith/ldmx-root-schema-evolution-testbench](https://github.com/tomeichlersmith/ldmx-root-schema-evolution-testbench/tree/main) in the `slow-clone-schema-evolve` sub-directory.

I have a simple class `Header` with two `int` members that have changed names.  
The `v1` `Header` uses camel case names while the `v2` `Header` uses snake case names  
and includes an updated `#pragma read` statement in its `LinkDef.h` file to be  
able to evolve the `v1` schema into `v2`.

Running the `./show` script displays all of the grizzly details, but the summary is

- I can write, read, and copy\[1\] a TTree of v1 while only using v1
- I can write, read, and copy a TTree of v2 while only using v2
- I can write v1 and read it with v2, but if I attempt to copy v1 with v2, the output file does not read correctly (even though the printouts while doing the copy are correct)
- I can avoid this write-out error by manually syncing the addresses between the input and output TTree (instead of using `CloneTree`), but then I cannot expect branches that are not “observed” while copying to be copied at all.

## Compile

Normal config and build cycle using CMake to find and configure the ROOT installation.

```bash
cmake -B build -S .
cmake --build build

```

## Run

Write a file using the old version of the Header object and attempt to read that  
file with both the old and new versions.  
Reading goes okay, but copying with the new schema and then reading does not go okay.

```bash
$ ./build/write-v1 v1-output.root
$ ./build/read-v1 v1-output.root
{ run: 42, event: 0 }
{ run: 42, event: 1 }
{ run: 42, event: 2 }
{ run: 42, event: 3 }
{ run: 42, event: 4 }
{ run: 42, event: 5 }
{ run: 42, event: 6 }
{ run: 42, event: 7 }
{ run: 42, event: 8 }
{ run: 42, event: 9 }
$ ./build/read-v2 v1-output.root
manual schema evolution rule being applied
{ run: 42, event: 0 }
manual schema evolution rule being applied
{ run: 42, event: 1 }
manual schema evolution rule being applied
{ run: 42, event: 2 }
manual schema evolution rule being applied
{ run: 42, event: 3 }
manual schema evolution rule being applied
{ run: 42, event: 4 }
manual schema evolution rule being applied
{ run: 42, event: 5 }
manual schema evolution rule being applied
{ run: 42, event: 6 }
manual schema evolution rule being applied
{ run: 42, event: 7 }
manual schema evolution rule being applied
{ run: 42, event: 8 }
manual schema evolution rule being applied
{ run: 42, event: 9 }
$ ./build/copy-v2-clone-tree v1-output.root v2-clone-tree-copy-v1-output.root
manual schema evolution rule being applied                                                                            
{ run: 42, event: 0 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 1 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 2 }                                                                                                 
manual schema evolution rule being applied
{ run: 42, event: 3 }
manual schema evolution rule being applied
{ run: 42, event: 4 }
manual schema evolution rule being applied
{ run: 42, event: 5 }
manual schema evolution rule being applied
{ run: 42, event: 6 }
manual schema evolution rule being applied
{ run: 42, event: 7 }
manual schema evolution rule being applied
{ run: 42, event: 8 }
manual schema evolution rule being applied
{ run: 42, event: 9 }
$ ./build/read-v2 v2-clone-tree-copy-v1-output.root
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
manual schema evolution rule being applied
{ run: -1904246784, event: -1904246784 }
$ denv ./build/copy-v2-manual data/v1-out
put.root data/v2-copy-manual-v1-output.root                                                                           
manual schema evolution rule being applied                                                                            
{ run: 42, event: 0 }                                                                                                 
manual schema evolution rule being applied
{ run: 42, event: 1 }
manual schema evolution rule being applied
{ run: 42, event: 2 }
manual schema evolution rule being applied
{ run: 42, event: 3 }
manual schema evolution rule being applied
{ run: 42, event: 4 }
manual schema evolution rule being applied
{ run: 42, event: 5 }
manual schema evolution rule being applied
{ run: 42, event: 6 }
manual schema evolution rule being applied
{ run: 42, event: 7 }
manual schema evolution rule being applied
{ run: 42, event: 8 }
manual schema evolution rule being applied
{ run: 42, event: 9 }
$ denv ./build/read-v2 data/v2-copy-manual-v1-output.root 
{ run: 42, event: 0 }
{ run: 42, event: 1 }
{ run: 42, event: 2 }
{ run: 42, event: 3 }
{ run: 42, event: 4 }
{ run: 42, event: 5 }
{ run: 42, event: 6 }
{ run: 42, event: 7 }
{ run: 42, event: 8 }
{ run: 42, event: 9 }

```

* * *

1. When I say “copy” here, I mean “slow clone”. I am focusing on slow cloning because our data processing framework slow clones while allowing the user to read some of the branches and potentially write new ones.

---

<div class="post-metadata">

**Author:** ![mczurylo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mczurylo/32/33269_2.png) [@mczurylo](https://root-forum.cern.ch/u/mczurylo)\
**Post date:** [October 22, 2025, 3:03pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/2 "2025-10-22T15:03:11Z")

</div>

Hi @tomeichlersmith,

thanks for reporting. Maybe @pcanal could help you here.

Cheers,

Marta

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [October 22, 2025, 3:16pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/3 "2025-10-22T15:16:41Z")

</div>

> [@tomeichlersmith](#):
>
> - I can write v1 and read it with v2, but if I attempt to copy v1 with v2, the output file does not read correctly (even though the printouts while doing the copy are correct)
> - I can avoid this write-out error by manually syncing the addresses between the input and output TTree (instead of using `CloneTree`), but then I cannot expect branches that are not “observed” while copying to be copied at all.

This is (for better or worse) the behavior as I expect since `CloneTree` as no way to know that the data were renamed (or more exactly it is not implemented and is likely ‘hard’ to do in a generic way).

The solution is to combine both option, i.e.:

- Use CloneTree
- Call SetBranchAddress to `syncing the addresses between the input and output TTree` just of the renamed data members.

---

<div class="post-metadata">

**Author:** ![tomeichlersmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tomeichlersmith/32/39455_2.png) [@tomeichlersmith](https://root-forum.cern.ch/u/tomeichlersmith)\
**Post date:** [October 22, 2025, 4:12pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/4 "2025-10-22T16:12:15Z")

</div>

Can you provide more detail on how to call `SetBranchAddress` for just the renamed data members?

In the example, I do call `SetBranchAddress` on the input TTree:

> <https://github.com/tomeichlersmith/ldmx-root-schema-evolution-testbench/blob/1c05027bdb58a9d5360b2177744712a0cc1f2c73/slow-clone-schema-evolve/copy.cxx#L30-L31>

This is done _before_ calling `CloneTree`. Are you saying I should do the `SetBranchAddress` call _after_ `CloneTree` ? on the output TTree as well? or some option where I `SetBranchAddress` for specific members of my `Header` class?

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [October 22, 2025, 4:44pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/5 "2025-10-22T16:44:50Z")

</div>

> This is done _before_ calling `CloneTree`. Are you saying I should do the `SetBranchAddress` call _after_ `CloneTree` ? on the output TTree as well? or some option where I `SetBranchAddress` for specific members of my `Header` class?

What I meant what do the `SetBranchAddress` before the CloneTree but _also_ call the `SetBranchAddress` on the output for the new branches …

**Except** that I realize that `CloneTree` is actually not what you (seem to) want. `CloneTree` will keep the structure the same as the input. Since the live object does not have a memory slot for the rename members (the system does not know they are ‘just’ rename, just that there are input to a rule), the address used is likely not properly passed on to the clone (I guess this is a bug).

So a work-around (as long as the type of the member did not change) is to set the branch address (using the old name of the members) in the output Tree to the current address in memory of the data members.

> I can avoid this write-out error by manually syncing the addresses between the input and output TTree (instead of using `CloneTree`), but then I cannot expect branches that are not “observed” while copying to be copied at all.

This might actually be the best solution. And to make it work you can do:

```auto
auto inputTree = file->Get<Tree>(treename);
TTree *outputTree = createOutputTree();
inputTree->GetEntry(0); // Make sure the address are populated in the inputTree
inputTree->CopyAddresses(outputTree);
changedType *transfer = nullptr;
inputTree->SetBranchAddress(toplevel_branch_name, &transfer);
outputTree->SetBranchAddress(toplevel_branch_name, &transfer);

```

---

<div class="post-metadata">

**Author:** ![tomeichlersmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tomeichlersmith/32/39455_2.png) [@tomeichlersmith](https://root-forum.cern.ch/u/tomeichlersmith)\
**Post date:** [October 22, 2025, 6:28pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/6 "2025-10-22T18:28:48Z")

</div>

What do you imagine is in `createOutputTree`?

When I just `new TTree` in place of `createOutputTree`:

> <https://github.com/tomeichlersmith/ldmx-root-schema-evolution-testbench/blob/d08c236bec7656b4eda1ff5f93739e91eca310bc/slow-clone-schema-evolve/copy.cxx#L41-L46>

I get a few warnings that are understandable:

```auto
# when attempting to copy
Warning in <TTree::CopyAddresses>: Could not find branch named 'header' in tree named 'tree'
Error in <TTree::SetBranchAddress>: unknown branch -> header

# when attempting to read the copy
Error in <TTreeReaderValueBase::CreateProxy()>: The tree does not have a branch called header. You could check with TTree::Print() for available branches.

```

I want to inherit the structure of the input tree for all branches that are not “observed” (i.e. read in memory while doing the copying/slow cloning). This feels like what `CloneTree` is intended to do, so is there a way to clone a tree and then detach specific branches from their old memory slots? I had assumed that `SetBranchAddress` would do this, but when I try to replace `createOutputTree` with `input_tree→CloneTree(0)`, it still doesn’t work.

---

<div class="post-metadata">

**Author:** ![tomeichlersmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tomeichlersmith/32/39455_2.png) [@tomeichlersmith](https://root-forum.cern.ch/u/tomeichlersmith)\
**Post date:** [October 22, 2025, 6:37pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/7 "2025-10-22T18:37:07Z")

</div>

More detail on “it still doesn’t work”:

```diff
diff --git i/slow-clone-schema-evolve/copy.cxx w/slow-clone-schema-evolve/copy.cxx
index 92c653c..07d4adf 100644
--- i/slow-clone-schema-evolve/copy.cxx
+++ w/slow-clone-schema-evolve/copy.cxx
@@ -38,8 +38,8 @@ int main(int nargs, char** argv) {
   /**
    * Solution as described by @pcanal on ROOT Forum.
    */
- TTree* output_tree = new TTree("tree", "tree");
   input_tree->GetEntry(0);
+ TTree* output_tree = input_tree->CloneTree(0);
   input_tree->CopyAddresses(output_tree);
   Header* h_ptr = nullptr; //new Header;
   input_tree->SetBranchAddress("header", &h_ptr);

```

```auto
$ denv ./build/copy-v2-copy-addr data/v1-output.root data/v2-copy-addr-clone-tree-v1-output.root                                                               
manual schema evolution rule being applied                                                                            
manual schema evolution rule being applied                                                                            
{ run: 42, event: 0 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 1 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 2 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 3 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 4 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 5 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 6 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 7 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 8 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 9 }
$ denv ./build/read-v2 data/v2-copy-addr-
clone-tree-v1-output.root                                                                                             
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                         

```

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [October 22, 2025, 7:40pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/8 "2025-10-22T19:40:48Z")

</div>

> What do you imagine is in `createOutputTree`?

I assume that in

> I can avoid this write-out error by manually syncing the addresses between the input and output TTree (instead of using `CloneTree`)

there was a step creating the output `TTree`.

> This feels like what `CloneTree` is intended to do, so is there a way to clone a tree and then detach specific branches from their old memory slots?

Maybe … i.e. `SetBranchAddress` on those (sub)branches **after** the first call to `GetEntry(0)` so that it is not overridden by the setting of the top level addresses.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [October 22, 2025, 7:44pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/9 "2025-10-22T19:44:05Z")

</div>

> but when I try to replace `createOutputTree` with `input_tree→CloneTree(0)`, it still doesn’t work.

Yes but in that scenario, the output tree has the old structure and you need to explicitly connect the sub-branches of the renamed data member to the in memory object (it is probably a bug that connecting the cloned tree to the scratch area where the old data member are staged but there might also be lifetime issues).

---

<div class="post-metadata">

**Author:** ![tomeichlersmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tomeichlersmith/32/39455_2.png) [@tomeichlersmith](https://root-forum.cern.ch/u/tomeichlersmith)\
**Post date:** [October 23, 2025, 2:19pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/10 "2025-10-23T14:19:48Z")

</div>

Ok, this is still not working. Here is the full copying program:

> <https://github.com/tomeichlersmith/ldmx-root-schema-evolution-testbench/blob/470de904f17d42017db9e2dac66fa170e32c7f34/slow-clone-schema-evolve/copy.cxx#L15-L35>

This reads appropriately while copying, but the resulting file it writes is not readable by either v1 or v2.

```auto
Copying v1-output with v2 producing v2-copy-v1-output:
                                                    
manual schema evolution rule being applied                                                                            
manual schema evolution rule being applied                                                                            
{ run: 42, event: 0 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 1 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 2 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 3 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 4 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 5 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 6 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 7 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 8 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 9 }       

Contents of v2-copy-v1-output according to v2:                                                                        
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 536879104, event: 536879104 }         

Contents of v2-copy-v1-output according to v1:
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }
{ run: 536879104, event: 536879104 }

```

Moving `input_tree→GetEntry(0)` to before `CloneTree` also does not work, but instead of writing garbage data, it writes all zeroes (from the default constructor?)

```diff
diff --git a/slow-clone-schema-evolve/copy.cxx b/slow-clone-schema-evolve/copy.cxx
index 1913d6a..155e434 100644
--- a/slow-clone-schema-evolve/copy.cxx
+++ b/slow-clone-schema-evolve/copy.cxx
@@ -17,8 +17,8 @@ int main(int nargs, char** argv) {
   TTree* input_tree{f.Get<TTree>("tree")};
   TFile o{argv[2], "recreate"};
 
- input_tree->GetEntry(0);
   TTree* output_tree = input_tree->CloneTree(0);
+ input_tree->GetEntry(0);
   Header* h_ptr = nullptr; //new Header;
   input_tree->SetBranchAddress("header", &h_ptr);
   output_tree->SetBranchAddress("header", &h_ptr);

```

Results in

```auto
Copying v1-output with v2:                                                                                            
manual schema evolution rule being applied                                                                            
manual schema evolution rule being applied                                                                            
{ run: 42, event: 0 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 1 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 2 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 3 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 4 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 5 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 6 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 7 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 8 }                                                                                                 
manual schema evolution rule being applied                                                                            
{ run: 42, event: 9 }         

Contents of v2-copy-v1-output according to v2:                                                                        
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied                                                                            
{ run: 0, event: 0 }                                                                                                  
manual schema evolution rule being applied
{ run: 0, event: 0 }
manual schema evolution rule being applied
{ run: 0, event: 0 }
manual schema evolution rule being applied
{ run: 0, event: 0 }
manual schema evolution rule being applied
{ run: 0, event: 0 }
manual schema evolution rule being applied
{ run: 0, event: 0 }
manual schema evolution rule being applied
{ run: 0, event: 0 }

Contents of v2-copy-v1-output according to v1:
{ run: 0, event: 0 }
{ run: 0, event: 0 }
{ run: 0, event: 0 }
{ run: 0, event: 0 }
{ run: 0, event: 0 }
{ run: 0, event: 0 }
{ run: 0, event: 0 }
{ run: 0, event: 0 }
{ run: 0, event: 0 }
{ run: 0, event: 0 }

```

---

<div class="post-metadata">

**Author:** ![tomeichlersmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/tomeichlersmith/32/39455_2.png) [@tomeichlersmith](https://root-forum.cern.ch/u/tomeichlersmith)\
**Post date:** [October 31, 2025, 6:22pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/11 "2025-10-31T18:22:12Z")

</div>

I have found a reasonable solution for my use case by **requiring** access to the dictionary of all objects in the files.

While the leaf-based address syncing of `CloneTree` (and `CopyAddresses`) is able to copy trees without access to this dictionary, I was unable to figure out how to _replace_ the root branch (and its descedant branch/leaf) addresses with the new object in memory. This strategy is what I was trying to do above, but it did not work (perhaps due to some intricate bug/lifetime issue as suggested by @pcanal ).

Instead of using `CloneTree`/`CopyAddresses` at all, I can get schema evolution to be applied and clone the input tree to the output file by requiring access to the dictionary entries for all the objects in the input file and manually re-creating the branches of the input tree in the output tree.

My full implementation of this “shallow”/”dictionary-required” CloneTree is:

```cpp
  input_tree->GetEntry(0);
  TTree* output_tree = new TTree("tree","tree");
  auto input_branches = input_tree->GetListOfBranches();
  for (std::size_t i_br{0}; i_br < input_branches->GetEntriesFast(); i_br++) {
    auto br{dynamic_cast<TBranch*>(input_branches->UncheckedAt(i_br))};
    if (auto bre{dynamic_cast<TBranchElement*>(br)}; bre) {
      auto br = output_tree->Branch(
          bre->GetName(),
          bre->GetClassName(),
          bre->GetObject()
      );
      if (!br) {
        std::cout << "no dictionary-entry for class '" << bre->GetClassName()
          << "' written to '" << bre->GetName()
          << "', fall-back option of leaf-based address syncing not implemented since we want to evolve the schema" << std::endl;
        continue;
      }
    } else {
      auto leaf{br->GetLeaf(br->GetName())};
      static const std::map<std::string, std::string> TYPENAME_TO_LEAFLIST = {
        { "Int_t", "I" }
        // TODO: add rest of BSILFD options
      };
      std::string leaflist{br->GetName()};
      auto leaf_type_name{leaf->GetTypeName()};
      leaflist += "/" + TYPENAME_TO_LEAFLIST.at(br->GetLeaf(br->GetName())->GetTypeName());
      output_tree->Branch(
          br->GetName(),
          leaf->GetValuePointer(),
          leaflist.c_str()
      );
    }
  }

```

And then the `SetBranchAddress` and loop over events works as expected.

The implementation including my extra comments with my observations and other attempts is available on GitHub:

> <https://github.com/tomeichlersmith/ldmx-root-schema-evolution-testbench/blob/44a6b032186ec61739e09b63c1dc2b09e0ee9cd0/slow-clone-schema-evolve/copy.cxx#L24-L109>

**Sidenote** : Is there an easier/better way to create a `Branch` off a simple type besides dynamically looking up the leaf list character by name in some map? My reading of the ROOT `TLeaf` code makes me think this single-char representation of its type is just discarded upon creation.

---

<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:** [November 14, 2025, 6:22pm UTC](https://root-forum.cern.ch/t/quiet-writing-failure-when-applying-schema-evolution-while-slow-cloning/64350/12 "2025-11-14T18:22:37Z")

</div>

Closed on November 14, 2025, 6:22pm UTC

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