From 79436fcb730ab876a5b5677dd4d2a145d449c519 Mon Sep 17 00:00:00 2001 From: Braulio Rivas Abad Date: Wed, 28 Aug 2024 10:05:48 -0500 Subject: [PATCH] missing validation when bit was not mapped in dictionary --- js/filters/collections/mcparticle.js | 2 +- mappings/sim-status.js | 29 +++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/js/filters/collections/mcparticle.js b/js/filters/collections/mcparticle.js index f0b4ca7..657e7ed 100644 --- a/js/filters/collections/mcparticle.js +++ b/js/filters/collections/mcparticle.js @@ -45,7 +45,7 @@ function renderMCParticleFilters(viewObjects) { simStatusContainer.appendChild(simStatusTitle); const simStatusCheckboxesContainer = createCheckboxContainer(); - Object.entries(SimStatusBitFieldDisplayValues).forEach(([status, value]) => { + Object.entries(SimStatusBitFieldDisplayValues).forEach(([value, status]) => { const checkbox = new CheckboxComponent("simulatorStatus", status, value); checkboxes.simStatus.push(checkbox); simStatusCheckboxesContainer.appendChild(checkbox.render()); diff --git a/mappings/sim-status.js b/mappings/sim-status.js index d451253..859347c 100644 --- a/mappings/sim-status.js +++ b/mappings/sim-status.js @@ -1,12 +1,12 @@ export const SimStatusBitFieldDisplayValues = { - "Overlay": 23, - "Stopped": 24, - "LeftDetector": 25, - "DecayedInCalorimeter": 26, - "DecayedInTracker": 27, - "VertexIsNotEndpointOfParent": 28, - "Backscatter": 29, - "CreatedInSimulation": 30, + 23: "Overlay", + 24: "Stopped", + 25: "LeftDetector", + 26: "DecayedInCalorimeter", + 27: "DecayedInTracker", + 28: "VertexIsNotEndpointOfParent", + 29: "Backscatter", + 30: "CreatedInSimulation", }; export function parseBits(bit) { @@ -22,13 +22,16 @@ export function parseBits(bit) { } export function getSimStatusDisplayValues(bits) { - const values = Object.entries(SimStatusBitFieldDisplayValues); + const statuses = []; - return bits.map((bit) => { - const [value, _] = values.find(([_, v]) => v === bit); - - return value; + bits.forEach((bit) => { + const value = SimStatusBitFieldDisplayValues[bit]; + if (value !== undefined) { + statuses.push(value); + } }); + + return statuses; } export function getSimStatusDisplayValuesFromBit(bit) {