CbmRoot
Loading...
Searching...
No Matches
CbmLitResultChecker.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2012 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
10#include "CbmLitResultChecker.h"
11
12// Add the define statement teporarily to silence the compiler
13// warnings till the problem is fixed in boost
14#define BOOST_BIND_GLOBAL_PLACEHOLDERS 1
15#include <boost/property_tree/json_parser.hpp>
16
17#include <iostream>
18using boost::property_tree::json_parser_error;
19using std::cout;
20using std::pair;
21
23
25
26void CbmLitResultChecker::DoCheck(const string& qaFile, const string& idealFile, const string& checkFile)
27{
28 ptree qa, ideal, check;
29
30 try {
31 read_json(qaFile.c_str(), qa);
32 }
33 catch (json_parser_error& error) {
34 cout << error.what();
35 }
36
37 try {
38 read_json(idealFile.c_str(), ideal);
39 }
40 catch (json_parser_error& error) {
41 cout << error.what();
42 }
43
44 DoCheck(qa, ideal, check);
45
46 try {
47 write_json(checkFile.c_str(), check);
48 }
49 catch (json_parser_error& error) {
50 cout << error.what();
51 }
52}
53
54void CbmLitResultChecker::DoCheck(const ptree& qa, const ptree& ideal, ptree& out)
55{
56 // Build map out of property tree for convenience.
57 map<string, Double_t> mymap;
58 PropertyTreeToMap("", qa, mymap);
59
60 // Iterate over the map, get each property and compare it to ideal.
61 for (map<string, Double_t>::const_iterator it = mymap.begin(); it != mymap.end(); it++) {
62 map<string, Double_t>::value_type v = *it;
63
64 boost::optional<Double_t> vmin = ideal.get_optional<Double_t>(v.first + ".min");
65 boost::optional<Double_t> vmax = ideal.get_optional<Double_t>(v.first + ".max");
66
67 // Check if value exists in ideal
68 if (!vmin || !vmax) {
69 // -1 in the output tree indicates that value was not checked because
70 // it was not found in ideal property tree
71 out.put(v.first, -1.f);
72 continue;
73 }
74 else {
75 // Check that qa value lays within (min, max) limits
76 if (v.second >= vmin && v.second <= vmax) {
77 // Qa value is within limits
78 out.put(v.first, 1.f);
79 }
80 else {
81 // Qa value is out of range
82 out.put(v.first, 0.f);
83 }
84 }
85 }
86}
87
88void CbmLitResultChecker::PropertyTreeToMap(const string& path, const ptree& pt, map<string, Double_t>& mymap) const
89{
90 if (pt.size() == 0) {
91 mymap.insert(pair<string, Double_t>(path, pt.get_value(-1.f)));
92 return;
93 }
94 for (ptree::const_iterator it = pt.begin(); it != pt.end(); it++) {
95 ptree::value_type v = *it;
96 string path1 = (path != "") ? (path + "." + v.first) : v.first;
97 PropertyTreeToMap(path1, v.second, mymap);
98 }
99}
Automatic checker of QA results.
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
virtual ~CbmLitResultChecker()
Destructor.
void PropertyTreeToMap(const string &path, const ptree &pt, map< string, Double_t > &mymap) const
Build recursively map out of property tree.
void DoCheck(const string &qaFile, const string &idealFile, const string &checkFile)
Check QA results based on predefined values.
CbmLitResultChecker()
Constructor.