Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /**
0002  * Pre-build edits of a ROOT TGeo tree, run in the geometry worker before
0003  * jsroot builds three.js objects. What to remove and edit arrives as data
0004  * with each load request (`withRootGeometryRules()`); this module only knows
0005  * how to apply it.
0006  */
0007 
0008 import { editGeoNodes, findGeoNodes, removeGeoNode } from '@dexvis/root-geo-tree-editor';
0009 import type { DetectorEditRules } from '@dexvis/firebird-ng/api';
0010 
0011 /** Removes the top-level detectors whose names start with one of `removeNames`. */
0012 export function pruneTopLevelDetectors(geoManager: any, removeNames: readonly string[]): { nodes: any[]; removedNodes: any[] } {
0013   const volume = geoManager.fMasterVolume === undefined ? geoManager.fVolume : geoManager.fMasterVolume;
0014   const nodes: any[] = volume?.fNodes?.arr ?? [];
0015   const removedNodes = nodes.filter(node => removeNames.some(prefix => node.fName.startsWith(prefix)));
0016   for (const node of removedNodes) {
0017     removeGeoNode(node);
0018   }
0019   return { nodes, removedNodes };
0020 }
0021 
0022 /**
0023  * Applies detector edit rules to the top-level nodes of a TGeo tree. A
0024  * pattern may match several detectors (two copies of one detector, or
0025  * 'Tracker*' matching Tracker and TrackerSupport): each match gets the rules.
0026  * A pattern that matches nothing is skipped, so one rule set serves several
0027  * geometry versions.
0028  */
0029 export function applyDetectorEditRules(geoManager: any, detectors: readonly DetectorEditRules[]): void {
0030   console.time('[RootGeometryProcessor] Processing time');
0031   for (const detector of detectors) {
0032     for (const { geoNode } of findGeoNodes(geoManager, detector.namePattern, 1)) {
0033       // One rule per pass: a rule sees the tree the previous rules left
0034       for (const rule of detector.editRules) {
0035         editGeoNodes(geoNode, [rule]);
0036       }
0037     }
0038   }
0039   console.timeEnd('[RootGeometryProcessor] Processing time');
0040   console.log(`[RootGeometryProcessor] Done processing ${detectors.length} detectors`);
0041 }