Skip to content
Draft
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
5 changes: 3 additions & 2 deletions lib/server/services/run/RunService.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const { getEnvironmentOrFail } = require('../environment/getEnvironmentOrFail.js
const { EnvironmentConfiguration } = require('../environment/EnvironmentConfiguration.js');
const { TriggerValue } = require('../../../domain/enums/TriggerValue.js');
const { flpRoleService } = require('../flp/FlpRoleService.js');
const { ALICE_L3_CURRENT_LEVEL_SQL, ALICE_DIPOLE_CURRENT_LEVEL_SQL } = require('./aliceMagnetCurrentLevelSql.js');

/**
* @typedef RunIdentifier object to uniquely identify a run
Expand Down Expand Up @@ -465,8 +466,8 @@ class RunService {
async getAllAliceL3AndDipoleLevelsForPhysicsRuns() {
const queryBuilder = dataSource.createQueryBuilder()
.set('attributes', (sequelize) => [
[sequelize.literal('DISTINCT ROUND(IF(alice_l3_polarity = \'NEGATIVE\', -1, 1) * alice_l3_current / 1000)'), 'l3Level'],
[sequelize.literal('ROUND(IF(alice_dipole_polarity = \'NEGATIVE\', -1, 1) * alice_dipole_current / 1000)'), 'dipoleLevel'],
[sequelize.literal(`DISTINCT ${ALICE_L3_CURRENT_LEVEL_SQL}`), 'l3Level'],
[sequelize.literal(ALICE_DIPOLE_CURRENT_LEVEL_SQL), 'dipoleLevel'],
])
.where('aliceL3Current').not().is(null)
.where('aliceL3Polarity').not().is(null)
Expand Down
25 changes: 25 additions & 0 deletions lib/server/services/run/aliceMagnetCurrentLevelSql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* 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.
*/

/**
* Return the SQL expression of a magnet's signed current, rounded to kA
*
* @param {'l3'|'dipole'} magnet the magnet, as named in the runs table columns
* @return {string} the SQL expression
*/
const currentLevelSql = (magnet) =>
`ROUND(IF(alice_${magnet}_polarity = 'NEGATIVE', -1, 1) * alice_${magnet}_current / 1000)`;

exports.ALICE_L3_CURRENT_LEVEL_SQL = currentLevelSql('l3');

exports.ALICE_DIPOLE_CURRENT_LEVEL_SQL = currentLevelSql('dipole');
25 changes: 6 additions & 19 deletions lib/usecases/run/GetAllRunsUseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { PhysicalConstant } = require('../../domain/enums/PhysicalConstant');
const { BadParameterError } = require('../../server/errors/BadParameterError');
const { gaqService } = require('../../server/services/qualityControlFlag/GaqService.js');
const { qcFlagSummaryService } = require('../../server/services/qualityControlFlag/QcFlagSummaryService.js');
const { ALICE_L3_CURRENT_LEVEL_SQL, ALICE_DIPOLE_CURRENT_LEVEL_SQL } = require('../../server/services/run/aliceMagnetCurrentLevelSql.js');
const { DetectorType } = require('../../domain/enums/DetectorTypes.js');
const { unpackNumberRange } = require('../../utilities/rangeUtils.js');
const { splitStringToStringsTrimmed } = require('../../utilities/stringUtils.js');
Expand Down Expand Up @@ -182,26 +183,12 @@ class GetAllRunsUseCase {
}

if (magnets) {
const { l3: aliceL3Current, dipole: aliceDipoleCurrent } = magnets;
if (aliceL3Current !== undefined) {
/**
* The alice l3 current computed from its absolute value and polarity
* @param {Function} literal function to create an object representing a database literal expression
* @return {Object} the object representing the column
*/
const computedColumn = ({ literal }) =>
literal('ROUND(alice_l3_current * IF(`alice_l3_polarity` = \'NEGATIVE\', -1, 1) / 1000)');
filteringQueryBuilder.where(computedColumn).is(aliceL3Current);
const { l3: l3Level, dipole: dipoleLevel } = magnets;
if (l3Level !== undefined) {
filteringQueryBuilder.where(({ literal }) => literal(ALICE_L3_CURRENT_LEVEL_SQL)).is(l3Level);
}
if (aliceDipoleCurrent !== undefined) {
/**
* The alice dipole current computed from its absolute value and polarity
* @param {Function} literal function to create an object representing a database literal expression
* @return {Object} the object representing the column
*/
const computedColumn = ({ literal }) =>
literal('ROUND(alice_dipole_current * IF(`alice_dipole_polarity` = \'NEGATIVE\', -1, 1) / 1000)');
filteringQueryBuilder.where(computedColumn).is(aliceDipoleCurrent);
if (dipoleLevel !== undefined) {
filteringQueryBuilder.where(({ literal }) => literal(ALICE_DIPOLE_CURRENT_LEVEL_SQL)).is(dipoleLevel);
}
}

Expand Down
Loading