CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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::createIOVContainerIfNecessary(){
00018   ora::Database& db = m_session.storage();
00019   if( !db.exists() ){
00020     if(m_log) *m_log << "INFO: Creating condition database in "<<db.connectionString()<<std::endl;
00021     db.create(cond::DbSession::COND_SCHEMA_VERSION);
00022     db.setAccessPermission(cond::DbSession::CONDITIONS_GENERAL_READER, false );
00023     db.setAccessPermission( cond::DbSession::CONDITIONS_GENERAL_WRITER, true );
00024   } 
00025   std::set<std::string> conts = db.containers();
00026   if( conts.find( cond::IOVNames::container() )==conts.end() ){
00027     if(m_log) *m_log << "INFO: Creating container \"" << cond::IOVNames::container() << "\" in "<<db.connectionString()<<std::endl;
00028     ora::Container c = db.createContainer( cond::IOVNames::container(), cond::IOVNames::container() );
00029     c.setAccessPermission( cond::DbSession::CONDITIONS_GENERAL_READER, false );
00030     c.setAccessPermission( cond::DbSession::CONDITIONS_GENERAL_WRITER, true );
00031     return true;
00032   }
00033   if(m_log) *m_log << "INFO: container \"" << cond::IOVNames::container() << "\" already exists in the database "<<db.connectionString()<<std::endl;
00034   return false;
00035 }
00036 
00037 bool cond::IOVSchemaUtility::dropIOVContainer(){
00038   ora::Database& db = m_session.storage();
00039   std::set<std::string> conts = db.containers();
00040   if( conts.find( cond::IOVNames::container() )==conts.end() ){
00041     if(m_log) *m_log << "WARNING: container \"" << cond::IOVNames::container() << "\" does not exist in the database "<<db.connectionString()<<std::endl;
00042     return false;
00043   }
00044   if(m_log) *m_log << "INFO: Dropping container \"" << cond::IOVNames::container() << "\" from "<<db.connectionString()<<std::endl;
00045   db.dropContainer( cond::IOVNames::container() );
00046   return true;
00047 }
00048 
00049 void cond::IOVSchemaUtility::createPayloadContainer( const std::string& payloadName, 
00050                                                      const std::string& payloadTypeName ){
00051   ora::Database& db = m_session.storage();
00052   std::set<std::string> conts = db.containers();
00053   if( conts.find( payloadName ) != conts.end()) throw cond::Exception("Container \""+payloadName+"\" already exists.");
00054   if(m_log) *m_log << "INFO: Creating container \"" << payloadName << "\" in "<<db.connectionString()<<std::endl;
00055   ora::Container c = db.createContainer( payloadTypeName, payloadName );
00056   c.setAccessPermission( cond::DbSession::CONDITIONS_GENERAL_READER, false );
00057   c.setAccessPermission( cond::DbSession::CONDITIONS_GENERAL_WRITER, true );
00058 }
00059 
00060 void cond::IOVSchemaUtility::dropPayloadContainer( const std::string& payloadName ){
00061   ora::Database& db = m_session.storage();
00062   std::set<std::string> conts = db.containers();
00063   if( conts.find( payloadName )!=conts.end() ){
00064     if(m_log) *m_log << "INFO: Dropping container \"" << payloadName << "\" from "<<db.connectionString()<<std::endl;
00065     db.dropContainer( payloadName );
00066     return;
00067   } 
00068   if(m_log) *m_log << "WARNING: container \"" << payloadName << "\" does not exist in the database "<<db.connectionString()<<std::endl;
00069 }
00070 
00071 void cond::IOVSchemaUtility::dropAll(){
00072   ora::Database& db = m_session.storage();
00073   if(m_log) *m_log << "INFO: Dropping database in "<<db.connectionString()<<std::endl;
00074   db.drop();
00075 }
00076