diff --git a/Algorithms/CMakeLists.txt b/Algorithms/CMakeLists.txt index a9131529eda70dbc4309492fd0aa1d8e03fbaa69..cb73a2e35c638c02777d1e621d5d018aaa45935b 100644 --- a/Algorithms/CMakeLists.txt +++ b/Algorithms/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(Digitization) add_subdirectory(Fatras) add_subdirectory(Generators) -#add_subdirectory(MaterialMapping) +add_subdirectory(MaterialMapping) add_subdirectory(Propagation) diff --git a/Algorithms/MaterialMapping/CMakeLists.txt b/Algorithms/MaterialMapping/CMakeLists.txt index 081d29199caaf9ca6f4b8d7ea3b06614025353f5..63f151b27fbac81ca97d2b67070a74bac52f6cdc 100644 --- a/Algorithms/MaterialMapping/CMakeLists.txt +++ b/Algorithms/MaterialMapping/CMakeLists.txt @@ -1,8 +1,8 @@ file(GLOB_RECURSE src_files "src/MaterialMapping.cpp") -#if (USE_GEANT4) -# SET(src_files "src/GeantinoRecording.cpp" ${src_files}) -# include(${Geant4_USE_FILE}) -#endif() +if (USE_GEANT4) + SET(src_files "src/GeantinoRecording.cpp" ${src_files}) + include(${Geant4_USE_FILE}) +endif() add_library(ACTFWMaterialMapping SHARED ${src_files}) target_include_directories(ACTFWMaterialMapping PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/> $<INSTALL_INTERFACE:include>) diff --git a/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/GeantinoRecording.hpp b/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/GeantinoRecording.hpp index 63e03d6258107cfba3fbf4993acbbaf35fb454fc..64b433c0bc07c2e1eb23d3856c8cdf530f7caddb 100644 --- a/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/GeantinoRecording.hpp +++ b/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/GeantinoRecording.hpp @@ -12,7 +12,6 @@ #include "ACTFW/Framework/BareAlgorithm.hpp" #include "ACTFW/Framework/ProcessCode.hpp" #include "ACTFW/GeometryInterfaces/IGeant4Service.hpp" -#include "ACTFW/Writers/IWriterT.hpp" #include "Acts/Extrapolator/MaterialInteractor.hpp" #include "Acts/Utilities/Definitions.hpp" #include "Acts/Utilities/Logger.hpp" diff --git a/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/IMaterialWriter.hpp b/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/IMaterialWriter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..483a69b5791372a8846b232e3d70b79d8afab8b2 --- /dev/null +++ b/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/IMaterialWriter.hpp @@ -0,0 +1,74 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2019 Acts project team +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#pragma once + +#include <map> +#include "Acts/Utilities/GeometryID.hpp" + +namespace Acts { + +class ISurfaceMaterial; +class IVolumeMaterial; + +using SurfaceMaterialMap + = std::map<GeometryID, std::shared_ptr<const ISurfaceMaterial>>; + +using VolumeMaterialMap + = std::map<GeometryID, std::shared_ptr<const IVolumeMaterial>>; + +using DetectorMaterialMaps = std::pair<SurfaceMaterialMap, VolumeMaterialMap>; +}; + +namespace FW { + +/// @class IMaterialWriter +/// +/// Interface definition for material writing +class IMaterialWriter +{ +public: + /// Virtual Destructor + virtual ~IMaterialWriter() = default; + + /// The single wirter class + /// + /// @param detMaterial the detector material maps + virtual void + writeMaterial(const Acts::DetectorMaterialMaps& detMaterial) + = 0; +}; + +/// @class MaterialWriterT +/// +/// @tparam writer_t is the actual implementation +template <typename writer_t> +class MaterialWriterT : virtual public IMaterialWriter +{ +public: + /// Constructor + /// + /// @tparam writer_t the templated writer implementation + /// + /// @param impl the actaul implementation of the writer + MaterialWriterT(writer_t impl) : m_impl(std::move(impl)) {} + + /// The single wirter class + /// + /// @param detMaterial the detector material maps + void + writeMaterial(const Acts::DetectorMaterialMaps& detMaterial) + { + m_impl.write(detMaterial); + } + +private: + /// The writer implementation + writer_t m_impl; +}; +} diff --git a/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/MaterialMapping.hpp b/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/MaterialMapping.hpp index 0af807ed4312d65e63f79f8036633677e9711e8b..c91addb8fd865d2accd5e24375379822b82a8b1a 100644 --- a/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/MaterialMapping.hpp +++ b/Algorithms/MaterialMapping/include/ACTFW/MaterialMapping/MaterialMapping.hpp @@ -15,15 +15,17 @@ #include "ACTFW/Framework/BareAlgorithm.hpp" #include "ACTFW/Framework/ProcessCode.hpp" #include "ACTFW/Framework/WhiteBoard.hpp" -#include "ACTFW/Writers/IWriterT.hpp" -#include "Acts/Material/ISurfaceMaterial.hpp" +#include "ACTFW/MaterialMapping/IMaterialWriter.hpp" #include "Acts/Plugins/MaterialMapping/SurfaceMaterialMapper.hpp" #include "Acts/Utilities/GeometryContext.hpp" #include "Acts/Utilities/Logger.hpp" #include "Acts/Utilities/MagneticFieldContext.hpp" namespace Acts { + class TrackingGeometry; +class ISurfaceMaterial; +class IVolumeMaterial; using SurfaceMaterialMap = std::map<GeometryID, std::shared_ptr<const ISurfaceMaterial>>; @@ -73,14 +75,14 @@ public: std::shared_ptr<Acts::SurfaceMaterialMapper> materialMapper = nullptr; /// The writer of the material - std::vector<std::shared_ptr<FW::IWriterT<Acts::DetectorMaterialMaps>>> - materialWriters; + std::vector<std::shared_ptr<IMaterialWriter>> materialWriters; /// The TrackingGeometry to be mapped on std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry = nullptr; // Geometry context for the state creation std::reference_wrapper<const Acts::GeometryContext> geoContext; + // MagneticField context for the state creation std::reference_wrapper<const Acts::MagneticFieldContext> magFieldContext; }; diff --git a/Algorithms/MaterialMapping/src/GeantinoRecording.cpp b/Algorithms/MaterialMapping/src/GeantinoRecording.cpp index 1872b2e6f69c0dcaded1a7c47e5d073cc0d3a29f..e46731f9a853bf377ad595156262784a8ceff1bb 100644 --- a/Algorithms/MaterialMapping/src/GeantinoRecording.cpp +++ b/Algorithms/MaterialMapping/src/GeantinoRecording.cpp @@ -65,11 +65,8 @@ FW::GeantinoRecording::execute(const FW::AlgorithmContext& context) const << " MaterialTracks. Writing them now onto file..."); // Write the recorded material to the event store - if (context.eventStore.add(m_cfg.geantMaterialCollection, - std::move(recordedMaterial)) - == FW::ProcessCode::ABORT) { - return FW::ProcessCode::ABORT; - } + context.eventStore.add(m_cfg.geantMaterialCollection, + std::move(recordedMaterial)); return FW::ProcessCode::SUCCESS; } diff --git a/Algorithms/MaterialMapping/src/MaterialMapping.cpp b/Algorithms/MaterialMapping/src/MaterialMapping.cpp index c2c1770a555546da5abdff88200795b08643617c..bee81566d8f2d4398ce71f0110ae55f097194768 100644 --- a/Algorithms/MaterialMapping/src/MaterialMapping.cpp +++ b/Algorithms/MaterialMapping/src/MaterialMapping.cpp @@ -53,8 +53,9 @@ FW::MaterialMapping::~MaterialMapping() detectorMaterial.first.insert({key, std::move(value)}); } + // Loop over the available writers and write the maps for (auto& imw : m_cfg.materialWriters) { - imw->write(writeContext, detectorMaterial); + imw->writeMaterial(detectorMaterial); } } @@ -62,14 +63,10 @@ FW::ProcessCode FW::MaterialMapping::execute(const FW::AlgorithmContext& context) const { - const std::vector<Acts::RecordedMaterialTrack>* mtrackCollection = nullptr; - // Write to the collection to the EventStore - if (context.eventStore.get(m_cfg.collection, mtrackCollection) - == FW::ProcessCode::ABORT) { - ACTS_ERROR("Could not read the material steps from EventStore!"); - return FW::ProcessCode::ABORT; - } + const auto& mtrackCollection + = context.eventStore.get<const std::vector<Acts::RecordedMaterialTrack>*>( + m_cfg.collection); // To make it work with the framework needs a lock guard auto mappingState