Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Estimate entry size before sorting in ROOT readers #3871

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/Io/Root/src/RootMaterialTrackReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ RootMaterialTrackReader::RootMaterialTrackReader(const Config& config,
{
// necessary to guarantee that m_inputChain->GetV1() is valid for the
// entire range
m_inputChain->SetEstimate(nentries);
m_inputChain->SetEstimate(nentries + 1);

m_entryNumbers.resize(nentries);
m_inputChain->Draw("event_id", "", "goff");
Expand Down
4 changes: 4 additions & 0 deletions Examples/Io/Root/src/RootParticleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ RootParticleReader::RootParticleReader(const RootParticleReader::Config& config,

// Sort the entry numbers of the events
{
// necessary to guarantee that m_inputChain->GetV1() is valid for the
// entire range
m_inputChain->SetEstimate(m_events + 1);

m_entryNumbers.resize(m_events);
m_inputChain->Draw("event_id", "", "goff");
RootUtility::stableSort(m_inputChain->GetEntries(), m_inputChain->GetV1(),
Expand Down
4 changes: 4 additions & 0 deletions Examples/Io/Root/src/RootTrackSummaryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ RootTrackSummaryReader::RootTrackSummaryReader(

// Sort the entry numbers of the events
{
// necessary to guarantee that m_inputChain->GetV1() is valid for the
// entire range
m_inputChain->SetEstimate(m_events + 1);

m_entryNumbers.resize(m_events);
m_inputChain->Draw("event_nr", "", "goff");
RootUtility::stableSort(m_inputChain->GetEntries(), m_inputChain->GetV1(),
Expand Down
12 changes: 7 additions & 5 deletions Examples/Io/Root/src/RootVertexReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

#include "ActsExamples/Io/Root/RootVertexReader.hpp"

#include "Acts/Definitions/PdgParticle.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/EventData/SimParticle.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsExamples/Io/Root/RootUtility.hpp"
#include "ActsFatras/EventData/ProcessType.hpp"

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <stdexcept>
Expand Down Expand Up @@ -64,11 +63,14 @@ RootVertexReader::RootVertexReader(const RootVertexReader::Config& config,

// Sort the entry numbers of the events
{
// necessary to guarantee that m_inputChain->GetV1() is valid for the
// entire range
m_inputChain->SetEstimate(m_events + 1);

m_entryNumbers.resize(m_events);
m_inputChain->Draw("event_id", "", "goff");
// Sort to get the entry numbers of the ordered events
TMath::Sort(m_inputChain->GetEntries(), m_inputChain->GetV1(),
m_entryNumbers.data(), false);
RootUtility::stableSort(m_inputChain->GetEntries(), m_inputChain->GetV1(),
m_entryNumbers.data(), false);
}
}

Expand Down
9 changes: 7 additions & 2 deletions Examples/Scripts/TrackingPerformance/TreeReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ struct TrackStatesReader : public TreeReader {
// It's not necessary if you just need to read one file, but please do it to
// synchronize events if multiple root files are read
if (sortEvents) {
tree->SetEstimate(tree->GetEntries() + 1);
entryNumbers.resize(tree->GetEntries());
tree->Draw("event_nr", "", "goff");
// Sort to get the entry numbers of the ordered events
Expand Down Expand Up @@ -338,6 +339,7 @@ struct TrackSummaryReader : public TreeReader {
// It's not necessary if you just need to read one file, but please do it to
// synchronize events if multiple root files are read
if (sortEvents) {
tree->SetEstimate(tree->GetEntries() + 1);
entryNumbers.resize(tree->GetEntries());
tree->Draw("event_nr", "", "goff");
// Sort to get the entry numbers of the ordered events
Expand Down Expand Up @@ -368,7 +370,8 @@ struct TrackSummaryReader : public TreeReader {
std::vector<std::vector<double>>* outlierLayer =
new std::vector<std::vector<double>>;
std::vector<unsigned int>* nMajorityHits = new std::vector<unsigned int>;
std::vector<std::uint64_t>* majorityParticleId = new std::vector<std::uint64_t>;
std::vector<std::uint64_t>* majorityParticleId =
new std::vector<std::uint64_t>;

std::vector<bool>* hasFittedParams = new std::vector<bool>;

Expand Down Expand Up @@ -427,6 +430,7 @@ struct ParticleReader : public TreeReader {
// It's not necessary if you just need to read one file, but please do it to
// synchronize events if multiple root files are read
if (sortEvents) {
tree->SetEstimate(tree->GetEntries() + 1);
entryNumbers.resize(tree->GetEntries());
tree->Draw("event_id", "", "goff");
// Sort to get the entry numbers of the ordered events
Expand All @@ -436,7 +440,8 @@ struct ParticleReader : public TreeReader {
}

// Get all the particles with requested event id
std::vector<ParticleInfo> getParticles(const std::uint32_t& eventNumber) const {
std::vector<ParticleInfo> getParticles(
const std::uint32_t& eventNumber) const {
// Find the start entry and the batch size for this event
std::string eventNumberStr = std::to_string(eventNumber);
std::string findStartEntry = "event_id<" + eventNumberStr;
Expand Down
Loading