Skip to content

Commit b0d78a4

Browse files
committed
include qcFlags
1 parent 0e8da18 commit b0d78a4

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

lib/database/adapters/RunAdapter.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class RunAdapter {
7575
*/
7676
this.userAdapter = null;
7777

78+
/**
79+
* @type {QcFlagAdapter|null}
80+
*/
81+
this.qcFlagAdapter = null;
82+
7883
this.toEntity = this.toEntity.bind(this);
7984
this.toDatabase = this.toDatabase.bind(this);
8085
this.toMinifiedEntity = this.toMinifiedEntity.bind(this);
@@ -167,6 +172,7 @@ class RunAdapter {
167172
phaseShiftAtEndBeam2,
168173
userStart,
169174
userStop,
175+
qcFlags,
170176
} = databaseObject;
171177

172178
/**
@@ -281,6 +287,8 @@ class RunAdapter {
281287
entityObject.muInelasticInteractionRate = null;
282288
}
283289

290+
entityObject.qcFlags = qcFlags ? qcFlags.map(this.qcFlagAdapter.toEntity) : [];
291+
284292
return entityObject;
285293
}
286294

lib/database/adapters/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ runAdapter.logAdapter = logAdapter;
139139
runAdapter.runTypeAdapter = runTypeAdapter;
140140
runAdapter.tagAdapter = tagAdapter;
141141
runAdapter.userAdapter = userAdapter;
142+
runAdapter.qcFlagAdapter = qcFlagAdapter;
142143

143144
simulationPassQcFlagAdapter.simulationPassAdapter = simulationPassAdapter;
144145
simulationPassQcFlagAdapter.qcFlagAdapter = qcFlagAdapter;

lib/domain/dtos/filters/RunFilterDto.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ exports.RunFilterDto = Joi.object({
9090
odcTopologyFullName: Joi.string().trim(),
9191
detectors: DetectorsFilterDto,
9292
lhcPeriods: Joi.string().trim(),
93+
lhcPeriodIds: Joi.array().items(Joi.number().positive().integer()),
9394
dataPassIds: Joi.array().items(Joi.number()),
9495
simulationPassIds: Joi.array().items(Joi.number()),
9596
runTypes: CustomJoi.stringArray().items(Joi.string()).single().optional(),

lib/usecases/run/GetAllRunsUseCase.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class GetAllRunsUseCase {
5151
epn,
5252
fillNumbers,
5353
lhcPeriods,
54+
lhcPeriodIds,
5455
dataPassIds,
5556
simulationPassIds,
5657
nDetectors,
@@ -340,6 +341,19 @@ class GetAllRunsUseCase {
340341
});
341342
}
342343

344+
if (lhcPeriodIds) {
345+
const runNumbers = (await RunRepository.findAll({
346+
attributes: ['runNumber'],
347+
raw: true,
348+
include: {
349+
association: 'lhcPeriod',
350+
attributes: [],
351+
where: { id: { [Op.in]: lhcPeriodIds } },
352+
},
353+
})).map(({ runNumber }) => runNumber);
354+
filteringQueryBuilder.where('runNumber').oneOf(...runNumbers);
355+
}
356+
343357
if (dataPassIds) {
344358
const runNumbers = (await RunRepository.findAll({
345359
attributes: ['runNumber'],
@@ -460,6 +474,71 @@ class GetAllRunsUseCase {
460474
fetchQueryBuilder.orderBy(property, sort[property]);
461475
}
462476

477+
if (filter?.include?.effectiveQcFlags) {
478+
const [dataPassId] = filter?.dataPassIds ?? [];
479+
const [simulationPassId] = filter?.simulationPassIds ?? [];
480+
const [lhcPeriodId] = filter?.lhcPeriodIds ?? [];
481+
482+
if (Boolean(dataPassId) + Boolean(simulationPassId) + Boolean(lhcPeriodId) > 1) {
483+
throw new BadParameterError('If including QC flags, one and exactly one'
484+
+ 'of `dataPassId`, `simulationPassId` and `lhcPeriodId` is required');
485+
}
486+
487+
if (dataPassId) {
488+
fetchQueryBuilder.include({
489+
association: 'qcFlags',
490+
required: false,
491+
include: [
492+
{
493+
association: 'dataPasses',
494+
required: true,
495+
where: { id: dataPassId },
496+
},
497+
{
498+
association: 'effectivePeriods',
499+
required: true,
500+
},
501+
],
502+
});
503+
} else if (simulationPassId) {
504+
fetchQueryBuilder.include({
505+
association: 'qcFlags',
506+
required: false,
507+
include: [
508+
{
509+
association: 'simulationPasses',
510+
required: true,
511+
where: { id: simulationPassId },
512+
},
513+
{
514+
association: 'effectivePeriods',
515+
required: true,
516+
},
517+
],
518+
});
519+
} else {
520+
fetchQueryBuilder.include({
521+
association: 'qcFlags',
522+
required: false,
523+
include: [
524+
{
525+
association: 'simulationPasses',
526+
required: false,
527+
},
528+
{
529+
association: 'dataPasses',
530+
required: false,
531+
},
532+
{
533+
association: 'effectivePeriods',
534+
required: true,
535+
},
536+
],
537+
}).where('$qcFlags.dataPasses.id$').is(null)
538+
.where('$qcFlags.simulationPasses.id$').is(null);
539+
}
540+
}
541+
463542
const runs = (await RunRepository.findAll(fetchQueryBuilder)).map(runAdapter.toEntity);
464543

465544
return { count, runs };

0 commit comments

Comments
 (0)