@@ -87,6 +87,7 @@ class RunAdapter {
8787 this . qcFlagAdapter = null ;
8888
8989 this . toEntity = this . toEntity . bind ( this ) ;
90+ this . toSummary = this . toSummary . bind ( this ) ;
9091 this . toLhcFillSummary = this . toLhcFillSummary . bind ( this ) ;
9192 this . toDatabase = this . toDatabase . bind ( this ) ;
9293 this . toMinifiedEntity = this . toMinifiedEntity . bind ( this ) ;
@@ -119,6 +120,26 @@ class RunAdapter {
119120 }
120121 }
121122
123+ /**
124+ * Adds detectors along with their qualities to an entity
125+ *
126+ * @param {Detector[] } detectors the list of detector models
127+ * @param {object } entityObject the entity object that is to be modified
128+ * @param {boolean } [addDetectorQuality = true] if detectorQuality should be included
129+ * @returns {void }
130+ */
131+ _computeQcFlags ( qcFlags = [ ] , entityObject , isSummary = false ) {
132+ const adaptedQcFlags = isSummary
133+ ? qcFlags . map ( this . qcFlagAdapter . toSummary )
134+ : qcFlags . map ( this . qcFlagAdapter . toEntity ) ;
135+
136+ entityObject . qcFlags = adaptedQcFlags . reduce ( ( acc , qcFlag ) => {
137+ acc [ qcFlag . dplDetectorId ] = acc [ qcFlag . dplDetectorId ] ?? [ ] ;
138+ acc [ qcFlag . dplDetectorId ] . push ( qcFlag ) ;
139+ return acc ;
140+ } , { } ) ;
141+ }
142+
122143 /**
123144 * Converts the given database object to an entity object.
124145 *
@@ -311,12 +332,91 @@ class RunAdapter {
311332 ? lhcFill . collidingBunchesCount ?? extractNumberOfCollidingLhcBunchCrossings ( lhcFill . fillingSchemeName )
312333 : null ;
313334
314- const adaptedQcFlags = qcFlags ? qcFlags . map ( this . qcFlagAdapter . toEntity ) : [ ] ;
315- entityObject . qcFlags = adaptedQcFlags . reduce ( ( acc , qcFlag ) => {
316- acc [ qcFlag . dplDetectorId ] = acc [ qcFlag . dplDetectorId ] ?? [ ] ;
317- acc [ qcFlag . dplDetectorId ] . push ( qcFlag ) ;
318- return acc ;
319- } , { } ) ;
335+ this . _computeQcFlags ( qcFlags , entityObject ) ;
336+
337+ return entityObject ;
338+ }
339+
340+ /**
341+ * Converts the given database object to an summary object.
342+ *
343+ * @param {SequelizeRun } databaseObject Object to convert.
344+ * @returns {Run } Converted summary object.
345+ */
346+ toSummary ( databaseObject ) {
347+ const {
348+ detectors,
349+ eorReasons,
350+ runNumber,
351+ timeO2Start,
352+ timeO2End,
353+ timeTrgStart,
354+ timeTrgEnd,
355+ firstTfTimestamp,
356+ lastTfTimestamp,
357+ qcTimeStart,
358+ qcTimeEnd,
359+ inelasticInteractionRateAvg,
360+ inelasticInteractionRateAtStart,
361+ inelasticInteractionRateAtMid,
362+ inelasticInteractionRateAtEnd,
363+ aliceL3Polarity,
364+ aliceL3Current,
365+ aliceDipolePolarity,
366+ aliceDipoleCurrent,
367+ qcFlags = [ ] ,
368+ } = databaseObject ;
369+
370+ /**
371+ * @type {Run }
372+ */
373+ const entityObject = {
374+ runNumber,
375+ timeO2Start : timeO2Start ? new Date ( timeO2Start ) . getTime ( ) : timeO2Start ,
376+ timeO2End : timeO2End ? new Date ( timeO2End ) . getTime ( ) : timeO2End ,
377+ timeTrgStart : timeTrgStart ? new Date ( timeTrgStart ) . getTime ( ) : timeTrgStart ,
378+ timeTrgEnd : timeTrgEnd ? new Date ( timeTrgEnd ) . getTime ( ) : timeTrgEnd ,
379+ firstTfTimestamp : firstTfTimestamp ? new Date ( firstTfTimestamp ) . getTime ( ) : firstTfTimestamp ,
380+ lastTfTimestamp : lastTfTimestamp ? new Date ( lastTfTimestamp ) . getTime ( ) : lastTfTimestamp ,
381+ qcTimeStart : qcTimeStart ? new Date ( qcTimeStart ) . getTime ( ) : qcTimeStart ,
382+ qcTimeEnd : qcTimeEnd ? new Date ( qcTimeEnd ) . getTime ( ) : qcTimeEnd ,
383+ id : databaseObject . id ,
384+ runDuration : databaseObject . runDuration ,
385+ environmentId : databaseObject . environmentId ,
386+ runType : databaseObject . runType ,
387+ definition : databaseObject . definition ,
388+ calibrationStatus : databaseObject . calibrationStatus ,
389+ runQuality : databaseObject . runQuality ,
390+ nDetectors : databaseObject . nDetectors ,
391+ nFlps : databaseObject . nFlps ,
392+ nEpns : databaseObject . nEpns ,
393+ dd_flp : databaseObject . dd_flp ,
394+ dcs : databaseObject . dcs ,
395+ epn : databaseObject . epn ,
396+ epnTopology : databaseObject . epnTopology ,
397+ nSubtimeframes : databaseObject . nSubtimeframes ,
398+ bytesReadOut : databaseObject . bytesReadOut ,
399+ fillNumber : databaseObject . fillNumber ,
400+ lhcBeamMode : databaseObject . lhcBeamMode ,
401+ odcTopologyFullName : databaseObject . odcTopologyFullName ,
402+ triggerValue : databaseObject . triggerValue ,
403+ tags : databaseObject . tags ,
404+ pdpBeamType : databaseObject . pdpBeamType ,
405+ lhcPeriod : databaseObject . lhcPeriod ,
406+ aliceL3Polarity,
407+ aliceL3Current,
408+ aliceDipolePolarity,
409+ aliceDipoleCurrent,
410+ } ;
411+
412+ entityObject . eorReasons = eorReasons ? eorReasons . map ( this . eorReasonAdapter . toSummary ) : [ ] ;
413+ entityObject . inelasticInteractionRateAvg = inelasticInteractionRateAvg ;
414+ entityObject . inelasticInteractionRateAtStart = inelasticInteractionRateAtStart ;
415+ entityObject . inelasticInteractionRateAtMid = inelasticInteractionRateAtMid ;
416+ entityObject . inelasticInteractionRateAtEnd = inelasticInteractionRateAtEnd ;
417+
418+ this . _addDetectorsToObject ( detectors , entityObject ) ;
419+ this . _computeQcFlags ( qcFlags , entityObject , true ) ;
320420
321421 return entityObject ;
322422 }
0 commit comments