Stop multiplying FITPARAMETER header comments on MSR round-trip

Importing a fitted MSR captures the comment lines of its FITPARAMETER
block so they can be replayed above the matching parameters. Fitted files
repeat the column header (No/Name/Value/Step/PosErr) and ### separators
before every parameter, so replaying them per parameter grew the generated
block by a header copy on each pass.

captureImportedMSRFitParameterStructure now skips pure ### separator lines
and the canonical column header while capturing; the template already
writes them exactly once. Genuine author comments are still preserved.
This commit is contained in:
Zaher Salman committed 2026-10-11 10:38:28 +02:00
1 parent 88df374787
commit ee49679ee5
3 files changed
+94

No files matched your search

+10
View File
@@ -24,6 +24,16 @@ release path documented in [`TODO.md`](TODO.md).
entries that were never theory parameters (e.g. `Field` and `Energy`) can be
used as custom parameter names again.
### MSR generation
- Importing a fitted MSR and regenerating no longer multiplies the FITPARAMETER
structural decorations. Fitted files repeat the column header
(`# No Name Value Step PosErr Min Max`) and `######`
separators before every parameter; those were captured as per-parameter
comments and replayed on each round-trip, growing the block on every pass.
The column header and pure separator lines are now treated as generator-owned
structure, written once by the template, while genuine author comments above
parameters are still preserved.
### Desktop configuration links
- The desktop build now registers a `musrflow://` URL scheme (the packaged
Linux builds carry the matching `MimeType=x-scheme-handler/musrflow;`
+13
View File
@@ -4456,6 +4456,19 @@ function captureImportedMSRFitParameterStructure(msrText) {
continue;
}
if (trimmed[0] === "#" || /^#+$/.test(trimmed)) {
// FITPARAMETER structural decorations belong to the generator, not to
// the replayed comment stream: the column header (No/Name/Value/Step/
// PosErr) and pure ### separators surround a block that the template
// always writes exactly once. Fitted files repeat that header before
// every parameter, so replaying it per parameter multiplies it on each
// round-trip. Drop those two shapes while capturing; meaningful author
// comments (# text...) are still kept and replayed.
if (/^#+\s*$/.test(trimmed)) {
continue;
}
if (/^#.*?\bNo\b\s+\bName\b\s+\bValue\b\s+\bStep\b\s+\bPosErr\b/i.test(trimmed)) {
continue;
}
pending.push(trimmed);
continue;
}
+71
View File
@@ -1868,6 +1868,76 @@ function testImportedMSRParameterOrderAndComments(lib) {
lib.resetImportedMSRParameterStructure();
}
function testImportedMSRRepeatedHeaderDoesNotMultiply(lib) {
const header = "# No Name Value Step PosErr Min Max";
const sep = "###############################################################";
// A fitted MSR repeats the structural column header before every parameter
// (and a separator after it). Replaying those as per-parameter comments made
// the generated FITPARAMETER block grow a new header copy on every round-trip.
const importedMsr = [
"FITPARAMETER",
header, sep,
" 1 Lam_0514 0.777 0.011 none 0.0 5.0",
header, sep,
" 2 Asy_0514 0.198 0.006 none 0.0 0.4",
header, sep,
" 3 Alpha_0514 1.234 0.012 none 0.5 1.5",
sep, sep,
"THEORY",
"asymmetry 2",
"GLOBAL",
"fittype 2",
"RUN /data/run514 MUE4 PSI MUSR-ROOT",
"COMMANDS",
"MIGRAD",
"PLOT 2",
"runs 1 2",
""
].join("\n");
lib.captureImportedMSRFitParameterStructure(importedMsr);
const comments = JSON.parse(JSON.stringify(lib.importedMSRFitParameterComments));
assert.strictEqual(comments.length, 3);
for (const entry of comments) {
assert.deepStrictEqual(entry.before, []);
}
assert.deepStrictEqual(comments[comments.length - 1].after, []);
const config = {
all: {
fitAsyType: "AsymmetryGLB",
theoFunBlock: "asymmetry Asy",
runNumbers: "514",
selYear: "2024",
instrName: "LEM",
dataRoot: "/psi.ch/data",
LRBF: "1 5,3 7",
valAlpha: "1.234", errAlpha: "0.012", minAlpha: "0.5", maxAlpha: "1.5",
valAsy: "0.198", errAsy: "0.006", minAsy: "0.0", maxAsy: "0.4",
valLam: "0.777", errLam: "0.011", minLam: "0.0", maxLam: "5.0"
},
funOptions: [
{ value: "Lam", disabled: false },
{ value: "Asy", disabled: false },
{ value: "Alpha", disabled: false }
],
funLines: [],
sharedFlags: {}
};
const model = lib.buildModelBlocks(config, lib.getFitType(config.all));
// The template writes the column header exactly once; the parameter block
// must not reintroduce it (or the pure separators) per parameter.
assert.strictEqual(model.parameterBlock.indexOf(header), -1);
assert.strictEqual(model.parameterBlock.split("\n").some(function(line) {
return /^#+\s*$/.test(line.trim());
}), false);
// The imported order is still honoured.
assert.ok(model.parameterBlock.indexOf("Lam_0514") < model.parameterBlock.indexOf("Asy_0514"));
assert.ok(model.parameterBlock.indexOf("Asy_0514") < model.parameterBlock.indexOf("Alpha_0514"));
lib.resetImportedMSRParameterStructure();
}
function testPhysicalParameterOrder(lib) {
function selectFrom(values) {
return {
@@ -3943,6 +4013,7 @@ testBuildFourierBlockOptions(lib);
testExactNameFitParameterSync(lib);
testBuildMSRUsesGUIParameterValues(lib);
testImportedMSRParameterOrderAndComments(lib);
testImportedMSRRepeatedHeaderDoesNotMultiply(lib);
testPhysicalParameterOrder(lib);
testSingleHistogramPlotRunsAllHistograms(lib);
testPlotYAxisRangeGeneration(lib);