Skip to content

Commit

Permalink
pass dynamically data for bitfield elements and exchange class betwee…
Browse files Browse the repository at this point in the history
…n gen and sim
  • Loading branch information
brauliorivas committed Jun 5, 2024
1 parent 2769764 commit 66222e3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 35 deletions.
26 changes: 23 additions & 3 deletions js/menu/filter/builders.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ValueCheckBox, BitfieldCheckbox } from "./parameters.js";

export class CheckboxBuilder {
constructor(name, fullName, classType) {
constructor(name, fullName) {
this.uniqueValues = new Set();
this.checkBoxes = [];
this.name = name;
this.fullName = fullName;
this.classType = classType;
}

add(val) {
Expand All @@ -13,7 +14,7 @@ export class CheckboxBuilder {

setCheckBoxes() {
this.checkBoxes = Array.from(this.uniqueValues).map(
(option) => new this.classType(this.name, option)
(option) => new ValueCheckBox(this.name, option)
);
this.checkBoxes.sort((a, b) => a.value - b.value);
}
Expand All @@ -33,3 +34,22 @@ export class CheckboxBuilder {
this.checkBoxes.forEach((checkbox) => checkbox.render(options));
}
}

export class BitFieldBuilder extends CheckboxBuilder {
constructor(name, fullName, dictionary) {
super(name, fullName);
this.dictionary = dictionary;
}

setCheckBoxes() {
this.checkBoxes = Array.from(this.uniqueValues).map(
(option) =>
new BitfieldCheckbox(
this.name,
option,
BitfieldCheckbox.getDisplayValue(this.dictionary, option)
)
);
this.checkBoxes.sort((a, b) => a.value - b.value);
}
}
23 changes: 15 additions & 8 deletions js/menu/filter/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
currentParticles,
visibleParticles,
} from "../../main.js";
import { CheckboxBuilder } from "./builders.js";
import { CheckboxBuilder, BitFieldBuilder } from "./builders.js";
import {
Range,
Checkbox,
Expand Down Expand Up @@ -109,16 +109,23 @@ parametersRange = parametersRange.sort((a, b) =>

parametersRange = parametersRange.map((parameter) => new Range(parameter));

const bits = new CheckboxBuilder(
const bitFieldDisplayValues = {
23: "Overlay",
24: "Stopped",
25: "LeftDetector",
26: "DecayedInCalorimeter",
27: "DecayedInTracker",
28: "VertexIsNotEndpointOfParent",
29: "Backscatter",
30: "CreatedInSimulation",
};

const bits = new BitFieldBuilder(
"simStatus",
"Simulator status",
ValueCheckBox
);
const genStatus = new CheckboxBuilder(
"genStatus",
"Generator status",
BitfieldCheckbox
bitFieldDisplayValues
);
const genStatus = new CheckboxBuilder("genStatus", "Generator status");

function applyFilter(particlesHandler, currentParticles, visibleParticles) {
const rangeFunctions = Range.buildFilter(parametersRange);
Expand Down
37 changes: 13 additions & 24 deletions js/menu/filter/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,22 @@ export class Range extends FilterParameter {
export class Checkbox extends FilterParameter {
value;

constructor(property, value) {
constructor(property, value, displayValue = null) {
super(property);
this.value = value;
if (displayValue) {
this.displayValue = displayValue;
} else {
this.displayValue = value;
}
}

render(container) {
const div = document.createElement("div");
container.appendChild(div);

const label = document.createElement("label");
const text = this.getDisplayValue();
label.textContent = text;
label.textContent = this.displayValue;
div.appendChild(label);

const input = document.createElement("input");
Expand All @@ -132,10 +136,6 @@ export class Checkbox extends FilterParameter {
});
}

getDisplayValue() {
return this.displayValue ?? this.value;
}

buildCondition() {
if (!this.checked) return null;

Expand All @@ -160,26 +160,15 @@ export class Checkbox extends FilterParameter {

export class ValueCheckBox extends Checkbox {
// Classic checkbox
constructor(property, value) {
super(property, value);
constructor(property, value, displayValue) {
super(property, value, displayValue);
}
}

const bitFieldDisplayValues = {
23: "BitOverlay",
24: "BitStopped",
25: "BitLeftDetector",
26: "BitDecayedInCalorimeter",
27: "BitDecayedInTracker",
28: "BitVertexIsNotEndpointOfParent",
29: "BitBackscatter",
30: "BitCreatedInSimulation",
};

export class BitfieldCheckbox extends Checkbox {
// Bit manipulation EDM4hep
constructor(property, value) {
super(property, value);
constructor(property, value, displayValue) {
super(property, value, displayValue);
}

buildCondition() {
Expand All @@ -189,8 +178,8 @@ export class BitfieldCheckbox extends Checkbox {
(parseInt(particle[this.property]) & (1 << parseInt(this.value))) !== 0;
}

getDisplayValue() {
return bitFieldDisplayValues[this.value] ?? this.value;
static getDisplayValue(dictionary, option) {
return dictionary[option] ?? option;
}
}

Expand Down

0 comments on commit 66222e3

Please sign in to comment.