Skip to content

Commit b5ce317

Browse files
committed
Common: TreeStream optional upper limit on file size
Signed-off-by: Felix Schlepper <[email protected]>
1 parent 43223a4 commit b5ce317

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Common/Utils/include/CommonUtils/TreeStream.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class TreeStream
6363
const char* getName() const { return mTree.GetName(); }
6464
void setID(int id) { mID = id; }
6565
int getID() const { return mID; }
66+
void setMaxFileSize(Long64_t max) { mMaxFileSize = max; }
67+
Long64_t getMaxFileSize() const { return mMaxFileSize; }
6668

6769
TreeStream& operator<<(const Bool_t& b)
6870
{
@@ -177,6 +179,7 @@ class TreeStream
177179
int mNextNameCounter = 0; ///< next name counter
178180
int mStatus = 0; ///< status of the layout
179181
TString mNextName; ///< name for next entry
182+
Long64_t mMaxFileSize{0}; ///< optional upper limit on file size
180183

181184
ClassDefNV(TreeStream, 0);
182185
};

Common/Utils/include/CommonUtils/TreeStreamRedirector.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,25 @@ class TreeStreamRedirector
4444
TreeStreamRedirector(const char* fname = "", const char* option = "recreate");
4545
virtual ~TreeStreamRedirector();
4646
void Close();
47-
TFile* GetFile() { return mDirectory->GetFile(); }
4847
TDirectory* GetDirectory() { return mDirectory; }
49-
virtual TreeStream& operator<<(Int_t id);
50-
virtual TreeStream& operator<<(const char* name);
48+
TFile* GetFile() { return mDirectory->GetFile(); }
49+
Long64_t GetMaxFileSize() const noexcept { return mMaxFileSize; }
5150
void SetDirectory(TDirectory* sfile);
5251
void SetFile(TFile* sfile);
52+
void SetMaxFileSize(Long64_t max) { mMaxFileSize = max; }
5353
static void FixLeafNameBug(TTree* tree);
5454

55+
virtual TreeStream& operator<<(Int_t id);
56+
virtual TreeStream& operator<<(const char* name);
57+
5558
private:
5659
TreeStreamRedirector(const TreeStreamRedirector& tsr);
5760
TreeStreamRedirector& operator=(const TreeStreamRedirector& tsr);
5861

5962
std::unique_ptr<TDirectory> mOwnDirectory; // own directory of the redirector
6063
TDirectory* mDirectory = nullptr; // output directory
6164
std::vector<std::unique_ptr<TreeStream>> mDataLayouts; // array of data layouts
65+
Long64_t mMaxFileSize{0}; // optional upper limit on file size
6266

6367
ClassDefNV(TreeStreamRedirector, 0);
6468
};

Common/Utils/src/TreeStream.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "CommonUtils/TreeStream.h"
1515
#include <TBranch.h>
16+
#include <TFile.h>
1617

1718
using namespace o2::utils;
1819

@@ -108,6 +109,11 @@ void TreeStream::Fill()
108109
{
109110
// Fill the tree
110111

112+
// Stop filling if maximum file size is exceeded
113+
if (mMaxFileSize != 0 && mTree.GetDirectory()->GetFile()->GetEND() > mMaxFileSize) {
114+
return;
115+
}
116+
111117
int entries = mElements.size();
112118
if (entries > mTree.GetNbranches()) {
113119
BuildTree();

Common/Utils/src/TreeStreamRedirector.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ TreeStream& TreeStreamRedirector::operator<<(Int_t id)
7777
mDataLayouts.emplace_back(std::unique_ptr<TreeStream>(new TreeStream(Form("Tree%d", id))));
7878
auto layout = mDataLayouts.back().get();
7979
layout->setID(id);
80+
layout->setMaxFileSize(mMaxFileSize);
8081
if (backup) {
8182
backup->cd();
8283
}
@@ -101,6 +102,7 @@ TreeStream& TreeStreamRedirector::operator<<(const char* name)
101102
mDataLayouts.emplace_back(std::unique_ptr<TreeStream>(new TreeStream(name)));
102103
auto layout = mDataLayouts.back().get();
103104
layout->setID(-1);
105+
layout->setMaxFileSize(mMaxFileSize);
104106
if (backup) {
105107
backup->cd();
106108
}

0 commit comments

Comments
 (0)