7 #include <boost/regex.hpp>
13 namespace persistency {
20 std::pair<std::string, std::shared_ptr<void> > readBackPayload =
fetch(sourcePayloadId, sourceSession);
21 return import(sourceSession, sourcePayloadId, readBackPayload.first, readBackPayload.second.get(), destSession);
27 cond::throwException(
"Payload with hash" + sourcePayloadId +
" has not been found in the source database.",
30 boost::posix_time::ptime
now = boost::posix_time::microsec_clock::universal_time();
55 std::cout <<
" Loading source iov..." << std::endl;
57 auto iovs =
p.selectAll();
58 if (iovs.size() == 0) {
59 std::cout <<
" Tag contains 0 iovs." << std::endl;
62 std::cout <<
" Iov size:" << iovs.size() <<
" timeType:" <<
p.tagInfo().timeType <<
" payloadObjectType=\""
63 <<
p.tagInfo().payloadType <<
"\"" << std::endl;
65 if ((*iovs.begin()).
since > begin)
66 begin = (*iovs.begin()).
since;
68 std::cout <<
" No Iov in the selected range." << std::endl;
83 editor = destSession.
editIov(destTag);
85 std::cout <<
" INFO. Destination Tag " << destTag
86 <<
" already exists. Provided description will be ignored." << std::endl;
87 if (editor.
timeType() !=
p.tagInfo().timeType)
88 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
90 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
94 p.tagInfo().payloadType, destTag,
p.tagInfo().timeType,
p.tagInfo().synchronizationType);
101 std::set<cond::Hash> pids;
102 std::set<cond::Time_t> sinces;
103 auto iiov = iovs.find(begin);
105 while (iiov != iovs.end()) {
107 if (sinces.find(newSince) != sinces.end()) {
108 std::cout <<
" WARNING. Skipping duplicated since=" << newSince << std::endl;
112 auto usedIov =
p.getInterval(newSince);
118 auto diovs =
dp.selectAll();
119 auto ie = diovs.find(newSince);
120 if (ie != diovs.end()) {
121 if (((*ie).since == newSince) && ((*ie).payloadId == usedIov.payloadId)) {
127 editor.
insert(newSince, ph);
128 sinces.insert(newSince);
130 if (niovs && (niovs % 1000 == 0))
131 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
134 if (iiov == iovs.end() || (*iiov).since >
end) {
137 newSince = (*iiov).since;
140 if (exists &&
override) {
141 std::cout <<
" Adding overlying iovs..." << std::endl;
143 auto diovs =
dp.selectRange(begin,
end);
144 std::set<cond::Time_t> extraSinces;
145 for (
const auto& iov : diovs) {
146 auto siov =
p.getInterval(iov.since);
147 if (siov.since != iov.since) {
148 if (extraSinces.find(iov.since) == extraSinces.end()) {
149 editor.
insert(iov.since, siov.payloadId);
150 extraSinces.insert(iov.since);
152 if (niovs && (niovs % 1000 == 0))
153 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
158 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
159 std::cout <<
" Flushing changes..." << std::endl;
160 editor.
flush(editingNote, forceInsert);
174 std::cout <<
" Loading source iov..." << std::endl;
176 auto iovs =
p.selectAll();
177 if (iovs.size() == 0) {
178 std::cout <<
" Tag contains 0 iovs." << std::endl;
181 std::cout <<
" Iov size:" << iovs.size() <<
" timeType:" <<
p.tagInfo().timeType <<
" payloadObjectType=\""
182 <<
p.tagInfo().payloadType <<
"\"" << std::endl;
185 auto iiov = iovs.find(sourceSince);
186 if (iiov == iovs.end()) {
187 std::cout <<
"ERROR: No Iov valid found for target time " << sourceSince << std::endl;
194 std::cout <<
" INFO. Destination Tag " << destTag
195 <<
" already exists. Provided description will be ignored." << std::endl;
196 editor = session.
editIov(destTag);
197 if (editor.
timeType() !=
p.tagInfo().timeType)
198 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
200 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
204 session.
createIov(
p.tagInfo().payloadType, destTag,
p.tagInfo().timeType,
p.tagInfo().synchronizationType);
211 editor.
insert(destSince, (*iiov).payloadId);
213 std::cout <<
" Flushing changes..." << std::endl;