Skip to content

Commit

Permalink
blueprint: Rename RootBlueprintNode to Blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger committed Nov 26, 2024
1 parent 40a9c71 commit ff823a4
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 112 deletions.
42 changes: 34 additions & 8 deletions Core/include/Acts/Geometry/Blueprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,46 @@

#pragma once

#include <memory>
#include "Acts/Geometry/BlueprintNode.hpp"
#include "Acts/Geometry/PortalShell.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"

namespace Acts {

class TrackingVolume;
class GeometryContext;

class Blueprint {
std::unique_ptr<TrackingVolume> build();
class Blueprint : public BlueprintNode {
public:
struct Config {
ExtentEnvelope envelope = ExtentEnvelope::Zero();
GeometryIdentifierHook geometryIdentifierHook = {};
};

// void setStaticVolume(std::unique_ptr<TrackingVolume> volume);
Blueprint(const Config& cfg);

// void setCylinderContainer(
// const std::function<std::unique_ptr<BlueprintNode>(
// std::unique_ptr<CylinderContainerBlueprintNode> cylinder)>& factory);
const std::string& name() const override;

std::unique_ptr<TrackingGeometry> construct(
const Options& options, const GeometryContext& gctx,
const Logger& logger = Acts::getDummyLogger());

protected:
Volume& build(const Options& options, const GeometryContext& gctx,
const Logger& logger = Acts::getDummyLogger()) override;

PortalShellBase& connect(
const Options& options, const GeometryContext& gctx,
const Logger& logger = Acts::getDummyLogger()) override;

void finalize(const Options& options, const GeometryContext& gctx,
TrackingVolume& parent,
const Logger& logger = Acts::getDummyLogger()) override;

void addToGraphviz(std::ostream& os) const override;

private:
Config m_cfg;
};

} // namespace Acts
53 changes: 0 additions & 53 deletions Core/include/Acts/Geometry/RootBlueprintNode.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "Acts/Geometry/RootBlueprintNode.hpp"
#include "Acts/Geometry/Blueprint.hpp"

#include "Acts/Geometry/CuboidVolumeBounds.hpp"
#include "Acts/Geometry/CylinderVolumeBounds.hpp"
Expand All @@ -18,41 +18,41 @@

namespace Acts {

RootBlueprintNode::RootBlueprintNode(const Config &cfg) : m_cfg(cfg) {}
Blueprint::Blueprint(const Config &cfg) : m_cfg(cfg) {}

const std::string &RootBlueprintNode::name() const {
const std::string &Blueprint::name() const {
static const std::string root = "root";
return root;
}

Volume &RootBlueprintNode::build(const Options & /*options*/,
const GeometryContext & /*gctx*/,
const Logger & /*logger*/) {
Volume &Blueprint::build(const Options & /*options*/,
const GeometryContext & /*gctx*/,
const Logger & /*logger*/) {
throw std::logic_error("Root node cannot be built");
}

PortalShellBase &RootBlueprintNode::connect(const Options & /*options*/,
const GeometryContext & /*gctx*/,
const Logger & /*logger*/) {
PortalShellBase &Blueprint::connect(const Options & /*options*/,
const GeometryContext & /*gctx*/,
const Logger & /*logger*/) {
throw std::logic_error("Root node cannot be connected");
}

void RootBlueprintNode::finalize(const Options & /*options*/,
const GeometryContext & /*gctx*/,
TrackingVolume & /*parent*/,
const Logger & /*logger*/) {
void Blueprint::finalize(const Options & /*options*/,
const GeometryContext & /*gctx*/,
TrackingVolume & /*parent*/,
const Logger & /*logger*/) {
throw std::logic_error("Root node cannot be finalized");
}

void RootBlueprintNode::addToGraphviz(std::ostream &os) const {
void Blueprint::addToGraphviz(std::ostream &os) const {
GraphViz::Node node{
.id = name(), .label = "World", .shape = GraphViz::Shape::House};

os << node;
BlueprintNode::addToGraphviz(os);
}

std::unique_ptr<TrackingGeometry> RootBlueprintNode::construct(
std::unique_ptr<TrackingGeometry> Blueprint::construct(
const Options &options, const GeometryContext &gctx, const Logger &logger) {
using enum BinningValue;

Expand Down
2 changes: 1 addition & 1 deletion Core/src/Geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ target_sources(
PortalError.cpp
PortalShell.cpp
BlueprintNode.cpp
RootBlueprintNode.cpp
Blueprint.cpp
CylinderContainerBlueprintNode.cpp
StaticBlueprintNode.cpp
LayerBlueprintNode.cpp
Expand Down
25 changes: 12 additions & 13 deletions Examples/Python/src/Blueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "Acts/Geometry/Blueprint.hpp"

#include "Acts/Definitions/Units.hpp"
#include "Acts/Geometry/BlueprintNode.hpp"
#include "Acts/Geometry/CylinderContainerBlueprintNode.hpp"
#include "Acts/Geometry/CylinderVolumeStack.hpp"
#include "Acts/Geometry/LayerBlueprintNode.hpp"
#include "Acts/Geometry/MaterialDesignatorBlueprintNode.hpp"
#include "Acts/Geometry/RootBlueprintNode.hpp"
#include "Acts/Geometry/StaticBlueprintNode.hpp"
#include "Acts/Navigation/NavigationStream.hpp"
#include "Acts/Plugins/Python/Utilities.hpp"
Expand Down Expand Up @@ -63,7 +64,7 @@ void pseudoNavigation(const TrackingGeometry& trackingGeometry,
Vector3 position = Vector3::Zero();

double theta = thetaDist(rnd);
double phi = 2 * M_PI * dist(rnd);
double phi = 2 * std::numbers::pi * dist(rnd);

Vector3 direction;
direction[0] = std::sin(theta) * std::cos(phi);
Expand Down Expand Up @@ -283,28 +284,26 @@ void addBlueprint(Context& ctx) {
});

{
auto n =
py::class_<RootBlueprintNode, BlueprintNode,
std::shared_ptr<RootBlueprintNode>>(m, "RootBlueprintNode");
auto n = py::class_<Blueprint, BlueprintNode, std::shared_ptr<Blueprint>>(
m, "Blueprint");

n.def(py::init<const RootBlueprintNode::Config&>())
.def_property_readonly("name", &RootBlueprintNode::name)
n.def(py::init<const Blueprint::Config&>())
.def_property_readonly("name", &Blueprint::name)
// Return value needs to be shared pointer because python otherwise
// can't manage the lifetime
.def(
"construct",
[](RootBlueprintNode& self,
const RootBlueprintNode::Options& options,
[](Blueprint& self, const Blueprint::Options& options,
const GeometryContext& gctx,
Logging::Level level) -> std::shared_ptr<TrackingGeometry> {
return self.construct(
options, gctx, *getDefaultLogger("RootBlueprintNode", level));
return self.construct(options, gctx,
*getDefaultLogger("Blueprint", level));
},
py::arg("options"), py::arg("gctx"),
py::arg("level") = Logging::INFO);

auto c = py::class_<RootBlueprintNode::Config>(n, "Config").def(py::init());
ACTS_PYTHON_STRUCT_BEGIN(c, RootBlueprintNode::Config);
auto c = py::class_<Blueprint::Config>(n, "Config").def(py::init());
ACTS_PYTHON_STRUCT_BEGIN(c, Blueprint::Config);
ACTS_PYTHON_MEMBER(envelope);
ACTS_PYTHON_MEMBER(geometryIdentifierHook);
ACTS_PYTHON_STRUCT_END();
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def write(root: acts.BlueprintNode, stage: int):

base = acts.Transform3.Identity()

root = acts.RootBlueprintNode(envelope=acts.ExtentEnvelope(r=[10 * mm, 10 * mm]))
root = acts.Blueprint(envelope=acts.ExtentEnvelope(r=[10 * mm, 10 * mm]))

barrel = root.addCylinderContainer("Barrel", direction=bv.binR)

Expand Down
2 changes: 1 addition & 1 deletion Examples/Scripts/Python/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mm = acts.UnitConstants.mm
degree = acts.UnitConstants.degree

root = acts.RootBlueprintNode(envelope=acts.ExtentEnvelope(r=[10 * mm, 10 * mm]))
root = acts.Blueprint(envelope=acts.ExtentEnvelope(r=[10 * mm, 10 * mm]))


pixel = root.addCylinderContainer(direction=acts.BinningValue.binZ, name="Pixel")
Expand Down
40 changes: 20 additions & 20 deletions Tests/UnitTests/Core/Geometry/BlueprintNodeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/Units.hpp"
#include "Acts/Detector/ProtoBinning.hpp"
#include "Acts/Geometry/Blueprint.hpp"
#include "Acts/Geometry/CylinderContainerBlueprintNode.hpp"
#include "Acts/Geometry/CylinderVolumeBounds.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/LayerBlueprintNode.hpp"
#include "Acts/Geometry/MaterialDesignatorBlueprintNode.hpp"
#include "Acts/Geometry/RootBlueprintNode.hpp"
#include "Acts/Geometry/StaticBlueprintNode.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Navigation/INavigationPolicy.hpp"
Expand Down Expand Up @@ -48,7 +48,7 @@ inline std::vector<std::shared_ptr<Surface>> makeFanLayer(
double r = 300_mm, std::size_t nSensors = 8, double thickness = 0) {
auto recBounds = std::make_shared<RectangleBounds>(40_mm, 60_mm);

double deltaPhi = 2 * M_PI / nSensors;
double deltaPhi = 2 * std::numbers::pi / nSensors;
std::vector<std::shared_ptr<Surface>> surfaces;
for (std::size_t i = 0; i < nSensors; i++) {
// Create a fan of sensors
Expand Down Expand Up @@ -77,7 +77,7 @@ inline std::vector<std::shared_ptr<Surface>> makeBarrelLayer(
double thickness = 0, double hlPhi = 40_mm, double hlZ = 60_mm) {
auto recBounds = std::make_shared<RectangleBounds>(hlPhi, hlZ);

double deltaPhi = 2 * M_PI / nStaves;
double deltaPhi = 2 * std::numbers::pi / nStaves;
std::vector<std::shared_ptr<Surface>> surfaces;

for (std::size_t istave = 0; istave < nStaves; istave++) {
Expand Down Expand Up @@ -106,9 +106,9 @@ BOOST_AUTO_TEST_SUITE(Geometry);
BOOST_AUTO_TEST_SUITE(BlueprintNodeTest);

BOOST_AUTO_TEST_CASE(StaticBlueprintNodeConstruction) {
RootBlueprintNode::Config cfg;
Blueprint::Config cfg;
cfg.envelope[BinningValue::binZ] = {20_mm, 2_mm};
RootBlueprintNode root{cfg};
Blueprint root{cfg};

ActsScalar hlZ = 30_mm;
auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, hlZ);
Expand Down Expand Up @@ -160,10 +160,10 @@ BOOST_AUTO_TEST_CASE(CylinderContainerNode) {
ActsScalar hlZ = 30_mm;
auto cylBounds = std::make_shared<CylinderVolumeBounds>(10_mm, 20_mm, hlZ);

RootBlueprintNode::Config cfg;
Blueprint::Config cfg;
cfg.envelope[BinningValue::binZ] = {20_mm, 20_mm};
cfg.envelope[BinningValue::binR] = {0_mm, 20_mm};
auto root = std::make_unique<RootBlueprintNode>(cfg);
auto root = std::make_unique<Blueprint>(cfg);

auto& cyl = root->addCylinderContainer("Container", BinningValue::binZ);

Expand Down Expand Up @@ -361,10 +361,10 @@ BOOST_AUTO_TEST_CASE(NodeApiTestContainers) {
return makeFanLayer(layerBase, detectorElements, r, nSensors, thickness);
};

RootBlueprintNode::Config cfg;
Blueprint::Config cfg;
cfg.envelope[BinningValue::binZ] = {20_mm, 20_mm};
cfg.envelope[BinningValue::binR] = {0_mm, 20_mm};
auto root = std::make_unique<RootBlueprintNode>(cfg);
auto root = std::make_unique<Blueprint>(cfg);

root->addMaterial("GlobalMaterial", [&](MaterialDesignatorBlueprintNode&
mat) {
Expand Down Expand Up @@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE(NodeApiTestContainers) {

for (std::size_t i = 0; i < 5000; i++) {
double theta = thetaDist(rnd);
double phi = 2 * M_PI * dist(rnd);
double phi = 2 * std::numbers::pi * dist(rnd);

Vector3 direction;
direction[0] = std::sin(theta) * std::cos(phi);
Expand All @@ -516,10 +516,10 @@ BOOST_AUTO_TEST_CASE(NodeApiTestConfined) {
// Transform3 base{AngleAxis3{30_degree, Vector3{1, 0, 0}}};
Transform3 base{Transform3::Identity()};

RootBlueprintNode::Config cfg;
Blueprint::Config cfg;
cfg.envelope[BinningValue::binZ] = {20_mm, 20_mm};
cfg.envelope[BinningValue::binR] = {0_mm, 20_mm};
auto root = std::make_unique<RootBlueprintNode>(cfg);
auto root = std::make_unique<Blueprint>(cfg);

root->addCylinderContainer("Detector", BinningValue::binR, [&](auto& det) {
det.addStaticVolume(
Expand Down Expand Up @@ -595,10 +595,10 @@ BOOST_AUTO_TEST_CASE(LayerNodeDisk) {

std::vector<std::shared_ptr<Surface>> surfaces = makeFan(2.5_mm);

RootBlueprintNode root{{.envelope = ExtentEnvelope{{
.z = {2_mm, 2_mm},
.r = {3_mm, 5_mm},
}}}};
Blueprint root{{.envelope = ExtentEnvelope{{
.z = {2_mm, 2_mm},
.r = {3_mm, 5_mm},
}}}};

root.addLayer("Layer0", [&](auto& layer) {
layer.setSurfaces(surfaces)
Expand Down Expand Up @@ -642,10 +642,10 @@ BOOST_AUTO_TEST_CASE(LayerNodeCylinder) {
std::vector<std::shared_ptr<Surface>> surfaces =
makeBarrelLayer(base, detectorElements, 300_mm, 24, 8, 2.5_mm);

RootBlueprintNode root{{.envelope = ExtentEnvelope{{
.z = {2_mm, 2_mm},
.r = {3_mm, 5_mm},
}}}};
Blueprint root{{.envelope = ExtentEnvelope{{
.z = {2_mm, 2_mm},
.r = {3_mm, 5_mm},
}}}};

root.addLayer("Layer0", [&](auto& layer) {
layer.setSurfaces(surfaces)
Expand Down

0 comments on commit ff823a4

Please sign in to comment.