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
25 changes: 10 additions & 15 deletions app/lib/alimonitor-services/BookkeepingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BookkeepingService extends AbstractServiceSynchronizer {
timeTrgEnd: 'time_trg_end',
definition: 'run_type',
lhcBeamEnergy: 'energy',
detectors: 'detectors',
detectorsQualities: 'detectors',
aliceL3Current: 'l3_current_val',
aliceL3Polarity: 'l3_current_polarity',
aliceDipoleCurrent: 'dipole_current_val',
Expand Down Expand Up @@ -75,17 +75,11 @@ class BookkeepingService extends AbstractServiceSynchronizer {
dataAdjuster(run) {
try {
run = Utils.filterObject(run, this.ketpFields);
if (run.detectors) {
if (typeof run.detectors === 'string') {
if (run.detectors.includes(',')) { // TODO may other delimiters
run.detectors = run.detectors.split(/,/).map((d) => d.trim().toUpperCase());
} else {
run.detectors = run.detectors.split(/ +/).map((d) => d.trim().toUpperCase());
}
}
} else {
run.detectors = [];
}
const { detectors } = run;
delete run.detectors;
run.detectorNames = detectors.map(({ name }) => name.trim());
run.detectorQualities = detectors.map(({ quality }) => quality);

this.coilsCurrentsFieldsParsing(run, 'l3_current_val', 'l3_current_polarity', 'l3_current');
this.coilsCurrentsFieldsParsing(run, 'dipole_current_val', 'dipole_current_polarity', 'dipole_current');
ServicesDataCommons.mapBeamTypeToCommonFormat(run);
Expand Down Expand Up @@ -115,10 +109,10 @@ class BookkeepingService extends AbstractServiceSynchronizer {
const { period } = d;
const year = ServicesDataCommons.extractPeriodYear(period);
d = Utils.adjusetObjValuesToSql(d);

const period_insert = d.period ? `call insert_period(${d.period}, ${year}, ${d.beam_type});` : '';

const detectorsInSql = `${d.detectors}::varchar[]`;
const detectorInSql = `${d.detectorNames}::varchar[]`;
const detectorQualitiesInSql = `${d.detectorQualities}::varchar[]`;
const pgCommand = `${period_insert}; call insert_run (
${d.run_number},
${d.period},
Expand All @@ -129,7 +123,8 @@ class BookkeepingService extends AbstractServiceSynchronizer {
${d.run_type},
${d.fill_number},
${d.energy},
${detectorsInSql},
${detectorInSql},
${detectorQualitiesInSql},
${d.l3_current},
${d.dipole_current}
);`;
Expand Down
2 changes: 1 addition & 1 deletion app/lib/alimonitor-services/PassCorrectnessMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PassCorrectnessMonitor {

if (incorrect > 0) {
const logFunc = switchCase(errorsLoggingDepth, config.errorsLoggingDepths);
errors.forEach((e) => logFunc(logger, e));
errors.forEach((e) => logFunc(logger, e.stack));
logger.warn(`sync unseccessful for ${incorrect}/${dataSize}`);
}
if (omitted > 0) {
Expand Down
2 changes: 2 additions & 0 deletions app/lib/database/adapters/DetectorSubsystemAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class DetectorSubsystemAdapter {
const {
id,
name,
RunDetectors: { quality },
} = databaseObject;

return {
id,
name,
quality,
};
}

Expand Down
2 changes: 1 addition & 1 deletion app/lib/database/models/DetectorSubsystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = (sequelize) => {

DetectorSubsystem.associate = (models) => {
DetectorSubsystem.belongsToMany(models.Run, {
through: 'runs_detectors',
through: models.RunDetectors,
foreignKey: 'detector_id',
timestamps: false,
})
Expand Down
2 changes: 1 addition & 1 deletion app/lib/database/models/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = (sequelize) => {
Run.associate = (models) => {
Run.belongsTo(models.Period);
Run.belongsToMany(models.DetectorSubsystem, {
through: 'runs_detectors',
through: models.RunDetectors,
foreignKey: 'run_number',
timestamps: false,
});
Expand Down
24 changes: 24 additions & 0 deletions app/lib/database/models/RunDetectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @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.
*/

const Sequelize = require('sequelize');

module.exports = (sequelize) => {
const RunDetectors = sequelize.define('RunDetectors', {
quality: {
type: Sequelize.STRING,
},
}, { timestamps: false, tableName: 'runs_detectors' });

return RunDetectors;
};
2 changes: 2 additions & 0 deletions app/lib/database/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Run = require('./Run.js');
const DataPass = require('./DataPass.js');
const DetectorSubsystem = require('./DetectorSubsystem.js');
const SimulationPass = require('./SimulationPass.js');
const RunDetectors = require('./RunDetectors.js');

/**
*
Expand All @@ -33,6 +34,7 @@ const modelsFactory = (sequelize) => {
DataPass,
DetectorSubsystem,
SimulationPass,
RunDetectors,
};
models = Object.entries(models).map(([modelName, model]) => [modelName, model(sequelize)]); // instantiate models
models.forEach(([_, modelInstance]) => modelInstance.associate?.(sequelize.models)); // associate models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
*
* @property {number} id
* @property {string} name
* @property {string} quality
*/
1 change: 1 addition & 0 deletions app/lib/domain/entities/DetectorSubsystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
*
* @property {number} id
* @property {string} name
* @property {string} quality
*/
6 changes: 3 additions & 3 deletions app/lib/utils/sql-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ function adjusetObjValuesToSql(obj) {
res[k] = adjustValuesToSql(v);
}
} else {
res[k] = null;
res[k] = 'null';
}
}
return res;
}

function adjustValuesToSql(v) {
if (!v) {
return null;
return 'null';
}

if (Array.isArray(v)) {
Expand All @@ -47,7 +47,7 @@ function adjustValuesToSql(v) {

if (typeof v == 'string') {
if (v.length == 0) {
return null;
return 'null';
} else if (! sqlValueKeywords.includes(v?.trim().toUpperCase()) && isNaN(v)) {
return `'${v}'`;
}
Expand Down
5 changes: 4 additions & 1 deletion database/design.dbm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CAUTION: Do not modify this file unless you know what you are doing.
Unexpected results may occur if the code is changed deliberately.
-->
<dbmodel pgmodeler-ver="1.0.4" use-changelog="false" last-position="0,292" last-zoom="1" max-obj-count="31"
<dbmodel pgmodeler-ver="1.0.4" use-changelog="false" last-position="0,296" last-zoom="1" max-obj-count="31"
default-owner="postgres"
layers="Default layer"
active-layers="0"
Expand Down Expand Up @@ -312,6 +312,9 @@ CAUTION: Do not modify this file unless you know what you are doing.
<column name="run_number" not-null="true">
<type name="integer" length="0"/>
</column>
<column name="quality">
<type name="varchar" length="0"/>
</column>
<constraint name="runs_detectors_pkey" type="pk-constr" table="public.runs_detectors">
<columns names="detector_id,run_number" ref-type="src-columns"/>
</constraint>
Expand Down
1 change: 1 addition & 0 deletions database/exported/create-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ ALTER SEQUENCE public.runs_detectors_id_seq OWNER TO postgres;
CREATE TABLE public.runs_detectors (
detector_id integer NOT NULL,
run_number integer NOT NULL,
quality varchar,
CONSTRAINT runs_detectors_pkey PRIMARY KEY (detector_id,run_number),
CONSTRAINT rd_pair_unique UNIQUE (detector_id,run_number)
);
Expand Down
Binary file modified database/exported/design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@

create or replace procedure insert_detectors_for_runs(
_run_number bigint,
_detectors varchar[]
_detectors varchar[],
_detectors_qualities varchar[]
)
LANGUAGE plpgsql
AS $$
DEClARE d varchar;
DEClARE trg_id int;
DECLARE d varchar;
DECLARE q varchar;

DECLARE dq varchar[];
DEClARE trg_id integer;
BEGIN
foreach d in array _detectors loop
SELECT id INTO trg_id FROM detectors_subsystems WHERE name = d;
IF array_upper(_detectors, 1) IS NULL OR array_upper(_detectors_qualities, 1) IS NULL THEN
return;
END IF;
for i in 1 .. array_upper(_detectors, 1) loop
d = _detectors[i];
q = _detectors_qualities[i];

SELECT id INTO trg_id FROM detectors_subsystems WHERE name = d;

raise notice 'detector xdxd %', d;
-- inserting new detectors
IF trg_id IS NULL THEN
raise notice 'new detector % !!!', d;
Expand All @@ -22,7 +33,7 @@ BEGIN
-- inserting run x detector relation
IF NOT EXISTS (SELECT * FROM runs_detectors WHERE detector_id = trg_id AND run_number = _run_number) THEN
SELECT id INTO trg_id FROM detectors_subsystems WHERE name = d;
INSERT INTO runs_detectors(detector_id, run_number) VALUES(trg_id, _run_number);
INSERT INTO runs_detectors(detector_id, run_number, quality) VALUES(trg_id, _run_number, q);
END IF;
end loop;
END;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LANGUAGE plpgsql
AS $$
DEClARE prod_id int;
BEGIN
call insert_run(_run_number, _period, null, null, null, null, null, null, null, ARRAY[]::varchar[], null, null);
call insert_run(_run_number, _period, null, null, null, null, null, null, null, ARRAY[]::varchar[], ARRAY[]::varchar[], null, null);
SELECT id FROM simulation_passes INTO prod_id WHERE name = _prod_name;
if NOT EXISTS (SELECT * FROM runs WHERE run_number = _run_number) OR prod_id IS NULL THEN
RAISE EXCEPTION 'nulls %', now();
Expand All @@ -32,7 +32,7 @@ DEClARE prod_id int;
DECLARE _run_number integer;
BEGIN
foreach _run_number in array _run_numbers loop
call insert_run(_run_number, _period, null, null, null, null, null, null, null, ARRAY[]::varchar[], null, null);
call insert_run(_run_number, _period, null, null, null, null, null, null, null, ARRAY[]::varchar[], ARRAY[]::varchar[], null, null);
SELECT id FROM simulation_passes INTO prod_id WHERE name = _prod_name;
if NOT EXISTS (SELECT * FROM runs WHERE run_number = _run_number) OR prod_id IS NULL THEN
RAISE EXCEPTION 'nulls %', now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LANGUAGE plpgsql
AS $$
DEClARE prod_id int;
BEGIN
call insert_run(_run_number, _period, null, null, null, null, null, null, null, ARRAY[]::varchar[], null, null);
call insert_run(_run_number, _period, null, null, null, null, null, null, null, ARRAY[]::varchar[], ARRAY[]::varchar[], null, null);
SELECT id FROM data_passes INTO prod_id WHERE name = _prod_name;
IF NOT EXISTS (SELECT * FROM runs WHERE run_number = _run_number) THEN
RAISE EXCEPTION 'no run %', now();
Expand Down Expand Up @@ -36,7 +36,7 @@ DEClARE prod_id int;
DECLARE _run_number integer;
BEGIN
foreach _run_number in array _run_numbers loop
call insert_run(_run_number, _period, null, null, null, null, null, null, null, ARRAY[]::varchar[], null, null);
call insert_run(_run_number, _period, null, null, null, null, null, null, null, ARRAY[]::varchar[], ARRAY[]::varchar[], null, null);
SELECT id FROM data_passes INTO prod_id WHERE name = _prod_name;
IF NOT EXISTS (SELECT * FROM runs WHERE run_number = _run_number) OR prod_id IS NULL THEN
RAISE EXCEPTION 'nulls %', now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ create or replace procedure insert_run(
_fill_number integer,
_energy_per_beam float,
_detectors varchar[],
_detectors_qualities varchar[],
_l3_current float,
_dipole_current float)
LANGUAGE plpgsql
Expand Down Expand Up @@ -74,6 +75,6 @@ BEGIN
END IF;
END IF;

call insert_detectors_for_runs(_run_number, _detectors);
call insert_detectors_for_runs(_run_number, _detectors, _detectors_qualities);
END;
$$;
2 changes: 1 addition & 1 deletion rctmake
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ for stage in $STAGES; do
;;
clean | truncate)
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/run/delete-data.sql";
&& docker exec $DB_CONTAINER_NAME psql -U $RCT_DB_USER -d $RCT_DB_NAME -f "$DB_WORKINGDIR/delete-data.sql";
;;

ip)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = () => {
});

it('should parse undefined values as null', () => {
assert(Utils.adjustValuesToSql(undefined) === null);
assert(Utils.adjustValuesToSql(undefined) === 'null');
});

it('should return unquoted DEFAULT', () => {
Expand Down