Skip to content

Commit

Permalink
Modified RunInfo o2o to populate the conddb runinfo tables
Browse files Browse the repository at this point in the history
  • Loading branch information
ggovi committed Mar 10, 2017
1 parent 407ffab commit db560b9
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CondCore/PopCon/interface/PopConSourceHandler.h
Expand Up @@ -163,7 +163,10 @@ namespace popcon {
}

protected:


cond::persistency::Session& dbSession() const {
return m_session;
}

int add(value_type * payload, Summary * summary, Time_t time) {
Triplet t = {payload,summary,time};
Expand Down
6 changes: 6 additions & 0 deletions CondTools/RunInfo/bin/BuildFile.xml
@@ -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>
79 changes: 79 additions & 0 deletions CondTools/RunInfo/bin/conddb_import_runInfo.cpp
@@ -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);
}

24 changes: 24 additions & 0 deletions CondTools/RunInfo/interface/RunInfoUpdate.h
@@ -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
4 changes: 4 additions & 0 deletions CondTools/RunInfo/src/RunInfoHandler.cc
@@ -1,6 +1,7 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CondTools/RunInfo/interface/RunInfoHandler.h"
#include "CondTools/RunInfo/interface/RunInfoRead.h"
#include "CondTools/RunInfo/interface/RunInfoUpdate.h"
#include<iostream>
#include<vector>

Expand Down Expand Up @@ -67,4 +68,7 @@ void RunInfoHandler::getNewObjects() {
ss << "run number: " << m_since << ";";
m_userTextLog = ss.str();
edm::LogInfo( "RunInfoHandler" ) << "[" << "RunInfoHandler::" << __func__ << "]:" << m_name << ": END." << std::endl;
// update runinfo table in conditions db
RunInfoUpdate updater( dbSession() );
updater.appendNewRun( *r );
}
81 changes: 81 additions & 0 deletions CondTools/RunInfo/src/RunInfoUpdate.cc
@@ -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;
}

2 changes: 1 addition & 1 deletion CondTools/RunInfo/src/RunSummaryHandler.cc
Expand Up @@ -73,7 +73,7 @@ void RunSummaryHandler::getNewObjects() {

// transfer fake run for 1 to since for the first time
if (tagInfo().size==0){
m_to_transfer.push_back(std::make_pair((RunSummary*) (r->Fake_RunSummary()),1));
m_to_transfer.push_back(std::make_pair((RunSummary*) (r->Fake_RunSummary()),1));
}

// transfer also empty run if tag already existing
Expand Down

0 comments on commit db560b9

Please sign in to comment.