Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RMetaData.cxx
Go to the documentation of this file.
1// Author: Ivan Kabadzhov CERN 10/2022
2
3/*************************************************************************
4 * Copyright (C) 1995-2022, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
12#include <stdexcept> // std::logic_error
13
14namespace ROOT {
15namespace RDF {
16namespace Experimental {
17
18void RMetaData::Add(const std::string &key, int val)
19{
20 fJson[key] = val;
21}
22
23void RMetaData::Add(const std::string &key, double val)
24{
25 fJson[key] = val;
26}
27
28void RMetaData::Add(const std::string &key, const std::string &val)
29{
30 fJson[key] = val;
31}
32
33std::string RMetaData::Dump(const std::string &key) const
34{
35 return fJson[key].dump();
36}
37
38int RMetaData::GetI(const std::string &key) const
39{
40 if (!fJson.contains(key))
41 throw std::logic_error("No key with name " + key + " in the metadata object.");
42 if (!fJson[key].is_number_integer())
43 throw std::logic_error("Key " + key + " is not of type int.");
44 return fJson[key].get<int>();
45}
46
47double RMetaData::GetD(const std::string &key) const
48{
49 if (!fJson.contains(key))
50 throw std::logic_error("No key with name " + key + " in the metadata object.");
51 if (!fJson[key].is_number_float())
52 throw std::logic_error("Key " + key + " is not of type double.");
53 return fJson[key].get<double>();
54}
55
56std::string RMetaData::GetS(const std::string &key) const
57{
58 if (!fJson.contains(key))
59 throw std::logic_error("No key with name " + key + " in the metadata object.");
60 if (!fJson[key].is_string())
61 throw std::logic_error("Key " + key + " is not of type string.");
62 return fJson[key].get<std::string>();
63}
64
65int RMetaData::GetI(const std::string &key, int defaultVal) const
66{
67 if (!fJson.contains(key))
68 return defaultVal;
69 if (!fJson[key].is_number_integer())
70 throw std::logic_error("Key " + key + " is not of type int.");
71 return fJson[key].get<int>();
72}
73
74double RMetaData::GetD(const std::string &key, double defaultVal) const
75{
76 if (!fJson.contains(key))
77 return defaultVal;
78 if (!fJson[key].is_number_float())
79 throw std::logic_error("Key " + key + " is not of type double.");
80 return fJson[key].get<double>();
81}
82
83const std::string RMetaData::GetS(const std::string &key, const std::string &defaultVal) const
84{
85 if (!fJson.contains(key))
86 return defaultVal;
87 if (!fJson[key].is_string())
88 throw std::logic_error("Key " + key + " is not of type string.");
89 return fJson[key].get<std::string>();
90}
91
92} // namespace Experimental
93} // namespace RDF
94} // namespace ROOT
std::string Dump(const std::string &key) const
Definition RMetaData.cxx:33
std::string GetS(const std::string &key) const
Definition RMetaData.cxx:56
void Add(const std::string &key, int val)
Definition RMetaData.cxx:18
double GetD(const std::string &key) const
Definition RMetaData.cxx:47
int GetI(const std::string &key) const
Definition RMetaData.cxx:38
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.