7 #include <boost/filesystem.hpp>
8 #include <boost/regex.hpp>
9 #include <boost/bind.hpp>
13 namespace persistency {
23 if( log )
std::cout <<
" Loading source iov..."<<std::endl;
26 if( log )
std::cout <<
" Tag contains 0 iovs."<<std::endl;
38 exists = destSession.
existsIov( destTag );
43 }
else if( policy ==
NEW ){
47 editor = destSession.
editIov( destTag );
54 std::set<cond::Hash> pids;
55 std::set<cond::Time_t>
sinces;
58 if( sinces.find(
iov.since ) != sinces.end() ){
59 if( log )
std::cout <<
" WARNING. Skipping duplicated since="<<
iov.since<<std::endl;
62 sinces.insert(
iov.since );
64 auto usedIov = p.getInterval(
iov.since );
65 std::pair<std::string,boost::shared_ptr<void> > readBackPayload =
fetch( usedIov.payloadId, sourceSession );
66 cond::Hash ph =
import( sourceSession, usedIov.payloadId, readBackPayload.first, readBackPayload.second.get(), destSession );
70 if( log && niovs && (niovs%1000==0) )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
72 if( log )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
73 if( log )
std::cout <<
" Flushing changes..."<<std::endl;
82 bool operator()(
const cond::Time_t& x,
const std::pair<cond::Time_t,boost::posix_time::ptime>& y ){
return ( x < y.first ); }
95 if( log )
std::cout <<
" Loading source iov..."<<std::endl;
98 if( log )
std::cout <<
" Tag contains 0 iovs."<<std::endl;
103 if( (*p.
begin()).since > begin ) begin = (*p.
begin()).since;
105 if( log )
std::cout <<
" No Iov in the selected range."<<std::endl;
115 exists = destSession.
existsIov( destTag );
118 editor = destSession.
editIov( destTag );
120 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
122 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
"importIovs");
129 std::set<cond::Hash> pids;
130 std::set<cond::Time_t>
sinces;
131 auto iiov = p.
find( begin );
133 while( iiov != p.
end() ){
135 if( sinces.find( newSince ) != sinces.end() ){
136 if( log )
std::cout <<
" WARNING. Skipping duplicated since="<<newSince<<std::endl;
139 sinces.insert( newSince );
142 std::pair<std::string,boost::shared_ptr<void> > readBackPayload =
fetch( usedIov.payloadId, sourceSession );
143 cond::Hash ph =
import( sourceSession, usedIov.payloadId, readBackPayload.first, readBackPayload.second.get(), destSession );
144 editor.
insert( newSince, ph );
147 if( log && niovs && (niovs%1000==0) )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
149 if( iiov == p.
end() || (*iiov).since >
end ){
152 newSince = (*iiov).since;
155 if( log )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
156 if( log )
std::cout <<
" Flushing changes..."<<std::endl;
172 if( log )
std::cout <<
" Loading source iov..."<<std::endl;
175 if( log )
std::cout <<
" Tag contains 0 iovs."<<std::endl;
181 auto iiov = p.
find( sourceSince );
182 if( iiov == p.
end() ){
183 if( log )
std::cout <<
"ERROR: No Iov valid found for target time "<<sourceSince<<std::endl;
189 editor = session.
editIov( destTag );
191 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
193 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
"importIovs");
196 if( description.empty() ) editor.
setDescription(
"Created copying iovs from tag "+sourceTag );
200 editor.
insert( destSince, (*iiov).payloadId );
202 if( log )
std::cout <<
" Flushing changes..."<<std::endl;
cond::SynchronizationType synchronizationType() const
void clearIov(const std::string &tag)
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, bool log)
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()
size_t copyTag(const std::string &sourceTag, Session &sourceSession, const std::string &destTag, Session &destSession, UpdatePolicy policy, bool log)
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)
cond::Iov_t getInterval(cond::Time_t time)
std::pair< std::string, boost::shared_ptr< void > > fetch(const cond::Hash &payloadId, Session &session)
std::string connectionString()
bool copyIov(Session &session, const std::string &sourceTag, const std::string &destTag, cond::Time_t souceSince, cond::Time_t destSince, const std::string &description, bool log)
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::string payloadType() const
void throwException(const std::string &message, const std::string &methodName)