Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/firebird-ng/src/lib/builtin-loaders.spec.ts is written in an unsupported language. File is not indexed.

0001 /**
0002  * Which built-in loader opens a source: the first registered loader whose
0003  * `canLoad()` claims it (open-dex, open-geometry, loadFromConfig). Pinned
0004  * with the real built-ins composed by provideFirebird(), so a change to a
0005  * loader's extensions, schemes or registration order shows up here.
0006  */
0007 import { TestBed } from '@angular/core/testing';
0008 import { provideZonelessChangeDetection } from '@angular/core';
0009 import { provideHttpClient } from '@angular/common/http';
0010 import { provideHttpClientTesting } from '@angular/common/http/testing';
0011 import { ConfigService } from '@dexvis/app-features';
0012 import type { DataSource } from '@dexvis/firebird-core';
0013 import { provideFirebird } from './provide-firebird';
0014 import { injectEventLoaders, injectGeometryLoaders } from '@dexvis/firebird-ng/api';
0015 
0016 /** The id of the event loader that claims the source first, or null when none does. */
0017 function eventLoaderFor(source: DataSource): string | null {
0018   const loaders = TestBed.runInInjectionContext(() => injectEventLoaders());
0019   return loaders.find(loader => loader.canLoad(source))?.meta.id ?? null;
0020 }
0021 
0022 function geometryLoaderFor(source: DataSource): string | null {
0023   const loaders = TestBed.runInInjectionContext(() => injectGeometryLoaders());
0024   return loaders.find(loader => loader.canLoad(source))?.meta.id ?? null;
0025 }
0026 
0027 const picked = (name: string) => new File([], name);
0028 
0029 describe('built-in loader claims', () => {
0030   beforeEach(() => {
0031     localStorage.clear();
0032     TestBed.configureTestingModule({
0033       providers: [provideZonelessChangeDetection(), provideHttpClient(), provideHttpClientTesting(), provideFirebird()],
0034     });
0035   });
0036 
0037   describe('events', () => {
0038     it('opens DEX files with the DEX loader, whatever the scheme', () => {
0039       expect(eventLoaderFor('asset://data/sample.firebird.zip')).toBe('firebird-dex');
0040       expect(eventLoaderFor('asset://data/sample.firebird.json')).toBe('firebird-dex');
0041       expect(eventLoaderFor('https://host/d/sample.v1.firebird.zip')).toBe('firebird-dex');
0042       expect(eventLoaderFor('http://localhost:5454/api/v1/download?f=events.firebird.zip')).toBe('firebird-dex');
0043       expect(eventLoaderFor(picked('events.firebird.zip'))).toBe('firebird-dex');
0044     });
0045 
0046     it('converts ROOT files the browser can byte-range in the browser', () => {
0047       expect(eventLoaderFor('asset://data/run.edm4eic.root')).toBe('root2dex');
0048       expect(eventLoaderFor('http://host/run.edm4eic.root')).toBe('root2dex');
0049       expect(eventLoaderFor('https://host/run.edm4hep.root')).toBe('root2dex');
0050       expect(eventLoaderFor('http://localhost:5454/api/v1/download?f=run.edm4eic.root')).toBe('root2dex');
0051       expect(eventLoaderFor(picked('run.edm4eic.root'))).toBe('root2dex');
0052     });
0053 
0054     it('converts XRootD URLs and server paths through pyrobird', () => {
0055       expect(eventLoaderFor('root://dtn-eic.jlab.org//work/eic2/run.edm4eic.root')).toBe('edm4eic-root');
0056       expect(eventLoaderFor('data/run.edm4eic.root')).toBe('edm4eic-root');
0057     });
0058 
0059     it('claims no other asset:// file', () => {
0060       expect(eventLoaderFor('asset://data/example.whatever')).toBeNull();
0061       expect(eventLoaderFor('asset://data/notes.txt')).toBeNull();
0062     });
0063 
0064     it("sends every ROOT URL through pyrobird with events.rootConverter = 'server', and no picked ROOT file", () => {
0065       TestBed.inject(ConfigService).applySessionValue('events.rootConverter', 'server');
0066       expect(eventLoaderFor('https://host/run.edm4eic.root')).toBe('edm4eic-root');
0067       expect(eventLoaderFor('asset://data/run.edm4eic.root')).toBe('edm4eic-root');
0068       // The convert endpoint takes a URL or a server path; a picked file has neither
0069       expect(eventLoaderFor(picked('run.edm4eic.root'))).toBeNull();
0070       expect(eventLoaderFor('https://host/d/sample.firebird.zip')).toBe('firebird-dex');
0071     });
0072   });
0073 
0074   describe('geometry', () => {
0075     it('opens ROOT geometry by URL, server path or picked file', () => {
0076       expect(geometryLoaderFor('https://host/tgeo/detector.root')).toBe('root-geometry');
0077       expect(geometryLoaderFor('asset://geometry/detector.root')).toBe('root-geometry');
0078       expect(geometryLoaderFor(picked('detector.root'))).toBe('root-geometry');
0079       expect(geometryLoaderFor('https://host/detector.gdml')).toBeNull();
0080     });
0081   });
0082 });