1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include "FWCore/ParameterSet/interface/ParameterSetEntry.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/Digest.h"
#include <cassert>
#include <sstream>
#include <iostream>
namespace edm {
ParameterSetEntry::ParameterSetEntry() : isTracked_(false), thePSet_(nullptr), theID_() {}
ParameterSetEntry::ParameterSetEntry(ParameterSet const& pset, bool isTracked)
: isTracked_(isTracked), thePSet_(new ParameterSet(pset)), theID_() {
if (pset.isRegistered()) {
theID_ = pset.id();
}
}
ParameterSetEntry::ParameterSetEntry(ParameterSetID const& id, bool isTracked)
: isTracked_(isTracked), thePSet_(), theID_(id) {}
ParameterSetEntry::ParameterSetEntry(std::string_view rep) : isTracked_(rep[0] == '+'), thePSet_(), theID_() {
assert(rep[0] == '+' || rep[0] == '-');
assert(rep[2] == '(');
assert(rep[rep.size() - 1] == ')');
ParameterSetID newID(std::string(rep.begin() + 3, rep.end() - 1));
theID_.swap(newID);
}
void ParameterSetEntry::toString(std::string& result) const {
result += isTracked() ? "+Q(" : "-Q(";
if (!theID_.isValid()) {
throw edm::Exception(edm::errors::LogicError) << "ParameterSet::toString() called prematurely\n"
<< "before ParameterSet::registerIt() has been called\n"
<< "for all nested parameter sets\n";
}
theID_.toString(result);
result += ')';
}
void ParameterSetEntry::toDigest(cms::Digest& digest) const {
digest.append(isTracked() ? "+Q(" : "-Q(", 3);
if (!theID_.isValid()) {
throw edm::Exception(edm::errors::LogicError) << "ParameterSet::toString() called prematurely\n"
<< "before ParameterSet::registerIt() has been called\n"
<< "for all nested parameter sets\n";
}
theID_.toDigest(digest);
digest.append(")", 1);
}
std::string ParameterSetEntry::toString() const {
std::string result;
toString(result);
return result;
}
ParameterSet const& ParameterSetEntry::pset() const {
fillPSet();
return *thePSet_;
}
ParameterSet& ParameterSetEntry::psetForUpdate() {
fillPSet();
return *thePSet_;
}
void ParameterSetEntry::fillPSet() const {
if (nullptr == thePSet_.load()) {
auto tmp = std::make_unique<ParameterSet>(getParameterSet(theID_));
ParameterSet* expected = nullptr;
if (thePSet_.compare_exchange_strong(expected, tmp.get())) {
// thePSet_ was equal to nullptr and now is equal to tmp.get()
tmp.release();
}
}
}
void ParameterSetEntry::updateID() {
assert(pset().isRegistered());
theID_ = pset().id();
}
std::string ParameterSetEntry::dump(unsigned int indent) const {
std::ostringstream os;
const char* trackiness = (isTracked() ? "tracked" : "untracked");
os << "PSet " << trackiness << " = (" << pset().dump(indent) << ")";
return os.str();
}
std::ostream& operator<<(std::ostream& os, ParameterSetEntry const& psetEntry) {
os << psetEntry.dump();
return os;
}
} // namespace edm
|