SHiP Geometry Service
Framework-agnostic C++20 library wrapping the SHiP GeoModel geometry behind a stable interface.
Loading...
Searching...
No Matches
SHiPGeometryService.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 CERN for the benefit of the SHiP Collaboration
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4#pragma once
5
7
8#include <GeoModelKernel/GeoVPhysVol.h>
9#include <exception>
10#include <filesystem>
11#include <memory>
12#include <mutex>
13#include <string>
14
15class G4LogicalVolume;
16
17namespace ship {
18
27 public:
29 [[nodiscard]] static std::unique_ptr<SHiPGeometryService> fromSource();
30
32 [[nodiscard]] static std::unique_ptr<SHiPGeometryService> fromFile(
33 const std::filesystem::path& dbPath);
34
46 [[nodiscard]] static std::shared_ptr<SHiPGeometryService> sharedFromFile(
47 const std::filesystem::path& dbPath);
48
50 [[nodiscard]] static std::unique_ptr<SHiPGeometryService> fromWorld(PVConstLink world);
51
52 ~SHiPGeometryService() override = default;
53
54 // Non-copyable and non-movable (std::once_flag member; instances are
55 // only handed out via unique_ptr, so moves are not needed).
60
61 const GeoVPhysVol* geoModelWorld() const override;
62 G4LogicalVolume* geant4WorldLogical() override;
63 G4LogicalVolume* getLogicalVolume(const std::string& name) const override;
64
65 private:
66 SHiPGeometryService() = default;
67
68 PVConstLink m_world;
69 mutable std::once_flag m_g4ConversionDone;
70 G4LogicalVolume* m_g4WorldLV{nullptr};
71 std::exception_ptr m_conversionError;
72};
73
74} // namespace ship
Framework-agnostic interface to the SHiP detector geometry.
Definition IGeometryService.h:15
Concrete implementation of IGeometryService backed by GeoModel.
Definition SHiPGeometryService.h:26
SHiPGeometryService & operator=(const SHiPGeometryService &)=delete
const GeoVPhysVol * geoModelWorld() const override
GeoModel world physical volume (const — tree is immutable after build).
Definition SHiPGeometryService.cpp:126
static std::unique_ptr< SHiPGeometryService > fromWorld(PVConstLink world)
Wrap an already-built GeoModel world (e.g. a small test geometry).
Definition SHiPGeometryService.cpp:114
static std::unique_ptr< SHiPGeometryService > fromSource()
Build geometry from the C++ SHiPGeometryBuilder.
Definition SHiPGeometryService.cpp:49
SHiPGeometryService(const SHiPGeometryService &)=delete
G4LogicalVolume * getLogicalVolume(const std::string &name) const override
Look up a G4LogicalVolume by name within this service's converted tree (depth-first).
Definition SHiPGeometryService.cpp:188
G4LogicalVolume * geant4WorldLogical() override
G4LogicalVolume* for the world.
Definition SHiPGeometryService.cpp:130
static std::shared_ptr< SHiPGeometryService > sharedFromFile(const std::filesystem::path &dbPath)
Process-wide shared instance per geometry file, keyed by the canonical path.
Definition SHiPGeometryService.cpp:86
~SHiPGeometryService() override=default
SHiPGeometryService & operator=(SHiPGeometryService &&)=delete
SHiPGeometryService(SHiPGeometryService &&)=delete
static std::unique_ptr< SHiPGeometryService > fromFile(const std::filesystem::path &dbPath)
Load geometry from a previously written GeoModel SQLite database.
Definition SHiPGeometryService.cpp:62
Definition G4RayScanner.h:15