# Writing large trees into files

**URL:** <https://root-forum.cern.ch/t/writing-large-trees-into-files/55181>\
**Category:** ROOT\
**Created:** [June 5, 2023, 9:38am UTC](https://root-forum.cern.ch/t/writing-large-trees-into-files/55181 "2023-06-05T09:38:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![meyerma](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meyerma/32/29724_2.png) [@meyerma](https://root-forum.cern.ch/u/meyerma)\
**Post date:** [June 5, 2023, 9:38am UTC](https://root-forum.cern.ch/t/writing-large-trees-into-files/55181/1 "2023-06-05T09:38:49Z")

</div>

Hello,

I have been saving large trees recently and I am facing a memory issue while writing them.  
My tree are around 1.8GB. (100M events)

I am used to create a tree fill it. So far, so good.  
After playing with it I open a TFile, select/mkdir a TDirectory inside and I use TDirectory::WriteTObject to save at the right location.

For some reason, I managed to use TTree::ChangeFile and writing the file successfully, but this is not what I want. Would you have any suggestion how to proceed ?

Here is some

```auto
Fatal in <TBufferFile::AutoExpand>: Request to expand to a negative size, likely due to an integer overflow: 0x80007cf5 for a max of 0x7ffffffe.
aborting
[./6.28.04/lib/libCore.so] ErrorHandler (no debug info)
[./6.28.04/lib/libCore.so] TObject::Fatal(char const*, char const*, ...) const (no debug info)
[./6.28.04/lib/libCore.so] TBuffer::AutoExpand(int) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::WriteFastArray(char const*, int) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::WriteObjectClass(void const*, TClass const*, bool) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferIO::WriteObjectAny(void const*, TClass const*, bool) (no debug info)
[./6.28.04/lib/libCore.so] TObjArray::Streamer(TBuffer&) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::WriteFastArray(void*, TClass const*, int, TMemberStreamer*) (no debug info)
[./6.28.04/lib/libRIO.so] int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) (no debug info)
[./6.28.04/lib/libRIO.so] TStreamerInfoActions::GenericWriteAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::WriteClassBuffer(TClass const*, void*) (no debug info)
[./6.28.04/lib/libTree.so] TBranch::Streamer(TBuffer&) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::WriteObjectClass(void const*, TClass const*, bool) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferIO::WriteObjectAny(void const*, TClass const*, bool) (no debug info)
[./6.28.04/lib/libCore.so] TObjArray::Streamer(TBuffer&) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::WriteFastArray(void*, TClass const*, int, TMemberStreamer*) (no debug info)
[./6.28.04/lib/libRIO.so] int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) (no debug info)
[./6.28.04/lib/libRIO.so] TStreamerInfoActions::GenericWriteAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (no debug info)
[./6.28.04/lib/libRIO.so] TBufferFile::WriteClassBuffer(TClass const*, void*) (no debug info)
[./6.28.04/lib/libRIO.so] TKey::TKey(TObject const*, char const*, int, TDirectory*) (no debug info)
[./6.28.04/lib/libRIO.so] TFile::CreateKey(TDirectory*, TObject const*, char const*, int) (no debug info)
[./6.28.04/lib/libRIO.so] TDirectoryFile::WriteTObject(TObject const*, char const*, char const*, int) (no debug info)

```

Cheers, M.

---

<div class="post-metadata">

**Author:** ![meyerma](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meyerma/32/29724_2.png) [@meyerma](https://root-forum.cern.ch/u/meyerma)\
**Post date:** [June 5, 2023, 12:42pm UTC](https://root-forum.cern.ch/t/writing-large-trees-into-files/55181/2 "2023-06-05T12:42:54Z")

</div>

Hi @pcanal , I have been able to reduce the size of my tree and I end up now with errors like:

```auto
		Error in <TBufferFile::WriteByteCount>: bytecount too large (more than 1073741822)
		Error in <TBufferFile::WriteByteCount>: bytecount too large (more than 1073741822)

```

Would you maybe have some idea how to fix this ?  
I couldn’t figure out based on previous similar threads.

---

<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:** [June 5, 2023, 1:06pm UTC](https://root-forum.cern.ch/t/writing-large-trees-into-files/55181/3 "2023-06-05T13:06:34Z")

</div>

Hi,

This is unfortunately a hard limit (that we are currently working on lifting) and the only work-around is to use `ChangeFile` (or equivalent) to split the data in multiple files (well technically multiple `TTree`).

Cheers,  
Philippe.

---

<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:** [June 19, 2023, 1:07pm UTC](https://root-forum.cern.ch/t/writing-large-trees-into-files/55181/4 "2023-06-19T13:07:36Z")

</div>

Closed on June 19, 2023, 1:07pm UTC

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

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [February 11, 2024, 11:33am UTC](https://root-forum.cern.ch/t/writing-large-trees-into-files/55181/5 "2024-02-11T11:33:24Z")

</div>

Opened on February 11, 2024, 11:33am UTC


