7 #include "cetlib/container_algorithms.h" 13 #include "TClassRef.h" 15 #include "TTreeCloner.h" 26 RootOutputTree::makeTTree(TFile* filePtr,
string const& name,
int splitLevel)
28 auto tree =
new TTree{name.c_str(),
"", splitLevel};
31 <<
"Failed to create the tree: " << name <<
"\n";
33 if (tree->IsZombie()) {
35 <<
"Tree: " << name <<
" is a zombie.\n";
37 tree->SetDirectory(filePtr);
45 RootOutputTree::checkSplitLevelAndBasketSize(
46 cet::exempt_ptr<TTree const> inputTree)
const 49 if (inputTree ==
nullptr) {
52 for (
auto outputBranch : readBranches_) {
53 if (outputBranch ==
nullptr) {
56 TBranch* inputBranch =
57 const_cast<TTree*
>(inputTree.get())->
GetBranch(outputBranch->GetName());
58 if (inputBranch ==
nullptr) {
61 if ((inputBranch->GetSplitLevel() != outputBranch->GetSplitLevel()) ||
62 (inputBranch->GetBasketSize() != outputBranch->GetBasketSize())) {
64 <<
"Fast Cloning disabled because split level or basket size " 73 RootOutputTree::writeTTree(TTree* tree) noexcept(
false)
77 if (tree->GetNbranches() != 0) {
87 RootOutputTree::writeTree()
const 90 writeTTree(metaTree_);
94 RootOutputTree::fastCloneTree(cet::exempt_ptr<TTree const> intree)
96 unclonedReadBranches_.clear();
97 unclonedReadBranchNames_.clear();
98 if (!fastCloningEnabled_) {
103 if (intree->GetEntries() != 0) {
104 TTreeCloner cloner(const_cast<TTree*>(intree.get()),
107 TTreeCloner::kIgnoreMissingTopLevel |
108 TTreeCloner::kNoWarnings |
109 TTreeCloner::kNoFileCache);
110 if (cloner.IsValid()) {
111 tree_->SetEntries(tree_->GetEntries() + intree->GetEntries());
115 fastCloningEnabled_ =
false;
117 <<
"INFO: Unable to fast clone tree " << intree->GetName() <<
'\n' 118 <<
"INFO: ROOT reason is:\n" 119 <<
"INFO: " << cloner.GetWarning() <<
'\n' 120 <<
"INFO: Processing will continue, tree will be slow cloned.";
123 for (
auto const& val : readBranches_) {
124 if (val->GetEntries() != tree_->GetEntries()) {
125 unclonedReadBranches_.push_back(val);
126 unclonedReadBranchNames_.insert(
string(val->GetName()));
134 vector<TBranch*>
const& branches,
138 for (
auto const b : branches) {
139 auto bytesWritten = b->Fill();
140 if (saveMemory && (bytesWritten > threshold)) {
142 b->DropBaskets(
"all");
148 RootOutputTree::fillTree()
151 metaTree_, metaBranches_,
false, saveMemoryObjectThreshold_);
152 bool saveMemory = (saveMemoryObjectThreshold_ > -1);
154 tree_, producedBranches_, saveMemory, saveMemoryObjectThreshold_);
155 if (fastCloningEnabled_) {
157 tree_, unclonedReadBranches_, saveMemory, saveMemoryObjectThreshold_);
160 tree_, readBranches_, saveMemory, saveMemoryObjectThreshold_);
168 TBranch* br = tree_->GetBranch(pd.
branchName().c_str());
172 tree_->ResetBranchAddress(br);
179 if (TBranch* br = tree_->GetBranch(pd.
branchName().c_str())) {
180 br->SetAddress(&pProd);
188 TClassRef cls = TClass::GetClass(pd.
wrappedName().c_str());
189 if (
auto br = tree_->GetBranch(pd.
branchName().c_str())) {
191 if (pProd ==
nullptr) {
198 auto prod =
reinterpret_cast<EDProduct*
>(cls->New());
200 br->SetAddress(&pProd);
207 if (bsize == BranchDescription::invalidBasketSize) {
211 if (splitlvl == BranchDescription::invalidSplitLevel) {
212 splitlvl = splitLevel_;
214 if (pProd !=
nullptr) {
216 <<
"OutputItem product pointer is not nullptr!\n";
218 auto prod =
reinterpret_cast<EDProduct*
>(cls->New());
220 TBranch* branch = tree_->Branch(pd.
branchName().c_str(),
235 if (pd.
compression() != BranchDescription::invalidCompression) {
241 std::unique_ptr<EDProduct> dummy(static_cast<EDProduct*>(cls->New()));
244 for (
auto i = nEntries_; i > 0; --i) {
245 auto cnt = branch->Fill();
250 if ((saveMemoryObjectThreshold_ > -1) &&
251 (bytesWritten > saveMemoryObjectThreshold_)) {
252 branch->FlushBaskets();
253 branch->DropBaskets(
"all");
258 producedBranches_.push_back(branch);
260 readBranches_.push_back(branch);
std::string const & wrappedName() const
ntuple GetBranch("organID") -> SetAddress(&xx)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
static void fillTreeBranches(TTree *, vector< TBranch * > const &branches, bool saveMemory, int64_t threshold)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string const & branchName() const