commit 305f4f4329e80e77b3906141203e9241be7188c0
parent b696d0f7b6d4564489bce772d451351101bddcfa
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 5 May 2026 15:34:17 +0200
The user can disable line check when reading the tree
When reading a tree, the signature of the input lines is compared to the
one stored with the tree. If the signatures do not match, it means that
the input lines are not the ones used to build the tree, and an error is
returned.
This verification adds a computational overhead, which becomes more
significant as the number of lines increases. If a user is certain that
the data matches, they can now disable this check at their own risk.
Note that the performance gain can be significant when the number of
input lines is in the millions.
The sln-slab program has therefore been enhanced with a new option (-d)
that allows the aforementioned verification to be disabled. Its man page
has been updated accordingly.
Diffstat:
5 files changed, 53 insertions(+), 16 deletions(-)
diff --git a/doc/sln-slab.1 b/doc/sln-slab.1
@@ -15,7 +15,7 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
-.Dd March 23, 2026
+.Dd May 5, 2026
.Dt SLN-SLAB 1
.Os
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@@ -25,7 +25,7 @@
.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.Sh SYNOPSIS
.Nm
-.Op Fl hsv
+.Op Fl dhsv
.Op Fl n Ar nrealisations
.Op Fl T Ar thickness
.Op Fl t Ar threads
@@ -82,6 +82,25 @@ This structure is generated by the
.Xr sln-build 1
tool.
.\""""""""""""""""""""""""""""""""""
+.It Fl d
+Disables verification of the correspondence between the lines provided
+by the
+.Fl l
+option and those used to construct
+the acceleration structure defined by the
+.Fl a
+option.
+.Pp
+Warning!
+It is always recommended to verify that the data is correct, even though
+this verification can take a significant amount of time when there are a
+large number of lines.
+Anyway, a user who is
+.Em certain
+of the data’s consistency may nevertheless use this option
+.Pq at their own risk
+to disable this verification and thus speed up the execution.
+.\""""""""""""""""""""""""""""""""""
.It Fl h
Display short help and exit.
.It Fl l Ar lines
@@ -101,6 +120,7 @@ By default the number of realisations is 10000.
.\""""""""""""""""""""""""""""""""""
.It Fl S Ar nu_min , Ns Ar nu_max
The spectral range, in cm^-1, over which the computations are performed.
+The default spectral range is from 0 to infinity.
.\""""""""""""""""""""""""""""""""""
.It Fl s
Specifies that input lines are formatted according to the binary format
diff --git a/src/sln.h b/src/sln.h
@@ -160,8 +160,19 @@ struct sln_tree_read_args {
* therefore be defined. */
const char* filename; /* Name of the file to read */
FILE* file; /* Stream from where data are read. NULL <=> read from file */
+
+ /* Verify that the digital signature of the input lines matches the one stored
+ * in the tree. In other words, ensure that this list of lines is indeed the
+ * one used to construct the tree. An error is returned if the signatures do
+ * not match.
+ *
+ * Although it is always advisable to verify that the data matches what is
+ * expected, calculating the signatures of the lines can be time-consuming.
+ * Therefore, a user who is _certain_ that the data matches can disable this
+ * verification */
+ int disable_line_hash_check;
};
-#define SLN_TREE_READ_ARGS_NULL__ {NULL,NULL,NULL,NULL}
+#define SLN_TREE_READ_ARGS_NULL__ {NULL,NULL,NULL,NULL,0}
static const struct sln_tree_read_args SLN_TREE_READ_ARGS_NULL =
SLN_TREE_READ_ARGS_NULL__;
diff --git a/src/sln_slab.c b/src/sln_slab.c
@@ -53,11 +53,12 @@ struct args {
/* Miscellaneous */
unsigned nthreads_hint; /* Hint on the number of threads to use */
+ int disable_line_hash_check;
int lines_in_shtr_format;
int verbose;
int quit;
};
-#define ARGS_DEFAULT__ {NULL,NULL,NULL,1,{0,DBL_MAX},10000,UINT_MAX,0,0,0}
+#define ARGS_DEFAULT__ {NULL,NULL,NULL,1,{0,DBL_MAX},10000,UINT_MAX,0,0,0,0}
static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
struct cmd {
@@ -83,7 +84,7 @@ static void
usage(FILE* stream)
{
fprintf(stream,
-"usage: sln-slab [-hsv] [-n nrealisations] [-T thickness] [-t threads]\n"
+"usage: sln-slab [-dhsv] [-n nrealisations] [-T thickness] [-t threads]\n"
" -S nu_min,nu_max -a accel_struct -m molparams -l lines\n");
}
@@ -110,9 +111,10 @@ args_init(struct args* args, int argc, char** argv)
*args = ARGS_DEFAULT;
- while((opt = getopt(argc, argv, "a:hl:m:n:S:sT:t:v")) != -1) {
+ while((opt = getopt(argc, argv, "a:dhl:m:n:S:sT:t:v")) != -1) {
switch(opt) {
case 'a': args->tree = optarg; break;
+ case 'd': args->disable_line_hash_check = 1; break;
case 'h':
usage(stdout);
args->quit = 1;
@@ -289,6 +291,7 @@ cmd_init(struct cmd* cmd, const struct args* args)
tree_args.metadata = molparams;
tree_args.lines = lines;
tree_args.filename = args->tree;
+ tree_args.disable_line_hash_check = args->disable_line_hash_check;
res = sln_tree_read(sln, &tree_args, &cmd->tree);
if(res != RES_OK) goto error;
diff --git a/src/sln_tree.c b/src/sln_tree.c
@@ -535,16 +535,18 @@ sln_tree_read
SHTR(isotope_metadata_ref_get(args->metadata));
tree->args.metadata = args->metadata;
- res = shtr_line_list_hash(args->lines, hash_lines1);
- if(res != RES_OK) goto error;
-
- READ(hash_lines2, sizeof(hash256_T));
- if(!hash256_eq(hash_lines1, hash_lines2)) {
- ERROR(sln,
- "%s: the input list of lines is not the one used to build the tree.\n",
- stream.name);
- res = RES_BAD_ARG;
- goto error;
+ READ(hash_lines1, sizeof(hash256_T));
+ if(!args->disable_line_hash_check) {
+ res = shtr_line_list_hash(args->lines, hash_lines2);
+ if(res != RES_OK) goto error;
+
+ if(!hash256_eq(hash_lines1, hash_lines2)) {
+ ERROR(sln,
+ "%s: the input list of lines is not the one used to build the tree.\n",
+ stream.name);
+ res = RES_BAD_ARG;
+ goto error;
+ }
}
SHTR(line_list_ref_get(args->lines));
diff --git a/src/test_sln_tree.c b/src/test_sln_tree.c
@@ -498,6 +498,7 @@ test_tree_serialization
rargs.filename = "nop";
CHK(sln_tree_read(sln, &rargs, &tree2) == RES_IO_ERR);
rargs.filename = filename;
+ rargs.disable_line_hash_check = 1;
CHK(sln_tree_read(sln, &rargs, &tree2) == RES_OK);
check_tree_equality(tree1, tree2);