diff --git a/cgi/single_musrfit.cgi b/cgi/single_musrfit.cgi index e73c57b..ffe54bc 100755 --- a/cgi/single_musrfit.cgi +++ b/cgi/single_musrfit.cgi @@ -1505,21 +1505,20 @@ sub perform_series_artifact_collection { if !-x $MSR2DATA_BIN; my $base_run = $run_numbers[0]; - # The series artifacts follow the canonical multirun global names so the - # parameter plot button (which expects the ordinary global export layout) - # keeps working: the combined display file is `base+global.msr` - # and the parameter table is `base+global_par.dat`. - my $combined_name = $base_run . "+global" . $suffix . ".msr"; + # Keep display-only independent-series artifacts separate from genuine + # global-fit results that may already exist in the same HTTP job folder. + my $combined_name = $base_run . "+series" . $suffix . ".msr"; my $combined_path = "$work_path/$combined_name"; - # msr2data's multirun export reads its input under the `_tmpl` template - # name, so the combined runnable content is staged there for the export. - my $template_name = $base_run . "+global_tmpl.msr"; + # msr2data still needs a base+global.msr staging input. A unique + # internal suffix prevents collision with the normal `_tmpl` global path. + my $template_suffix = "_musrflow_series_" . $$ . "_" . time(); + my $template_name = $base_run . "+global" . $template_suffix . ".msr"; my $template_path = "$work_path/$template_name"; - my $parameter_name = $base_run . "+global" . $suffix . "_par.dat"; + my $parameter_name = $base_run . "+series" . $suffix . "_par.dat"; my $parameter_path = "$work_path/$parameter_name"; - my $out_name = $base_run . "+global" . $suffix . ".out"; + my $out_name = $base_run . "+series" . $suffix . ".out"; my $out_path = "$work_path/$out_name"; - foreach my $stale_path ($combined_path, $template_path, $parameter_path) { + foreach my $stale_path ($combined_path, $parameter_path) { return $failure->("series-artifact-output-invalid", "A series output path is unsafe") if -l $stale_path || (-e $stale_path && !-f $stale_path); return $failure->("series-artifact-output-remove-failed", @@ -1563,7 +1562,8 @@ sub perform_series_artifact_collection { my $parameter_cmd = "cd " . shell_quote($work_path) . " && " . shell_quote($MSR2DATA_BIN) . " " . shell_quote($run_argument) - . " _tmpl new global data -o " . shell_quote($parameter_name); + . " " . shell_quote($template_suffix) + . " new global data -o " . shell_quote($parameter_name); my $parameter_result = run_logged_command( $out_path, "msr2data independent series collection", $parameter_cmd ); diff --git a/muSRFitelec.js b/muSRFitelec.js index 4f4fd45..5661065 100644 --- a/muSRFitelec.js +++ b/muSRFitelec.js @@ -1004,24 +1004,26 @@ async function collectIndependentSeriesArtifactsLocal(spec) { } } - // The series artifacts follow the canonical multirun global names so the - // parameter plot button (which expects the ordinary global export layout) - // keeps working: the combined display file is `base+global.msr` and - // the parameter table is `base+global_par.dat`. - let combinedName = baseRun + "+global" + suffix + ".msr"; + // Independent-series artifacts use their own namespace. A genuine global + // fit can legitimately exist beside the same per-run files and must never + // be removed or replaced by display-only post-processing. + let combinedName = baseRun + "+series" + suffix + ".msr"; let combinedPath = nodePath.join(workPath, combinedName); - // msr2data's multirun export reads its input under the `_tmpl` template - // name, so the combined runnable content is staged there for the export. - let templateName = baseRun + "+global_tmpl.msr"; + // msr2data global-data mode requires a `base+global.msr` input. + // Give the staging file a process-unique suffix so an ordinary `_tmpl` + // global-fit template is neither overwritten nor deleted. + let templateSuffix = "_musrflow_series_" + process.pid + "_" + + Date.now().toString(36); + let templateName = baseRun + "+global" + templateSuffix + ".msr"; let templatePath = nodePath.join(workPath, templateName); - let parameterName = baseRun + "+global" + suffix + "_par.dat"; + let parameterName = baseRun + "+series" + suffix + "_par.dat"; let parameterPath = nodePath.join(workPath, parameterName); - let logName = baseRun + "+global" + suffix + ".out"; + let logName = baseRun + "+series" + suffix + ".out"; let logPath = nodePath.join(workPath, logName); result.logPath = logPath; try { - for (let stalePath of [combinedPath, templatePath, parameterPath]) { + for (let stalePath of [combinedPath, parameterPath]) { if (!nodeFs.existsSync(stalePath)) continue; if (!isSafeSeriesRegularFile(stalePath)) { result.reason = "series-artifact-output-invalid"; @@ -1093,28 +1095,31 @@ async function collectIndependentSeriesArtifactsLocal(spec) { // same `new global data` form and `_tmpl` staging as the ordinary // multirun export, producing the global .dat layout (stripped base // names, one row per run) that the parameter plot button reads. - nodeFs.copyFileSync(combinedPath, templatePath); - let parameterCode = runMsr2data("parameter msr2data", - [runsArg, "_tmpl", "new", "global", "data", "-o", parameterName]); - if (isSafeSeriesRegularFile(parameterPath) - && nodeFs.statSync(parameterPath).size > 0) { - try { - cleanMusrfitParameterDataHeader(parameterPath); - } catch (error) { - result.warnings.push("Could not normalize the parameter-table header."); + nodeFs.copyFileSync(combinedPath, templatePath, nodeFs.constants.COPYFILE_EXCL); + try { + let parameterCode = runMsr2data("parameter msr2data", + [runsArg, templateSuffix, "new", "global", "data", "-o", parameterName]); + if (isSafeSeriesRegularFile(parameterPath) + && nodeFs.statSync(parameterPath).size > 0) { + try { + cleanMusrfitParameterDataHeader(parameterPath); + } catch (error) { + result.warnings.push("Could not normalize the parameter-table header."); + } + // A non-empty table is usable even if header cleanup or the + // external program's status is imperfect. + result.parameterDataPath = parameterPath; + if (parameterCode !== 0) { + result.warnings.push("msr2data returned code " + parameterCode + + " but produced the parameter table."); + } + } else { + result.warnings.push("msr2data did not produce parameter data."); } - // A non-empty table is usable even if header cleanup or the - // external program's status is imperfect. - result.parameterDataPath = parameterPath; - if (parameterCode !== 0) { - result.warnings.push("msr2data returned code " + parameterCode - + " but produced the parameter table."); + } finally { + if (isSafeSeriesRegularFile(templatePath)) { + nodeFs.unlinkSync(templatePath); } - } else { - result.warnings.push("msr2data did not produce parameter data."); - } - if (isSafeSeriesRegularFile(templatePath)) { - nodeFs.unlinkSync(templatePath); } } } else { diff --git a/tests/cgi-series-collection.test.js b/tests/cgi-series-collection.test.js index 3e903bf..792e36f 100644 --- a/tests/cgi-series-collection.test.js +++ b/tests/cgi-series-collection.test.js @@ -75,6 +75,8 @@ try { fs.mkdirSync(workPath, { recursive: true }); fs.writeFileSync(path.join(workPath, "514_asy.msr"), fittedMSR(514)); fs.writeFileSync(path.join(workPath, "515_asy.msr"), fittedMSR(515)); + fs.writeFileSync(path.join(workPath, "514+global_asy.msr"), "genuine global fit\n"); + fs.writeFileSync(path.join(workPath, "514+global_tmpl.msr"), "genuine global template\n"); const m2dArgsPath = path.join(testRoot, "msr2data-args.txt"); const viewArgsPath = path.join(testRoot, "musrview-args.txt"); @@ -83,7 +85,7 @@ try { fs.writeFileSync(fakeMsr2data, [ "#!/bin/sh", "printf '%s\\n' \"$*\" >> \"$MUSRFLOW_TEST_M2D_ARGS\"", - "printf 'RUN Asy_ Asy_PosErr\\n514 0.2 0.01\\n515 0.21 0.01\\n' > 514+global_asy_par.dat", + "printf 'RUN Asy_ Asy_PosErr\\n514 0.2 0.01\\n515 0.21 0.01\\n' > 514+series_asy_par.dat", "exit 9", "" ].join("\n")); @@ -91,7 +93,7 @@ try { fs.writeFileSync(fakeMusrview, [ "#!/bin/sh", "printf '%s\\n' \"$*\" > \"$MUSRFLOW_TEST_VIEW_ARGS\"", - ": > 514+global_asy_0.root", + ": > 514+series_asy_0.root", "exit 0", "" ].join("\n")); @@ -128,21 +130,21 @@ try { const responseText = execution.stdout.split(/\r?\n\r?\n/).slice(1).join("\n\n"); const response = JSON.parse(responseText); assert.strictEqual(response.ok, true); - assert.strictEqual(response.parameter_url, "/tmp/seriesjob/514+global_asy_par.dat"); - assert.strictEqual(response.msr_url, "/tmp/seriesjob/514+global_asy.msr"); + assert.strictEqual(response.parameter_url, "/tmp/seriesjob/514+series_asy_par.dat"); + assert.strictEqual(response.msr_url, "/tmp/seriesjob/514+series_asy.msr"); assert.deepStrictEqual(response.root_urls, - ["/tmp/seriesjob/514+global_asy_0.root"]); + ["/tmp/seriesjob/514+series_asy_0.root"]); assert.match(response.warnings.join("\n"), /returned code 9/); const m2dArgs = fs.readFileSync(m2dArgsPath, "utf8").trim().split(/\r?\n/); assert.strictEqual(m2dArgs.length, 1); - assert.strictEqual(m2dArgs[0], - "[514 515] _tmpl new global data -o 514+global_asy_par.dat"); + assert.match(m2dArgs[0], + /^\[514 515\] _musrflow_series_\d+_\d+ new global data -o 514\+series_asy_par\.dat$/); assert.strictEqual(fs.readFileSync(viewArgsPath, "utf8").trim(), - "--timeout 300 --root 514+global_asy.msr"); + "--timeout 300 --root 514+series_asy.msr"); assert.strictEqual(fs.readFileSync( - path.join(workPath, "514+global_asy_par.dat"), "utf8" + path.join(workPath, "514+series_asy_par.dat"), "utf8" ).split(/\r?\n/)[0], "RUN Asy Asy_PosErr"); - const combinedText = fs.readFileSync(path.join(workPath, "514+global_asy.msr"), "utf8"); + const combinedText = fs.readFileSync(path.join(workPath, "514+series_asy.msr"), "utf8"); assert.match(combinedText, /^runs\s+1\s+2$/m); assert.match(combinedText, /^# Common parameters for all runs$/m); assert.match(combinedText, /^# Specific parameters for run 514$/m); @@ -159,11 +161,14 @@ try { // msr2data's `new global data` export considers every run converged. assert.match(combinedText, /^STATISTIC --- \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/m); assert.match(combinedText, /^ chisq = 202\.4, NDF = 200, chisq\/NDF = 1\.012$/m); - // The combined display MSR now carries the canonical +global name, and the - // msr2data `_tmpl` staging file is removed after the export. - assert.strictEqual(fs.existsSync(path.join(workPath, "514+global_asy.msr")), true); - assert.strictEqual(fs.existsSync(path.join(workPath, "514+global_tmpl.msr")), false); - assert.strictEqual(fs.existsSync(path.join(workPath, "514+series_asy.msr")), false); + assert.strictEqual(fs.existsSync(path.join(workPath, "514+series_asy.msr")), true); + assert.strictEqual(fs.readFileSync(path.join(workPath, "514+global_asy.msr"), "utf8"), + "genuine global fit\n"); + assert.strictEqual(fs.readFileSync(path.join(workPath, "514+global_tmpl.msr"), "utf8"), + "genuine global template\n"); + assert.strictEqual(fs.readdirSync(workPath).some(function(name) { + return /^514\+global_musrflow_series_/.test(name); + }), false); assert.match(response.command_log, /msr2data independent series collection/); assert.doesNotMatch(response.command_log, /msr2data independent series display/); assert.match(response.command_log, /\[exit code 9\]/); @@ -200,7 +205,7 @@ try { ); assert.strictEqual(singleHistResponse.ok, true); const singleHistCombined = fs.readFileSync( - path.join(workPath, "514+global_asy.msr"), "utf8" + path.join(workPath, "514+series_asy.msr"), "utf8" ); assert.strictEqual((singleHistCombined.match(/^RUN\b/gm) || []).length, 4); assert.strictEqual((singleHistCombined.match(/^forward 21 25$/gm) || []).length, 2); diff --git a/tests/series-runner-adapters.test.js b/tests/series-runner-adapters.test.js index 1b964c2..9f7a837 100644 --- a/tests/series-runner-adapters.test.js +++ b/tests/series-runner-adapters.test.js @@ -207,10 +207,14 @@ async function testElectronSeriesArtifactCollection() { fs.writeFileSync(path.join(tempDirectory, run + "_asy.msr"), runnableMSR(run, true), "utf8"); } + const genuineGlobal = path.join(tempDirectory, "514+global_asy.msr"); + const genuineTemplate = path.join(tempDirectory, "514+global_tmpl.msr"); + fs.writeFileSync(genuineGlobal, "genuine global fit\n", "utf8"); + fs.writeFileSync(genuineTemplate, "genuine global template\n", "utf8"); const fakeChildProcess = { spawnSync: function(command, args, options) { syncCalls.push({ command: command, args: args.slice(), cwd: options.cwd }); - fs.writeFileSync(path.join(options.cwd, "514+global_asy_par.dat"), + fs.writeFileSync(path.join(options.cwd, "514+series_asy_par.dat"), "RUN Asy_ Asy_PosErr\n514 0.2 0.01\n515 0.21 0.01\n", "utf8"); return { status: 7, stdout: "parameter data written\n", stderr: "" }; }, @@ -238,15 +242,17 @@ async function testElectronSeriesArtifactCollection() { assert.strictEqual(result.ok, true); assert.strictEqual(result.parameterDataPath, - path.join(tempDirectory, "514+global_asy_par.dat")); + path.join(tempDirectory, "514+series_asy_par.dat")); assert.strictEqual(result.combinedMSRPath, - path.join(tempDirectory, "514+global_asy.msr")); + path.join(tempDirectory, "514+series_asy.msr")); assert.strictEqual(result.plotStarted, true); assert.match(result.warnings.join("\n"), /returned code 7/); assert.strictEqual(syncCalls.length, 1); - assert.deepStrictEqual(Array.from(syncCalls[0].args), - ["[514 515]", "_tmpl", "new", "global", "data", "-o", "514+global_asy_par.dat"]); - assert.deepStrictEqual(Array.from(asyncCalls[0].args), ["514+global_asy.msr"]); + assert.match(syncCalls[0].args[1], /^_musrflow_series_\d+_[a-z0-9]+$/); + assert.deepStrictEqual(Array.from(syncCalls[0].args.slice(0, 1)), ["[514 515]"]); + assert.deepStrictEqual(Array.from(syncCalls[0].args.slice(2)), + ["new", "global", "data", "-o", "514+series_asy_par.dat"]); + assert.deepStrictEqual(Array.from(asyncCalls[0].args), ["514+series_asy.msr"]); assert.match(fs.readFileSync(result.parameterDataPath, "utf8"), /^RUN Asy Asy_PosErr/m); const combinedText = fs.readFileSync(result.combinedMSRPath, "utf8"); @@ -256,11 +262,12 @@ async function testElectronSeriesArtifactCollection() { assert.match(combinedText, /^ 1 Asy_0514 0\.2 0\.01$/m); assert.match(combinedText, /^ 2 Asy_0515 0\.2 0\.01$/m); assert.match(combinedText, /^asymmetry map1$/m); - // The combined display MSR now carries the canonical +global name, and - // the msr2data `_tmpl` staging file is removed after the export. - assert.strictEqual(fs.existsSync(path.join(tempDirectory, "514+global_asy.msr")), true); - assert.strictEqual(fs.existsSync(path.join(tempDirectory, "514+global_tmpl.msr")), false); - assert.strictEqual(fs.existsSync(path.join(tempDirectory, "514+series_asy.msr")), false); + assert.strictEqual(fs.existsSync(path.join(tempDirectory, "514+series_asy.msr")), true); + assert.strictEqual(fs.readFileSync(genuineGlobal, "utf8"), "genuine global fit\n"); + assert.strictEqual(fs.readFileSync(genuineTemplate, "utf8"), "genuine global template\n"); + assert.strictEqual(fs.readdirSync(tempDirectory).some(function(name) { + return /^514\+global_musrflow_series_/.test(name); + }), false); await new Promise(function(resolve) { setImmediate(resolve); }); } finally { fs.rmSync(tempDirectory, { recursive: true, force: true }); diff --git a/tests/web-runner.test.js b/tests/web-runner.test.js index a7d1a7f..25b0a83 100644 --- a/tests/web-runner.test.js +++ b/tests/web-runner.test.js @@ -277,10 +277,10 @@ async function testWebSeriesCollectionRegistersArtifactsAndPlot() { code: 0, reason: "series-artifacts-collected", job_name: "job", - msr_url: "/tmp/job/514+global_asy.msr", - out_url: "/tmp/job/514+global_asy.out", - parameter_url: "/tmp/job/514+global_asy_par.dat", - root_urls: ["/tmp/job/514+global_asy_0.root"], + msr_url: "/tmp/job/514+series_asy.msr", + out_url: "/tmp/job/514+series_asy.out", + parameter_url: "/tmp/job/514+series_asy_par.dat", + root_urls: ["/tmp/job/514+series_asy_0.root"], root_items: ["fMainCanvas0;1"], command_log: "$ msr2data [514 515] _tmpl new global data\n", warnings: ["msr2data returned code 9 but produced usable series artifacts"] @@ -302,9 +302,9 @@ async function testWebSeriesCollectionRegistersArtifactsAndPlot() { }); assert.strictEqual(result.ok, true); - assert.strictEqual(result.parameterDataPath, "/tmp/job/514+global_asy_par.dat"); - assert.strictEqual(result.combinedMSRPath, "/tmp/job/514+global_asy.msr"); - assert.strictEqual(result.plotPath, "/tmp/job/514+global_asy_0.root"); + assert.strictEqual(result.parameterDataPath, "/tmp/job/514+series_asy_par.dat"); + assert.strictEqual(result.combinedMSRPath, "/tmp/job/514+series_asy.msr"); + assert.strictEqual(result.plotPath, "/tmp/job/514+series_asy_0.root"); assert.strictEqual(result.plotStarted, true); assert.match(result.warnings[0], /returned code 9/); assert.strictEqual(calls.length, 1); @@ -316,8 +316,8 @@ async function testWebSeriesCollectionRegistersArtifactsAndPlot() { }); assert.strictEqual(plots.length, 1); assert.deepStrictEqual(Array.from(plots[0].urls), - ["/tmp/job/514+global_asy_0.root"]); - assert.strictEqual(plots[0].options.msrPath, "/tmp/job/514+global_asy.msr"); + ["/tmp/job/514+series_asy_0.root"]); + assert.strictEqual(plots[0].options.msrPath, "/tmp/job/514+series_asy.msr"); assert.match(logs[0], /msr2data/); }