00001
00002 #include "CondCore/DBCommon/interface/Exception.h"
00003 #include "CondCore/Utilities/interface/CondPyInterface.h"
00004 #include "CondCore/IOVService/interface/IOVProxy.h"
00005 #include "CondCore/DBCommon/interface/LogDBEntry.h"
00006
00007
00008 #include "CondCore/DBCommon/interface/ClassInfoLoader.h"
00009 #include "CondCore/DBCommon/interface/ClassID.h"
00010 #include "CondCore/DBCommon/interface/Exception.h"
00011
00012 #include "StorageSvc/DbReflex.h"
00013
00014 #include "FWCore/PluginManager/interface/PluginManager.h"
00015
00016
00017 #include <boost/python.hpp>
00018 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
00019
00020 using namespace boost::python;
00021
00022 #include<iostream>
00023
00024 namespace {
00025
00026
00027 boost::shared_ptr<cond::ClassInfo> pyInfo(std::string const & token) {
00028 static std::string const prefix = cond::idCategories::pythonIDCategory + "/";
00029 std::string pluginName = prefix + cond::classID(token);
00030 return boost::shared_ptr<cond::ClassInfo>(cond::ClassInfoFactory::get()->create(pluginName));
00031 }
00032
00033 std::string moduleNameByTag(cond::CondDB & db, std::string const & tag) {
00034 cond::IOVProxy iov = db.iov(tag);
00035 if (0==iov.size()) return std::string();
00036 return pyInfo(iov.begin()->payloadToken())->resource();
00037 }
00038
00039 std::string moduleNameByToken(std::string const & token) {
00040 if (token.empty()) return std::string();
00041 return pyInfo(token)->resource();
00042 }
00043
00044 std::string moduleName(cond::CondDB & db, std::string const & ss) {
00045
00046 if (ss[0]=='[') return moduleNameByToken(ss);
00047 return moduleNameByTag(db,ss);
00048 }
00049
00050
00051
00052
00053
00054
00055 void exceptionTranslator(const std::exception & e)
00056 {
00057 PyErr_SetString(PyExc_RuntimeError, e.what());
00058 }
00059
00060
00061 boost::python::tuple
00062 getState(cond::LogDBEntry& l)
00063 {
00064 return boost::python::make_tuple(
00065 l.logId,
00066 l.destinationDB,
00067 l.provenance,
00068 l.usertext,
00069 l.iovtag,
00070 l.iovtimetype,
00071 l.payloadIdx,
00072 l.payloadName,
00073 l.payloadToken,
00074 l.payloadContainer,
00075 l.exectime,
00076 l.execmessage
00077 );
00078 }
00079
00080
00081 void append2VS(std::vector<std::string> & v, std::string s) {
00082 v.push_back(s);
00083 }
00084
00085 }
00086
00087 BOOST_PYTHON_MODULE(pluginCondDBPyInterface) {
00088
00089 def("append2VS",&append2VS);
00090
00091 class_<cond::LogDBEntry>("LogDBEntry")
00092 .def("getState",getState)
00093 .def_readonly("logId", &cond::LogDBEntry::logId)
00094 .def_readonly("destinationDB", &cond::LogDBEntry::destinationDB)
00095 .def_readonly("provenance", &cond::LogDBEntry::provenance)
00096 .def_readonly("usertext", &cond::LogDBEntry::usertext)
00097 .def_readonly("iovtag", &cond::LogDBEntry::iovtag)
00098 .def_readonly("iovtimetype", &cond::LogDBEntry::iovtimetype)
00099 .def_readonly("payloadIdx", &cond::LogDBEntry::payloadIdx)
00100 .def_readonly("payloadName", &cond::LogDBEntry::payloadName)
00101 .def_readonly("payloadToken", &cond::LogDBEntry::payloadToken)
00102 .def_readonly("payloadContainer", &cond::LogDBEntry::payloadContainer)
00103 .def_readonly("exectime", &cond::LogDBEntry::exectime)
00104 .def_readonly("execmessage", &cond::LogDBEntry::execmessage)
00105 ;
00106
00107 class_<std::vector<std::string> >("VString")
00108 .def(vector_indexing_suite<std::vector<std::string> >())
00109 ;
00110
00111 class_<std::vector<float> >("VFloat")
00112 .def(vector_indexing_suite<std::vector<float> >())
00113 ;
00114
00115 class_<std::vector<int> >("VInt")
00116 .def(vector_indexing_suite<std::vector<int> >())
00117 ;
00118
00119 class_<cond::IOVElement>("IOVElement", init<>())
00120 .def("since", &cond::IOVElement::since)
00121 .def("till", &cond::IOVElement::till)
00122 .def("payloadToken", &cond::IOVElement::payloadToken, return_value_policy<copy_const_reference>())
00123 ;
00124
00125 class_<cond::IOVProxy>("IOV", init<>())
00126 .def("size", &cond::IOVProxy::size)
00127 .def("setRange", &cond::IOVProxy::setRange)
00128 .def("head", &cond::IOVProxy::head)
00129 .def("tail", &cond::IOVProxy::tail)
00130 .add_property("elements", range( &cond::IOVProxy::begin, &cond::IOVProxy::end))
00131 ;
00132
00133
00134 class_<cond::FWIncantation>("FWIncantation", init<>());
00135
00136 class_<cond::CondDB>("CondDB", init<>())
00137 .def("allTags", &cond::CondDB::allTags)
00138 .def("iov", &cond::CondDB::iov)
00139 .def("iovWithLib", &cond::CondDB::iovWithLib)
00140 .def("payLoad", &cond::CondDB::payLoad)
00141 .def("moduleName",moduleName)
00142 .def("lastLogEntry", &cond::CondDB::lastLogEntry)
00143 .def("lastLogEntryOK", &cond::CondDB::lastLogEntryOK)
00144 ;
00145
00146
00147 class_<cond::RDBMS>("RDBMS", init<>())
00148 .def(init<std::string>())
00149 .def(init<std::string, std::string>())
00150 .def("setLogger",&cond::RDBMS::setLogger)
00151 .def("getDB", &cond::RDBMS::getDB)
00152 ;
00153
00154
00155
00156 register_exception_translator<std::exception>(exceptionTranslator);
00157
00158
00159 }