Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/config/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* or submit itself to any jurisdiction.
*/

const { roles, detectors, pageNames, filterTypes, filterInputTypes, fieldNames, quality } = require('./rct-data');
const { roles, detectors, pageNames, filterTypes, filterInputTypes, fieldNames, quality, mapping } = require('./rct-data');
const { bookkeeping } = require('./outerServices');

module.exports = { // Properties that will be provided to frontend in the public folder
Expand All @@ -22,6 +22,7 @@ module.exports = { // Properties that will be provided to frontend in the public

roles,
quality,
mapping,
endpoints: {
login: '/login/',
logout: '/logout/',
Expand Down
4 changes: 2 additions & 2 deletions app/config/rct-data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ const { filterTypes, filterInputTypes } = require('./filterTypes.js');
const detectors = require('./detectors.js').sort();
const roles = require('./roles.js');
const physicalParticlesData = require('./physicalParticlesData.js');
const beamTypesMappings = require('./beamTypesMappings.js');
const healthcheckQueries = require('./healthcheckQueries.js');
const quality = require('./quality');
const mapping = require('./mapping');

module.exports = {
pageNames,
viewTypes,
mapping,
pagesViewGroups,
fieldNames,
filterTypes,
Expand All @@ -34,6 +35,5 @@ module.exports = {
roles,
quality,
physicalParticlesData,
beamTypesMappings,
...healthcheckQueries,
};
27 changes: 27 additions & 0 deletions app/config/rct-data/mapping/beamType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const beamType = {
values: {
pp: 'p-p',
nn: 'n-n',
XeXe: 'Xe-Xe',
PbPb: 'Pb-Pb',
pPb: 'p-Pb',
Pbp: 'p-Pb',
pA: 'p-A',
},
};

module.exports = beamType;
25 changes: 25 additions & 0 deletions app/config/rct-data/mapping/energy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const energy = {
values: {
['6800']: 6800,
['7000']: 7000,
['5360/2']: 5360 / 2,
['450']: 450,
},
acceptableMargin: 0.01,
};

module.exports = energy;
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
* or submit itself to any jurisdiction.
*/

const beamTypesMappings = {
pp: 'p-p',
nn: 'n-n',
XeXe: 'Xe-Xe',
PbPb: 'Pb-Pb',
pPb: 'p-Pb',
Pbp: 'p-Pb',
pA: 'p-A',
};
const beamType = require('./beamType.js');
const energy = require('./energy.js');

module.exports = beamTypesMappings;
module.exports = {
beamType: beamType,
energy: energy,
};
2 changes: 1 addition & 1 deletion app/lib/alimonitor-services/ServicesDataCommons.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { rctData } = require('../config/configProvider.js');
function mapBeamTypeToCommonFormat(dataObject) {
dataObject.beam_type = Utils.switchCase(
dataObject.beam_type,
rctData.beamTypesMappings,
rctData.mapping.beamType.values,
{ default: dataObject.beam_type },
);
return dataObject;
Expand Down
11 changes: 11 additions & 0 deletions app/public/utils/dataProcessing/dataProcessingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ export const extractPeriodName = (dataPassName) => {
const [period] = dataPassName.split('_');
return period;
};

export const getClosestDefinedEnergy = (energy, definedEnergies, acceptableMargin) => {
const definedEnergyValues = Object.values(definedEnergies);
const closest = definedEnergyValues.reduce(
(acc, current) => Math.abs(current - energy) < Math.abs(acc - energy) ? current : acc,
definedEnergyValues[0],
);
return Math.abs(closest - energy) <= acceptableMargin
? Object.keys(definedEnergies).find((key) => definedEnergies[key] === closest)
: energy.toString();
};
35 changes: 32 additions & 3 deletions test/public/utils/dataProcessing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,43 @@

const req = require('esm')(module)
const assert = require('assert');
const { extractPeriodName } = req('../../../app/public/utils/dataProcessing/dataProcessingUtils');
const { extractPeriodName, getClosestDefinedEnergy } = req('../../../app/public/utils/dataProcessing/dataProcessingUtils');

module.exports = () => {
const dataPassName = 'LHC18q_calo_cluster_pass3';
const expectedPeriodName = 'LHC18q';
describe('Extract period name', () => {
const dataPassName = 'LHC18q_calo_cluster_pass3';
const expectedPeriodName = 'LHC18q';

it('should return correct value', () => {
assert(extractPeriodName(dataPassName) === expectedPeriodName);
});
});

describe('Get closest defined energy', () => {
const definedEnergyValues = {
"450": 450,
"6800": 6800,
"7000": 7000,
"5360/2": 2680
};
it('should return the input energy if nothing is withing the acceptable margin', () => {
const energy = 6900;
const acceptableMargin = 10;
assert(getClosestDefinedEnergy(energy, definedEnergyValues, acceptableMargin) === energy.toString());
});

it('should resolve edge cases', () => {
const energy = 6900;
const acceptableMargin = 100;
const expectedOutcome = "6800";
assert(getClosestDefinedEnergy(energy, definedEnergyValues, acceptableMargin) === expectedOutcome);
});

it('should return the key energy', () => {
const energy = 2680;
const acceptableMargin = 1;
const expectedOutcome = "5360/2";
assert(getClosestDefinedEnergy(energy, definedEnergyValues, acceptableMargin) === expectedOutcome);
});
});
};