Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified RunInfo o2o to populate the conddb runinfo tables
- Loading branch information
Showing
7 changed files
with
199 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<use name="CondTools/RunInfo"/> | ||
<use name="CondFormats/RunInfo"/> | ||
<bin file="conddb_import_runInfo.cpp" name="conddb_import_runInfo"> | ||
<use name="CondCore/Utilities"/> | ||
<use name="CondCore/CondDB"/> | ||
</bin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "CondCore/CondDB/interface/ConnectionPool.h" | ||
#include "CondCore/CondDB/interface/RunInfoEditor.h" | ||
#include "CondCore/Utilities/interface/Utilities.h" | ||
#include "CondTools/RunInfo/interface/RunInfoUpdate.h" | ||
#include "CondFormats/RunInfo/interface/RunInfo.h" | ||
#include <iostream> | ||
|
||
#include <sstream> | ||
|
||
namespace cond { | ||
|
||
class RunInfoUtils : public cond::Utilities { | ||
public: | ||
RunInfoUtils(); | ||
~RunInfoUtils(); | ||
int execute(); | ||
}; | ||
} | ||
|
||
cond::RunInfoUtils::RunInfoUtils():Utilities("conddb_import_runInfo"){ | ||
addConnectOption("fromConnect","f","source connection string (optional, default=connect)"); | ||
addConnectOption("connect","c","target connection string (required)"); | ||
addAuthenticationOptions(); | ||
addOption<std::string>("tag","t","source tag (required)"); | ||
addOption<size_t>("max_entries","m","max entries to migrate (default=1000)"); | ||
} | ||
|
||
cond::RunInfoUtils::~RunInfoUtils(){ | ||
} | ||
|
||
boost::posix_time::ptime parseTimeFromIsoString( const std::string& isoString ){ | ||
boost::posix_time::time_input_facet* tif = new boost::posix_time::time_input_facet; | ||
tif->set_iso_extended_format(); | ||
std::istringstream iss( isoString ); | ||
iss.imbue(std::locale(std::locale::classic(),tif)); | ||
boost::posix_time::ptime ret; | ||
iss >> ret; | ||
return ret; | ||
} | ||
|
||
int cond::RunInfoUtils::execute(){ | ||
|
||
std::string connect = getOptionValue<std::string>("connect"); | ||
std::string fromConnect = getOptionValue<std::string>("fromConnect"); | ||
|
||
// this is mandatory | ||
std::string tag = getOptionValue<std::string>("tag"); | ||
std::cout <<"# Source tag is "<<tag<<std::endl; | ||
|
||
size_t max_entries = 1000; | ||
if(hasOptionValue("max_entries")) max_entries = getOptionValue<size_t>("max_entries"); | ||
|
||
persistency::ConnectionPool connPool; | ||
if( hasOptionValue("authPath") ){ | ||
connPool.setAuthenticationPath( getOptionValue<std::string>( "authPath") ); | ||
} | ||
if(hasDebug()) connPool.setMessageVerbosity( coral::Debug ); | ||
connPool.configure(); | ||
|
||
persistency::Session session = connPool.createSession( connect, true ); | ||
std::cout <<"# Connecting to target database on "<<connect<<std::endl; | ||
persistency::Session sourceSession = connPool.createSession( fromConnect ); | ||
std::cout <<"# Connecting to source database on "<<fromConnect<<std::endl; | ||
RunInfoUpdate updater( session ); | ||
persistency::TransactionScope tsc( session.transaction() ); | ||
tsc.start(false); | ||
sourceSession.transaction().start(); | ||
updater.import( max_entries, tag, sourceSession ); | ||
sourceSession.transaction().commit(); | ||
tsc.commit(); | ||
return 0; | ||
} | ||
|
||
int main( int argc, char** argv ){ | ||
|
||
cond::RunInfoUtils utilities; | ||
return utilities.run(argc,argv); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef CondTools_RunInfo_RunInfoUpdate_h | ||
#define CondTools_RunInfo_RunInfoUpdate_h | ||
|
||
#include "CondFormats/RunInfo/interface/RunInfo.h" | ||
|
||
namespace cond { | ||
namespace persistency { | ||
class Session; | ||
} | ||
} | ||
|
||
class RunInfoUpdate { | ||
public: | ||
explicit RunInfoUpdate( cond::persistency::Session& dbSession ); | ||
|
||
~RunInfoUpdate(); | ||
void appendNewRun( const RunInfo& run ); | ||
|
||
size_t import( size_t maxEntries, const std::string& tag, cond::persistency::Session& sourceSession ); | ||
private: | ||
cond::persistency::Session& m_dbSession; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "CondTools/RunInfo/interface/RunInfoUpdate.h" | ||
#include "CondCore/CondDB/interface/Session.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
|
||
namespace { | ||
boost::posix_time::ptime parseTimeFromIsoString( const std::string& isoString ){ | ||
boost::posix_time::time_input_facet* tif = new boost::posix_time::time_input_facet; | ||
tif->set_iso_extended_format(); | ||
std::istringstream iss( isoString ); | ||
iss.imbue(std::locale(std::locale::classic(),tif)); | ||
boost::posix_time::ptime ret; | ||
iss >> ret; | ||
return ret; | ||
} | ||
|
||
void getRunTimeParams( const RunInfo& runInfo, boost::posix_time::ptime& start, boost::posix_time::ptime& end ){ | ||
std::string startStr = runInfo.m_start_time_str; | ||
if( startStr != "null" ){ | ||
start = parseTimeFromIsoString( startStr ); | ||
} | ||
end = start; | ||
std::string stopStr = runInfo.m_stop_time_str; | ||
if( stopStr != "null" ){ | ||
end = parseTimeFromIsoString( stopStr ); | ||
} | ||
} | ||
} | ||
|
||
RunInfoUpdate::RunInfoUpdate( cond::persistency::Session& dbSession ): | ||
m_dbSession(dbSession){ | ||
} | ||
|
||
RunInfoUpdate::~RunInfoUpdate() {} | ||
|
||
void RunInfoUpdate::appendNewRun( const RunInfo& runInfo ){ | ||
cond::persistency::RunInfoEditor runInfoWriter = m_dbSession.editRunInfo(); | ||
boost::posix_time::ptime start; | ||
boost::posix_time::ptime end; | ||
getRunTimeParams( runInfo, start, end ); | ||
edm::LogInfo( "RunInfoUpdate" ) << "[RunInfoUpdate::" << __func__ << "]: Checking run " <<runInfo.m_run<<" for insertion in Condition DB"<< std::endl; | ||
runInfoWriter.insertNew( runInfo.m_run, start, end ); | ||
size_t newRuns = runInfoWriter.flush(); | ||
edm::LogInfo( "RunInfoUpdate" ) << "[RunInfoUpdate::" << __func__ << "]: "<<newRuns<<" new run(s) inserted."<< std::endl; | ||
} | ||
|
||
// only used in import command tool | ||
size_t RunInfoUpdate::import( size_t maxEntries, const std::string& sourceTag, cond::persistency::Session& sourceSession ){ | ||
cond::persistency::RunInfoEditor editor; | ||
std::cout << "# Loading tag "<<sourceTag<<"..."<<std::endl; | ||
cond::persistency::IOVProxy runInfoTag = sourceSession.readIov( sourceTag, true ); | ||
editor = m_dbSession.editRunInfo(); | ||
cond::Time_t lastRun = editor.getLastInserted(); | ||
std::cout <<"# Last run found in RunInfo db : "<<lastRun<<std::endl; | ||
cond::persistency::IOVProxy::Iterator it = runInfoTag.begin(); | ||
if( lastRun>0 ){ | ||
it = runInfoTag.find( lastRun+1 ); | ||
} | ||
if( it == runInfoTag.end() || (*it).since==lastRun ){ | ||
std::cout <<"# No more run found to be imported."<<std::endl; | ||
return 0; | ||
} | ||
size_t n_entries = 0; | ||
while( it != runInfoTag.end() && n_entries<=maxEntries){ | ||
auto h = (*it).payloadId; | ||
std::shared_ptr<RunInfo> runInfo = sourceSession.fetchPayload<RunInfo>( h ); | ||
if(runInfo->m_run != -1){ | ||
n_entries++; | ||
std::cout <<"# Inserting run #"<<runInfo->m_run<<" (from since="<<(*it).since<<")" << std::endl; | ||
boost::posix_time::ptime start; | ||
boost::posix_time::ptime end; | ||
getRunTimeParams( *runInfo, start, end ); | ||
editor.insert( runInfo->m_run, start, end ); | ||
} else { | ||
std::cout <<"# Skipping fake run #" <<std::endl; | ||
} | ||
it++; | ||
} | ||
editor.flush(); | ||
return n_entries; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters