Skip to content

Commit

Permalink
Merge pull request #9 from HSF/sponce_regexp
Browse files Browse the repository at this point in the history
Allowed to use regular expressions in paths describing what to keep/drop
  • Loading branch information
sponce authored Jul 12, 2022
2 parents fff2bd8 + 7e81270 commit 12ab259
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ This is loading the various external libraries. Copy as is unless you want to us
```
This is the core of the conversion, where you define what to convert and how.

The first entry `hide_children` defines a list of path prefixes matching the subparts to be ignored.
Any entry in the geometry starting with one of these prefix will be dropped as well as all its children
The first entry `hide_children` defines a list of paths matching the subparts to be ignored.
Paths can be string or regular expressions. Any entry in the geometry starting with one of the strings or matching of
of the regular expression will be dropped as well as all its children

Here is an example of a potential hide_chidren declaration :
Here is an example of a potential hide_chidren declaration (2 strings and 1 regular expression) :
```javascript
var hide_children = [
"_dd_Geometry_BeforeMagnetRegion_VP_Supports_lvDeliveryPipe",
"_dd_Geometry_BeforeMagnetRegion_Rich1_lvRich1PhDetSupFrame"
"_dd_Geometry_BeforeMagnetRegion_Rich1_lvRich1PhDetSupFrame",
/_dd_Geometry_BeforeMagnetRegion_.*Test.*/
];
```

Expand All @@ -54,21 +56,22 @@ matching one item in the phoenix "Detector" menu :
* the key is the menu item name, including its hierarchy, with ' > ' as a separator.
So "a > b > c" will be entry c in submenu b of menu a
* the value is an array of 2 items :
* a list of prefixes of paths to consider. These paths and all their children (but the ones is `hide_children`
will be part of the current entry
* a list of paths to consider, given as a set of strings and regular expressions.
Paths starting with one of the strings or matching one of the regular expresions
will be part of the current entry as well as all their children (but the ones is `hide_children` obviously)
* a boolean or a float between 0 and 1 defining the initial visibility of the entry in phoenix
* false means not visible
* true means visible
* float means visible with that opacity
Here is an example of a potential subpart declaration, with all 3 items within a `VP` submenu :
```javascript
var subparts = {
"VP > Modules" : [[/_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVP(Left|Right)_pvModule[1234567890]*WithSupport_pvModule/,
/_dd_Geometry_BeforeMagnetRegion_VP.*Nikhef.*/], true],
"VP > Support" : [[/_dd_Geometry_BeforeMagnetRegion_VP.*Foot.*/,
/_dd_Geometry_BeforeMagnetRegion_VP.*Clamp.*/], true],
"VP > RFFoil" : [["_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPLeft_pvLeftRFFoil",
"_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPRight_pvRightRFFoil"], false], // not visible
"VP > Modules" : [["_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPLeft_pvModule",
"_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPRight_pvModule"], true], // visible
"VP > Structure" : [["_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPLeft_pvLeftDetSup",
"_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPRight_pvRightDetSup"], .3] // opacity 0.3
"_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPRight_pvRightRFFoil"], false],
};
```

Expand Down
12 changes: 7 additions & 5 deletions export_LHCb.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

var hide_children = [

// Drop VP delivery pipes
"_dd_Geometry_BeforeMagnetRegion_VP_Supports_lvDeliveryPipe",

// Drop Rich1 DetSupFrame and QuadrantModule
"_dd_Geometry_BeforeMagnetRegion_Rich1_lvRich1PhDetSupFrame",
"_dd_Geometry_BeforeMagnetRegion_Rich1_lvRich1Mirror1QuadrantModule",
Expand Down Expand Up @@ -68,10 +65,15 @@
"_dd_Structure_LHCb_AfterMagnetRegion_Pipe",
"_dd_Structure_LHCb_DownstreamRegion_Pipe"], true],
// VP
"VP > Modules" : [[/_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVP(Left|Right)_pvModule[1234567890]*WithSupport_pvModule/], true],
"VP > Support" : [[/_dd_Geometry_BeforeMagnetRegion_VP.*Foot.*/,
/_dd_Geometry_BeforeMagnetRegion_VP.*Nikhef.*/,
/_dd_Geometry_BeforeMagnetRegion_VP.*Clamp.*/], true],
"VP > RFFoil" : [["_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPLeft_pvLeftRFFoil",
"_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPRight_pvRightRFFoil"], false],
"VP > Modules" : [["_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPLeft_pvModule",
"_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPRight_pvModule"], true],
"VP > DeliveryPipes" : [[/_dd_Geometry_BeforeMagnetRegion_VP.*DeliveryPipe.*/,
/_dd_Geometry_BeforeMagnetRegion_VP.*Braze.*/,
/_dd_Geometry_BeforeMagnetRegion_VP.*CoolingConnector.*/], false],
"VP > Structure" : [["_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPLeft_pvLeftDetSup",
"_dd_Geometry_BeforeMagnetRegion_VP_lvVP_pvVPRight_pvRightDetSup"], .3],
// UT
Expand Down
16 changes: 11 additions & 5 deletions phoenixExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
*/

/// checks whether a name matches one of the given paths
function startsWith(name, paths) {
function matches(name, paths) {
for (const path of paths) {
if (name.startsWith(path)) {
return true;
if (typeof(path) == "string") {
if (name.startsWith(path)) {
return true;
}
} else { // needs to be a regexp
if (name.match(path)) {
return true;
}
}
}
return false;
Expand All @@ -39,7 +45,7 @@ function filterArrayInPlace(a, condition, thisArg) {
function cleanup_geometry(node, hidden_paths, max_level=999, level = 0) {
if (node.fVolume.fNodes) {
// drop hidden nodes, and everything after level 4
filterArrayInPlace(node.fVolume.fNodes.arr, n=>level<max_level&&!startsWith(n.fName, hidden_paths));
filterArrayInPlace(node.fVolume.fNodes.arr, n=>level<max_level&&!matches(n.fName, hidden_paths));
// recurse to children
for (const snode of node.fVolume.fNodes.arr) {
cleanup_geometry(snode, hidden_paths, max_level, level + 1);
Expand Down Expand Up @@ -190,7 +196,7 @@ function keep_only_subpart(volume, paths) {
var anyfound = false;
for (var j = 0; j < volume.fNodes.arr.length; j++) {
var snode = volume.fNodes.arr[j];
if (startsWith(snode.fName, paths)) {
if (matches(snode.fName, paths)) {
// need to be resursive in case something deeper was hidden in previous round
set_visible_recursively(snode);
anyfound=true;
Expand Down

0 comments on commit 12ab259

Please sign in to comment.