Skip to content

Commit

Permalink
feat: easy surface debug print (#1327)
Browse files Browse the repository at this point in the history
During debugging the GSF propagation I noticed that it is rather verbose to print the full surface information (you need to create a `std::stringstream` object, invoke the `surface.toStream(...)` method and then print the stream...).

Therefore I implemented a more easy-to-use `operator<<` which can be used like this:

```c++
std::cout << std::tie(surface, geometryContext) << "\n";
```

This also simplifies some logging statements.
  • Loading branch information
benjaminhuth committed Jul 15, 2022
1 parent 2dbe81f commit 55b8ce6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
20 changes: 7 additions & 13 deletions Core/include/Acts/Propagator/Navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,19 +988,13 @@ class Navigator {
<< stepper.outputStepSize(state.stepping));
return true;
} else {
if (logger().doPrint(Logging::VERBOSE)) {
std::ostringstream os;
os << "Boundary ";
os << std::distance(state.navigation.navBoundaryIter,
state.navigation.navBoundaries.end());
os << " out of " << state.navigation.navBoundaries.size();
os << " not reachable anymore, switching to next.";
logger.log(Logging::VERBOSE, os.str());
os.str("");
os << "Targeted boundary surface was: \n";
boundarySurface->toStream(state.geoContext, os);
logger.log(Logging::VERBOSE, os.str());
}
ACTS_VERBOSE("Boundary "
<< std::distance(state.navigation.navBoundaryIter,
state.navigation.navBoundaries.end())
<< " out of " << state.navigation.navBoundaries.size()
<< " not reachable anymore, switching to next.");
ACTS_VERBOSE("Targeted boundary surface was: \n"
<< std::tie(*boundarySurface, state.geoContext));
}
// Increase the iterator to the next one
++state.navigation.navBoundaryIter;
Expand Down
11 changes: 11 additions & 0 deletions Core/include/Acts/Surfaces/Surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,15 @@ class Surface : public virtual GeometryObject,
const GeometryContext& gctx, const FreeVector& parameters) const;
};

/// Print surface information to the provided stream. Internally invokes the
/// `surface.toStream(...)`-method. This can be easily used e.g. like `std::cout
/// << std::tie(surface, geometryContext);`
inline std::ostream& operator<<(
std::ostream& os,
const std::tuple<const Surface&, const GeometryContext&>& tup) {
const auto [surface, gctx] = tup;
surface.toStream(gctx, os);
return os;
}

} // namespace Acts
9 changes: 3 additions & 6 deletions Core/src/Geometry/TrackingVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,9 @@ Acts::TrackingVolume::compatibleBoundaries(
for (auto& bsIter : bSurfaces) {
// Get the boundary surface pointer
const auto& bSurfaceRep = bsIter->surfaceRepresentation();
if (logger().doPrint(Logging::VERBOSE)) {
std::ostringstream os;
os << "Consider boundary surface " << &bSurfaceRep << " :\n";
bSurfaceRep.toStream(gctx, os);
logger().log(Logging::VERBOSE, os.str());
}
ACTS_VERBOSE("Consider boundary surface " << bSurfaceRep.geometryId()
<< " :\n"
<< std::tie(bSurfaceRep, gctx));

// Exclude the boundary where you are on
if (excludeObject != &bSurfaceRep) {
Expand Down

0 comments on commit 55b8ce6

Please sign in to comment.