Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
ExtentJsonConverter.cpp
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file ExtentJsonConverter.cpp
1
// This file is part of the Acts project.
2
//
3
// Copyright (C) 2022 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 http://mozilla.org/MPL/2.0/.
8
9
#include "
Acts/Plugins/Json/ExtentJsonConverter.hpp
"
10
11
#include "
Acts/Definitions/Algebra.hpp
"
12
#include "
Acts/Plugins/Json/UtilitiesJsonConverter.hpp
"
13
#include "
Acts/Utilities/BinningType.hpp
"
14
#include "
Acts/Utilities/Enumerate.hpp
"
15
#include "
Acts/Utilities/Range1D.hpp
"
16
#include "
Acts/Utilities/RangeXD.hpp
"
17
18
#include <array>
19
#include <iterator>
20
#include <vector>
21
22
void
Acts::to_json
(nlohmann::json&
j
,
const
Acts::Extent
&
e
) {
23
const
auto
& bValueNames =
binningValueNames
();
24
25
{
26
nlohmann::json jrange;
27
const
auto
& xrange = e.
range
();
28
for
(
auto
[
ib
, ibv] :
enumerate
(
s_binningValues
)) {
29
if
(e.
constrains
(ibv)) {
30
jrange[bValueNames[
ib
]] = xrange[
ib
];
31
}
32
}
33
j[
"range"
] = jrange;
34
}
35
36
{
37
nlohmann::json jenvelope;
38
const
auto
& envelope = e.
envelope
();
39
for
(
auto
[
ib
, ibv] :
enumerate
(
s_binningValues
)) {
40
if
(envelope[ibv] !=
zeroEnvelope
) {
41
jenvelope[bValueNames[
ib
]] =
42
Range1D<ActsScalar>
(envelope[
ib
][0], envelope[
ib
][1]);
43
}
44
}
45
if
(!jenvelope.empty()) {
46
j[
"envelope"
] = jenvelope;
47
}
48
}
49
}
50
51
void
Acts::from_json
(
const
nlohmann::json&
j
,
Acts::Extent
&
e
) {
52
const
auto
& bValueNames =
binningValueNames
();
53
54
{
55
const
auto
& jrange = j[
"range"
];
56
for
(
auto
[
ib
, bvn] :
enumerate
(bValueNames)) {
57
if
(jrange.contains(bvn)) {
58
e.
set
(static_cast<BinningValue>(
ib
), jrange[bvn][
"min"
],
59
jrange[bvn][
"max"
]);
60
}
61
}
62
}
63
64
if
(j.contains(
"envelope"
)) {
65
const
auto
& jenvelope = j[
"envelope"
];
66
ExtentEnvelope
envelope;
67
for
(
auto
[
ib
, bvn] :
enumerate
(bValueNames)) {
68
if
(jenvelope.find(bvn) != jenvelope.end()) {
69
envelope[
ib
] = {jenvelope[bvn][
"min"
], jenvelope[bvn][
"max"
]};
70
}
71
}
72
e.
setEnvelope
(envelope);
73
}
74
}
acts
blob
sPHENIX
Plugins
Json
src
ExtentJsonConverter.cpp
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:17:41
using
1.8.2 with
sPHENIX GitHub integration