Skip to content

Commit

Permalink
revert: "refactor: Use ordered json (#686)" (#778)
Browse files Browse the repository at this point in the history
Downgrade `nlohmann::json` back down to `3.7.3` to be able to ship a version that ATLAS can use sooner.
  • Loading branch information
paulgessinger committed Apr 21, 2021
1 parent 7e045b6 commit 4c3d6ac
Show file tree
Hide file tree
Showing 13 changed files with 4,617 additions and 7,616 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ set(_acts_dd4hep_version 1.11)
set(_acts_doxygen_version 1.8.15)
set(_acts_eigen3_version 3.3.7)
set(_acts_hepmc3_version 3.2.1)
set(_acts_nlohmanjson_version 3.9.1)
set(_acts_nlohmanjson_version 3.7.3)
set(_acts_root_version 6.20)
set(_acts_tbb_version 2020.1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GeometryHierarchyMapJsonConverter {
///
/// @param container Geometry hierarchy map that should be encoded
/// @return Encoded Json object
nlohmann::ordered_json toJson(const Container& container) const;
nlohmann::json toJson(const Container& container) const;

/// Decode a Json object into a geometry hierarchy map.
///
Expand All @@ -70,8 +70,8 @@ class GeometryHierarchyMapJsonConverter {

std::string m_valueIdentifier;

static nlohmann::ordered_json encodeIdentifier(GeometryIdentifier id) {
nlohmann::ordered_json encoded;
static nlohmann::json encodeIdentifier(GeometryIdentifier id) {
nlohmann::json encoded;
// only store non-zero identifiers
if (id.volume()) {
encoded["volume"] = id.volume();
Expand Down Expand Up @@ -104,16 +104,16 @@ class GeometryHierarchyMapJsonConverter {
// implementations

template <typename value_t>
nlohmann::ordered_json GeometryHierarchyMapJsonConverter<value_t>::toJson(
nlohmann::json GeometryHierarchyMapJsonConverter<value_t>::toJson(
const Container& container) const {
// encode header
nlohmann::ordered_json encoded = nlohmann::json::object();
nlohmann::json encoded = nlohmann::json::object();
encoded[kHeaderKey] = {
{"format-version", kFormatVersion},
{"value-identifier", m_valueIdentifier},
};
// encode entries
nlohmann::ordered_json entries = nlohmann::json::array();
nlohmann::json entries = nlohmann::json::array();
for (std::size_t i = 0; i < container.size(); ++i) {
auto entry = encodeIdentifier(container.idAt(i));
entry["value"] = nlohmann::json(container.valueAt(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ class MaterialMapJsonConverter {
/// Convert a DetectorMaterialMaps to json
///
/// @param maps The material map collection
nlohmann::ordered_json materialMapsToJson(const DetectorMaterialMaps& maps);
nlohmann::json materialMapsToJson(const DetectorMaterialMaps& maps);

/// Convert a tracking geometry to json.
/// Can be used to initialise the material mapping process.
///
/// @param tGeometry is the tracking geometry
nlohmann::ordered_json trackingGeometryToJson(
const TrackingGeometry& tGeometry);
nlohmann::json trackingGeometryToJson(const TrackingGeometry& tGeometry);

/// Go through a volume to find subvolume, layers and surfaces.
/// Store volumes and surfaces in two vector used to initialised the geometry
Expand Down
18 changes: 8 additions & 10 deletions Plugins/Json/src/MaterialMapJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Acts::MaterialMapJsonConverter::MaterialMapJsonConverter(

/// Convert method
///
nlohmann::ordered_json Acts::MaterialMapJsonConverter::materialMapsToJson(
nlohmann::json Acts::MaterialMapJsonConverter::materialMapsToJson(
const DetectorMaterialMaps& maps) {
VolumeMaterialMap volumeMap = maps.second;
std::vector<std::pair<GeometryIdentifier, const IVolumeMaterial*>>
Expand All @@ -183,7 +183,7 @@ nlohmann::ordered_json Acts::MaterialMapJsonConverter::materialMapsToJson(
}
GeometryHierarchyMap<const IVolumeMaterial*> hierarchyVolumeMap(
mapVolumeInit);
nlohmann::ordered_json materialVolume =
nlohmann::json materialVolume =
m_volumeMaterialConverter.toJson(hierarchyVolumeMap);
SurfaceMaterialMap surfaceMap = maps.first;
std::vector<std::pair<GeometryIdentifier, const ISurfaceMaterial*>>
Expand All @@ -193,9 +193,9 @@ nlohmann::ordered_json Acts::MaterialMapJsonConverter::materialMapsToJson(
}
GeometryHierarchyMap<const ISurfaceMaterial*> hierarchySurfaceMap(
mapSurfaceInit);
nlohmann::ordered_json materialSurface =
nlohmann::json materialSurface =
m_surfaceMaterialConverter.toJson(hierarchySurfaceMap);
nlohmann::ordered_json materialMap;
nlohmann::json materialMap;
materialMap["Volumes"] = materialVolume;
materialMap["Surfaces"] = materialSurface;
return materialMap;
Expand Down Expand Up @@ -230,7 +230,7 @@ Acts::MaterialMapJsonConverter::jsonToMaterialMaps(
return maps;
}

nlohmann::ordered_json Acts::MaterialMapJsonConverter::trackingGeometryToJson(
nlohmann::json Acts::MaterialMapJsonConverter::trackingGeometryToJson(
const Acts::TrackingGeometry& tGeometry) {
std::vector<std::pair<GeometryIdentifier, Acts::TrackingVolumeAndMaterial>>
volumeHierarchy;
Expand All @@ -240,13 +240,11 @@ nlohmann::ordered_json Acts::MaterialMapJsonConverter::trackingGeometryToJson(
tGeometry.highestTrackingVolume());
GeometryHierarchyMap<Acts::TrackingVolumeAndMaterial> hierarchyVolumeMap(
volumeHierarchy);
nlohmann::ordered_json jsonVolumes =
m_volumeConverter.toJson(hierarchyVolumeMap);
nlohmann::json jsonVolumes = m_volumeConverter.toJson(hierarchyVolumeMap);
GeometryHierarchyMap<Acts::SurfaceAndMaterial> hierarchySurfaceMap(
surfaceHierarchy);
nlohmann::ordered_json jsonSurfaces =
m_surfaceConverter.toJson(hierarchySurfaceMap);
nlohmann::ordered_json hierarchyMap;
nlohmann::json jsonSurfaces = m_surfaceConverter.toJson(hierarchySurfaceMap);
nlohmann::json hierarchyMap;
hierarchyMap["Volumes"] = jsonVolumes;
hierarchyMap["Surfaces"] = jsonSurfaces;
return hierarchyMap;
Expand Down
41 changes: 4 additions & 37 deletions thirdparty/nlohmann_json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.1)
## PROJECT
## name and version
##
project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX)
project(nlohmann_json VERSION 3.7.3 LANGUAGES CXX)

##
## INCLUDE
Expand All @@ -15,16 +15,9 @@ include(ExternalProject)
##
## OPTIONS
##

if (POLICY CMP0077)
# Allow CMake 3.13+ to override options when using FetchContent / add_subdirectory.
cmake_policy(SET CMP0077 NEW)
endif ()

option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ON)
option(JSON_Install "Install CMake targets during install step." ON)
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF)
option(JSON_ImplicitConversions "Enable implicit conversions." ON)

##
## CONFIGURATION
Expand All @@ -40,7 +33,6 @@ set(NLOHMANN_JSON_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(NLOHMANN_JSON_CMAKE_PROJECT_CONFIG_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Config.cmake")
set(NLOHMANN_JSON_CMAKE_PROJECT_TARGETS_FILE "${NLOHMANN_JSON_CMAKE_CONFIG_DIR}/${PROJECT_NAME}Targets.cmake")
set(NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

if (JSON_MultipleHeaders)
set(NLOHMANN_JSON_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR}/include/")
Expand All @@ -50,10 +42,6 @@ else()
message(STATUS "Using the single-header code from ${NLOHMANN_JSON_INCLUDE_BUILD_DIR}")
endif()

if (NOT JSON_ImplicitConversions)
message(STATUS "Implicit conversions are disabled")
endif()

##
## TARGET
## create target and add include path
Expand All @@ -66,12 +54,6 @@ else()
target_compile_features(${NLOHMANN_JSON_TARGET_NAME} INTERFACE cxx_std_11)
endif()

target_compile_definitions(
${NLOHMANN_JSON_TARGET_NAME}
INTERFACE
JSON_USE_IMPLICIT_CONVERSIONS=$<BOOL:${JSON_ImplicitConversions}>
)

target_include_directories(
${NLOHMANN_JSON_TARGET_NAME}
INTERFACE
Expand All @@ -91,12 +73,6 @@ if (MSVC)
)
endif()

# Install a pkg-config file, so other tools can find this.
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/pkg-config.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
)

##
## TESTS
## create and configure the unit test target
Expand All @@ -113,13 +89,8 @@ endif()
## install header files, generate and install cmake config files for find_package()
##
include(CMakePackageConfigHelpers)
# use a custom package version config file instead of
# write_basic_package_version_file to ensure that it's architecture-independent
# https://github.com/nlohmann/json/issues/1697
configure_file(
"cmake/nlohmann_jsonConfigVersion.cmake.in"
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE}
@ONLY
write_basic_package_version_file(
${NLOHMANN_JSON_CMAKE_VERSION_CONFIG_FILE} COMPATIBILITY SameMajorVersion
)
configure_file(
${NLOHMANN_JSON_CMAKE_CONFIG_TEMPLATE}
Expand All @@ -141,7 +112,7 @@ if(JSON_Install)
FILES ${NLOHMANN_NATVIS_FILE}
DESTINATION .
)
endif()
endif()
export(
TARGETS ${NLOHMANN_JSON_TARGET_NAME}
NAMESPACE ${PROJECT_NAME}::
Expand All @@ -157,8 +128,4 @@ endif()
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${NLOHMANN_JSON_CONFIG_INSTALL_DIR}
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION ${NLOHMANN_JSON_PKGCONFIG_INSTALL_DIR}
)
endif()

0 comments on commit 4c3d6ac

Please sign in to comment.