CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CondCore/MetaDataService/src/MetaData.cc

Go to the documentation of this file.
00001 #include "CondCore/MetaDataService/interface/MetaData.h"
00002 #include "CondCore/ORA/interface/Database.h"
00003 #include "CondCore/DBCommon/interface/Exception.h"
00004 #include "RelationalAccess/SchemaException.h"
00005 #include <memory>
00006 //#include <iostream>
00007 
00008 
00009 namespace {
00010 
00011     std::string mdErrorPrefix(const std::string& source, const std::string& name) {
00012       return source+std::string(": metadata entry \"")+name+std::string("\" ");
00013     }
00014     
00015 
00016     void mdError(const std::string& source, const std::string& name, const std::string& mess) {
00017       throw cond::Exception(mdErrorPrefix(source,name)+mess);
00018     }
00019     
00020     void mdDuplicateEntryError(const std::string& source, const std::string& name) {
00021       mdError(source, name, "Already exists");
00022     }
00023 
00024     void mdNoEntry(const std::string& source, const std::string& name) {
00025       mdError(source, name, "does not exists");
00026     }
00027 
00028 }
00029 
00030 
00031 cond::MetaData::MetaData(cond::DbSession& userSession):m_userSession( userSession ){
00032 }
00033 cond::MetaData::~MetaData(){
00034 }
00035 bool 
00036 cond::MetaData::addMapping(const std::string& name, 
00037                            const std::string& iovtoken, 
00038                            cond::TimeType ){
00039   try{
00040     if(!m_userSession.storage().exists()) return false;
00041     ora::OId oid;
00042     oid.fromString( iovtoken );
00043     m_userSession.storage().setObjectName( name, oid );
00044   }catch( const coral::DuplicateEntryInUniqueKeyException& er ){
00045     mdDuplicateEntryError("addMapping",name);
00046   }catch(std::exception& er){
00047     mdError("MetaData::addMapping",name,er.what());
00048   }
00049   return true;
00050 }
00051 
00052 const std::string 
00053 cond::MetaData::getToken( const std::string& name ) const{
00054   bool ok=false;
00055   std::string iovtoken("");
00056   if(!m_userSession.storage().exists()) return iovtoken;
00057   try{
00058     ora::OId oid;
00059     ok = m_userSession.storage().getItemId( name, oid );
00060     if(ok) {
00061       iovtoken = oid.toString();
00062     }
00063   }catch(const std::exception& er){
00064     mdError("MetaData::getToken", name,er.what() );
00065   }
00066   if (!ok) mdNoEntry("MetaData::getToken", name);
00067   return iovtoken;
00068 }
00069 
00070 bool cond::MetaData::hasTag( const std::string& name ) const{
00071   bool result=false;
00072   if(!m_userSession.storage().exists()) return result;
00073   try{
00074     ora::OId oid;
00075     result = m_userSession.storage().getItemId( name, oid );
00076   }catch(const std::exception& er){
00077     mdError("MetaData::hasTag", name, er.what() );
00078   }
00079   return result;
00080 }
00081 
00082 void 
00083 cond::MetaData::listAllTags( std::vector<std::string>& result ) const{
00084   try{
00085     m_userSession.storage().listObjectNames( result );
00086   }catch(const std::exception& er){
00087     throw cond::Exception( std::string("MetaData::listAllTags: " )+er.what() );
00088   }
00089 }
00090 
00091 void 
00092 cond::MetaData::deleteAllEntries(){
00093   try{
00094     m_userSession.storage().eraseAllNames();
00095   }catch(const std::exception& er){
00096     throw cond::Exception( std::string("MetaData::deleteAllEntries: " )+er.what() );
00097   }
00098 }
00099 
00100 void cond::MetaData::deleteEntryByTag( const std::string& tag ){
00101   try{
00102     m_userSession.storage().eraseObjectName( tag );   
00103   }catch(const std::exception& er){
00104     throw cond::Exception( std::string("MetaData::deleteEntryByTag: " )+er.what() );
00105   }
00106 }