Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/firebird-ng/workers/root-file/src/lib/root-file-worker.ts is written in an unsupported language. File is not indexed.

0001 /**
0002  * The ROOT file worker: `runRootFileWorker(self)` in a worker entry module of
0003  * the application (see `withWorkers()`). It reports what a ROOT file holds,
0004  * and converts podio events to Firebird DEX off the main thread.
0005  *
0006  * Two jobs, deliberately separate:
0007  *
0008  * - `probe` reports NEUTRAL FACTS - the file's top-level keys with their ROOT
0009  *   class names. It does not decide what the file is for. Deciding is the
0010  *   routing control's job, which asks the DI-registered loaders (each knows
0011  *   what its own format looks like).
0012  * - `open`/`convert` delegate to @dexvis/root2dex, whose only concern is
0013  *   producing DEX.
0014  *
0015  * A file stays OPEN under its handle between conversions (see
0016  * root-file.protocol.ts): opening reads the key directory, the streamer info
0017  * and the TTree metadata, and paying that once per file is what makes "show
0018  * event 7, now show event 12" fast. Only the baskets of the requested entries
0019  * are read, so a multi-GB file never lands in the browser.
0020  *
0021  * Keeping this in a worker also keeps jsroot out of the main bundle: the chunk
0022  * is fetched when the first file is opened, not at page load.
0023  */
0024 
0025 // jsroot declares its subpath modules (jsroot/io) in the types
0026 // of its main entry; the reference loads them without importing the main
0027 // entry, whose module graph is several times the size of the io entry.
0028 /// <reference types="jsroot" />
0029 import { openFile } from 'jsroot/io';
0030 import { Root2DexConverter, collectionGroupsFor } from '@dexvis/root2dex';
0031 import { RootFileSession, type RootFileRequest } from './root-file.protocol';
0032 import type { WorkerScope } from '@dexvis/firebird-ng/api';
0033 
0034 /**
0035  * Runs the ROOT file worker in `scope`, the global scope of a worker entry
0036  * module (`self`): answers the probe, open, convert and close requests of
0037  * RootFileService.
0038  *
0039  * ```ts
0040  * // root-file.worker.ts, the module withWorkers({ rootFile }) starts
0041  * import { runRootFileWorker } from '@dexvis/firebird-ng/workers/root-file';
0042  * runRootFileWorker(self);
0043  * ```
0044  */
0045 export function runRootFileWorker(scope: WorkerScope): void {
0046   const session = new RootFileSession(
0047     {
0048       async listKeys(source) {
0049         const file = (await openFile(source as never)) as {
0050           fKeys?: Array<{ fName: string; fClassName: string }>;
0051         };
0052         return (file.fKeys ?? []).map(key => ({ name: key.fName, className: key.fClassName }));
0053       },
0054       open: source => Root2DexConverter.open(source),
0055       collectionGroups: collectionGroupsFor,
0056     },
0057     message => scope.postMessage(message),
0058   );
0059   scope.addEventListener('message', ({ data }: MessageEvent<RootFileRequest>) => void session.handle(data));
0060 }