From a41450413da07b4ad67006747568bfc3e2ab233c Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Wed, 6 May 2026 15:43:27 +0200 Subject: [PATCH] Harden merging of VLAs Protect for the case all the VLAs are empty. Validate number of entries if fast cloning is used. --- Framework/AODMerger/src/aodMerger.cxx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Framework/AODMerger/src/aodMerger.cxx b/Framework/AODMerger/src/aodMerger.cxx index 11dae2dc5eac4..124c68ad97a30 100644 --- a/Framework/AODMerger/src/aodMerger.cxx +++ b/Framework/AODMerger/src/aodMerger.cxx @@ -286,6 +286,21 @@ int main(int argc, char* argv[]) } outputDir->cd(); auto outputTree = inputTree->CloneTree(-1, (fastCopy) ? "fast" : ""); + // Validate that all branches have the same number of entries after CloneTree. + // Fast copy from remote (xrootd) sources can silently produce corrupt trees + // if a read fails mid-transfer. + { + auto expectedEntries = outputTree->GetEntries(); + TObjArray* clonedBranches = outputTree->GetListOfBranches(); + for (int ib = 0; ib < clonedBranches->GetEntriesFast(); ++ib) { + auto* br = (TBranch*)clonedBranches->UncheckedAt(ib); + if (br->GetEntries() != expectedEntries) { + printf(" *** FATAL ***: After CloneTree, branch %s has %lld entries but tree has %lld\n", + br->GetName(), br->GetEntries(), expectedEntries); + exitCode = 7; + } + } + } currentDirSize += inputTree->GetTotBytes(); // NOTE outputTree->GetTotBytes() is 0, so we use the inputTree here alreadyCopied = true; outputTree->SetAutoFlush(0); @@ -308,6 +323,7 @@ int main(int argc, char* argv[]) // detect VLA if (((TLeaf*)br->GetListOfLeaves()->First())->GetLeafCount() != nullptr) { int maximum = ((TLeaf*)br->GetListOfLeaves()->First())->GetLeafCount()->GetMaximum(); + maximum = std::max(maximum, 1); // get type static TClass* cls; @@ -477,4 +493,4 @@ int main(int argc, char* argv[]) printf("\n"); return exitCode; -} \ No newline at end of file +}