7 #include <boost/filesystem.hpp>
8 #include <boost/regex.hpp>
9 #include <boost/bind.hpp>
14 namespace persistency {
21 std::pair<std::string, std::shared_ptr<void> > readBackPayload =
fetch(sourcePayloadId, sourceSession);
22 return import(sourceSession, sourcePayloadId, readBackPayload.first, readBackPayload.second.get(), destSession);
28 cond::throwException(
"Payload with hash" + sourcePayloadId +
" has not been found in the source database.",
31 boost::posix_time::ptime
now = boost::posix_time::microsec_clock::universal_time();
56 std::cout <<
" Loading source iov..." << std::endl;
58 auto iovs =
p.selectAll();
59 if (iovs.size() == 0) {
60 std::cout <<
" Tag contains 0 iovs." << std::endl;
63 std::cout <<
" Iov size:" << iovs.size() <<
" timeType:" <<
p.tagInfo().timeType <<
" payloadObjectType=\""
64 <<
p.tagInfo().payloadType <<
"\"" << std::endl;
66 if ((*iovs.begin()).
since > begin)
67 begin = (*iovs.begin()).
since;
69 std::cout <<
" No Iov in the selected range." << std::endl;
84 editor = destSession.
editIov(destTag);
86 std::cout <<
" INFO. Destination Tag " << destTag
87 <<
" already exists. Provided description will be ignored." << std::endl;
88 if (editor.
timeType() !=
p.tagInfo().timeType)
89 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
91 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
95 p.tagInfo().payloadType, destTag,
p.tagInfo().timeType,
p.tagInfo().synchronizationType);
102 std::set<cond::Hash> pids;
103 std::set<cond::Time_t> sinces;
104 auto iiov = iovs.find(begin);
106 while (iiov != iovs.end()) {
108 if (sinces.find(newSince) != sinces.end()) {
109 std::cout <<
" WARNING. Skipping duplicated since=" << newSince << std::endl;
113 auto usedIov =
p.getInterval(newSince);
119 auto diovs =
dp.selectAll();
120 auto ie = diovs.find(newSince);
121 if (ie != diovs.end()) {
122 if (((*ie).since == newSince) && ((*ie).payloadId == usedIov.payloadId)) {
128 editor.
insert(newSince, ph);
129 sinces.insert(newSince);
131 if (niovs && (niovs % 1000 == 0))
132 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
135 if (iiov == iovs.end() || (*iiov).since >
end) {
138 newSince = (*iiov).since;
141 if (exists &&
override) {
142 std::cout <<
" Adding overlying iovs..." << std::endl;
144 auto diovs =
dp.selectRange(begin,
end);
145 std::set<cond::Time_t> extraSinces;
146 for (
const auto& iov : diovs) {
147 auto siov =
p.getInterval(iov.since);
148 if (siov.since != iov.since) {
149 if (extraSinces.find(iov.since) == extraSinces.end()) {
150 editor.
insert(iov.since, siov.payloadId);
151 extraSinces.insert(iov.since);
153 if (niovs && (niovs % 1000 == 0))
154 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
159 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
160 std::cout <<
" Flushing changes..." << std::endl;
161 editor.
flush(editingNote, forceInsert);
175 std::cout <<
" Loading source iov..." << std::endl;
177 auto iovs =
p.selectAll();
178 if (iovs.size() == 0) {
179 std::cout <<
" Tag contains 0 iovs." << std::endl;
182 std::cout <<
" Iov size:" << iovs.size() <<
" timeType:" <<
p.tagInfo().timeType <<
" payloadObjectType=\""
183 <<
p.tagInfo().payloadType <<
"\"" << std::endl;
186 auto iiov = iovs.find(sourceSince);
187 if (iiov == iovs.end()) {
188 std::cout <<
"ERROR: No Iov valid found for target time " << sourceSince << std::endl;
195 std::cout <<
" INFO. Destination Tag " << destTag
196 <<
" already exists. Provided description will be ignored." << std::endl;
197 editor = session.
editIov(destTag);
198 if (editor.
timeType() !=
p.tagInfo().timeType)
199 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
201 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
205 session.
createIov(
p.tagInfo().payloadType, destTag,
p.tagInfo().timeType,
p.tagInfo().synchronizationType);
212 editor.
insert(destSince, (*iiov).payloadId);
214 std::cout <<
" Flushing changes..." << std::endl;