CbmRoot
CbmLitResultChecker.cxx
Go to the documentation of this file.
1 
6 #include "CbmLitResultChecker.h"
7 #include <boost/property_tree/json_parser.hpp>
8 #include <iostream>
9 using boost::property_tree::json_parser_error;
10 using std::cout;
11 using std::pair;
12 
14 
16 
17 void CbmLitResultChecker::DoCheck(const string& qaFile,
18  const string& idealFile,
19  const string& checkFile) {
20  ptree qa, ideal, check;
21 
22  try {
23  read_json(qaFile.c_str(), qa);
24  } catch (json_parser_error& error) { cout << error.what(); }
25 
26  try {
27  read_json(idealFile.c_str(), ideal);
28  } catch (json_parser_error& error) { cout << error.what(); }
29 
30  DoCheck(qa, ideal, check);
31 
32  try {
33  write_json(checkFile.c_str(), check);
34  } catch (json_parser_error& error) { cout << error.what(); }
35 }
36 
37 void CbmLitResultChecker::DoCheck(const ptree& qa,
38  const ptree& ideal,
39  ptree& out) {
40  // Build map out of property tree for convenience.
41  map<string, Double_t> mymap;
42  PropertyTreeToMap("", qa, mymap);
43 
44  // Iterate over the map, get each property and compare it to ideal.
45  for (map<string, Double_t>::const_iterator it = mymap.begin();
46  it != mymap.end();
47  it++) {
48  map<string, Double_t>::value_type v = *it;
49 
50  boost::optional<Double_t> vmin =
51  ideal.get_optional<Double_t>(v.first + ".min");
52  boost::optional<Double_t> vmax =
53  ideal.get_optional<Double_t>(v.first + ".max");
54 
55  // Check if value exists in ideal
56  if (!vmin || !vmax) {
57  // -1 in the output tree indicates that value was not checked because
58  // it was not found in ideal property tree
59  out.put(v.first, -1.f);
60  continue;
61  } else {
62  // Check that qa value lays within (min, max) limits
63  if (v.second >= vmin && v.second <= vmax) {
64  // Qa value is within limits
65  out.put(v.first, 1.f);
66  } else {
67  // Qa value is out of range
68  out.put(v.first, 0.f);
69  }
70  }
71  }
72 }
73 
75  const string& path,
76  const ptree& pt,
77  map<string, Double_t>& mymap) const {
78  if (pt.size() == 0) {
79  mymap.insert(pair<string, Double_t>(path, pt.get_value(-1.f)));
80  return;
81  }
82  for (ptree::const_iterator it = pt.begin(); it != pt.end(); it++) {
83  ptree::value_type v = *it;
84  string path1 = (path != "") ? (path + "." + v.first) : v.first;
85  PropertyTreeToMap(path1, v.second, mymap);
86  }
87 }
CbmLitResultChecker::PropertyTreeToMap
void PropertyTreeToMap(const string &path, const ptree &pt, map< string, Double_t > &mymap) const
Build recursively map out of property tree.
Definition: CbmLitResultChecker.cxx:74
CbmLitResultChecker::~CbmLitResultChecker
virtual ~CbmLitResultChecker()
Destructor.
Definition: CbmLitResultChecker.cxx:15
CbmLitResultChecker.h
Automatic checker of QA results.
CbmLitResultChecker::DoCheck
void DoCheck(const string &qaFile, const string &idealFile, const string &checkFile)
Check QA results based on predefined values.
Definition: CbmLitResultChecker.cxx:17
v
__m128 v
Definition: L1/vectors/P4_F32vec4.h:1
CbmLitResultChecker::CbmLitResultChecker
CbmLitResultChecker()
Constructor.
Definition: CbmLitResultChecker.cxx:13