LArSoft
v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
ParameterSetID.cc
Go to the documentation of this file.
1
// ======================================================================
2
//
3
// ParameterSetID
4
//
5
// ======================================================================
6
7
#include "
fhiclcpp/ParameterSetID.h
"
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
17
typedef
sha1::digest_t
digest_t
;
18
19
// ======================================================================
20
21
static
digest_t
const
&
22
invalid_id_
()
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
33
ParameterSetID::ParameterSetID
(
ParameterSet
const
& ps) :
valid_
(false),
id_
()
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
()) {
46
throw
exception
(
error::cant_happen
)
47
<<
"ParameterSetID construction failure: "
<<
id
48
<<
" != "
<<
to_string
() <<
".\n"
;
49
}
50
}
else
if
(
id
.empty()) {
51
id_
=
invalid_id_
();
52
}
else
{
53
throw
fhicl::exception
(
error::parse_error
)
54
<<
"Attempt to construct ParameterSetID from inappropriate input: "
<<
id
55
<<
".\n"
;
56
}
57
}
58
59
// ----------------------------------------------------------------------
60
61
bool
62
ParameterSetID::is_valid
()
const
63
{
64
return
valid_
;
65
}
66
67
string
68
ParameterSetID::to_string
()
const
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
79
ParameterSetID::invalidate
()
80
{
81
valid_
=
false
;
82
id_
=
invalid_id_
();
83
}
84
85
void
86
ParameterSetID::reset
(
ParameterSet
const
& ps)
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
95
ParameterSetID::swap
(
ParameterSetID
&
other
)
96
{
97
id_
.swap(other.
id_
);
98
std::swap
(
valid_
, other.
valid_
);
99
}
100
101
// ----------------------------------------------------------------------
102
103
bool
104
ParameterSetID::operator==
(
ParameterSetID
const
&
other
)
const
105
{
106
return
id_
== other.
id_
;
107
}
108
109
bool
110
ParameterSetID::operator!=
(
ParameterSetID
const
&
other
)
const
111
{
112
return
id_
!= other.
id_
;
113
}
114
115
bool
116
ParameterSetID::operator<
(
ParameterSetID
const
&
other
)
const
117
{
118
return
id_
< other.
id_
;
119
}
120
121
bool
122
ParameterSetID::operator>
(
ParameterSetID
const
&
other
)
const
123
{
124
return
id_
> other.
id_
;
125
}
126
127
bool
128
ParameterSetID::operator<=
(
ParameterSetID
const
&
other
)
const
129
{
130
return
id_
<= other.
id_
;
131
}
132
133
bool
134
ParameterSetID::operator>=
(
ParameterSetID
const
&
other
)
const
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
// ======================================================================
fhicl::ParameterSetID::swap
void swap(ParameterSetID &)
Definition:
ParameterSetID.cc:95
s
Float_t s
Definition:
plot.C:23
fhicl::ParameterSetID::to_string
std::string to_string() const
Definition:
ParameterSetID.cc:68
boost
Definition:
Voronoi.cxx:25
fhicl::ParameterSetID
Definition:
ParameterSetID.h:23
std
STL namespace.
fhicl::ParameterSetID::id_
cet::sha1::digest_t id_
Definition:
ParameterSetID.h:52
fhicl::ParameterSetID::operator>
bool operator>(ParameterSetID const &) const
Definition:
ParameterSetID.cc:122
ParameterSet.h
cet
Definition:
get_LibraryInfoCollection.h:10
fhicl::ParameterSetID::invalidate
void invalidate()
Definition:
ParameterSetID.cc:79
digest_t
sha1::digest_t digest_t
Definition:
ParameterSetID.cc:17
fhicl
parameter set interface
Definition:
ServiceProviderWrappers.h:37
fhicl::ParameterSetID::max_str_size
static std::size_t max_str_size()
Definition:
ParameterSetID.h:57
fhicl::other
Definition:
exception.h:26
ParameterSetID.h
std::swap
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
Definition:
HLTGlobalStatus.h:199
fhicl::ParameterSetID::operator<
bool operator<(ParameterSetID const &) const
Definition:
ParameterSetID.cc:116
fhicl::ParameterSetID::operator!=
bool operator!=(ParameterSetID const &) const
Definition:
ParameterSetID.cc:110
invalid_id_
static digest_t const & invalid_id_()
Definition:
ParameterSetID.cc:22
fhicl::ParameterSetID::operator==
bool operator==(ParameterSetID const &) const
Definition:
ParameterSetID.cc:104
fhicl::ParameterSetID::reset
void reset(ParameterSet const &)
Definition:
ParameterSetID.cc:86
fhicl::ParameterSetID::operator<=
bool operator<=(ParameterSetID const &) const
Definition:
ParameterSetID.cc:128
fhicl::ParameterSetID::operator>=
bool operator>=(ParameterSetID const &) const
Definition:
ParameterSetID.cc:134
fhicl::ParameterSetID::valid_
bool valid_
Definition:
ParameterSetID.h:51
fhicl::parse_error
Definition:
exception.h:20
fhicl::operator<<
std::ostream & operator<<(std::ostream &, ParameterSetID const &)
Definition:
ParameterSetID.cc:142
e
Float_t e
Definition:
plot.C:34
fhicl::ParameterSetID::is_valid
bool is_valid() const
Definition:
ParameterSetID.cc:62
fhicl::cant_happen
Definition:
exception.h:17
fhicl::exception
cet::coded_exception< error, detail::translate > exception
Definition:
exception.h:33
fhicl::ParameterSetID::ParameterSetID
ParameterSetID()
Definition:
ParameterSetID.cc:31
fhicl::ParameterSet::to_string
std::string to_string() const
Definition:
ParameterSet.h:137
fhicl::ParameterSet
Definition:
ParameterSet.h:34
fhiclcpp
ParameterSetID.cc
Generated on Wed Dec 12 2018 14:42:36 for LArSoft by
1.8.11