1111 * or submit itself to any jurisdiction.
1212 */
1313
14+ import { switchCase } from '/js/src/index.js' ;
1415import { getRemoteData } from '../../utilities/fetch/getRemoteData.js' ;
1516import { ObservableData } from '../../utilities/ObservableData.js' ;
16- import { DetectorType , DATA_TAKING_DETECTOR_TYPES } from '../../domain/enums/DetectorTypes.js' ;
17+ import { DetectorType , DATA_TAKING_DETECTOR_TYPES , QC_DETECTORS } from '../../domain/enums/DetectorTypes.js' ;
1718
1819import { NonPhysicalDetector } from '../../domain/enums/detectorsNames.mjs' ;
1920
@@ -32,10 +33,10 @@ const getPhysicalDetectorsFromAllDetectors = (allDetectors) => allDetectors.filt
3233 * Return the QC detectors from a list of detectors
3334 *
3435 * @param {Detector[] } allDetectors the list of all detectors
35- * @return {Detector[] } physical detectors
36+ * @return {Detector[] } QC detectors
3637 */
3738const getQcDetectorsFromAllDetectors = ( allDetectors ) => allDetectors
38- . filter ( ( { type, name } ) => [ DetectorType . PHYSICAL , DetectorType . QC ] . includes ( type ) && ! DETECTORS_EXCLUDED_FROM_QC . includes ( name ) ) ;
39+ . filter ( ( { type, name } ) => QC_DETECTORS . includes ( type ) && ! DETECTORS_EXCLUDED_FROM_QC . includes ( name ) ) ;
3940
4041/**
4142 * Service class to fetch detectors from the backend
@@ -72,9 +73,27 @@ export class DetectorsProvider extends RemoteDataProvider {
7273 * @inheritDoc
7374 */
7475 async getRemoteData ( ) {
75- const { data } = await getRemoteData ( '/api/detectors' ) ;
76- data . sort ( ( { name : name1 } , { name : name2 } ) => name1 . localeCompare ( name2 ) ) ;
77- return data ;
76+ const { data : detectors } = await getRemoteData ( '/api/detectors' ) ;
77+ const typeToOrderingKey = ( type ) => switchCase ( type , {
78+ [ DetectorType . OTHER ] : 0 ,
79+ [ DetectorType . VIRTUAL ] : 1 ,
80+ [ DetectorType . PHYSICAL ] : 2 ,
81+ [ DetectorType . AOT_GLO ] : 3 ,
82+ [ DetectorType . AOT_EVENT ] : 4 ,
83+ [ DetectorType . MUON_GLO ] : 5 ,
84+ [ DetectorType . QC_ONLY ] : 6 ,
85+ } ) ;
86+
87+ const orderingKey = ( detector1 , detector2 ) => {
88+ const specialPair = [ 'ZDC' , 'TST' ] ;
89+ if ( specialPair . includes ( detector1 . name ) && specialPair . includes ( detector2 . name ) ) {
90+ return detector1 . name === 'ZDC' ? 1 : - 1 ;
91+ }
92+ return - ( typeToOrderingKey ( detector1 . type ) - typeToOrderingKey ( detector2 . type ) ) * 10 + detector1 . name . localeCompare ( detector2 . name ) ;
93+ } ;
94+
95+ detectors . sort ( ( detector1 , detector2 ) => orderingKey ( detector1 , detector2 ) ) ;
96+ return detectors ;
7897 }
7998
8099 /**
0 commit comments