Skip to content

Commit 6e3db3a

Browse files
asalzburgerpaulgessingerkodiakhq[bot]
authored andcommitted
feat: move ROOT surface material map I/O to plugins (acts-project#4400)
This PR moves the I/O for material map reading/writing into `Plugins/Root` and removes the duplicated code from `RootMaterialWriter` and `RootMaterialDecorator`. It also harmonizes the usage/definition of `SurfaceMaterialMaps`. `VolumeMaterialMaps`, and `DetectorMaterialMaps` consistently by declaring them once. It is backward compatible, and introduces a new, common ROOT I/O material backend that can be shared between all material classes (homongeneous, binned, grid, indexed). This PR also allows UnitTests to be added for Material writing, the first ones are done with it, and it removes roughly 100 SonarCloud issues, mainly related to how we call and use ROOT. This will be followed by a PRs doing the same for Volume material and updated Grid based surface material. The reading gis kept backward-compatible. --- END COMMIT MESSAGE --- Any further description goes here, @-mentions are ok here! - Use a *conventional commits* prefix: [quick summary](https://www.conventionalcommits.org/en/v1.0.0/#summary) - We mostly use `feat`, `fix`, `refactor`, `docs`, `chore` and `build` types. - A milestone will be assigned by one of the maintainers --------- Co-authored-by: Paul Gessinger <hello@paulgessinger.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent d74bed0 commit 6e3db3a

31 files changed

+1712
-1059
lines changed

Core/include/Acts/Material/MaterialMapper.hpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Acts/MagneticField/MagneticFieldContext.hpp"
1313
#include "Acts/Material/MaterialInteraction.hpp"
1414
#include "Acts/Material/MaterialInteractionAssignment.hpp"
15+
#include "Acts/Material/TrackingGeometryMaterial.hpp"
1516
#include "Acts/Material/interface/IAssignmentFinder.hpp"
1617
#include "Acts/Material/interface/ISurfaceMaterialAccumulater.hpp"
1718
#include "Acts/Utilities/Logger.hpp"
@@ -24,14 +25,6 @@ namespace Acts {
2425
/// @brief material mapping procedure
2526
class MaterialMapper {
2627
public:
27-
/// @brief The material maps
28-
using SurfaceMaterialMaps =
29-
std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
30-
using VolumeMaterialMaps =
31-
std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>;
32-
using DetectorMaterialMaps =
33-
std::pair<SurfaceMaterialMaps, VolumeMaterialMaps>;
34-
3528
/// @brief nested configuration struct
3629
struct Config {
3730
// The assignment finder
@@ -83,7 +76,7 @@ class MaterialMapper {
8376
const Options& options = Options{}) const;
8477

8578
/// Finalize the maps
86-
DetectorMaterialMaps finalizeMaps(const State& state) const;
79+
TrackingGeometryMaterial finalizeMaps(const State& state) const;
8780

8881
private:
8982
/// Access method to the logger
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of the ACTS project.
2+
//
3+
// Copyright (C) 2016 CERN for the benefit of the ACTS project
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this
7+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
#pragma once
10+
11+
#include "Acts/Geometry/GeometryIdentifier.hpp"
12+
#include "Acts/Material/ISurfaceMaterial.hpp"
13+
#include "Acts/Material/IVolumeMaterial.hpp"
14+
15+
#include <map>
16+
#include <memory>
17+
#include <utility>
18+
19+
namespace Acts {
20+
21+
using SurfaceMaterialMaps =
22+
std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
23+
using VolumeMaterialMaps =
24+
std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>;
25+
using TrackingGeometryMaterial =
26+
std::pair<SurfaceMaterialMaps, VolumeMaterialMaps>;
27+
28+
} // namespace Acts

Core/src/Material/MaterialMapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ Acts::MaterialMapper::mapMaterial(State& state, const GeometryContext& gctx,
7979
return {mappedMaterial, unmappedMaterial};
8080
}
8181

82-
Acts::MaterialMapper::DetectorMaterialMaps Acts::MaterialMapper::finalizeMaps(
82+
Acts::TrackingGeometryMaterial Acts::MaterialMapper::finalizeMaps(
8383
const State& state) const {
8484
// The final maps
85-
DetectorMaterialMaps detectorMaterialMaps;
85+
TrackingGeometryMaterial detectorMaterialMaps;
8686
// The surface maps
8787
detectorMaterialMaps.first =
8888
m_cfg.surfaceMaterialAccumulater->finalizeMaterial(

Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/IMaterialWriter.hpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,7 @@
99
#pragma once
1010

1111
#include "Acts/Geometry/GeometryIdentifier.hpp"
12-
13-
#include <map>
14-
#include <memory>
15-
16-
namespace Acts {
17-
18-
class ISurfaceMaterial;
19-
class IVolumeMaterial;
20-
21-
using SurfaceMaterialMap =
22-
std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
23-
24-
using VolumeMaterialMap =
25-
std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>;
26-
27-
using DetectorMaterialMaps = std::pair<SurfaceMaterialMap, VolumeMaterialMap>;
28-
} // namespace Acts
12+
#include "Acts/Material/TrackingGeometryMaterial.hpp"
2913

3014
namespace ActsExamples {
3115

@@ -40,7 +24,8 @@ class IMaterialWriter {
4024
/// The single writer class
4125
///
4226
/// @param detMaterial the detector material maps
43-
virtual void writeMaterial(const Acts::DetectorMaterialMaps& detMaterial) = 0;
27+
virtual void writeMaterial(
28+
const Acts::TrackingGeometryMaterial& detMaterial) = 0;
4429
};
4530

4631
} // namespace ActsExamples

Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ class MappingMaterialDecorator : public IMaterialDecorator {
4141
public:
4242
using BinningMap = std::map<std::uint64_t, std::pair<int, int>>;
4343

44-
using VolumeMaterialMap =
45-
std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>;
46-
4744
MappingMaterialDecorator(const Acts::TrackingGeometry& tGeometry,
4845
Acts::Logging::Level level,
4946
bool clearSurfaceMaterial = true,
@@ -276,7 +273,7 @@ class MappingMaterialDecorator : public IMaterialDecorator {
276273
private:
277274
BinningMap m_binningMap;
278275

279-
VolumeMaterialMap m_volumeMaterialMap;
276+
VolumeMaterialMaps m_volumeMaterialMap;
280277

281278
bool m_clearSurfaceMaterial{true};
282279
bool m_clearVolumeMaterial{true};

Examples/Algorithms/MaterialMapping/include/ActsExamples/MaterialMapping/MaterialMapping.hpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Acts/MagneticField/MagneticFieldContext.hpp"
1414
#include "Acts/Material/MaterialInteraction.hpp"
1515
#include "Acts/Material/SurfaceMaterialMapper.hpp"
16+
#include "Acts/Material/TrackingGeometryMaterial.hpp"
1617
#include "Acts/Material/VolumeMaterialMapper.hpp"
1718
#include "Acts/Utilities/Logger.hpp"
1819
#include "ActsExamples/Framework/DataHandle.hpp"
@@ -32,18 +33,7 @@
3233
#include <vector>
3334

3435
namespace Acts {
35-
3636
class TrackingGeometry;
37-
class ISurfaceMaterial;
38-
class IVolumeMaterial;
39-
40-
using SurfaceMaterialMap =
41-
std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
42-
43-
using VolumeMaterialMap =
44-
std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>;
45-
46-
using DetectorMaterialMaps = std::pair<SurfaceMaterialMap, VolumeMaterialMap>;
4737
} // namespace Acts
4838

4939
namespace ActsExamples {

Examples/Algorithms/MaterialMapping/src/CoreMaterialMapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CoreMaterialMapping::CoreMaterialMapping(const CoreMaterialMapping::Config& cfg,
3636
}
3737

3838
CoreMaterialMapping::~CoreMaterialMapping() {
39-
Acts::DetectorMaterialMaps detectorMaterial =
39+
Acts::TrackingGeometryMaterial detectorMaterial =
4040
m_cfg.materialMapper->finalizeMaps(*m_mappingState);
4141
// Loop over the available writers and write the maps
4242
for (auto& imw : m_cfg.materiaMaplWriters) {

Examples/Algorithms/MaterialMapping/src/MaterialMapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ MaterialMapping::MaterialMapping(const MaterialMapping::Config& cfg,
4949

5050
ProcessCode MaterialMapping::finalize() {
5151
ACTS_INFO("Finalizing material mappig output");
52-
Acts::DetectorMaterialMaps detectorMaterial;
52+
Acts::TrackingGeometryMaterial detectorMaterial;
5353

5454
if (m_cfg.materialSurfaceMapper && m_cfg.materialVolumeMapper) {
5555
// Finalize all the maps using the cached state

Examples/Io/Json/include/ActsExamples/Io/Json/JsonMaterialWriter.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Acts/Geometry/GeometryIdentifier.hpp"
1313
#include "Acts/Material/ISurfaceMaterial.hpp"
1414
#include "Acts/Material/IVolumeMaterial.hpp"
15+
#include "Acts/Material/TrackingGeometryMaterial.hpp"
1516
#include "Acts/Plugins/Json/MaterialMapJsonConverter.hpp"
1617
#include "Acts/Utilities/EnumBitwiseOperators.hpp"
1718
#include "Acts/Utilities/Logger.hpp"
@@ -27,18 +28,7 @@
2728
#include <utility>
2829

2930
namespace Acts {
30-
3131
class TrackingGeometry;
32-
class ISurfaceMaterial;
33-
class IVolumeMaterial;
34-
35-
using SurfaceMaterialMap =
36-
std::map<GeometryIdentifier, std::shared_ptr<const ISurfaceMaterial>>;
37-
38-
using VolumeMaterialMap =
39-
std::map<GeometryIdentifier, std::shared_ptr<const IVolumeMaterial>>;
40-
41-
using DetectorMaterialMaps = std::pair<SurfaceMaterialMap, VolumeMaterialMap>;
4232
} // namespace Acts
4333

4434
namespace ActsExamples {
@@ -79,7 +69,8 @@ class JsonMaterialWriter : public IMaterialWriter {
7969
/// Write out the material map
8070
///
8171
/// @param detMaterial is the SurfaceMaterial and VolumeMaterial maps
82-
void writeMaterial(const Acts::DetectorMaterialMaps& detMaterial) override;
72+
void writeMaterial(
73+
const Acts::TrackingGeometryMaterial& detMaterial) override;
8374

8475
/// Write out the material map from Geometry
8576
///

Examples/Io/Json/src/JsonMaterialWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ActsExamples::JsonMaterialWriter::JsonMaterialWriter(
2828
ActsExamples::JsonMaterialWriter::~JsonMaterialWriter() = default;
2929

3030
void ActsExamples::JsonMaterialWriter::writeMaterial(
31-
const Acts::DetectorMaterialMaps& detMaterial) {
31+
const Acts::TrackingGeometryMaterial& detMaterial) {
3232
// Evoke the converter
3333
auto jOut = m_converter->materialMapsToJson(detMaterial);
3434
// And write the file(s)

0 commit comments

Comments
 (0)