From 2d5ded16ece8568409ece50a796c364681a85d31 Mon Sep 17 00:00:00 2001 From: Anders Kvellestad Date: Tue, 9 Dec 2025 21:44:30 +0100 Subject: [PATCH 1/6] Removed some unnecessary lookups in depresolver.cpp --- Core/src/depresolver.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Core/src/depresolver.cpp b/Core/src/depresolver.cpp index 0998232542..d378a55d25 100644 --- a/Core/src/depresolver.cpp +++ b/Core/src/depresolver.cpp @@ -611,9 +611,10 @@ namespace Gambit /// Evaluates ObsLike vertex, and everything it depends on, and prints results void DependencyResolver::calcObsLike(VertexID vertex) { - if (SortedParentVertices.find(vertex) == SortedParentVertices.end()) + auto found = SortedParentVertices.find(vertex); + if (found == SortedParentVertices.end()) core_error().raise(LOCAL_INFO, "Tried to calculate a function not in or not at top of dependency graph."); - std::vector order = SortedParentVertices.at(vertex); + std::vector order = found->second; for (const VertexID& v : order) { @@ -641,9 +642,10 @@ namespace Gambit // pointID is supplied by the scanner, and is used to tell the printer which model // point the results should be associated with. - if (SortedParentVertices.find(vertex) == SortedParentVertices.end()) + auto found = SortedParentVertices.find(vertex); + if (found == SortedParentVertices.end()) core_error().raise(LOCAL_INFO, "Tried to calculate a function not in or not at top of dependency graph."); - std::vector order = SortedParentVertices.at(vertex); + std::vector order = found->second; for (const VertexID& v : order) { @@ -1499,10 +1501,11 @@ namespace Gambit // Take any dependencies of loop-managed vertices that have already been resolved, // and add them as "hidden" dependencies to this loop manager. - if (edges_to_force_on_manager.find(entry.toVertex) != edges_to_force_on_manager.end()) + auto found_edges_it = edges_to_force_on_manager.find(entry.toVertex); + if (found_edges_it != edges_to_force_on_manager.end()) { - for (auto it = edges_to_force_on_manager.at(entry.toVertex).begin(); - it != edges_to_force_on_manager.at(entry.toVertex).end(); ++it) + for (auto it = found_edges_it->second.begin(); + it != found_edges_it->second.end(); ++it) { logger() << "Dynamically adding dependency of " << masterGraph[fromVertex]->origin() << "::" << masterGraph[fromVertex]->name() << " on " From f0c492f66d5d00e0bfeb19d7f36fddd6cda7a7bf Mon Sep 17 00:00:00 2001 From: Anders Kvellestad Date: Tue, 9 Dec 2025 22:59:04 +0100 Subject: [PATCH 2/6] Small efficiency improvements in Utils/src/interp_collection.cpp --- Utils/src/interp_collection.cpp | 218 ++++++++++++++++++-------------- 1 file changed, 121 insertions(+), 97 deletions(-) diff --git a/Utils/src/interp_collection.cpp b/Utils/src/interp_collection.cpp index e9ed2824cb..6dd5d3bb76 100644 --- a/Utils/src/interp_collection.cpp +++ b/Utils/src/interp_collection.cpp @@ -184,8 +184,8 @@ namespace Gambit n_interpolators = interpolator_names.size(); // Get unique entries of "xi" for the grid and grid size. - x1_vec = tab[x1_name]; x1_vec_unsorted = tab[x1_name]; + x1_vec = x1_vec_unsorted; sort(x1_vec.begin(), x1_vec.end()); x1_vec.erase(unique(x1_vec.begin(), x1_vec.end()), x1_vec.end()); int nx1 = x1_vec.size(); @@ -223,21 +223,23 @@ namespace Gambit for (size_t i=0;i<(x1_vec.size());i++) { + double x1_curr = x1_vec[i]; // Cache current value + double x1_next = x1_vec[i+1]; // Cache next value // In case of exact match - if (x1 == x1_vec[i]) + if (x1 == x1_curr) { - xi_lower[0] = x1_vec[i]; - xi_upper[0] = x1_vec[i]; + xi_lower[0] = x1_curr; + xi_upper[0] = x1_curr; x1_equal = true; } // Otherwise bounds as normal - if (x1 > x1_vec[i] && x1 < x1_vec[i+1]) + if (x1 > x1_curr && x1 < x1_next) { - xi_lower[0] = x1_vec[i]; - xi_upper[0] = x1_vec[i+1]; + xi_lower[0] = x1_curr; + xi_upper[0] = x1_next; } // End early if you have found all of the bounds - if (x1 < x1_vec[i] ) break; + if (x1 < x1_curr) break; } // Find the corresponding function values @@ -447,16 +449,16 @@ namespace Gambit n_interpolators = interpolator_names.size(); // Get unique entries of "xi" for the grid and grid size. - x1_vec = tab[x1_name]; x1_vec_unsorted = tab[x1_name]; + x1_vec = x1_vec_unsorted; sort(x1_vec.begin(), x1_vec.end()); x1_vec.erase(unique(x1_vec.begin(), x1_vec.end()), x1_vec.end()); int nx1 = x1_vec.size(); x1_min = x1_vec.front(); x1_max = x1_vec.back(); - x2_vec = tab[x2_name]; x2_vec_unsorted = tab[x2_name]; + x2_vec = x2_vec_unsorted; sort(x2_vec.begin(), x2_vec.end()); x2_vec.erase(unique(x2_vec.begin(), x2_vec.end()), x2_vec.end()); int nx2 = x2_vec.size(); @@ -495,40 +497,44 @@ namespace Gambit for (size_t i=0;i<(x1_vec.size());i++) { + double x1_curr = x1_vec[i]; + double x1_next = x1_vec[i+1]; // In case of exact match - if (x1 == x1_vec[i]) + if (x1 == x1_curr) { - xi_lower[0] = x1_vec[i]; - xi_upper[0] = x1_vec[i]; + xi_lower[0] = x1_curr; + xi_upper[0] = x1_curr; x1_equal = true; } // Otherwise bounds as normal - if (x1 > x1_vec[i] && x1 < x1_vec[i+1]) + if (x1 > x1_curr && x1 < x1_next) { - xi_lower[0] = x1_vec[i]; - xi_upper[0] = x1_vec[i+1]; + xi_lower[0] = x1_curr; + xi_upper[0] = x1_next; } // End early if you have found all of the bounds - if (x1 < x1_vec[i] ) break; + if (x1 < x1_curr ) break; } for (size_t i=0;i<(x2_vec.size());i++) { + double x2_curr = x2_vec[i]; + double x2_next = x2_vec[i+1]; // In case of exact match - if (x2 == x2_vec[i]) + if (x2 == x2_curr) { - xi_lower[1] = x2_vec[i]; - xi_upper[1] = x2_vec[i]; + xi_lower[1] = x2_curr; + xi_upper[1] = x2_curr; x2_equal = true; } // Otherwise bounds as normal - if (x2 > x2_vec[i] && x2 < x2_vec[i+1]) + if (x2 > x2_curr && x2 < x2_next) { - xi_lower[1] = x2_vec[i]; - xi_upper[1] = x2_vec[i+1]; + xi_lower[1] = x2_curr; + xi_upper[1] = x2_next; } - if (x2 < x2_vec[i]) break; + if (x2 < x2_curr) break; } // Find the corresponding function values @@ -641,32 +647,32 @@ namespace Gambit n_interpolators = interpolator_names.size(); // Get unique entries of "xi" for the grid and grid size. - x1_vec = tab[x1_name]; x1_vec_unsorted = tab[x1_name]; + x1_vec = x1_vec_unsorted; sort(x1_vec.begin(), x1_vec.end()); x1_vec.erase(unique(x1_vec.begin(), x1_vec.end()), x1_vec.end()); int nx1 = x1_vec.size(); x1_min = x1_vec.front(); x1_max = x1_vec.back(); - x2_vec = tab[x2_name]; x2_vec_unsorted = tab[x2_name]; + x2_vec = x2_vec_unsorted; sort(x2_vec.begin(), x2_vec.end()); x2_vec.erase(unique(x2_vec.begin(), x2_vec.end()), x2_vec.end()); int nx2 = x2_vec.size(); x2_min = x2_vec.front(); x2_max = x2_vec.back(); - x3_vec = tab[x3_name]; x3_vec_unsorted = tab[x3_name]; + x3_vec = x3_vec_unsorted; sort(x3_vec.begin(), x3_vec.end()); x3_vec.erase(unique(x3_vec.begin(), x3_vec.end()), x3_vec.end()); int nx3 = x3_vec.size(); x3_min = x3_vec.front(); x3_max = x3_vec.back(); - x4_vec = tab[x4_name]; x4_vec_unsorted = tab[x4_name]; + x4_vec = x4_vec_unsorted; sort(x4_vec.begin(), x4_vec.end()); x4_vec.erase(unique(x4_vec.begin(), x4_vec.end()), x4_vec.end()); int nx4 = x4_vec.size(); @@ -708,65 +714,73 @@ namespace Gambit // Determine edges (-1 to make sure it doesn't run over the last element) for (size_t i=0;i<(x1_vec.size());i++) { - // // In case of exact match - if (x1 == x1_vec[i]) + double x1_curr = x1_vec[i]; + double x1_next = x1_vec[i+1]; + // In case of exact match + if (x1 == x1_curr) { - xi_lower[0] = x1_vec[i]; - xi_upper[0] = x1_vec[i]; + xi_lower[0] = x1_curr; + xi_upper[0] = x1_curr; } // Otherwise bounds as normal - if (x1 > x1_vec[i] && x1 < x1_vec[i+1]) + if (x1 > x1_curr && x1 < x1_next) { - xi_lower[0] = x1_vec[i]; - xi_upper[0] = x1_vec[i+1]; + xi_lower[0] = x1_curr; + xi_upper[0] = x1_next; } // End early if you have found all of the bounds - if (x1 < x1_vec[i] ) break; + if (x1 < x1_curr) break; } for (size_t i=0;i<(x2_vec.size());i++) { - if (x2 == x2_vec[i]) + double x2_curr = x2_vec[i]; + double x2_next = x2_vec[i+1]; + if (x2 == x2_curr) { - xi_lower[1] = x2_vec[i]; - xi_upper[1] = x2_vec[i]; + xi_lower[1] = x2_curr; + xi_upper[1] = x2_curr; } - if (x2 > x2_vec[i] && x2 < x2_vec[i+1]) + if (x2 > x2_curr && x2 < x2_next) { - xi_lower[1] = x2_vec[i]; - xi_upper[1] = x2_vec[i+1]; + xi_lower[1] = x2_curr; + xi_upper[1] = x2_next; } - if (x2 < x2_vec[i]) break; + if (x2 < x2_curr) break; } for (size_t i=0;i<(x3_vec.size());i++) { - if (x3 == x3_vec[i]) + double x3_curr = x3_vec[i]; + double x3_next = x3_vec[i+1]; + if (x3 == x3_curr) { - xi_lower[2] = x3_vec[i]; - xi_upper[2] = x3_vec[i]; + xi_lower[2] = x3_curr; + xi_upper[2] = x3_curr; } - if (x3 > x3_vec[i] && x3 < x3_vec[i+1]) + if (x3 > x3_curr && x3 < x3_next) { - xi_lower[2] = x3_vec[i]; - xi_upper[2] = x3_vec[i+1]; + xi_lower[2] = x3_curr; + xi_upper[2] = x3_next; } - if (x3 < x3_vec[i]) break; + if (x3 < x3_curr) break; } for (size_t i=0;i<(x4_vec.size());i++) { - if (x4 == x4_vec[i]) + double x4_curr = x4_vec[i]; + double x4_next = x4_vec[i+1]; + if (x4 == x4_curr) { - xi_lower[3] = x4_vec[i]; - xi_upper[3] = x4_vec[i]; + xi_lower[3] = x4_curr; + xi_upper[3] = x4_curr; } - if (x4 > x4_vec[i] && x4 < x4_vec[i+1]) + if (x4 > x4_curr && x4 < x4_next) { - xi_lower[3] = x4_vec[i]; - xi_upper[3] = x4_vec[i+1]; + xi_lower[3] = x4_curr; + xi_upper[3] = x4_next; } - if (x4 < x4_vec[i]) break; + if (x4 < x4_curr) break; } // Find the corresponding function values @@ -907,40 +921,40 @@ namespace Gambit n_interpolators = interpolator_names.size(); // Get unique entries of "xi" for the grid and grid size. - x1_vec = tab[x1_name]; x1_vec_unsorted = tab[x1_name]; + x1_vec = x1_vec_unsorted; sort(x1_vec.begin(), x1_vec.end()); x1_vec.erase(unique(x1_vec.begin(), x1_vec.end()), x1_vec.end()); int nx1 = x1_vec.size(); x1_min = x1_vec.front(); x1_max = x1_vec.back(); - x2_vec = tab[x2_name]; x2_vec_unsorted = tab[x2_name]; + x2_vec = x2_vec_unsorted; sort(x2_vec.begin(), x2_vec.end()); x2_vec.erase(unique(x2_vec.begin(), x2_vec.end()), x2_vec.end()); int nx2 = x2_vec.size(); x2_min = x2_vec.front(); x2_max = x2_vec.back(); - x3_vec = tab[x3_name]; x3_vec_unsorted = tab[x3_name]; + x3_vec = x3_vec_unsorted; sort(x3_vec.begin(), x3_vec.end()); x3_vec.erase(unique(x3_vec.begin(), x3_vec.end()), x3_vec.end()); int nx3 = x3_vec.size(); x3_min = x3_vec.front(); x3_max = x3_vec.back(); - x4_vec = tab[x4_name]; x4_vec_unsorted = tab[x4_name]; + x4_vec = x4_vec_unsorted; sort(x4_vec.begin(), x4_vec.end()); x4_vec.erase(unique(x4_vec.begin(), x4_vec.end()), x4_vec.end()); int nx4 = x4_vec.size(); x4_min = x4_vec.front(); x4_max = x4_vec.back(); - x5_vec = tab[x5_name]; x5_vec_unsorted = tab[x5_name]; + x5_vec = x5_vec_unsorted; sort(x5_vec.begin(), x5_vec.end()); x5_vec.erase(unique(x5_vec.begin(), x5_vec.end()), x5_vec.end()); int nx5 = x5_vec.size(); @@ -983,80 +997,90 @@ namespace Gambit // This is split into 5 different loops since the number in each dimension may be different for (size_t i=0;i<(x1_vec.size());i++) { + double x1_curr = x1_vec[i]; + double x1_next = x1_vec[i+1]; // In case of exact match - if (x1 == x1_vec[i]) + if (x1 == x1_curr) { - xi_lower[0] = x1_vec[i]; - xi_upper[0] = x1_vec[i]; + xi_lower[0] = x1_curr; + xi_upper[0] = x1_curr; } // Otherwise bounds as normal - if (x1 > x1_vec[i] && x1 < x1_vec[i+1]) + if (x1 > x1_curr && x1 < x1_next) { - xi_lower[0] = x1_vec[i]; - xi_upper[0] = x1_vec[i+1]; + xi_lower[0] = x1_curr; + xi_upper[0] = x1_next; } // End early if you have found all of the bounds - if (x1 < x1_vec[i] ) break; + if (x1 < x1_curr) break; } for (size_t i=0;i<(x2_vec.size());i++) { - if (x2 == x2_vec[i]) + double x2_curr = x2_vec[i]; + double x2_next = x2_vec[i+1]; + if (x2 == x2_curr) { - xi_lower[1] = x2_vec[i]; - xi_upper[1] = x2_vec[i]; + xi_lower[1] = x2_curr; + xi_upper[1] = x2_curr; } - if (x2 > x2_vec[i] && x2 < x2_vec[i+1]) + if (x2 > x2_curr && x2 < x2_next) { - xi_lower[1] = x2_vec[i]; - xi_upper[1] = x2_vec[i+1]; + xi_lower[1] = x2_curr; + xi_upper[1] = x2_next; } - if (x2 < x2_vec[i]) break; + if (x2 < x2_curr) break; } for (size_t i=0;i<(x3_vec.size());i++) { - if (x3 == x3_vec[i]) + double x3_curr = x3_vec[i]; + double x3_next = x3_vec[i+1]; + if (x3 == x3_curr) { - xi_lower[2] = x3_vec[i]; - xi_upper[2] = x3_vec[i]; + xi_lower[1] = x3_curr; + xi_upper[1] = x3_curr; } - if (x3 > x3_vec[i] && x3 < x3_vec[i+1]) + if (x3 > x3_curr && x3 < x3_next) { - xi_lower[2] = x3_vec[i]; - xi_upper[2] = x3_vec[i+1]; + xi_lower[1] = x3_curr; + xi_upper[1] = x3_next; } - if (x3 < x3_vec[i]) break; + if (x3 < x3_curr) break; } for (size_t i=0;i<(x4_vec.size());i++) { - if (x4 == x4_vec[i]) + double x4_curr = x4_vec[i]; + double x4_next = x4_vec[i+1]; + if (x4 == x4_curr) { - xi_lower[3] = x4_vec[i]; - xi_upper[3] = x4_vec[i]; + xi_lower[1] = x4_curr; + xi_upper[1] = x4_curr; } - if (x4 > x4_vec[i] && x4 < x4_vec[i+1]) + if (x4 > x4_curr && x4 < x4_next) { - xi_lower[3] = x4_vec[i]; - xi_upper[3] = x4_vec[i+1]; + xi_lower[1] = x4_curr; + xi_upper[1] = x4_next; } - if (x4 < x4_vec[i]) break; + if (x4 < x4_curr) break; } for (size_t i=0;i<(x5_vec.size());i++) { - if (x5 == x5_vec[i]) + double x5_curr = x5_vec[i]; + double x5_next = x5_vec[i+1]; + if (x5 == x5_curr) { - xi_lower[4] = x5_vec[i]; - xi_upper[4] = x5_vec[i]; + xi_lower[1] = x5_curr; + xi_upper[1] = x5_curr; } - if (x5 > x5_vec[i] && x5 < x5_vec[i+1]) + if (x5 > x5_curr && x5 < x5_next) { - xi_lower[4] = x5_vec[i]; - xi_upper[4] = x5_vec[i+1]; + xi_lower[1] = x5_curr; + xi_upper[1] = x5_next; } - if (x5 < x5_vec[i]) break; + if (x5 < x5_curr) break; } // Find the corresponding function values From 760fcf13b7cf29d8f353fca9efa76e26c7f18f5e Mon Sep 17 00:00:00 2001 From: Anders Kvellestad Date: Tue, 9 Dec 2025 23:55:58 +0100 Subject: [PATCH 3/6] Various minor performance tweaks in ColliderBit (caching, pass-by-ref) --- .../include/gambit/ColliderBit/Utils.hpp | 8 +++--- ColliderBit/src/ColliderBit_eventloop.cpp | 27 ++++++++++++------- ColliderBit/src/Utils.cpp | 8 +++--- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/ColliderBit/include/gambit/ColliderBit/Utils.hpp b/ColliderBit/include/gambit/ColliderBit/Utils.hpp index 7b0341ca7c..4380bdc2c1 100644 --- a/ColliderBit/include/gambit/ColliderBit/Utils.hpp +++ b/ColliderBit/include/gambit/ColliderBit/Utils.hpp @@ -403,16 +403,16 @@ namespace Gambit /// Utility function for returning a collection of same-flavour, oppsosite-sign particle pairs - std::vector> getSFOSpairs(std::vector particles); + std::vector> getSFOSpairs(const std::vector& particles); /// Utility function for returning a collection of oppsosite-sign particle pairs - std::vector> getOSpairs(std::vector particles); + std::vector> getOSpairs(const std::vector& particles); /// Utility function for returning a collection of same-sign particle pairs - std::vector> getSSpairs(std::vector particles); + std::vector> getSSpairs(const std::vector& particles); /// Utility function for returning a collection of b-tagged jets - std::vector> getBJetPairs(std::vector bjets); + std::vector> getBJetPairs(const std::vector& bjets); /// @name Sorting diff --git a/ColliderBit/src/ColliderBit_eventloop.cpp b/ColliderBit/src/ColliderBit_eventloop.cpp index 6ffb5ad804..e0b29b56b0 100644 --- a/ColliderBit/src/ColliderBit_eventloop.cpp +++ b/ColliderBit/src/ColliderBit_eventloop.cpp @@ -154,7 +154,7 @@ namespace Gambit max_nEvents[collider] = colOptions.getValueOrDef(10000, "max_nEvents"); double mean_nEvents = colOptions.getValueOrDef(10000, "mean_nEvents"); result.ratio_MC_expected[collider] = colOptions.getValueOrDef(1.0, "mean_relative_nEvents"); - result.estimator = colOptions.getValueOrDef("MLE", "poisson_like_estimator"); + result.estimator = colOptions.getValueOrDef("MLE", "poisson_like_estimator"); // Check that the nEvents options given make sense. if (fixed_nEvents and (min_nEvents.at(collider) > max_nEvents.at(collider)) ) @@ -168,6 +168,7 @@ namespace Gambit if (colOptions.hasKey("mean_relative_nEvents")) { double max_lumi = GetMaxLumi(result.analyses.at(collider)); + std::map xsec_map = *Dep::InitialTotalCrossSection; double xsec = xsec_map[collider].xsec(); mean_nEvents = max_lumi * xsec * result.ratio_MC_expected[collider]; @@ -284,20 +285,28 @@ namespace Gambit piped_errors.check(ColliderBit_error()); piped_invalid_point.check(); + const int max_nEvents_collider = max_nEvents.at(collider); + const int desired_nEvents_collider = result.desired_nEvents[collider]; + // Convergence loop - while(((fixed_nEvents && result.current_event_count() < max_nEvents.at(collider)) or (!fixed_nEvents && result.current_event_count() < result.desired_nEvents[collider])) and not *Loop::done) + while(((fixed_nEvents && result.current_event_count() < max_nEvents_collider) or (!fixed_nEvents && result.current_event_count() < desired_nEvents_collider)) and not *Loop::done) { + const int max_nEvents_val = max_nEvents.at(collider); + const int min_nEvents_val = min_nEvents.at(collider); + const int stoppingres_val = stoppingres.at(collider); + const int desired_nEvents_val = result.desired_nEvents[collider]; + int eventCountBetweenConvergenceChecks = 0; #ifdef COLLIDERBIT_DEBUG - cout << DEBUG_PREFIX << "Starting main event loop. Will do " << stoppingres.at(collider) << " events before testing convergence." << endl; + cout << DEBUG_PREFIX << "Starting main event loop. Will do " << stoppingres_val << " events before testing convergence." << endl; #endif // Main event loop result.event_generation_began = true; #pragma omp parallel { - while(eventCountBetweenConvergenceChecks < stoppingres.at(collider) and - ((fixed_nEvents && result.current_event_count() < max_nEvents.at(collider)) or (!fixed_nEvents && result.current_event_count() < result.desired_nEvents[collider])) and + while(eventCountBetweenConvergenceChecks < stoppingres_val and + ((fixed_nEvents && result.current_event_count() < max_nEvents_val) or (!fixed_nEvents && result.current_event_count() < desired_nEvents_val)) and not *Loop::done and not result.end_of_event_file and not result.exceeded_maxFailedEvents and @@ -307,12 +316,12 @@ namespace Gambit bool thread_do_iteration = true; int thread_my_iteration; - // Increment counters before executing the corresponding event loop iteration, + // Increment counters before executing the corresponding event loop iteration, // to stop other threads from starting any event iterations beyond max_nEvents. #pragma omp critical { - if ( (fixed_nEvents && result.current_event_count() < max_nEvents.at(collider)) - or (!fixed_nEvents && result.current_event_count() < result.desired_nEvents[collider])) + if ( (fixed_nEvents && result.current_event_count() < max_nEvents_val) + or (!fixed_nEvents && result.current_event_count() < desired_nEvents_val)) { result.current_event_count()++; thread_my_iteration = result.current_event_count(); @@ -361,7 +370,7 @@ namespace Gambit // Don't bother with convergence stuff if we haven't passed the minimum number of events yet. // Only do this if we are using a fixed number of events. - if (fixed_nEvents and result.current_event_count() >= min_nEvents.at(collider)) + if (fixed_nEvents and result.current_event_count() >= min_nEvents_val) { #pragma omp parallel { diff --git a/ColliderBit/src/Utils.cpp b/ColliderBit/src/Utils.cpp index f8250bc34e..efc84d4d13 100644 --- a/ColliderBit/src/Utils.cpp +++ b/ColliderBit/src/Utils.cpp @@ -150,7 +150,7 @@ namespace Gambit // Utility function for returning a collection of same-flavour, oppsosite-sign particle pairs - std::vector> getSFOSpairs(std::vector particles) + std::vector> getSFOSpairs(const std::vector& particles) { std::vector> SFOSpair_container; for (size_t ip1=0; ip1> getOSpairs(std::vector particles) + std::vector> getOSpairs(const std::vector& particles) { std::vector> OSpair_container; for (size_t ip1=0;ip1> getSSpairs(std::vector particles) + std::vector> getSSpairs(const std::vector& particles) { std::vector> SSpair_container; for (size_t ip1=0;ip1> getBJetPairs(std::vector bjets) + std::vector> getBJetPairs(const std::vector& bjets) { std::vector> BJetpair_container; for (size_t ibj1=0; ibj1 Date: Wed, 10 Dec 2025 09:23:48 +0100 Subject: [PATCH 4/6] Added bounds check on path buffers in util_functions.cpp --- Utils/src/util_functions.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Utils/src/util_functions.cpp b/Utils/src/util_functions.cpp index d634147f4c..866cf1e7de 100644 --- a/Utils/src/util_functions.cpp +++ b/Utils/src/util_functions.cpp @@ -330,8 +330,14 @@ namespace Gambit /// Get directory name from full path+filename (POSIX) std::string dir_name(const std::string& path) { + if(path.size() >= 1000) + { + std::string msg = "Utils::dir_name error: path length (" + std::to_string(path.size()) + ") exceeds buffer size (1000)!"; + std::cerr << msg << std::endl; + abort(); + } char buffer[1000]; // temporary buffer for dirname to work with (it is a C function) - path.copy(buffer, path.size()); //TODO: error if path.size()>1000 + path.copy(buffer, path.size()); buffer[path.size()] = '\0'; std::string result = dirname(&buffer[0]); // should use the C function... return result; @@ -340,8 +346,14 @@ namespace Gambit /// Get file name from full path+filename (POSIX) std::string base_name(const std::string& path) { + if(path.size() >= 1000) + { + std::string msg = "Utils::base_name error: path length (" + std::to_string(path.size()) + ") exceeds buffer size (1000)!"; + std::cerr << msg << std::endl; + abort(); + } char buffer[1000]; // temporary buffer for basename to work with (it is a C function) - path.copy(buffer, path.size()); //TODO: error if path.size()>1000 + path.copy(buffer, path.size()); buffer[path.size()] = '\0'; std::string result = basename(&buffer[0]); // should use the C function... return result; From 79c57c9f79ec49ad6b37e1bf69564f10b52dd73e Mon Sep 17 00:00:00 2001 From: Anders Kvellestad Date: Wed, 10 Dec 2025 10:35:17 +0100 Subject: [PATCH 5/6] Fixed a bug (out of bounds) in the string comparison function check1 in util_functions.cpp --- Utils/src/util_functions.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Utils/src/util_functions.cpp b/Utils/src/util_functions.cpp index 866cf1e7de..9749f2de54 100644 --- a/Utils/src/util_functions.cpp +++ b/Utils/src/util_functions.cpp @@ -421,17 +421,15 @@ namespace Gambit bool check1(const std::string& s1, const std::string& s2) { if(s2.length() - s1.length() != 1){ return false; } - unsigned int i,j; - for(i=0,j=0; i Date: Wed, 10 Dec 2025 18:40:18 +0100 Subject: [PATCH 6/6] Fixed duplicated variables. --- ColliderBit/src/ColliderBit_eventloop.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ColliderBit/src/ColliderBit_eventloop.cpp b/ColliderBit/src/ColliderBit_eventloop.cpp index e0b29b56b0..672e9566dc 100644 --- a/ColliderBit/src/ColliderBit_eventloop.cpp +++ b/ColliderBit/src/ColliderBit_eventloop.cpp @@ -286,27 +286,25 @@ namespace Gambit piped_invalid_point.check(); const int max_nEvents_collider = max_nEvents.at(collider); + const int min_nEvents_collider = min_nEvents.at(collider); + const int stoppingres_collider = stoppingres.at(collider); const int desired_nEvents_collider = result.desired_nEvents[collider]; // Convergence loop while(((fixed_nEvents && result.current_event_count() < max_nEvents_collider) or (!fixed_nEvents && result.current_event_count() < desired_nEvents_collider)) and not *Loop::done) { - const int max_nEvents_val = max_nEvents.at(collider); - const int min_nEvents_val = min_nEvents.at(collider); - const int stoppingres_val = stoppingres.at(collider); - const int desired_nEvents_val = result.desired_nEvents[collider]; int eventCountBetweenConvergenceChecks = 0; #ifdef COLLIDERBIT_DEBUG - cout << DEBUG_PREFIX << "Starting main event loop. Will do " << stoppingres_val << " events before testing convergence." << endl; + cout << DEBUG_PREFIX << "Starting main event loop. Will do " << stoppingres_collider << " events before testing convergence." << endl; #endif // Main event loop result.event_generation_began = true; #pragma omp parallel { - while(eventCountBetweenConvergenceChecks < stoppingres_val and - ((fixed_nEvents && result.current_event_count() < max_nEvents_val) or (!fixed_nEvents && result.current_event_count() < desired_nEvents_val)) and + while(eventCountBetweenConvergenceChecks < stoppingres_collider and + ((fixed_nEvents && result.current_event_count() < max_nEvents_collider) or (!fixed_nEvents && result.current_event_count() < desired_nEvents_collider)) and not *Loop::done and not result.end_of_event_file and not result.exceeded_maxFailedEvents and @@ -320,8 +318,8 @@ namespace Gambit // to stop other threads from starting any event iterations beyond max_nEvents. #pragma omp critical { - if ( (fixed_nEvents && result.current_event_count() < max_nEvents_val) - or (!fixed_nEvents && result.current_event_count() < desired_nEvents_val)) + if ( (fixed_nEvents && result.current_event_count() < max_nEvents_collider) + or (!fixed_nEvents && result.current_event_count() < desired_nEvents_collider)) { result.current_event_count()++; thread_my_iteration = result.current_event_count(); @@ -370,7 +368,7 @@ namespace Gambit // Don't bother with convergence stuff if we haven't passed the minimum number of events yet. // Only do this if we are using a fixed number of events. - if (fixed_nEvents and result.current_event_count() >= min_nEvents_val) + if (fixed_nEvents and result.current_event_count() >= min_nEvents_collider) { #pragma omp parallel {