30 auto writeBinning = [&](nlohmann::json&
root,
31 const std::vector<BinningData>& binning,
33 nlohmann::json jbinning;
34 for (
const auto& bd : binning) {
35 jbinning.push_back(bd);
43 nlohmann::json jinternal;
44 if (its.layerType != Surface::SurfaceType::Other) {
45 jinternal[
"layerType"] =
static_cast<int>(its.layerType);
47 if (not its.surfaceBinning.empty()) {
48 writeBinning(jinternal, its.surfaceBinning,
"surfaceBinning");
50 j[
"internalStructure"] = jinternal;
56 nlohmann::json jcontainer;
57 nlohmann::json jconstituents;
58 for (
const auto& pvc : cts.constituentVolumes) {
59 jconstituents.push_back(pvc);
61 jcontainer[
"constituents"] = jconstituents;
62 writeBinning(jcontainer, cts.constituentBinning,
"constituentBinning");
63 jcontainer[
"layerContainer"] = cts.layerContainer;
64 j[
"containerStructure"] = jcontainer;
77 auto readBinning = [&](
const nlohmann::json&
root,
78 std::vector<BinningData>& binning,
81 if (root.find(key) == root.end() or root[key].is_null()) {
85 for (
const auto& jbinning : root[key]) {
86 binning.push_back(jbinning);
91 if (j.find(
"internalStructure") != j.end() and
92 not j[
"internalStructure"].is_null()) {
93 auto& jinternal = j[
"internalStructure"];
94 Surface::SurfaceType layerType =
95 static_cast<Surface::SurfaceType
>(jinternal[
"layerType"]);
96 std::vector<BinningData> surfaceBinning;
97 readBinning(jinternal, surfaceBinning,
"surfaceBinning");
102 if (j.find(
"containerStructure") != j.end() and
103 not j[
"containerStructure"].is_null()) {
104 std::vector<ProtoVolume> constituentVolumes;
105 auto& jcontainer = j[
"containerStructure"];
106 for (
const auto& jc : jcontainer[
"constituents"]) {
107 constituentVolumes.push_back(jc);
109 std::vector<BinningData> constituentBinning;
110 readBinning(jcontainer, constituentBinning,
"constituentBinning");
111 bool layerContainer = jcontainer[
"layerContainer"];
113 constituentVolumes, constituentBinning, layerContainer};