PSetTest.cc
Go to the documentation of this file.
2 #include <cassert>
3 #include <string>
4 #include <vector>
5 
6 int
7 main()
8 {
10 
11  pset.put<int>("a", -1);
12  assert(pset.get<int>("a") == -1);
13  try {
14  pset.get<unsigned int>("a", 0u);
15  assert(false);
16  }
17  catch (fhicl::exception const& e) {
18  assert(true);
19  }
20 
21  pset.put<std::string>("b", "string");
22  assert(pset.get<std::string>("b") == "string");
23 
24  pset.put<double>("c", 2.3);
25  assert(pset.get<double>("c") == 2.3);
26 
27  pset.put<bool>("d", true);
28  assert(pset.get<bool>("d") == true);
29 
30  std::vector<int> vi;
31  vi.push_back(-1);
32  vi.push_back(-2);
33  vi.push_back(-3);
34  pset.put<std::vector<int>>("e", vi);
35  assert(pset.get<std::vector<int>>("e")[1] == -2);
36 
37  try {
38  std::vector<unsigned int> vui_def;
39  pset.get<std::vector<unsigned int>>("e", vui_def);
40  assert(false);
41  }
42  catch (fhicl::exception const& e) {
43  assert(true);
44  }
45 
46  std::vector<double> vd;
47  vd.push_back(0.1);
48  vd.push_back(0.2);
49  vd.push_back(0.3);
50  pset.put<std::vector<double>>("f", vd);
51  assert(pset.get<std::vector<double>>("f")[1] == 0.2);
52 
53  std::vector<std::string> vs;
54  vs.push_back("str1");
55  vs.push_back("str2");
56  vs.push_back("str3");
57  pset.put<std::vector<std::string>>("g", vs);
58 
59  fhicl::ParameterSet pset2;
60  pset2.put<int>("a2", 1);
61  pset2.put<std::string>("b2", "bstring");
62  pset.put<fhicl::ParameterSet>("h", pset2);
63  assert(pset.get<fhicl::ParameterSet>("h").get<std::string>("b2") ==
64  "bstring");
65  assert(pset2.to_string() == "a2:1 b2:\"bstring\"");
66 
67  pset.put<unsigned int>("u1", 12);
68  assert(pset.get<unsigned int>("u1") == 12);
69 
70  pset.put<unsigned int>("u2", 0);
71  assert(pset.get<unsigned int>("u2") == 0);
72 
73  std::vector<unsigned int> vui;
74  vui.push_back(1);
75  vui.push_back(2);
76  vui.push_back(3);
77  pset.put<std::vector<unsigned int>>("vu", vui);
78  assert(pset.get<std::vector<int>>("vu")[1] == 2);
79  assert(pset.get<std::vector<unsigned int>>("vu")[1] == 2);
80 
81  pset.put<std::string>("int_str", "012");
82  assert(pset.get<int>("int_str") == 12);
83 
84  pset.put<std::string>("float_str", "003e2");
85  assert(pset.get<double>("float_str") == 3e2);
86 
87  pset.put<std::string>("float_str2", "003.200");
88  assert(pset.get<double>("float_str2") == 3.2);
89 
90  pset.put<bool>("b1", true);
91  assert(pset.get<bool>("b1") == true);
92 
93  pset.put<bool>("b2", false);
94  assert(pset.get<bool>("b2") == false);
95 
96  std::vector<std::string> names = pset.get_pset_names();
97  assert(!names.empty());
98  assert(names[0].compare("h") == 0);
99 
100  pset.put<std::string>("b3", "true");
101  assert(pset.get<bool>("b3") == true);
102  pset.put<std::string>("b4", "false");
103  assert(pset.get<bool>("b4") == false);
104 
105  return 0;
106 }
std::string string
Definition: nybbler.cc:12
int compare(unsigned *r, sha1::digest_t const &d)
Definition: sha1_test_2.cc:60
std::vector< std::string > get_pset_names() const
const double e
T get(std::string const &key) const
Definition: ParameterSet.h:271
static std::vector< std::string > const names
Definition: FragmentType.hh:8
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int main()
Definition: PSetTest.cc:7