ParameterSet_get_artInputTag_t.cc
Go to the documentation of this file.
3 #include "fhiclcpp/exception.h"
4 
5 #include <cassert>
6 #include <sstream>
7 #include <string>
8 #include <vector>
9 
10 namespace {
11  constexpr bool should_fail{false};
12 
13  void
14  retrieve(fhicl::ParameterSet const& pset,
15  std::string const& parm,
16  bool const should_succeed = true) try {
17  pset.get<art::InputTag>(parm);
18  assert(should_succeed);
19  }
20  catch (fhicl::exception const& e) {
21  assert(not should_succeed);
22  }
23 }
24 
25 int
27 {
28  //===========================================================
29  // Test 1-argument InputTag c'tor
30  //===========================================================
31 
33  pset.put<std::string>("first_key", "label:instance:processName");
34 
35  std::vector<std::string> vs;
36  for (unsigned i(0); i != 10; ++i) {
37  std::ostringstream value;
38  value << "label" << i << ":"
39  << "instance" << i << ":"
40  << "processName" << i;
41  vs.emplace_back(value.str());
42  }
43  pset.put("second_key", vs);
44 
45  auto const tag = pset.get<art::InputTag>("first_key");
46  auto const vec_tags = pset.get<std::vector<art::InputTag>>("second_key");
47 
48  auto const vec_tags_empty =
49  pset.get("third_key", std::vector<art::InputTag>{});
50 
51  assert(vec_tags_empty.empty());
52 
53  std::vector<art::InputTag> vtag;
54  assert(pset.get_if_present("second_key", vtag));
55 
56  //===========================================================
57  // Test multi-argument constructors
58  //===========================================================
59 
60  pset.put<std::vector<std::string>>("multi1", {"label", "instance"});
61  pset.put<std::vector<std::string>>("multi2",
62  {"label", "instance", "process"});
63  pset.put<std::vector<std::string>>("multierr1", {"label:something:else"});
64  pset.put<std::vector<std::string>>(
65  "multierr2", {"label", "instance", "process", "something", "else"});
66 
67  retrieve(pset, "multi1");
68  retrieve(pset, "multi2");
69  retrieve(pset, "multierr1", should_fail);
70  retrieve(pset, "multierr2", should_fail);
71 }
std::string string
Definition: nybbler.cc:12
const double e
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::optional< T > get_if_present(std::string const &key) const
Definition: ParameterSet.h:224
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33