CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CondCore/IOVService/src/IOVSchemaUtility.cc

Go to the documentation of this file.
00001 #include "CondCore/DBCommon/interface/DbSession.h"
00002 #include "CondCore/DBCommon/interface/Exception.h"
00003 #include "CondCore/IOVService/interface/IOVSchemaUtility.h"
00004 #include "CondCore/IOVService/interface/IOVNames.h"
00005 
00006 cond::IOVSchemaUtility::IOVSchemaUtility(cond::DbSession& session):
00007   m_session( session ),
00008   m_log(0){
00009 }
00010 
00011 cond::IOVSchemaUtility::IOVSchemaUtility(cond::DbSession& session, std::ostream& log):
00012   m_session( session ),
00013   m_log(&log){
00014 }
00015 cond::IOVSchemaUtility::~IOVSchemaUtility(){}
00016 
00017 bool cond::IOVSchemaUtility::existsIOVContainer(){
00018   bool ret = false;
00019   ora::Database& db = m_session.storage();
00020   if( db.exists() ){
00021     std::set<std::string> conts = db.containers();
00022     ret = ( conts.find( cond::IOVNames::container() )!=conts.end() );
00023   }
00024   return ret;
00025 }
00026 
00027 bool cond::IOVSchemaUtility::createIOVContainer(){
00028   ora::Database& db = m_session.storage();
00029   if( !db.exists() ){
00030     if(m_log) *m_log << "INFO: Creating condition database in "<<db.connectionString()<<std::endl;
00031     db.create(cond::DbSession::COND_SCHEMA_VERSION);
00032   } 
00033   std::set<std::string> conts = db.containers();
00034   if( conts.find( cond::IOVNames::container() )==conts.end() ){
00035     if(m_log) *m_log << "INFO: Creating container \"" << cond::IOVNames::container() << "\" in "<<db.connectionString()<<std::endl;
00036     db.createContainer( cond::IOVNames::container(), cond::IOVNames::container() );
00037     return true;
00038   }
00039   if(m_log) *m_log << "INFO: container \"" << cond::IOVNames::container() << "\" already exists in the database "<<db.connectionString()<<std::endl;
00040   return false;
00041 }
00042 
00043 bool cond::IOVSchemaUtility::dropIOVContainer(){
00044   ora::Database& db = m_session.storage();
00045   std::set<std::string> conts = db.containers();
00046   if( conts.find( cond::IOVNames::container() )==conts.end() ){
00047     if(m_log) *m_log << "WARNING: container \"" << cond::IOVNames::container() << "\" does not exist in the database "<<db.connectionString()<<std::endl;
00048     return false;
00049   }
00050   if(m_log) *m_log << "INFO: Dropping container \"" << cond::IOVNames::container() << "\" from "<<db.connectionString()<<std::endl;
00051   db.dropContainer( cond::IOVNames::container() );
00052   return true;
00053 }
00054 
00055 void cond::IOVSchemaUtility::createPayloadContainer( const std::string& payloadName, 
00056                                                      const std::string& payloadTypeName ){
00057   ora::Database& db = m_session.storage();
00058   std::set<std::string> conts = db.containers();
00059   if( conts.find( payloadName ) != conts.end()) throw cond::Exception("Container \""+payloadName+"\" already exists.");
00060   if(m_log) *m_log << "INFO: Creating container \"" << payloadName << "\" in "<<db.connectionString()<<std::endl;
00061   db.createContainer( payloadTypeName, payloadName );
00062 }
00063 
00064 void cond::IOVSchemaUtility::dropPayloadContainer( const std::string& payloadName ){
00065   ora::Database& db = m_session.storage();
00066   std::set<std::string> conts = db.containers();
00067   if( conts.find( payloadName )!=conts.end() ){
00068     if(m_log) *m_log << "INFO: Dropping container \"" << payloadName << "\" from "<<db.connectionString()<<std::endl;
00069     db.dropContainer( payloadName );
00070     return;
00071   } 
00072   if(m_log) *m_log << "WARNING: container \"" << payloadName << "\" does not exist in the database "<<db.connectionString()<<std::endl;
00073 }
00074 
00075 void cond::IOVSchemaUtility::dropAll(){
00076   ora::Database& db = m_session.storage();
00077   if(m_log) *m_log << "INFO: Dropping database in "<<db.connectionString()<<std::endl;
00078   db.drop();
00079 }
00080