7 #include <boost/filesystem.hpp> 8 #include <boost/regex.hpp> 9 #include <boost/bind.hpp> 14 namespace persistency {
18 std::pair<std::string,std::shared_ptr<void> > readBackPayload =
fetch( sourcePayloadId, sourceSession );
19 return import( sourceSession, sourcePayloadId, readBackPayload.first, readBackPayload.second.get(), destSession );
24 if( !sourceSession.
fetchPayloadData( sourcePayloadId, payloadType, payloadData, streamerInfoData ) ){
25 cond::throwException(
"Payload with hash"+sourcePayloadId+
" has not been found in the source database.",
"importPayload");
27 boost::posix_time::ptime
now = boost::posix_time::microsec_clock::universal_time();
28 return destSession.
storePayloadData( payloadType, std::make_pair( payloadData, streamerInfoData ),now );
34 bool operator()(
const cond::Time_t& x,
const std::pair<cond::Time_t,boost::posix_time::ptime>& y ){
return ( x < y.first ); }
50 std::cout <<
" Loading source iov..."<<std::endl;
53 std::cout <<
" Tag contains 0 iovs."<<std::endl;
60 std::cout <<
" No Iov in the selected range."<<std::endl;
70 exists = destSession.
existsIov( destTag );
74 dp = destSession.
readIov( destTag );
75 editor = destSession.
editIov( destTag );
76 if( !description.empty() )
std::cout <<
" INFO. Destination Tag "<<destTag<<
" already exists. Provided description will be ignored."<<std::endl;
78 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
80 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
"importIovs");
87 std::set<cond::Hash> pids;
88 std::set<cond::Time_t> sinces;
89 auto iiov = p.
find( begin );
91 while( iiov != p.
end() ){
93 if( sinces.find( newSince ) != sinces.end() ){
94 std::cout <<
" WARNING. Skipping duplicated since="<<newSince<<std::endl;
104 auto ie = dp.
find( newSince );
105 if( ie != dp.
end() ){
106 if( ((*ie).since == newSince) && ((*ie).payloadId == usedIov.payloadId) ) {
112 editor.
insert( newSince, ph );
113 sinces.insert( newSince );
115 if( niovs && (niovs%1000==0) )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
118 if( iiov == p.
end() || (*iiov).since >
end ){
121 newSince = (*iiov).since;
124 if( exists &&
override ){
125 std::cout <<
" Adding overlying iovs..."<<std::endl;
129 std::set<cond::Time_t> extraSinces;
130 for(
auto iov : dp ){
132 if( siov.since != iov.since ) {
133 if( extraSinces.find( iov.since )==extraSinces.end() ){
134 editor.
insert( iov.since, siov.payloadId );
135 extraSinces.insert( iov.since );
137 if( niovs && (niovs%1000==0) )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
142 std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
143 std::cout <<
" Flushing changes..."<<std::endl;
144 editor.
flush( editingNote, forceInsert );
158 std::cout <<
" Loading source iov..."<<std::endl;
161 std::cout <<
" Tag contains 0 iovs."<<std::endl;
167 auto iiov = p.
find( sourceSince );
168 if( iiov == p.
end() ){
169 std::cout <<
"ERROR: No Iov valid found for target time "<<sourceSince<<std::endl;
175 if( !description.empty() )
std::cout <<
" INFO. Destination Tag "<<destTag<<
" already exists. Provided description will be ignored."<<std::endl;
176 editor = session.
editIov( destTag );
178 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
180 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
"importIovs");
183 if( description.empty() ) editor.
setDescription(
"Created copying iovs from tag "+sourceTag );
187 editor.
insert( destSince, (*iiov).payloadId );
189 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)