Skip to content

Commit

Permalink
[ORCT-118] Handling incorrect data in Monte Carlo (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
xsalonx authored Sep 22, 2023
1 parent 1d5c368 commit b8882f4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
10 changes: 8 additions & 2 deletions app/lib/alimonitor-services/MonalisaService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@

const AbstractServiceSynchronizer = require('./AbstractServiceSynchronizer.js');
const Utils = require('../utils');
const { ServicesEndpointsFormatter, ServicesDataCommons: { mapBeamTypeToCommonFormat, extractPeriod } } = require('./helpers');
const { ServicesEndpointsFormatter,
ServicesDataCommons: {
mapBeamTypeToCommonFormat,
extractPeriod,
PERIOD_NAME_REGEX,
},
} = require('./helpers');
const MonalisaServiceDetails = require('./MonalisaServiceDetails.js');
const config = require('../config/configProvider.js');

Expand Down Expand Up @@ -74,7 +80,7 @@ class MonalisaService extends AbstractServiceSynchronizer {
const preprocesed = entries.map(([prodName, vObj]) => {
vObj['name'] = prodName.trim();
return vObj;
}).filter((r) => r.name?.match(/^LHC\d\d[a-zA-Z]_.*$/));
}).filter((r) => r.name?.match(PERIOD_NAME_REGEX.rightExtend('_.*$')));
return preprocesed.map(this.adjustDataUnit.bind(this));
}

Expand Down
9 changes: 5 additions & 4 deletions app/lib/alimonitor-services/MonalisaServiceMC.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

const AbstractServiceSynchronizer = require('./AbstractServiceSynchronizer.js');
const Utils = require('../utils');
const { ServicesEndpointsFormatter, ServicesDataCommons: { extractPeriod } } = require('./helpers');
const { ServicesEndpointsFormatter, ServicesDataCommons: { extractPeriod, PERIOD_NAME_REGEX } } = require('./helpers');
const config = require('../config/configProvider.js');

const { databaseManager: {
Expand Down Expand Up @@ -60,7 +60,7 @@ class MonalisaServiceMC extends AbstractServiceSynchronizer {
simPassAttributes['name'] = simPassName.trim();
return simPassAttributes;
})
.filter((simulationPass) => simulationPass.name?.match(/^LHC\d\d.*$/))
.filter((simulationPass) => simulationPass.name?.match(PERIOD_NAME_REGEX.rightExtend('.*')))
.map(this.adjustDataUnit.bind(this));
}

Expand All @@ -81,8 +81,9 @@ class MonalisaServiceMC extends AbstractServiceSynchronizer {
*/

simulationPass.anchoredPasses = parseListLikeString(simulationPass.anchoredPasses);
simulationPass.anchoredPeriods = parseListLikeString(simulationPass.anchoredPeriods).map((periodName) =>
extractPeriod(periodName, simulationPass.beam_type));
simulationPass.anchoredPeriods = parseListLikeString(simulationPass.anchoredPeriods)
.filter((periodName) => PERIOD_NAME_REGEX.test(periodName))
.map((periodName) => extractPeriod(periodName, simulationPass.beam_type));
simulationPass.runs = parseListLikeString(simulationPass.runs).map((s) => Number(s));

return simulationPass;
Expand Down
19 changes: 18 additions & 1 deletion app/lib/alimonitor-services/helpers/ServicesDataCommons.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
const Utils = require('../../utils');
const { rctData } = require('../../config/configProvider.js');

/**
* PERIOD_NAME_REGEX is a regular expression for examining
* whether given string can be considered period name, e.g. LHC22o is a period name.
* It is defined as ^LHC\d\d[a-zA-Z]+
* The regex can be (right) extended in order to match e.g.:
* 1. data passes, e.g. LHC22o_apass1 can be matched with PERIOD_NAME_REGEX.rightExtend('_apass\\d');
* 2. simulation passes, e.g. LHC21i12 can be matched with PERIOD_NAME_REGEX.rightExtend('.*');
*/
const PERIOD_NAME_REGEX = /^LHC\d\d[a-zA-Z]+/;
const rightExtendRegEx = (srcRegEx, suffix) => {
const extenedRegex = RegExp(srcRegEx.source + suffix);
extenedRegex.rightExtend = (_suffix) => rightExtendRegEx(extenedRegex, _suffix);
return extenedRegex;
};
PERIOD_NAME_REGEX.rightExtend = (suffix) => rightExtendRegEx(PERIOD_NAME_REGEX, suffix);

/**
* Update objectData.beam_type to valid format if mapping is provided with app config
* if not there is assumption that in other scenerio name is consistant with foramt '<typeA>-<typeB>'
Expand Down Expand Up @@ -56,7 +72,7 @@ function extractPeriodYear(name) {
*/
function extractPeriod(name, beamType = undefined) {
const [extractedName] = name.split('_');
if (! /LHC[0-9]{2}[a-z]+/.test(extractedName)) {
if (! PERIOD_NAME_REGEX.test(extractedName)) {
throw new Error(`Incorrect period name ${extractedName} extracted from ${name}`);
}
return {
Expand All @@ -70,4 +86,5 @@ module.exports = {
mapBeamTypeToCommonFormat,
extractPeriodYear,
extractPeriod,
PERIOD_NAME_REGEX,
};
3 changes: 1 addition & 2 deletions rctmake
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,7 @@ for stage in $STAGES; do
if [ -z "$DUMP_FILE" ]; then
usage "Dump file name unspecified, use flag -F|--dump-file <FILE>";
fi
docker cp "$PROJECT_DIR/database/utils/delete-data.sql" "$DB_CONTAINER_NAME:$DB_WORKINGDIR/delete-data.sql" \
&& docker exec $DB_CONTAINER_NAME psql -U $RCT_DB_USER -d $RCT_DB_NAME -f "$DB_WORKINGDIR/delete-data.sql" \
docker exec $DB_CONTAINER_NAME psql -U $RCT_DB_USER -d $RCT_DB_NAME -f "$DB_WORKINGDIR/database/utils/delete-data.sql" \
&& docker exec $DB_CONTAINER_NAME pg_restore --data-only -U $RCT_DB_USER -d $RCT_DB_NAME $CONTAINER_DUMP_PATH;
;;

Expand Down

0 comments on commit b8882f4

Please sign in to comment.