PandaRoot
JSONReadersHelper.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 namespace pt = boost::property_tree;
11 
12 #include <FairLogger.h>
13 #include <stdexcept>
14 #include <string>
15 
16 namespace JSONReaders {
17 inline std::pair<double, double> readPair(pt::ptree &tree)
18 {
19  if (tree.size() != 2) {
20  throw std::range_error("Expected two values e.g min/max not " + std::to_string(tree.size()));
21  // LOG(error) << "Expected two values eg. min/max not " << tree.size();
22  }
23  auto it = tree.begin();
24  double min = it->second.get_value<double>();
25  it++;
26  double max = it->second.get_value<double>();
27  return std::make_pair(min, max);
28 }
29 
30 inline std::pair<std::string, std::string> readStringPair(pt::ptree &tree)
31 {
32  if (tree.size() != 2) {
33  throw std::range_error("Expected two values e.g min/max not " + std::to_string(tree.size()));
34  // LOG(error) << "Expected two values eg. min/max not " << tree.size();
35  }
36  auto it = tree.begin();
37  std::string first = it->second.data();
38  it++;
39  std::string second = it->second.data();
40  return std::make_pair(first, second);
41 }
42 
43 inline std::array<double, 3> readTriplet(pt::ptree &tree)
44 {
45  if (tree.size() != 3) {
46  throw std::range_error("Expected three values e.g x/y/z not " + std::to_string(tree.size()));
47  // LOG(error) << << tree.size();
48  }
49  std::array<double, 3> xyz;
50  int index = 0;
51  for (auto val : tree) {
52  xyz[index++] = val.second.get_value<double>();
53  }
54  return xyz;
55 }
56 
57 inline std::vector<double> readVector(pt::ptree &tree)
58 {
59  std::vector<double> result;
60  for (auto val : tree) {
61  result.push_back(val.second.get_value<double>());
62  }
63  return result;
64 }
65 } // namespace JSONReaders
std::pair< double, double > readPair(pt::ptree &tree)
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
std::pair< std::string, std::string > readStringPair(pt::ptree &tree)
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:24
collection of helper methods to load in pairs, triplets or vectors of doubles from JSON files ...
std::array< double, 3 > readTriplet(pt::ptree &tree)
std::vector< double > readVector(pt::ptree &tree)