Skip to content

Harden merging of VLAs#15368

Draft
ktf wants to merge 1 commit intoAliceO2Group:devfrom
ktf:pr15368
Draft

Harden merging of VLAs#15368
ktf wants to merge 1 commit intoAliceO2Group:devfrom
ktf:pr15368

Conversation

@ktf
Copy link
Copy Markdown
Member

@ktf ktf commented May 6, 2026

Protect for the case all the VLAs are empty.

Validate number of entries if fast cloning is used.

@ktf ktf requested a review from a team as a code owner May 6, 2026 10:34
@jgrosseo jgrosseo marked this pull request as draft May 6, 2026 12:27
Comment thread Framework/AODMerger/src/aodMerger.cxx Outdated
if (((TLeaf*)br->GetListOfLeaves()->First())->GetLeafCount() != nullptr) {
int maximum = ((TLeaf*)br->GetListOfLeaves()->First())->GetLeafCount()->GetMaximum();
auto* sizeLeaf = ((TLeaf*)br->GetListOfLeaves()->First())->GetLeafCount();
// GetMaximum() can be unreliable (may return 0 or a stale value).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is based on?
It may be 0 when all VLAs are empty, right? What would be the stale value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also suspicious of that statement and I couldn't find any clue of it being correct, however the check itself is only potentially useless, but not wrong. Given the file is actually malformed*, I would keep it. Maybe we can move the validation behind an environment variable?

  • Tested with:
void test() {
  TFile *f = TFile::Open("AO2D.root");
  for (auto *key : *f->GetListOfKeys()) {
    auto *dir = dynamic_cast<TDirectoryFile*>(f->Get(key->GetName()));
    if (!dir) continue;
    for (auto *k2 : *dir->GetListOfKeys()) {
      auto *t = dynamic_cast<TTree*>(dir->Get(k2->GetName()));
      if (!t) continue;
      long long expected = t->GetEntries();
      for (auto *b : *t->GetListOfBranches()) {
        auto *br = (TBranch*)b;
        if (br->GetEntries() != expected) {
          printf("MISMATCH %s/%s branch %s: tree=%lld branch=%lld\n",
                 key->GetName(), k2->GetName(), br->GetName(), expected, br->GetEntries());
        }
      }
    }
  }

Comment thread Framework/AODMerger/src/aodMerger.cxx Outdated
Comment on lines +346 to +348
if (maximum == 0) {
maximum = 1; // all entries are empty arrays, but we still need a valid buffer
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how much CPU the scanning of the whole branch takes. Maybe not important.

Wouldn't these 3 lines be enough. Do we really need to check the validity of GetMaximum(). Shall we ask the ROOT team about it?

Comment thread Framework/AODMerger/src/aodMerger.cxx Outdated
Comment on lines +392 to +394
if (exitCode > 0) {
break;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this additional bail-out needed?

Protect for the case all the VLAs are empty.

Validate number of entries if fast cloning is used.
@ktf
Copy link
Copy Markdown
Member Author

ktf commented May 6, 2026

Updated to only check for 0 (which is for sure UB) and to validate the number of entries after a fast clone.

// detect VLA
if (((TLeaf*)br->GetListOfLeaves()->First())->GetLeafCount() != nullptr) {
int maximum = ((TLeaf*)br->GetListOfLeaves()->First())->GetLeafCount()->GetMaximum();
maximum = std::max(maximum, 1);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maximum = std::max(maximum, 1);
maximum = std::max(maximum, 1); // Can be 0 if all VLAs are empty but we need a valid buffer below

@jgrosseo
Copy link
Copy Markdown
Collaborator

jgrosseo commented May 6, 2026

This is fine with me.

@sawenzel @catalinristea As the merger is also used in MC productions and reco, could you also check if you are OK with it.

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants