From 4469425ce1c8e25aa4542e7841c92dda38effc5e Mon Sep 17 00:00:00 2001 From: Thomas Kittelmann Date: Sun, 8 Nov 2026 19:51:59 +0000 Subject: [PATCH 1/2] MCPLGen: state what a stat:sum value of -1 means, not what might have caused it The error message for an input file with stat:sum:initial_ray_count = -1 now only says what -1 means in MCPL (the value is not available), rather than guessing at what happened in the application writing the file. Assisted-by: Claude --- .../data/pkgs/MCPL/G4MCPLPlugins/pymod__MCPLGen/mod.cc | 8 +++----- .../pkgs_val/UnitTests/G4MCPLTests/app_mkfile/main.cc | 4 ++-- .../UnitTests/G4MCPLTests/scripts/testmcplstatsums.log | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/simplebuild_dgcode/data/pkgs/MCPL/G4MCPLPlugins/pymod__MCPLGen/mod.cc b/src/simplebuild_dgcode/data/pkgs/MCPL/G4MCPLPlugins/pymod__MCPLGen/mod.cc index 671946b..7efc5c6 100644 --- a/src/simplebuild_dgcode/data/pkgs/MCPL/G4MCPLPlugins/pymod__MCPLGen/mod.cc +++ b/src/simplebuild_dgcode/data/pkgs/MCPL/G4MCPLPlugins/pymod__MCPLGen/mod.cc @@ -294,11 +294,9 @@ void MCPLGen::init_weight_scale() return;//not present (e.g. files from older McStas versions): use weights as stored if ( !(nrays > 0.0) || !std::isfinite(nrays) ) { if (nrays == -1.0) - printf("MCPLGen ERROR - The input file has a stat:sum:initial_ray_count value which is not" - " available (for instance due to an interrupted run of the application writing the file," - " or because the file contains only a part of the particles of another file), so the weights" - " can not be normalised. Set normalise_by_initial_ray_count=false to use the weights as" - " stored in the file.\n"); + printf("MCPLGen ERROR - The input file has a stat:sum:initial_ray_count value of -1, which" + " means that the value is not available, so the weights can not be normalised. Set" + " normalise_by_initial_ray_count=false to use the weights as stored in the file.\n"); else printf("MCPLGen ERROR - The input file has an invalid stat:sum:initial_ray_count value (%g)," " so the weights can not be normalised. Set normalise_by_initial_ray_count=false to use" diff --git a/src/simplebuild_dgcode/data/pkgs_val/UnitTests/G4MCPLTests/app_mkfile/main.cc b/src/simplebuild_dgcode/data/pkgs_val/UnitTests/G4MCPLTests/app_mkfile/main.cc index f6793af..ea94056 100644 --- a/src/simplebuild_dgcode/data/pkgs_val/UnitTests/G4MCPLTests/app_mkfile/main.cc +++ b/src/simplebuild_dgcode/data/pkgs_val/UnitTests/G4MCPLTests/app_mkfile/main.cc @@ -4,8 +4,8 @@ // sb_g4mcpltests_mkfile FILENAME NPARTICLES WEIGHT INITIAL_RAY_COUNT // //A value of "none" for INITIAL_RAY_COUNT means that the file does not get a -//stat:sum:initial_ray_count, while "notfinal" leaves the value at -1 (as when -//the application writing the file was interrupted). +//stat:sum:initial_ray_count, while "notfinal" leaves the value at -1 (i.e. not +//available). #include "mcpl.h" #include diff --git a/src/simplebuild_dgcode/data/pkgs_val/UnitTests/G4MCPLTests/scripts/testmcplstatsums.log b/src/simplebuild_dgcode/data/pkgs_val/UnitTests/G4MCPLTests/scripts/testmcplstatsums.log index f6e001e..44b22bd 100644 --- a/src/simplebuild_dgcode/data/pkgs_val/UnitTests/G4MCPLTests/scripts/testmcplstatsums.log +++ b/src/simplebuild_dgcode/data/pkgs_val/UnitTests/G4MCPLTests/scripts/testmcplstatsums.log @@ -49,7 +49,7 @@ Output stat:sum:initial_geant4_weights = 10 ==> File with initial_ray_count which is not finalised - MCPLGen ERROR - The input file has a stat:sum:initial_ray_count value which is not available (for instance due to an interrupted run of the application writing the file, or because the file contains only a part of the particles of another file), so the weights can not be normalised. Set normalise_by_initial_ray_count=false to use the weights as stored in the file. + MCPLGen ERROR - The input file has a stat:sum:initial_ray_count value of -1, which means that the value is not available, so the weights can not be normalised. Set normalise_by_initial_ray_count=false to use the weights as stored in the file. (simulation failed as expected) ==> File with initial_ray_count which is not finalised, not normalised @@ -144,5 +144,5 @@ Output stat:sum:initial_ray_count = ==> File where initial_ray_count is unavailable - MCPLGen ERROR - The input file has a stat:sum:initial_ray_count value which is not available (for instance due to an interrupted run of the application writing the file, or because the file contains only a part of the particles of another file), so the weights can not be normalised. Set normalise_by_initial_ray_count=false to use the weights as stored in the file. + MCPLGen ERROR - The input file has a stat:sum:initial_ray_count value of -1, which means that the value is not available, so the weights can not be normalised. Set normalise_by_initial_ray_count=false to use the weights as stored in the file. (simulation failed as expected) From a5f5248c4471194422f614ebe8fca3ef4b64a416 Mon Sep 17 00:00:00 2001 From: Thomas Kittelmann Date: Sun, 8 Nov 2026 20:26:54 +0000 Subject: [PATCH 2/2] ExprParser: define ExprEntity::optimisedVersion in the library Move the definition from ASTNode.icc to ASTNode.cc, where the class template is explicitly instantiated, so it is no longer compiled into each library using it. This is what the TODO in ASTNode.icc asked for, so the TODO is removed. Assisted-by: Claude --- .../pkgs/Utils/ExprParser/libinc/ASTNode.icc | 25 ------------------- .../pkgs/Utils/ExprParser/libsrc/ASTNode.cc | 24 ++++++++++++++++++ 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/simplebuild_dgcode/data/pkgs/Utils/ExprParser/libinc/ASTNode.icc b/src/simplebuild_dgcode/data/pkgs/Utils/ExprParser/libinc/ASTNode.icc index eca8064..f90eaa8 100644 --- a/src/simplebuild_dgcode/data/pkgs/Utils/ExprParser/libinc/ASTNode.icc +++ b/src/simplebuild_dgcode/data/pkgs/Utils/ExprParser/libinc/ASTNode.icc @@ -81,31 +81,6 @@ namespace ExprParser { #endif } - template - inline ExprEntityPtr ExprEntity::optimisedVersion() - { - //todo: Can we move this to .cc and make sure implementations don't get copied to clients? - if (isConstant()) { - if (isConstantValue()) - return 0;//we are already optimal - return makeobj>(evaluate()); - } - optimiseChildren(); - auto p = specialOptimisedVersion(); - if (p) { - for (int i =0; i<100000; ++i) { - _ensure_type(p); - if (i==99999) - EXPRPARSER_THROW(LogicError,"non-converging optimisation loop"); - ExprEntityPtr p_opt = p->optimisedVersion(); - if (!p_opt) - break; - p = p_opt; - } - } - return p; - } - template inline ExprEntityConstantValue::ExprEntityConstantValue(TValue val) : ExprEntity(), diff --git a/src/simplebuild_dgcode/data/pkgs/Utils/ExprParser/libsrc/ASTNode.cc b/src/simplebuild_dgcode/data/pkgs/Utils/ExprParser/libsrc/ASTNode.cc index bec4a5d..f4b8efe 100644 --- a/src/simplebuild_dgcode/data/pkgs/Utils/ExprParser/libsrc/ASTNode.cc +++ b/src/simplebuild_dgcode/data/pkgs/Utils/ExprParser/libsrc/ASTNode.cc @@ -2,6 +2,30 @@ namespace ExprParser { + template + ExprEntityPtr ExprEntity::optimisedVersion() + { + if (isConstant()) { + if (isConstantValue()) + return 0;//we are already optimal + return makeobj>(evaluate()); + } + optimiseChildren(); + auto p = specialOptimisedVersion(); + if (p) { + for (int i =0; i<100000; ++i) { + _ensure_type(p); + if (i==99999) + EXPRPARSER_THROW(LogicError,"non-converging optimisation loop"); + ExprEntityPtr p_opt = p->optimisedVersion(); + if (!p_opt) + break; + p = p_opt; + } + } + return p; + } + template class ExprEntity; template class ExprEntity; template class ExprEntity;