Skip to content

Commit

Permalink
feat(geometry): Allow operator<< on surfaces without detector elements
Browse files Browse the repository at this point in the history
We previously disallowed this, but this is only necessary if we have a
detector element. Arguably, specifically for printing it can sometimes
be inconvenient to have to pass around a geometry context just for this.
  • Loading branch information
paulgessinger committed Aug 1, 2024
1 parent d224d80 commit 262d259
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Core/include/Acts/Surfaces/Surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ class Surface : public virtual GeometryObject,
virtual ActsMatrix<2, 3> localCartesianToBoundLocalDerivative(
const GeometryContext& gctx, const Vector3& position) const = 0;

/// Outstream operator for surfaces without an associated detector element
/// @note This operator checks if an associated detector element is set
/// and will throws an exception if that's the case.
/// @param os The output stream
/// @param srf The surface to print
/// @return The output stream
friend std::ostream& operator<<(std::ostream& os, const Surface& srf);

protected:
/// Output Method for std::ostream, to be overloaded by child classes
///
Expand Down
13 changes: 13 additions & 0 deletions Core/src/Surfaces/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,16 @@ void Acts::Surface::assignSurfaceMaterial(
void Acts::Surface::associateLayer(const Acts::Layer& lay) {
m_associatedLayer = (&lay);
}

std::ostream& Acts::operator<<(std::ostream& os, const Acts::Surface& srf) {
if (srf.associatedDetectorElement() != nullptr) {
throw std::runtime_error(
"Cannot print Surface with associated DetectorElement without geometry "
"context");
}
// Using a default context is ONLY safe, if the surface does not have an
// associated detector element, which we ensure right above.
Acts::GeometryContext defaultContext;
os << srf.toStream(defaultContext);
return os;
}

0 comments on commit 262d259

Please sign in to comment.