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 #include "FWCore/PluginManager/interface/ProblemTracker.h"
00011 #include "FWCore/Utilities/interface/Presence.h"
00012 #include "FWCore/PluginManager/interface/PresenceFactory.h"
00013 #include "FWCore/ParameterSet/interface/MakeParameterSets.h"
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017
00018 #include "CondCore/DBCommon/interface/CoralTransaction.h"
00019 #include "CondCore/DBCommon/interface/PoolTransaction.h"
00020 #include "CondCore/DBCommon/interface/ConnectionHandler.h"
00021 #include "CondCore/DBCommon/interface/Connection.h"
00022 #include "CondCore/DBCommon/interface/AuthenticationMethod.h"
00023 #include "CondCore/DBCommon/interface/SessionConfiguration.h"
00024 #include "CondCore/DBCommon/interface/MessageLevel.h"
00025 #include "CondCore/DBCommon/interface/DBSession.h"
00026 #include "CondCore/DBCommon/interface/Exception.h"
00027 #include "CondCore/DBCommon/interface/FipProtocolParser.h"
00028 #include "CondCore/MetaDataService/interface/MetaData.h"
00029 #include "CondCore/IOVService/interface/IOVService.h"
00030 #include "CondCore/IOVService/interface/IOVIterator.h"
00031 #include "CondCore/DBCommon/interface/Logger.h"
00032
00033 #include <iterator>
00034 #include <iostream>
00035 #include <sstream>
00036
00037
00038 namespace cond {
00039
00040 namespace impl {
00041 struct FWMagic {
00042
00043 edm::AssertHandler ah;
00044 boost::shared_ptr<edm::ServiceRegistry::Operate> operate;
00045 };
00046 }
00047
00048 FWIncantation::~FWIncantation(){}
00049
00050
00051 FWIncantation::FWIncantation() : magic(new impl::FWMagic) {
00052
00053
00054
00055
00056
00057 boost::shared_ptr<edm::Presence> theMessageServicePresence;
00058 theMessageServicePresence = boost::shared_ptr<edm::Presence>(edm::PresenceFactory::get()->
00059 makePresence("MessageServicePresence").release());
00060
00061
00062 std::string config =
00063 "process x = {"
00064 "service = MessageLogger {"
00065 "untracked vstring destinations = {'infos.mlog','warnings.mlog'}"
00066 "untracked PSet infos = {"
00067 "untracked string threshold = 'INFO'"
00068 "untracked PSet default = {untracked int32 limit = 1000000}"
00069 "untracked PSet FwkJob = {untracked int32 limit = 0}"
00070 "}"
00071 "untracked PSet warnings = {"
00072 "untracked string threshold = 'WARNING'"
00073 "untracked PSet default = {untracked int32 limit = 1000000}"
00074 "}"
00075 "untracked vstring fwkJobReports = {'FrameworkJobReport.xml'}"
00076 "untracked vstring categories = {'FwkJob'}"
00077 "untracked PSet FrameworkJobReport.xml = {"
00078 "untracked PSet default = {untracked int32 limit = 0}"
00079 "untracked PSet FwkJob = {untracked int32 limit = 10000000}"
00080 "}"
00081 "}"
00082 "service = JobReportService{}"
00083 "service = SiteLocalConfigService{}"
00084 "}";
00085
00086
00087 boost::shared_ptr<std::vector<edm::ParameterSet> > pServiceSets;
00088 boost::shared_ptr<edm::ParameterSet> params_;
00089 edm::makeParameterSets(config, params_, pServiceSets);
00090
00091
00092 edm::ServiceToken tempToken(edm::ServiceRegistry::createSet(*pServiceSets.get()));
00093
00094
00095 magic->operate.reset(new edm::ServiceRegistry::Operate(tempToken));
00096
00097 }
00098
00099
00100
00101
00102 CondDB::CondDB() : me(0){}
00103 CondDB::CondDB(cond::Connection * conn, boost::shared_ptr<cond::Logger> ilog) :
00104 me(conn), logger(ilog) {
00105 }
00106
00107
00108 CondDB::CondDB(const CondDB & other) : me(other.me), logger(other.logger) {
00109 other.me=0;
00110 }
00111
00112 CondDB & CondDB::operator=(const CondDB & other) {
00113 if (me==other.me) return *this;
00114 if (me!=0) me->disconnect();
00115 me = other.me;
00116 logger = other.logger;
00117 other.me=0;
00118 return *this;
00119 }
00120
00121 CondDB::~CondDB() {
00122 if (me)
00123 me->disconnect();
00124 }
00125
00126
00127 std::string CondDB::allTags() const {
00128 std::ostringstream ss;
00129
00130 cond::CoralTransaction& coraldb=me->coralTransaction();
00131 cond::MetaData metadata_svc(coraldb);
00132 std::vector<std::string> alltags;
00133 coraldb.start(true);
00134 metadata_svc.listAllTags(alltags);
00135 coraldb.commit();
00136
00137 std::copy (alltags.begin(),
00138 alltags.end(),
00139 std::ostream_iterator<std::string>(ss," ")
00140 );
00141 return ss.str();
00142 }
00143
00144 std::string CondDB::iovToken(std::string const & tag) const {
00145 cond::CoralTransaction& coraldb=me->coralTransaction();
00146 cond::MetaData metadata_svc(coraldb);
00147 coraldb.start(true);
00148 std::string token=metadata_svc.getToken(tag);
00149 coraldb.commit();
00150 return token;
00151 }
00152
00153 IOVProxy CondDB::iov(std::string const & tag) const {
00154 return IOVProxy(me->poolTransaction(),iovToken(tag),true);
00155 }
00156
00157 IOVProxy CondDB::iovWithLib(std::string const & tag) const {
00158 return IOVProxy(me->poolTransaction(),iovToken(tag),false);
00159 }
00160
00161 IOVElement CondDB::payLoad(std::string const & token) const {
00162 return IOVElement(0,0,token,&me->poolTransaction());
00163
00164 }
00165
00166
00167 cond::LogDBEntry CondDB::lastLogEntry(std::string const & tag) const {
00168 cond::LogDBEntry entry;
00169 if (logger)
00170 logger->LookupLastEntryByTag(tag,entry,false);
00171 return entry;
00172 }
00173
00174 cond::LogDBEntry CondDB::lastLogEntryOK(std::string const & tag) const{
00175 cond::LogDBEntry entry;
00176 if (logger)
00177 logger->LookupLastEntryByTag(tag,entry,true);
00178 return entry;
00179 }
00180
00181
00182
00183 RDBMS::RDBMS() : session(new DBSession) {
00184 session->configuration().setAuthenticationMethod( cond::XML );
00185 session->configuration().setMessageLevel( cond::Error );
00186 session->open();
00187 }
00188 RDBMS::~RDBMS() {}
00189
00190 RDBMS::RDBMS(std::string const & authPath) : session(new DBSession) {
00191 std::string authenv(std::string("CORAL_AUTH_PATH=")+authPath);
00192 ::putenv(const_cast<char*>(authenv.c_str()));
00193 session->configuration().setAuthenticationMethod( cond::XML );
00194 session->configuration().setMessageLevel( cond::Error );
00195 session->open();
00196 }
00197
00198 RDBMS::RDBMS(std::string const & user,std::string const & pass) : session(new DBSession) {
00199 std::string userenv(std::string("CORAL_AUTH_USER=")+user);
00200 std::string passenv(std::string("CORAL_AUTH_PASSWORD=")+pass);
00201 ::putenv(const_cast<char*>(userenv.c_str()));
00202 ::putenv(const_cast<char*>(passenv.c_str()));
00203 session->configuration().setAuthenticationMethod( cond::Env );
00204 session->configuration().setMessageLevel( cond::Error );
00205 session->open();
00206 }
00207
00208 void RDBMS::setLogger(std::string const & connstr) {
00209 cond::ConnectionHandler::Instance().registerConnection(connstr,*session,-1);
00210 cond::Connection & conn = *cond::ConnectionHandler::Instance().getConnection(connstr);
00211 conn.connect(session.get());
00212 logger.reset(new cond::Logger(&conn));
00213 }
00214
00215
00216
00217 CondDB RDBMS::getDB(std::string const & db) {
00218 cond::ConnectionHandler::Instance().registerConnection(db,*session,-1);
00219 cond::Connection & conn = *cond::ConnectionHandler::Instance().getConnection(db);
00220 conn.connect(session.get());
00221 return CondDB(&conn,logger);
00222 }
00223
00224 }