10 namespace persistency {
17 std::pair<std::string, std::shared_ptr<void> > readBackPayload =
fetch(sourcePayloadId, sourceSession);
18 return import(sourceSession, sourcePayloadId, readBackPayload.first, readBackPayload.second.get(), destSession);
24 cond::throwException(
"Payload with hash" + sourcePayloadId +
" has not been found in the source database.",
27 boost::posix_time::ptime
now = boost::posix_time::microsec_clock::universal_time();
52 std::cout <<
" Loading source iov..." << std::endl;
54 auto iovs =
p.selectAll();
55 if (iovs.size() == 0) {
56 std::cout <<
" Tag contains 0 iovs." << std::endl;
59 std::cout <<
" Iov size:" << iovs.size() <<
" timeType:" <<
p.tagInfo().timeType <<
" payloadObjectType=\"" 60 <<
p.tagInfo().payloadType <<
"\"" << std::endl;
62 if ((*iovs.begin()).
since > begin)
63 begin = (*iovs.begin()).
since;
65 std::cout <<
" No Iov in the selected range." << std::endl;
80 editor = destSession.
editIov(destTag);
82 std::cout <<
" INFO. Destination Tag " << destTag
83 <<
" already exists. Provided description will be ignored." << std::endl;
84 if (editor.
timeType() !=
p.tagInfo().timeType)
85 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
87 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
91 p.tagInfo().payloadType, destTag,
p.tagInfo().timeType,
p.tagInfo().synchronizationType);
98 std::set<cond::Hash> pids;
99 std::set<cond::Time_t> sinces;
100 auto iiov = iovs.find(begin);
102 while (iiov != iovs.end()) {
104 if (sinces.find(newSince) != sinces.end()) {
105 std::cout <<
" WARNING. Skipping duplicated since=" << newSince << std::endl;
109 auto usedIov =
p.getInterval(newSince);
115 auto diovs =
dp.selectAll();
116 auto ie = diovs.find(newSince);
117 if (ie != diovs.end()) {
118 if (((*ie).since == newSince) && ((*ie).payloadId == usedIov.payloadId)) {
125 sinces.insert(newSince);
127 if (niovs && (niovs % 1000 == 0))
128 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
131 if (iiov == iovs.end() || (*iiov).since > end) {
134 newSince = (*iiov).since;
137 if (exists &&
override) {
138 std::cout <<
" Adding overlying iovs..." << std::endl;
140 auto diovs =
dp.selectRange(begin, end);
141 std::set<cond::Time_t> extraSinces;
142 for (
const auto& iov : diovs) {
143 auto siov =
p.getInterval(iov.since);
144 if (siov.since != iov.since) {
145 if (extraSinces.find(iov.since) == extraSinces.end()) {
146 editor.
insert(iov.since, siov.payloadId);
147 extraSinces.insert(iov.since);
149 if (niovs && (niovs % 1000 == 0))
150 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
155 std::cout <<
" Total of iov inserted: " << niovs <<
" payloads: " << pids.size() << std::endl;
156 std::cout <<
" Flushing changes..." << std::endl;
157 editor.
flush(editingNote, forceInsert);
171 std::cout <<
" Loading source iov..." << std::endl;
173 auto iovs =
p.selectAll();
174 if (iovs.size() == 0) {
175 std::cout <<
" Tag contains 0 iovs." << std::endl;
178 std::cout <<
" Iov size:" << iovs.size() <<
" timeType:" <<
p.tagInfo().timeType <<
" payloadObjectType=\"" 179 <<
p.tagInfo().payloadType <<
"\"" << std::endl;
182 auto iiov = iovs.find(sourceSince);
183 if (iiov == iovs.end()) {
184 std::cout <<
"ERROR: No Iov valid found for target time " << sourceSince << std::endl;
191 std::cout <<
" INFO. Destination Tag " << destTag
192 <<
" already exists. Provided description will be ignored." << std::endl;
193 editor = session.
editIov(destTag);
194 if (editor.
timeType() !=
p.tagInfo().timeType)
195 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
197 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
201 session.
createIov(
p.tagInfo().payloadType, destTag,
p.tagInfo().timeType,
p.tagInfo().synchronizationType);
208 editor.
insert(destSince, (*iiov).payloadId);
210 std::cout <<
" Flushing changes..." << std::endl;
std::string payloadType() 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)
Transaction & transaction()
void throwException(const std::string &message, const std::string &methodName)
unsigned long long Time_t
void start(bool readOnly=true)
bool fetchPayloadData(const cond::Hash &payloadHash, std::string &payloadType, cond::Binary &payloadData, cond::Binary &streamerInfoData)
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)
IOVProxy readIov(const std::string &tag)
IOVEditor editIov(const std::string &tag)
void insert(cond::Time_t since, const cond::Hash &payloadHash, bool checkType=false)
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)
void throwException(const std::string &message, const std::string &methodName)