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);
27 if (!sourceSession.
fetchPayloadData(sourcePayloadId, payloadType, payloadData, streamerInfoData)) {
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();
32 return destSession.
storePayloadData(payloadType, std::make_pair(payloadData, streamerInfoData), now);
56 std::cout <<
" Loading source iov..." << std::endl;
59 std::cout <<
" Tag contains 0 iovs." << std::endl;
68 std::cout <<
" No Iov in the selected range." << std::endl;
82 dp = destSession.
readIov(destTag);
83 editor = destSession.
editIov(destTag);
84 if (!description.empty())
85 std::cout <<
" INFO. Destination Tag " << destTag
86 <<
" already exists. Provided description will be ignored." << std::endl;
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 if (description.empty())
100 std::set<cond::Hash> pids;
101 std::set<cond::Time_t> sinces;
102 auto iiov = p.
find(begin);
104 while (iiov != p.
end()) {
106 if (sinces.find(newSince) != sinces.end()) {
107 std::cout <<
" WARNING. Skipping duplicated since=" << newSince << std::endl;
117 auto ie = dp.
find(newSince);
118 if (ie != dp.
end()) {
119 if (((*ie).since == newSince) && ((*ie).payloadId == usedIov.payloadId)) {
125 editor.
insert(newSince, ph);
126 sinces.insert(newSince);
128 if (niovs && (niovs % 1000 == 0))
129 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
132 if (iiov == p.
end() || (*iiov).since >
end) {
135 newSince = (*iiov).since;
138 if (exists &&
override) {
139 std::cout <<
" Adding overlying iovs..." << std::endl;
143 std::set<cond::Time_t> extraSinces;
144 for (
auto iov : dp) {
146 if (siov.since != iov.since) {
147 if (extraSinces.find(iov.since) == extraSinces.end()) {
148 editor.
insert(iov.since, siov.payloadId);
149 extraSinces.insert(iov.since);
151 if (niovs && (niovs % 1000 == 0))
152 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
157 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
158 std::cout <<
" Flushing changes..." << std::endl;
159 editor.
flush(editingNote, forceInsert);
173 std::cout <<
" Loading source iov..." << std::endl;
176 std::cout <<
" Tag contains 0 iovs." << std::endl;
183 auto iiov = p.
find(sourceSince);
184 if (iiov == p.
end()) {
185 std::cout <<
"ERROR: No Iov valid found for target time " << sourceSince << std::endl;
191 if (!description.empty())
192 std::cout <<
" INFO. Destination Tag " << destTag
193 <<
" already exists. Provided description will be ignored." << std::endl;
194 editor = session.
editIov(destTag);
196 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
198 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
202 if (description.empty())
203 editor.
setDescription(
"Created copying iovs from tag " + sourceTag);
208 editor.
insert(destSince, (*iiov).payloadId);
210 std::cout <<
" Flushing changes..." << std::endl;
cond::SynchronizationType synchronizationType() const
bool copyIov(Session &session, const std::string &sourceTag, const std::string &destTag, cond::Time_t souceSince, cond::Time_t destSince, const std::string &description)
size_t importIovs(const std::string &sourceTag, Session &sourceSession, const std::string &destTag, Session &destSession, cond::Time_t begin, cond::Time_t end, const std::string &description, const std::string &editingNote, bool override, bool serialize, bool forceInsert)
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
void setDescription(const std::string &description)
std::string payloadObjectType() const
Transaction & transaction()
void throwException(const std::string &message, const std::string &methodName)
IOVProxy readIov(const std::string &tag, bool full=false)
cond::TimeType timeType() const
unsigned long long Time_t
Iterator find(cond::Time_t time)
void start(bool readOnly=true)
bool fetchPayloadData(const cond::Hash &payloadHash, std::string &payloadType, cond::Binary &payloadData, cond::Binary &streamerInfoData)
cond::Iov_t getInterval(cond::Time_t time)
cond::Hash importPayload(Session &sourceSession, const cond::Hash &sourcePayloadId, Session &destSession, bool reserialize)
std::string connectionString()
cond::Hash storePayloadData(const std::string &payloadObjectType, const std::pair< Binary, Binary > &payloadAndStreamerInfoData, const boost::posix_time::ptime &creationTime)
IOVEditor editIov(const std::string &tag)
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
void loadRange(const std::string &tag, const cond::Time_t &begin, const cond::Time_t &end)
bool existsIov(const std::string &tag)
cond::TimeType timeType() const
bool operator()(const cond::Time_t &x, const std::pair< cond::Time_t, boost::posix_time::ptime > &y)
std::pair< std::string, std::shared_ptr< void > > fetch(const cond::Hash &payloadId, Session &session)
std::string payloadType() const
void throwException(const std::string &message, const std::string &methodName)