13 #include "TClassRef.h" 15 #include "TTreeCloner.h" 30 RootOutputTree::makeTTree(TFile* filePtr,
string const&
name,
int splitLevel)
32 TTree*
tree =
new TTree(name.c_str(),
"", splitLevel);
35 <<
"Failed to create the tree: " << name <<
"\n";
37 if (tree->IsZombie()) {
39 <<
"Tree: " << name <<
" is a zombie.\n";
41 tree->SetDirectory(filePtr);
49 RootOutputTree::checkSplitLevelAndBasketSize(
53 if (inputTree ==
nullptr) {
56 for (
auto outputBranch : readBranches_) {
57 if (outputBranch ==
nullptr) {
60 TBranch* inputBranch =
61 const_cast<TTree*
>(inputTree.
get())->GetBranch(outputBranch->GetName());
62 if (inputBranch ==
nullptr) {
65 if ((inputBranch->GetSplitLevel() != outputBranch->GetSplitLevel()) ||
66 (inputBranch->GetBasketSize() != outputBranch->GetBasketSize())) {
68 <<
"Fast Cloning disabled because split level or basket size " 77 RootOutputTree::writeTTree(TTree*
tree) noexcept(
false)
81 if (
tree->GetNbranches() != 0) {
91 RootOutputTree::writeTree()
const 93 writeTTree(tree_.load());
94 writeTTree(metaTree_.load());
100 unclonedReadBranches_.clear();
101 unclonedReadBranchNames_.clear();
102 if (!fastCloningEnabled_.load()) {
107 if (intree->GetEntries() != 0) {
108 TTreeCloner cloner(const_cast<TTree*>(intree.
get()),
111 TTreeCloner::kIgnoreMissingTopLevel |
112 TTreeCloner::kNoWarnings |
113 TTreeCloner::kNoFileCache);
114 if (cloner.IsValid()) {
115 tree_.load()->SetEntries(tree_.load()->GetEntries() +
116 intree->GetEntries());
120 fastCloningEnabled_ =
false;
122 <<
"INFO: Unable to fast clone tree " << intree->GetName() <<
'\n' 123 <<
"INFO: ROOT reason is:\n" 124 <<
"INFO: " << cloner.GetWarning() <<
'\n' 125 <<
"INFO: Processing will continue, tree will be slow cloned.";
128 for (
auto const&
val : readBranches_) {
129 if (
val->GetEntries() != tree_.load()->GetEntries()) {
130 unclonedReadBranches_.push_back(
val);
131 unclonedReadBranchNames_.insert(
string(
val->GetName()));
139 vector<TBranch*>
const& branches,
143 for (
auto const b : branches) {
144 auto bytesWritten =
b->Fill();
145 if (saveMemory && (bytesWritten > threshold)) {
147 b->DropBaskets(
"all");
153 RootOutputTree::fillTree()
158 saveMemoryObjectThreshold_.load());
159 bool saveMemory = (saveMemoryObjectThreshold_.load() > -1);
163 saveMemoryObjectThreshold_.load());
164 if (fastCloningEnabled_.load()) {
166 unclonedReadBranches_,
168 saveMemoryObjectThreshold_.load());
173 saveMemoryObjectThreshold_.load());
181 TBranch* br = tree_.load()->GetBranch(bd.
branchName().c_str());
185 tree_.load()->ResetBranchAddress(br);
195 TClassRef cls = TClass::GetClass(bd.
wrappedName().c_str());
196 if (TBranch* br = tree_.load()->GetBranch(bd.
branchName().c_str())) {
198 if (pProd ==
nullptr) {
208 br->SetAddress(&pProd);
215 if (bsize == BranchDescription::invalidBasketSize) {
216 bsize = basketSize_.load();
219 if (splitlvl == BranchDescription::invalidSplitLevel) {
220 splitlvl = splitLevel_.load();
222 if (pProd !=
nullptr) {
224 <<
"OutputItem product pointer is not nullptr!\n";
228 TBranch* branch = tree_.load()->Branch(bd.
branchName().c_str(),
241 if (bd.
compression() != BranchDescription::invalidCompression) {
244 if (nEntries_.load() > 0) {
247 std::unique_ptr<EDProduct>
dummy(static_cast<EDProduct*>(cls->New()));
250 for (
auto i = nEntries_.load();
i > 0; --
i) {
251 auto cnt = branch->Fill();
256 if ((saveMemoryObjectThreshold_.load() > -1) &&
257 (bytesWritten > saveMemoryObjectThreshold_.load())) {
258 branch->FlushBaskets();
259 branch->DropBaskets(
"all");
264 producedBranches_.push_back(branch);
266 readBranches_.push_back(branch);
bool produced() const noexcept
std::string const & wrappedName() const noexcept
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
int basketSize() const noexcept
pointer get() const noexcept
static void fillTreeBranches(TTree *, vector< TBranch * > const &branches, bool saveMemory, int64_t threshold)
int splitLevel() const noexcept
int compression() const noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
cet::LibraryManager dummy("noplugin")
std::string const & branchName() const noexcept