5 #include <boost/filesystem.hpp>
9 namespace persistency {
20 if( log && !forValidation )
std::cout <<
" Loading source iov..."<<std::endl;
23 if( log )
std::cout <<
" Tag contains 0 iovs."<<std::endl;
35 exists = destSession.
existsIov( destTag );
40 }
else if( policy ==
NEW ){
44 editor = destSession.
editIov( destTag );
55 std::set<cond::Hash> pids;
56 std::set<cond::Time_t>
sinces;
59 if( sinces.find(
iov.since ) != sinces.end() ){
60 if( log && !forValidation )
std::cout <<
" WARNING. Skipping duplicated since="<<
iov.since<<std::endl;
63 sinces.insert(
iov.since );
65 auto usedIov = p.getInterval(
iov.since );
66 std::pair<std::string,boost::shared_ptr<void> > readBackPayload =
fetch( usedIov.payloadId, sourceSession );
67 cond::Hash ph =
import( readBackPayload.first, readBackPayload.second.get(), destSession );
71 if( log && !forValidation && niovs && (niovs%1000==0) )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
73 if( log && !forValidation)
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
74 if( log && !forValidation)
std::cout <<
" Flushing changes..."<<std::endl;
90 if( log )
std::cout <<
" Loading source iov..."<<std::endl;
93 if( log )
std::cout <<
" Tag contains 0 iovs."<<std::endl;
105 exists = destSession.
existsIov( destTag );
108 editor = destSession.
editIov( destTag );
110 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
112 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
"importIovs");
118 std::set<cond::Hash> pids;
119 std::set<cond::Time_t>
sinces;
120 auto iiov = p.
find( begin );
122 while( iiov != p.
end() ){
124 if( sinces.find( newSince ) != sinces.end() ){
125 if( log )
std::cout <<
" WARNING. Skipping duplicated since="<<newSince<<std::endl;
128 sinces.insert( newSince );
131 std::pair<std::string,boost::shared_ptr<void> > readBackPayload =
fetch( usedIov.payloadId, sourceSession );
132 cond::Hash ph =
import( readBackPayload.first, readBackPayload.second.get(), destSession );
133 editor.
insert( newSince, ph );
136 if( log && niovs && (niovs%1000==0) )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
138 if( iiov == p.
end() || (*iiov).since >
end ){
141 newSince = (*iiov).since;
144 if( log )
std::cout <<
" Total of iov inserted: "<<niovs<<
" payloads: "<<pids.size()<<std::endl;
145 if( log )
std::cout <<
" Flushing changes..."<<std::endl;
160 if( log )
std::cout <<
" Loading source iov..."<<std::endl;
163 if( log )
std::cout <<
" Tag contains 0 iovs."<<std::endl;
169 auto iiov = p.
find( sourceSince );
170 if( iiov == p.
end() ){
171 if( log )
std::cout <<
"ERROR: No Iov valid found for target time "<<sourceSince<<std::endl;
177 editor = session.
editIov( destTag );
179 throwException(
"TimeType of the destination tag does not match with the source tag timeType.",
"importIovs");
181 throwException(
"PayloadType of the destination tag does not match with the source tag payloadType.",
"importIovs");
187 editor.
insert( destSince, (*iiov).payloadId );
189 if( log )
std::cout <<
" Flushing changes..."<<std::endl;
198 size_t ret =
copyTag( tag, session, destTag, writeSession,
NEW,
false,
true );
208 size_t n1 =
exportTagToFile( firstTag, firstTag, firstSession, firstFileName );
210 std::cout <<
"Can't compare empty tag "<<firstTag<<std::endl;
213 size_t n2 =
exportTagToFile( secondTag, firstTag, secondSession, secondFileName );
215 std::cout <<
"Can't compare empty tag "<<secondTag<<std::endl;
223 FILE*
file1 = fopen( firstFileName.c_str(),
"r" );
227 FILE* file2 = fopen( secondFileName.c_str(),
"r" );
229 throwException(
"Can't open file "+secondFileName,
"compareTags" );
238 size_t r1 = fread( buf1, 1, N, file1 );
239 size_t r2 = fread( buf2, 1, N, file2 );
241 if( r1 != r2 || memcmp( buf1, buf2, r1)) {
246 }
while(!feof(file2) || !feof(file2));
248 std::cout <<
" "<<totSize<<
" bytes compared."<<std::endl;
272 bool ret =
compareTags( refTag, refSession, refFile, candTag, candSession, candFile );
cond::SynchronizationType synchronizationType() const
void clearIov(const std::string &tag)
void setDescription(const std::string &description)
std::string payloadObjectType() const
Transaction & transaction()
std::tuple< std::string, std::string, std::string > parseConnectionString(const std::string &connectionString)
IOVProxy readIov(const std::string &tag, bool full=false)
cond::TimeType timeType() const
unsigned long long Time_t
tuple path
else: Piece not in the list, fine.
Session createSession(const std::string &connectionString, bool writeCapable=false, BackendType backType=DEFAULT_DB)
size_t copyTag(const std::string &sourceTag, Session &sourceSession, const std::string &destTag, Session &destSession, UpdatePolicy policy, bool log, bool forValidation)
Iterator find(cond::Time_t time)
size_t exportTagToFile(const std::string &tag, const std::string &destTag, Session &session, const std::string fileName)
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()
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 copyIov(Session &session, const std::string &sourceTag, const std::string &destTag, cond::Time_t souceSince, cond::Time_t destSince, bool log)
bool validateTag(const std::string &refTag, Session &refSession, const std::string &candTag, Session &candSession)
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::OFFLINE)
std::string payloadType() const
bool compareTags(const std::string &firstTag, Session &firstSession, const std::string &firstFileName, const std::string &secondTag, Session &secondSession, const std::string &secondFileName)
void throwException(const std::string &message, const std::string &methodName)
size_t importIovs(const std::string &sourceTag, Session &sourceSession, const std::string &destTag, Session &destSession, cond::Time_t begin, cond::Time_t end, bool log)