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 "CondCore/DBCommon/interface/DbTransaction.h"
00024 #include "CondCore/DBCommon/interface/DbScopedTransaction.h"
00025 #include "CondCore/DBCommon/interface/Exception.h"
00026 #include "CondCore/DBCommon/interface/FipProtocolParser.h"
00027 #include "CondCore/MetaDataService/interface/MetaData.h"
00028 #include "CondCore/DBCommon/interface/Logger.h"
00029 #include "CondCore/TagCollection/interface/TagCollectionRetriever.h"
00030
00031 #include <iterator>
00032 #include <iostream>
00033 #include <sstream>
00034
00035
00036 namespace cond {
00037
00038 static void topinit(){
00039 if(!edmplugin::PluginManager::isAvailable())
00040 edmplugin::PluginManager::configure(edmplugin::standard::config());
00041 return;
00042 }
00043
00044 namespace impl {
00045 struct FWMagic {
00046
00047 edm::AssertHandler ah;
00048 boost::shared_ptr<edm::ServiceRegistry::Operate> operate;
00049 };
00050 }
00051
00052 FWIncantation::~FWIncantation(){}
00053
00054
00055 FWIncantation::FWIncantation() : magic(new impl::FWMagic) {
00056 topinit();
00057
00058
00059
00060
00061 boost::shared_ptr<edm::Presence> theMessageServicePresence;
00062 theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->
00063 makePresence("MessageServicePresence").release());
00064
00065
00066
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 boost::shared_ptr<std::vector<edm::ParameterSet> > psets(new std::vector<edm::ParameterSet>);
00102 edm::ParameterSet pSet;
00103 pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
00104 psets->push_back(pSet);
00105
00106
00107 edm::ServiceToken tempToken(edm::ServiceRegistry::createSet(*psets.get()));
00108
00109
00110 magic->operate.reset(new edm::ServiceRegistry::Operate(tempToken));
00111
00112 }
00113
00114
00115
00116
00117 CondDB::CondDB() : me(){
00118
00119 }
00120 CondDB::CondDB(cond::DbSession& session, boost::shared_ptr<cond::Logger> ilog) :
00121 me(session), logger(ilog) {
00122
00123 }
00124
00125
00126 CondDB::CondDB(const CondDB & other) : me(other.me), logger(other.logger) {
00127 }
00128
00129 CondDB & CondDB::operator=(const CondDB & other) {
00130 if (this==&other) return *this;
00131 me = other.me;
00132 logger = other.logger;
00133 return *this;
00134 }
00135
00136 CondDB::~CondDB() {
00137 }
00138
00139
00140 std::string CondDB::allTags() const {
00141 std::ostringstream ss;
00142
00143 cond::MetaData metadata_svc(me);
00144 std::vector<std::string> alltags;
00145 me.transaction().start(true);
00146 metadata_svc.listAllTags(alltags);
00147 me.transaction().commit();
00148
00149 std::copy (alltags.begin(),
00150 alltags.end(),
00151 std::ostream_iterator<std::string>(ss," ")
00152 );
00153 return ss.str();
00154 }
00155
00156 std::string CondDB::iovToken(std::string const & tag) const {
00157 cond::MetaData metadata_svc(me);
00158 me.transaction().start(true);
00159 std::string token=metadata_svc.getToken(tag);
00160 me.transaction().commit();
00161 return token;
00162 }
00163
00164
00165 IOVProxy CondDB::iov(std::string const & tag) const {
00166 return IOVProxy(me,iovToken(tag),true,true);
00167 }
00168
00169 IOVProxy CondDB::iovWithLib(std::string const & tag) const {
00170 return IOVProxy(me,iovToken(tag),false,true);
00171 }
00172 IOVElementProxy CondDB::payLoad(std::string const & token) const {
00174 return IOVElementProxy(0,0,token,me);
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
00193
00194 RDBMS::RDBMS() : connection(new DbConnection) {
00195
00196 connection->configure( cond::CmsDefaults );
00197 }
00198 RDBMS::~RDBMS() {}
00199
00200 RDBMS::RDBMS(std::string const & authPath, bool debug) : connection(new DbConnection) {
00201
00202 connection->configuration().setAuthenticationPath(authPath);
00203 if (debug)
00204 connection->configuration().setMessageLevel( coral::Debug );
00205 else
00206 connection->configuration().setMessageLevel( coral::Error );
00207 connection->configuration().setPoolAutomaticCleanUp( false );
00208 connection->configuration().setConnectionTimeOut(0);
00209
00210 connection->configure();
00211 }
00212
00213 RDBMS::RDBMS(std::string const & user,std::string const & pass) : connection(new DbConnection) {
00214
00215 std::string userenv(std::string("CORAL_AUTH_USER=")+user);
00216 std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass);
00217 ::putenv(const_cast<char*>(userenv.c_str()));
00218 ::putenv(const_cast<char*>(passenv.c_str()));
00219 connection->configuration().setMessageLevel( coral::Error );
00220 connection->configuration().setPoolAutomaticCleanUp( false );
00221 connection->configuration().setConnectionTimeOut(0);
00222 connection->configure();
00223 }
00224
00225 void RDBMS::setLogger(std::string const & connstr) {
00226 DbSession loggerSession = connection->createSession();
00227 loggerSession.open( connstr );
00228 logger.reset(new cond::Logger(loggerSession));
00229 }
00230
00231
00232
00233 CondDB RDBMS::getDB(std::string const & db) {
00234 DbSession dbSession = connection->createSession();
00235 dbSession.open( db );
00236 return CondDB(dbSession,logger);
00237 }
00238
00239 CondDB RDBMS::getReadOnlyDB(std::string const & db) {
00240 DbSession dbSession = connection->createSession();
00241 dbSession.open( db, true );
00242 return CondDB(dbSession,logger);
00243 }
00244
00245 GlobalTag const & RDBMS::globalTag(std::string const & connstr,
00246 std::string const & gname,
00247 std::string const & prefix,
00248 std::string const & postfix) const {
00249 DbSession session = connection->createSession();
00250 session.open( connstr );
00251 cond::DbScopedTransaction tr(session);
00252 tr.start(true);
00253 TagCollectionRetriever gtr(session, prefix,postfix);
00254 const_cast<GlobalTag&>(m_globalTag).clear();
00255 gtr.getTagCollection(gname,const_cast<GlobalTag&>(m_globalTag));
00256 tr.commit();
00257 return m_globalTag;
00258 }
00259
00260
00261 }