Skip to content

Commit

Permalink
fix: GeometryView3D default output directory doesn't work. (#954)
Browse files Browse the repository at this point in the history
In #917 I introduced an output directory to `GeometryView3D`. I set the default to "." as that usually means the current directory. Due to the way we currently look for file extensions, this didn't actually work. I didn't actually test the default, so that broke the output writing.

This PR works around this by checking if the default value "." is given, and replaces this with the actual `$PWD`. This is not super robust, and ideally we should revise all of this using `boost::filesystem`, which I'll try to do in a future PR.

Aside from this, this PR also make the geometry examples correctly pipe through the `--output-dir` option to the geometry view output.
  • Loading branch information
paulgessinger committed Aug 24, 2021
1 parent 3d67ee8 commit 4452021
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Core/src/Visualization/GeometryView3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "Acts/Surfaces/SurfaceArray.hpp"
#include "Acts/Utilities/UnitVectors.hpp"

#include <limits.h>
#include <unistd.h>

namespace {
std::string joinPaths(const std::string& a, const std::string& b) {
if (b.substr(0, 1) == "/" || a.empty()) {
Expand All @@ -34,6 +37,13 @@ std::string joinPaths(const std::string& a, const std::string& b) {

return a + "/" + b;
}

std::string getWorkingDirectory() {
char buffer[PATH_MAX];
return (getcwd(buffer, sizeof(buffer)) ? std::string(buffer)
: std::string(""));
}

} // namespace

void Acts::GeometryView3D::drawPolyhedron(IVisualization3D& helper,
Expand Down Expand Up @@ -66,7 +76,9 @@ void Acts::GeometryView3D::drawSurfaceArray(
IVisualization3D& helper, const SurfaceArray& surfaceArray,
const GeometryContext& gctx, const Transform3& transform,
const ViewConfig& sensitiveConfig, const ViewConfig& passiveConfig,
const ViewConfig& gridConfig, const std::string& outputDir) {
const ViewConfig& gridConfig, const std::string& _outputDir) {
std::string outputDir =
_outputDir == "." ? getWorkingDirectory() : _outputDir;
// Draw all the surfaces
Extent arrayExtent;
for (const auto& sf : surfaceArray.surfaces()) {
Expand Down Expand Up @@ -161,7 +173,10 @@ void Acts::GeometryView3D::drawVolume(IVisualization3D& helper,
void Acts::GeometryView3D::drawLayer(
IVisualization3D& helper, const Layer& layer, const GeometryContext& gctx,
const ViewConfig& layerConfig, const ViewConfig& sensitiveConfig,
const ViewConfig& gridConfig, const std::string& outputDir) {
const ViewConfig& gridConfig, const std::string& _outputDir) {
std::string outputDir =
_outputDir == "." ? getWorkingDirectory() : _outputDir;

if (layerConfig.visible) {
auto layerVolume = layer.representingVolume();
if (layerVolume != nullptr) {
Expand Down Expand Up @@ -192,7 +207,9 @@ void Acts::GeometryView3D::drawTrackingVolume(
const GeometryContext& gctx, const ViewConfig& containerView,
const ViewConfig& volumeView, const ViewConfig& layerView,
const ViewConfig& sensitiveView, const ViewConfig& gridView, bool writeIt,
const std::string& tag, const std::string& outputDir) {
const std::string& tag, const std::string& _outputDir) {
std::string outputDir =
_outputDir == "." ? getWorkingDirectory() : _outputDir;
if (tVolume.confinedVolumes() != nullptr) {
const auto& subVolumes = tVolume.confinedVolumes()->arrayObjects();
for (const auto& tv : subVolumes) {
Expand Down

0 comments on commit 4452021

Please sign in to comment.