LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ParameterSetID.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // ParameterSetID
4 //
5 // ======================================================================
6 
8 
9 #include "boost/format.hpp"
10 #include "fhiclcpp/ParameterSet.h"
11 
12 using namespace boost;
13 using namespace cet;
14 using namespace fhicl;
15 using namespace std;
16 
18 
19 // ======================================================================
20 
21 static digest_t const&
23 {
24  static digest_t invalid_value = {
25  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
26  return invalid_value;
27 }
28 
29 // ----------------------------------------------------------------------
30 
31 ParameterSetID::ParameterSetID() : valid_(false), id_(invalid_id_()) {}
32 
34 {
35  reset(ps);
36 }
37 
38 ParameterSetID::ParameterSetID(std::string const& id)
39  : valid_(id.size() == max_str_size()), id_()
40 {
41  if (valid_) {
42  for (size_t i = 0, e = id_.size(); i != e; ++i) {
43  id_[i] = std::stoi(id.substr(i * 2, 2), nullptr, 16);
44  }
45  if (id != to_string()) {
47  << "ParameterSetID construction failure: " << id
48  << " != " << to_string() << ".\n";
49  }
50  } else if (id.empty()) {
51  id_ = invalid_id_();
52  } else {
54  << "Attempt to construct ParameterSetID from inappropriate input: " << id
55  << ".\n";
56  }
57 }
58 
59 // ----------------------------------------------------------------------
60 
61 bool
63 {
64  return valid_;
65 }
66 
67 string
69 {
70  string s;
71  for (std::size_t i = 0; i != id_.size(); ++i)
72  s += str(format("%02x") % (unsigned int)id_[i]);
73  return s;
74 }
75 
76 // ----------------------------------------------------------------------
77 
78 void
80 {
81  valid_ = false;
82  id_ = invalid_id_();
83 }
84 
85 void
87 {
88  string const& hash(ps.to_string());
89  sha1 sha(hash.c_str());
90 
91  id_ = sha.digest(), valid_ = true;
92 }
93 
94 void
96 {
97  id_.swap(other.id_);
98  std::swap(valid_, other.valid_);
99 }
100 
101 // ----------------------------------------------------------------------
102 
103 bool
105 {
106  return id_ == other.id_;
107 }
108 
109 bool
111 {
112  return id_ != other.id_;
113 }
114 
115 bool
117 {
118  return id_ < other.id_;
119 }
120 
121 bool
123 {
124  return id_ > other.id_;
125 }
126 
127 bool
129 {
130  return id_ <= other.id_;
131 }
132 
133 bool
135 {
136  return id_ >= other.id_;
137 }
138 
139 // ----------------------------------------------------------------------
140 
141 ostream&
142 fhicl::operator<<(ostream& os, ParameterSetID const& psid)
143 {
144  return os << psid.to_string();
145 }
146 
147 // ======================================================================
void swap(ParameterSetID &)
Float_t s
Definition: plot.C:23
std::string to_string() const
STL namespace.
cet::sha1::digest_t id_
bool operator>(ParameterSetID const &) const
sha1::digest_t digest_t
parameter set interface
static std::size_t max_str_size()
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
bool operator<(ParameterSetID const &) const
bool operator!=(ParameterSetID const &) const
static digest_t const & invalid_id_()
bool operator==(ParameterSetID const &) const
void reset(ParameterSet const &)
bool operator<=(ParameterSetID const &) const
bool operator>=(ParameterSetID const &) const
std::ostream & operator<<(std::ostream &, ParameterSetID const &)
Float_t e
Definition: plot.C:34
bool is_valid() const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::string to_string() const
Definition: ParameterSet.h:137