Skip to content

Commit

Permalink
refactor: Remove dependency on Boost.program_options from detectors (#…
Browse files Browse the repository at this point in the history
…1697)

This removes the dependencies of the Examples detectors from Boost.program_options. This is done by moving the class `IDetectorBase` to the `Run` folder and creating new classes called `GenericDetectorWithOptions` etc., that inherit from it.

The next step would be to make the binaries compilation optional, but I wanted to seperate these things from each other.
  • Loading branch information
benjaminhuth committed Nov 29, 2022
1 parent 2e7113d commit 4a2d047
Show file tree
Hide file tree
Showing 116 changed files with 817 additions and 624 deletions.
2 changes: 0 additions & 2 deletions Examples/Detectors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
add_subdirectory(Common)
add_subdirectory(ContextualDetector)
add_subdirectory_if(DD4hepDetector ACTS_BUILD_EXAMPLES_DD4HEP)
add_subdirectory(EmptyDetector)
add_subdirectory(GenericDetector)
add_subdirectory(MagneticField)
add_subdirectory(TGeoDetector)
Expand Down
11 changes: 0 additions & 11 deletions Examples/Detectors/Common/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion Examples/Detectors/ContextualDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target_link_libraries(
ActsExamplesDetectorContextual
PUBLIC
ActsCore ActsPluginIdentification
ActsExamplesFramework ActsExamplesDetectorsCommon ActsExamplesDetectorGeneric)
ActsExamplesFramework ActsExamplesDetectorGeneric)

install(
TARGETS ActsExamplesDetectorContextual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@
#pragma once

#include "Acts/Definitions/Units.hpp"
#include "ActsExamples/Detector/IBaseDetector.hpp"
#include "ActsExamples/GenericDetector/GenericDetector.hpp"
#include "ActsExamples/Utilities/OptionsFwd.hpp"

#include <memory>
#include <vector>

namespace Acts {
class TrackingGeometry;
class IMaterialDecorator;
} // namespace Acts

namespace ActsExamples {
class IContextDecorator;
} // namespace ActsExamples

namespace ActsExamples::Contextual {
class InternallyAlignedDetectorElement;
class InternalAlignmentDecorator;

class AlignedDetector : public ActsExamples::IBaseDetector {
class AlignedDetector {
public:
// using DetectorElement =
// ActsExamples::Contextual::InternallyAlignedDetectorElement;
// using DetectorElementPtr = std::shared_ptr<DetectorElement>;
// using Decorator = ActsExamples::Contextual::InternalAlignmentDecorator;
// using DetectorStore = std::vector<std::vector<DetectorElementPtr>>;
using ContextDecorators =
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>;
using TrackingGeometryPtr = std::shared_ptr<const Acts::TrackingGeometry>;

struct Config : public GenericDetector::Config {
/// Seed for the decorator random numbers.
Expand Down Expand Up @@ -54,16 +59,9 @@ class AlignedDetector : public ActsExamples::IBaseDetector {
Mode mode = Mode::Internal;
};

void addOptions(
boost::program_options::options_description& opt) const override;

std::pair<ActsExamples::IBaseDetector::TrackingGeometryPtr, ContextDecorators>
finalize(const boost::program_options::variables_map& vm,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator) override;

std::pair<ActsExamples::IBaseDetector::TrackingGeometryPtr, ContextDecorators>
finalize(const Config& cfg,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator);
std::pair<TrackingGeometryPtr, ContextDecorators> finalize(
const Config& cfg,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator);

std::vector<std::vector<std::shared_ptr<Generic::GenericDetectorElement>>>&
detectorStore() {
Expand All @@ -76,4 +74,4 @@ class AlignedDetector : public ActsExamples::IBaseDetector {
m_detectorStore;
};

} // namespace ActsExamples::Contextual
} // namespace ActsExamples::Contextual
93 changes: 2 additions & 91 deletions Examples/Detectors/ContextualDetector/src/AlignedDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,103 +17,14 @@
#include "ActsExamples/ContextualDetector/InternallyAlignedDetectorElement.hpp"
#include "ActsExamples/Framework/IContextDecorator.hpp"
#include "ActsExamples/GenericDetector/BuildGenericDetector.hpp"
#include "ActsExamples/GenericDetector/GenericDetectorOptions.hpp"

#include <boost/program_options.hpp>

using namespace Acts::UnitLiterals;
namespace ActsExamples::Contextual {

void AlignedDetector::addOptions(
boost::program_options::options_description& opt) const {
// Add the generic geometry options
ActsExamples::Options::addGenericGeometryOptions(opt);
// specify the rotation setp
opt.add_options()(
"align-seed",
boost::program_options::value<size_t>()->default_value(1324354657),
"Seed for the decorator random numbers.")(
"align-iovsize",
boost::program_options::value<size_t>()->default_value(100),
"Size of a valid IOV.")(
"align-flushsize",
boost::program_options::value<size_t>()->default_value(200),
"Span until garbage collection is active.")(
"align-no-gc", boost::program_options::bool_switch())(
"align-sigma-iplane",
boost::program_options::value<double>()->default_value(100.),
"Sigma of the in-plane misalignment in [um]")(
"align-sigma-oplane",
boost::program_options::value<double>()->default_value(50.),
"Sigma of the out-of-plane misalignment in [um]")(
"align-sigma-irot",
boost::program_options::value<double>()->default_value(20.),
"Sigma of the in-plane rotation misalignment in [mrad]")(
"align-sigma-orot",
boost::program_options::value<double>()->default_value(0.),
"Sigma of the out-of-plane rotation misalignment in [mrad]")(
"align-loglevel",
boost::program_options::value<size_t>()->default_value(3),
"Output log level of the alignment decorator.")(
"align-firstnominal",
boost::program_options::value<bool>()->default_value(false),
"Keep the first iov batch nominal.")(
"align-mode",
boost::program_options::value<std::string>()->default_value("internal"));
}

auto AlignedDetector::finalize(
const boost::program_options::variables_map& vm,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator)
-> std::pair<TrackingGeometryPtr, ContextDecorators> {
// --------------------------------------------------------------------------------

Config cfg;

cfg.buildLevel = vm["geo-generic-buildlevel"].template as<size_t>();
// set geometry building logging level
cfg.surfaceLogLevel =
Acts::Logging::Level(vm["geo-surface-loglevel"].template as<size_t>());
cfg.layerLogLevel =
Acts::Logging::Level(vm["geo-layer-loglevel"].template as<size_t>());
cfg.volumeLogLevel =
Acts::Logging::Level(vm["geo-volume-loglevel"].template as<size_t>());

cfg.buildProto = (vm["mat-input-type"].template as<std::string>() == "proto");

cfg.decoratorLogLevel =
Acts::Logging::Level(vm["align-loglevel"].template as<size_t>());

cfg.seed = vm["align-seed"].template as<size_t>();
cfg.iovSize = vm["align-iovsize"].template as<size_t>();
cfg.flushSize = vm["align-flushsize"].template as<size_t>();
cfg.doGarbageCollection = !vm["align-no-gc"].as<bool>();

// The misalingments
cfg.sigmaInPlane = vm["align-sigma-iplane"].template as<double>() * 1_um;
cfg.sigmaOutPlane = vm["align-sigma-oplane"].template as<double>() * 1_um;
cfg.sigmaInRot = vm["align-sigma-irot"].template as<double>() * 0.001;
cfg.sigmaOutRot = vm["align-sigma-orot"].template as<double>() * 0.001;
cfg.firstIovNominal = vm["align-firstnominal"].template as<bool>();

auto mode = vm["align-mode"].as<std::string>();
if (mode == "external") {
cfg.mode = Config::Mode::External;
} else if (mode == "internal") {
cfg.mode = Config::Mode::Internal;
} else {
throw std::invalid_argument{
"--align-mode must be 'external' or 'internal'"};
}

return finalize(cfg, mdecorator);
}

auto AlignedDetector::finalize(
const Config& cfg,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator)
-> std::pair<ActsExamples::IBaseDetector::TrackingGeometryPtr,
ContextDecorators> {
-> std::pair<TrackingGeometryPtr, ContextDecorators> {
ContextDecorators aContextDecorators;

// Let's create a reandom number service
Expand Down Expand Up @@ -198,4 +109,4 @@ auto AlignedDetector::finalize(
std::move(aTrackingGeometry), std::move(aContextDecorators));
}

} // namespace ActsExamples::Contextual
} // namespace ActsExamples::Contextual
2 changes: 1 addition & 1 deletion Examples/Detectors/DD4hepDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target_link_libraries(
ActsExamplesDetectorDD4hep
PUBLIC
ActsCore ActsPluginDD4hep
ActsExamplesFramework ActsExamplesDetectorsCommon
ActsExamplesFramework
ROOT::Geom ROOT::GenVector)

if(${DD4hep_VERSION} VERSION_LESS 1.11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@
#pragma once

#include "ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp"
#include "ActsExamples/Detector/IBaseDetector.hpp"
#include "ActsExamples/Utilities/OptionsFwd.hpp"

#include <memory>
#include <vector>

namespace Acts {
class TrackingGeometry;
class IMaterialDecorator;
} // namespace Acts

namespace ActsExamples {
class IContextDecorator;
} // namespace ActsExamples

namespace ActsExamples {
namespace DD4hep {

struct DD4hepDetector : public IBaseDetector {
struct DD4hepDetector {
using ContextDecorators =
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>;
using TrackingGeometryPtr = std::shared_ptr<const Acts::TrackingGeometry>;

std::shared_ptr<DD4hepGeometryService> geometryService;
dd4hep::Detector* lcdd = nullptr;

void addOptions(
boost::program_options::options_description& opt) const override;

std::pair<IBaseDetector::TrackingGeometryPtr, ContextDecorators> finalize(
const boost::program_options::variables_map& vm,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator) override;

std::pair<IBaseDetector::TrackingGeometryPtr, ContextDecorators> finalize(
std::pair<TrackingGeometryPtr, ContextDecorators> finalize(
DD4hepGeometryService::Config config,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator);
};
Expand Down
16 changes: 0 additions & 16 deletions Examples/Detectors/DD4hepDetector/src/DD4hepDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "ActsExamples/DD4hepDetector/DD4hepDetectorOptions.hpp"
#include "ActsExamples/DD4hepDetector/DD4hepGeometryService.hpp"
#include "ActsExamples/Framework/IContextDecorator.hpp"

Expand All @@ -19,21 +18,6 @@
namespace ActsExamples {
namespace DD4hep {

void DD4hepDetector::addOptions(
boost::program_options::options_description& opt) const {
ActsExamples::Options::addDD4hepOptions(opt);
}

auto DD4hepDetector::finalize(
const boost::program_options::variables_map& vm,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator)
-> std::pair<TrackingGeometryPtr, ContextDecorators> {
// read the detector config & dd4hep detector
auto dd4HepDetectorConfig =
ActsExamples::Options::readDD4hepConfig<po::variables_map>(vm);
return finalize(dd4HepDetectorConfig, mdecorator);
}

auto DD4hepDetector::finalize(
ActsExamples::DD4hep::DD4hepGeometryService::Config config,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator)
Expand Down
13 changes: 0 additions & 13 deletions Examples/Detectors/EmptyDetector/CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion Examples/Detectors/GenericDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ target_link_libraries(
PUBLIC ActsCore ActsPluginIdentification)
target_link_libraries(
ActsExamplesDetectorGeneric
PUBLIC ActsExamplesFramework ActsExamplesDetectorsCommon)
PUBLIC ActsExamplesFramework)

install(
TARGETS ActsExamplesDetectorGeneric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@
#pragma once

#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/Detector/IBaseDetector.hpp"
#include "ActsExamples/Utilities/OptionsFwd.hpp"

#include <memory>
#include <vector>

namespace Acts {
class TrackingGeometry;
class IMaterialDecorator;
} // namespace Acts

namespace ActsExamples {
class IContextDecorator;
} // namespace ActsExamples

namespace ActsExamples {
namespace Generic {
class GenericDetectorElement;
}
} // namespace ActsExamples

struct GenericDetector : public ActsExamples::IBaseDetector {
struct GenericDetector {
using DetectorElement = ActsExamples::Generic::GenericDetectorElement;
using DetectorElementPtr = std::shared_ptr<DetectorElement>;
using DetectorStore = std::vector<std::vector<DetectorElementPtr>>;

using ContextDecorators =
std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>;
using TrackingGeometryPtr = std::shared_ptr<const Acts::TrackingGeometry>;

struct Config {
size_t buildLevel{3};
Acts::Logging::Level surfaceLogLevel{Acts::Logging::INFO};
Expand All @@ -37,14 +48,7 @@ struct GenericDetector : public ActsExamples::IBaseDetector {
/// The Store of the detector elements (lifetime: job)
DetectorStore detectorStore;

void addOptions(
boost::program_options::options_description& opt) const override;

std::pair<ActsExamples::IBaseDetector::TrackingGeometryPtr, ContextDecorators>
finalize(const boost::program_options::variables_map& vm,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator) override;

std::pair<ActsExamples::IBaseDetector::TrackingGeometryPtr, ContextDecorators>
finalize(const Config& cfg,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator);
std::pair<TrackingGeometryPtr, ContextDecorators> finalize(
const Config& cfg,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator);
};

0 comments on commit 4a2d047

Please sign in to comment.