Skip to content

Commit

Permalink
Handle prefer_saved option for TF1
Browse files Browse the repository at this point in the history
Now usage of save points default
for TF1 therefore it is normal if evaluation failed. Inform problem
to TWebCanvas when not configured.
Provide central method to parse tf1 options
  • Loading branch information
linev committed May 22, 2024
1 parent 7424dbe commit b3ecc9c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 55 deletions.
46 changes: 27 additions & 19 deletions modules/hist/TF1Painter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ function produceTAxisLogScale(axis, num, min, max) {
axis.fXmax = Math.exp(lmax);
}

function scanTF1Options(opt) {
if (!isStr(opt)) opt = '';
let p = opt.indexOf(';webcanv_hist'), webcanv_hist = false, prefer_saved = false;
if (p >= 0) {
webcanv_hist = true;
opt = opt.slice(0, p);
}
p = opt.indexOf(';force_saved'); // only to support old JSON files from TWebCanvas
if (p < 0)
p = opt.indexOf(';prefer_saved');
if (p >= 0) {
prefer_saved = true;
opt = opt.slice(0, p);
}
return { opt, webcanv_hist, prefer_saved };
}


/**
* @summary Painter for TF1 object
*
Expand Down Expand Up @@ -89,7 +107,7 @@ class TF1Painter extends TH1Painter {
xmax = Math.max(xmax, gr.zoom_xmax);
}

this._use_saved_points = (tf1.fSave.length > 3) && (settings.PreferSavedPoints || this.force_saved);
this._use_saved_points = (tf1.fSave.length > 3) && (settings.PreferSavedPoints || this.prefer_saved);

const ensureBins = num => {
if (hist.fNcells !== num + 2) {
Expand Down Expand Up @@ -297,29 +315,20 @@ class TF1Painter extends TH1Painter {
}

/** @summary fill information for TWebCanvas
* @desc Used to inform webcanvas when evaluation failed
* @private */
fillWebObjectOptions(opt) {
// mark that saved points are used or evaluation failed
opt.fcust = this._fail_eval ? 'func_fail' : '';
opt.fcust = this._fail_eval && !this.prefer_saved ? 'func_fail' : '';
}

/** @summary draw TF1 object */
static async draw(dom, tf1, opt) {
if (!isStr(opt)) opt = '';
let p = opt.indexOf(';webcanv_hist'), webcanv_hist = false, force_saved = false;
if (p >= 0) {
webcanv_hist = true;
opt = opt.slice(0, p);
}
p = opt.indexOf(';force_saved');
if (p >= 0) {
force_saved = true;
opt = opt.slice(0, p);
}

const web = scanTF1Options(opt);
opt = web.opt;
delete web.opt;
let hist;

if (webcanv_hist) {
if (web.webcanv_hist) {
const dummy = new ObjectPainter(dom);
hist = dummy.getPadPainter()?.findInPrimitives('Func', clTH1D);
}
Expand All @@ -335,8 +344,7 @@ class TF1Painter extends TH1Painter {
const painter = new TF1Painter(dom, hist);

painter.$func = tf1;
painter.webcanv_hist = webcanv_hist;
painter.force_saved = force_saved;
Object.assign(painter, web);

painter.createTF1Histogram(tf1, hist);

Expand All @@ -345,4 +353,4 @@ class TF1Painter extends TH1Painter {

} // class TF1Painter

export { TF1Painter, produceTAxisLogScale };
export { TF1Painter, produceTAxisLogScale, scanTF1Options };
27 changes: 9 additions & 18 deletions modules/hist/TF2Painter.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHistogram, setHistogramTitle, kNoStats, settings, gStyle, clTF2, clTH2F, isStr, isFunc } from '../core.mjs';
import { TH2Painter } from '../hist/TH2Painter.mjs';
import { proivdeEvalPar } from '../base/func.mjs';
import { produceTAxisLogScale } from '../hist/TF1Painter.mjs';
import { produceTAxisLogScale, scanTF1Options } from '../hist/TF1Painter.mjs';
import { ObjectPainter, getElementMainPainter } from '../base/ObjectPainter.mjs';
import { DrawOptions, floatToString } from '../base/BasePainter.mjs';
import { THistPainter } from '../hist2d/THistPainter.mjs';
Expand Down Expand Up @@ -62,7 +62,7 @@ class TF2Painter extends TH2Painter {
if ((nsave > 0) && (nsave !== (func.fSave[nsave+4]+1) * (func.fSave[nsave+5]+1)))
nsave = 0;

this._use_saved_points = (nsave > 0) && (settings.PreferSavedPoints || this.force_saved);
this._use_saved_points = (nsave > 0) && (settings.PreferSavedPoints || this.prefer_saved);

const fp = this.getFramePainter(),
pad = this.getPadPainter()?.getRootPad(true),
Expand Down Expand Up @@ -281,25 +281,17 @@ class TF2Painter extends TH2Painter {
}

/** @summary fill information for TWebCanvas
* @desc Used to inform webcanvas when evaluation failed
* @private */
fillWebObjectOptions(opt) {
// mark that saved points are used or evaluation failed
opt.fcust = this._fail_eval ? 'func_fail' : '';
opt.fcust = this._fail_eval && !this.prefer_saved ? 'func_fail' : '';
}

/** @summary draw TF2 object */
static async draw(dom, tf2, opt) {
if (!isStr(opt)) opt = '';
let p = opt.indexOf(';webcanv_hist'), webcanv_hist = false, force_saved = false;
if (p >= 0) {
webcanv_hist = true;
opt = opt.slice(0, p);
}
p = opt.indexOf(';force_saved');
if (p >= 0) {
force_saved = true;
opt = opt.slice(0, p);
}
const web = scanTF1Options(opt);
opt = web.opt;
delete web.opt;

const d = new DrawOptions(opt);
if (d.empty())
Expand All @@ -319,7 +311,7 @@ class TF2Painter extends TH2Painter {

let hist;

if (webcanv_hist) {
if (web.webcanv_hist) {
const dummy = new ObjectPainter(dom);
hist = dummy.getPadPainter()?.findInPrimitives('Func', clTH2F);
}
Expand All @@ -332,8 +324,7 @@ class TF2Painter extends TH2Painter {
const painter = new TF2Painter(dom, hist);

painter.$func = tf2;
painter.webcanv_hist = webcanv_hist;
painter.force_saved = force_saved;
Object.assign(painter, web);
painter.createTF2Histogram(tf2, hist);
return THistPainter._drawHist(painter, opt);
}
Expand Down
27 changes: 9 additions & 18 deletions modules/hist/TF3Painter.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHistogram, setHistogramTitle, kNoStats, settings, clTF3, clTH2F, isStr } from '../core.mjs';
import { TH2Painter } from '../hist/TH2Painter.mjs';
import { proivdeEvalPar } from '../base/func.mjs';
import { produceTAxisLogScale } from '../hist/TF1Painter.mjs';
import { produceTAxisLogScale, scanTF1Options } from '../hist/TF1Painter.mjs';
import { ObjectPainter, getElementMainPainter } from '../base/ObjectPainter.mjs';
import { DrawOptions } from '../base/BasePainter.mjs';
import { THistPainter } from '../hist2d/THistPainter.mjs';
Expand Down Expand Up @@ -74,7 +74,7 @@ class TF3Painter extends TH2Painter {
createTF3Histogram(func, hist) {
const nsave = func.fSave.length - 9;

this._use_saved_points = (nsave > 0) && (settings.PreferSavedPoints || this.force_saved);
this._use_saved_points = (nsave > 0) && (settings.PreferSavedPoints || this.prefer_saved);

const fp = this.getFramePainter(),
pad = this.getPadPainter()?.getRootPad(true),
Expand Down Expand Up @@ -238,25 +238,17 @@ class TF3Painter extends TH2Painter {
}

/** @summary fill information for TWebCanvas
* @desc Used to inform webcanvas when evaluation failed
* @private */
fillWebObjectOptions(opt) {
// mark that saved points are used or evaluation failed
opt.fcust = this._fail_eval ? 'func_fail' : '';
opt.fcust = this._fail_eval && !this.prefer_saved ? 'func_fail' : '';
}

/** @summary draw TF3 object */
static async draw(dom, tf3, opt) {
if (!isStr(opt)) opt = '';
let p = opt.indexOf(';webcanv_hist'), webcanv_hist = false, force_saved = false;
if (p >= 0) {
webcanv_hist = true;
opt = opt.slice(0, p);
}
p = opt.indexOf(';force_saved');
if (p >= 0) {
force_saved = true;
opt = opt.slice(0, p);
}
const web = scanTF1Options(opt);
opt = web.opt;
delete web.opt;

const d = new DrawOptions(opt);
if (d.empty() || (opt === 'gl'))
Expand All @@ -271,7 +263,7 @@ class TF3Painter extends TH2Painter {

let hist;

if (webcanv_hist) {
if (web.webcanv_hist) {
const dummy = new ObjectPainter(dom);
hist = dummy.getPadPainter()?.findInPrimitives('Func', clTH2F);
}
Expand All @@ -284,8 +276,7 @@ class TF3Painter extends TH2Painter {
const painter = new TF3Painter(dom, hist);

painter.$func = tf3;
painter.webcanv_hist = webcanv_hist;
painter.force_saved = force_saved;
Object.assign(painter, web);
painter.createTF3Histogram(tf3, hist);
return THistPainter._drawHist(painter, opt);
}
Expand Down

0 comments on commit b3ecc9c

Please sign in to comment.