Go to the documentation of this file.00001 #include "CondCore/Utilities/interface/CondPyInterface.h"
00002
00003 #include <exception>
00004 #include <iostream>
00005 #include <iomanip>
00006 #include <fstream>
00007 #include <string>
00008 #include <vector>
00009 #include "FWCore/Utilities/interface/Exception.h"
00010
00011 #include "FWCore/PluginManager/interface/ProblemTracker.h"
00012 #include "FWCore/Utilities/interface/Presence.h"
00013 #include "FWCore/PluginManager/interface/PresenceFactory.h"
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017
00018
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "FWCore/PluginManager/interface/PluginManager.h"
00021 #include "FWCore/PluginManager/interface/standard.h"
00022
00023 #include "FWCore/PluginManager/interface/PluginFactory.h"
00024
00025 #include "CondCore/DBCommon/interface/Auth.h"
00026 #include "CondCore/DBCommon/interface/DbTransaction.h"
00027 #include "CondCore/DBCommon/interface/Exception.h"
00028 #include "CondCore/DBCommon/interface/FipProtocolParser.h"
00029 #include "CondCore/DBCommon/interface/ClassID.h"
00030 #include "CondCore/MetaDataService/interface/MetaData.h"
00031 #include "CondCore/DBCommon/interface/Logger.h"
00032 #include "CondCore/TagCollection/interface/TagCollectionRetriever.h"
00033
00034 #include <iterator>
00035 #include <iostream>
00036 #include <sstream>
00037
00038
00039 namespace cond {
00040
00041 static void topinit(){
00042 if(!edmplugin::PluginManager::isAvailable())
00043 edmplugin::PluginManager::configure(edmplugin::standard::config());
00044 return;
00045 }
00046
00047 namespace impl {
00048 struct FWMagic {
00049
00050 edm::AssertHandler ah;
00051 boost::shared_ptr<edm::ServiceRegistry::Operate> operate;
00052 };
00053 }
00054
00055 FWIncantation::~FWIncantation(){}
00056
00057
00058 FWIncantation::FWIncantation() : magic(new impl::FWMagic) {
00059 topinit();
00060
00061
00062
00063
00064 boost::shared_ptr<edm::Presence> theMessageServicePresence;
00065 theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->
00066 makePresence("MessageServicePresence").release());
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 boost::shared_ptr<std::vector<edm::ParameterSet> > psets(new std::vector<edm::ParameterSet>);
00105 edm::ParameterSet pSet;
00106 pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
00107 psets->push_back(pSet);
00108
00109
00110 edm::ServiceToken tempToken(edm::ServiceRegistry::createSet(*psets.get()));
00111
00112
00113 magic->operate.reset(new edm::ServiceRegistry::Operate(tempToken));
00114
00115 }
00116
00117
00118
00119
00120 CondDB::CondDB() : me(){
00121
00122 }
00123 CondDB::CondDB(cond::DbSession& session, boost::shared_ptr<cond::Logger> ilog) :
00124 me(session), logger(ilog) {
00125
00126 }
00127
00128
00129 CondDB::CondDB(const CondDB & other) : me(other.me), logger(other.logger) {
00130 }
00131
00132 CondDB & CondDB::operator=(const CondDB & other) {
00133 if (this==&other) return *this;
00134 me = other.me;
00135 logger = other.logger;
00136 return *this;
00137 }
00138
00139 CondDB::~CondDB() {
00140 }
00141
00142
00143 std::string CondDB::allTags() const {
00144 std::ostringstream ss;
00145
00146 cond::MetaData metadata_svc(me);
00147 std::vector<std::string> alltags;
00148 metadata_svc.listAllTags(alltags);
00149
00150 std::copy (alltags.begin(),
00151 alltags.end(),
00152 std::ostream_iterator<std::string>(ss," ")
00153 );
00154 return ss.str();
00155 }
00156
00157 std::string CondDB::iovToken(std::string const & tag) const {
00158 cond::MetaData metadata_svc(me);
00159 std::string token=metadata_svc.getToken(tag);
00160 return token;
00161 }
00162
00163
00164 IOVProxy CondDB::iov(std::string const & tag) const {
00165 return IOVProxy(me,iovToken(tag));
00166 }
00167
00168 IOVProxy CondDB::iovWithLib(std::string const & tag) const {
00169 return IOVProxy(me,iovToken(tag));
00170 }
00171
00172 IOVElementProxy CondDB::payLoad(std::string const & token) const {
00174 return IOVElementProxy(0,0,token);
00175 }
00176
00177
00178 cond::LogDBEntry CondDB::lastLogEntry(std::string const & tag) const {
00179 cond::LogDBEntry entry;
00180 if (logger)
00181 logger->LookupLastEntryByTag(tag,entry,false);
00182 return entry;
00183 }
00184
00185 cond::LogDBEntry CondDB::lastLogEntryOK(std::string const & tag) const{
00186 cond::LogDBEntry entry;
00187 if (logger)
00188 logger->LookupLastEntryByTag(tag,entry,true);
00189 return entry;
00190 }
00191
00192 void CondDB::startTransaction() const {
00193 me.transaction().start();
00194 }
00195 void CondDB::startReadOnlyTransaction() const {
00196 me.transaction().start(true);
00197 }
00198 void CondDB::commitTransaction() const {
00199 me.transaction().commit();
00200 }
00201
00202 void CondDB::closeSession() const {
00203
00204 me.close();
00205 }
00206
00207 RDBMS::RDBMS() : connection(new DbConnection) {
00208
00209 connection->configure( cond::CmsDefaults );
00210 }
00211 RDBMS::~RDBMS() {}
00212
00213 RDBMS::RDBMS(std::string const & authPath, bool debug) : connection(new DbConnection) {
00214
00215 connection->configuration().setAuthenticationPath(authPath);
00216 if (debug)
00217 connection->configuration().setMessageLevel( coral::Debug );
00218 else
00219 connection->configuration().setMessageLevel( coral::Error );
00220 connection->configuration().setPoolAutomaticCleanUp( false );
00221 connection->configuration().setConnectionTimeOut(0);
00222
00223 connection->configure();
00224 }
00225
00226 RDBMS::RDBMS(std::string const & user,std::string const & pass) : connection(new DbConnection) {
00227
00228 std::string userenv(std::string("CORAL_AUTH_USER=")+user);
00229 std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass);
00230 ::putenv(const_cast<char*>(userenv.c_str()));
00231 ::putenv(const_cast<char*>(passenv.c_str()));
00232 connection->configuration().setMessageLevel( coral::Error );
00233 connection->configuration().setPoolAutomaticCleanUp( false );
00234 connection->configuration().setConnectionTimeOut(0);
00235 connection->configure();
00236 }
00237
00238 void RDBMS::setLogger(std::string const & connstr) {
00239 DbSession loggerSession = connection->createSession();
00240 logger.reset(new cond::Logger(loggerSession));
00241 logger->connect( connstr, true );
00242 }
00243
00244
00245
00246 CondDB RDBMS::getDB(std::string const & db) {
00247 DbSession dbSession = connection->createSession();
00248 dbSession.open( db, cond::Auth::COND_WRITER_ROLE );
00249 return CondDB(dbSession,logger);
00250 }
00251
00252 CondDB RDBMS::getReadOnlyDB(std::string const & db) {
00253 DbSession dbSession = connection->createSession();
00254 dbSession.open( db, cond::Auth::COND_READER_ROLE, true );
00255 return CondDB(dbSession,logger);
00256 }
00257
00258 GlobalTag const & RDBMS::globalTag(std::string const & connstr,
00259 std::string const & gname,
00260 std::string const & prefix,
00261 std::string const & postfix) const {
00262 DbSession session = connection->createSession();
00263 session.open( connstr, true );
00264 session.transaction().start( true );
00265 TagCollectionRetriever gtr(session, prefix,postfix);
00266 const_cast<GlobalTag&>(m_globalTag).clear();
00267 gtr.getTagCollection(gname,const_cast<GlobalTag&>(m_globalTag));
00268 session.transaction().commit();
00269 return m_globalTag;
00270 }
00271
00272
00273 }