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 #include "CondFormats/Common/interface/TimeConversions.h"
00007
00008
00009 #include "CondCore/DBCommon/interface/ClassID.h"
00010 #include "CondCore/DBCommon/interface/Exception.h"
00011
00012 #include "FWCore/PluginManager/interface/PluginManager.h"
00013 #include "FWCore/PluginManager/interface/standard.h"
00014 #include "CondCore/TagCollection/interface/TagCollectionRetriever.h"
00015
00016 #include <boost/python.hpp>
00017 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
00018
00019 #include "CondCore/Utilities/interface/PayLoadInspector.h"
00020
00021 #include <set>
00022 #include <vector>
00023 #include <string>
00024 #include <iostream>
00025
00026 using namespace boost::python;
00027
00028 namespace {
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 std::vector<std::string> payloadContainers(cond::IOVProxy & iov) {
00073
00074 std::vector<std::string> v_classes;
00075 v_classes.insert(v_classes.end(),iov.payloadClasses().begin(),iov.payloadClasses().end());
00076 return v_classes;
00077 }
00078
00079 std::vector<std::string> payloadModules(cond::CondDB & db, std::string const & tag) {
00080
00081 std::string const prefix = cond::idCategories::pythonIDCategory + "/";
00082 cond::IOVProxy iov = db.iov(tag);
00083 std::vector<std::string> v_modules;
00084 std::set<std::string>::const_iterator sBegin = iov.payloadClasses().begin();
00085 std::set<std::string>::const_iterator sEnd = iov.payloadClasses().end();
00086 for(std::set<std::string>::const_iterator s = sBegin; s != sEnd; ++s) {
00087 boost::shared_ptr<cond::ClassInfo> cInfo(cond::ClassInfoFactory::get()->create(prefix + (*s)));
00088 v_modules.push_back(cInfo->resource());
00089 }
00090 return v_modules;
00091 }
00092
00093
00094
00095
00096
00097
00098 void exceptionTranslator(const std::exception & e)
00099 {
00100 PyErr_SetString(PyExc_RuntimeError, e.what());
00101 }
00102
00103
00104 boost::python::tuple
00105 getLogState(cond::LogDBEntry& l)
00106 {
00107 return boost::python::make_tuple(
00108 l.logId,
00109 l.destinationDB,
00110 l.provenance,
00111 l.usertext,
00112 l.iovtag,
00113 l.iovtimetype,
00114 l.payloadIdx,
00115 l.payloadClass,
00116 l.payloadToken,
00117 l.exectime,
00118 l.execmessage
00119 );
00120 }
00121
00122 boost::python::tuple
00123 getTagState(cond::TagMetadata& l)
00124 {
00125 return boost::python::make_tuple(
00126 l.tag,
00127 l.pfn,
00128 l.recordname,
00129 l.labelname,
00130 l.objectname
00131 );
00132 }
00133
00134
00135 void append2VS(std::vector<std::string> & v, std::string s) {
00136 v.push_back(s);
00137 }
00138
00139 boost::python::tuple unpackTime(cond::Time_t iValue) {
00140 cond::UnpackedTime l = cond::time::unpack(iValue);
00141 return boost::python::make_tuple(l.first,l.second);
00142 }
00143
00144 }
00145
00146 BOOST_PYTHON_MODULE(pluginCondDBPyInterface) {
00147
00148 def("append2VS",&append2VS);
00149
00150 def("unpackTime",&unpackTime);
00151
00152 class_<cond::LogDBEntry>("LogDBEntry")
00153 .def("getState",getLogState)
00154 .def_readonly("logId", &cond::LogDBEntry::logId)
00155 .def_readonly("destinationDB", &cond::LogDBEntry::destinationDB)
00156 .def_readonly("provenance", &cond::LogDBEntry::provenance)
00157 .def_readonly("usertext", &cond::LogDBEntry::usertext)
00158 .def_readonly("iovtag", &cond::LogDBEntry::iovtag)
00159 .def_readonly("iovtimetype", &cond::LogDBEntry::iovtimetype)
00160 .def_readonly("payloadIdx", &cond::LogDBEntry::payloadIdx)
00161 .def_readonly("payloadClass", &cond::LogDBEntry::payloadClass)
00162 .def_readonly("payloadToken", &cond::LogDBEntry::payloadToken)
00163 .def_readonly("exectime", &cond::LogDBEntry::exectime)
00164 .def_readonly("execmessage", &cond::LogDBEntry::execmessage)
00165 ;
00166
00167 class_<cond::TagMetadata>("TagEntry")
00168 .def("getState",getTagState)
00169 .def_readonly("tag", &cond::TagMetadata::tag)
00170 .def_readonly("pfn", &cond::TagMetadata::pfn)
00171 .def_readonly("record", &cond::TagMetadata::recordname)
00172 .def_readonly("label", &cond::TagMetadata::labelname)
00173 .def_readonly("object", &cond::TagMetadata::objectname)
00174 ;
00175
00176 class_<cond::GlobalTag >("GlobalTag", init<>())
00177 .def("size", &cond::GlobalTag::size)
00178 .add_property("elements", boost::python::range( &cond::GlobalTag::begin, &cond::GlobalTag::end))
00179 ;
00180
00181 class_<std::vector<std::string> >("VString")
00182 .def(vector_indexing_suite<std::vector<std::string> >())
00183 ;
00184
00185 class_<std::vector<float> >("VFloat")
00186 .def(vector_indexing_suite<std::vector<float> >())
00187 ;
00188
00189 class_<std::vector<int> >("VInt")
00190 .def(vector_indexing_suite<std::vector<int> >())
00191 ;
00192
00193 enum_<cond::TimeType>("timetype")
00194 .value("runnumber",cond::runnumber)
00195 .value("timestamp",cond::timestamp)
00196 .value("lumiid",cond::lumiid)
00197 .value("hash",cond::hash)
00198 .value("userid",cond::userid)
00199 ;
00200
00201 class_<cond::IOVElementProxy>("IOVElement", init<>())
00202 .def(init<cond::Time_t, cond::Time_t, std::string>())
00203 .def("since", &cond::IOVElementProxy::since)
00204 .def("till", &cond::IOVElementProxy::till)
00205 .def("payloadToken", &cond::IOVElementProxy::token, return_value_policy<copy_const_reference>())
00206 ;
00207
00208 class_<cond::IOVRange>("IOVRange", init<>())
00209 .def("front", &cond::IOVRange::front)
00210 .def("back", &cond::IOVRange::back)
00211 .def("size", &cond::IOVRange::size)
00212 .add_property("elements", boost::python::range(&cond::IOVRange::begin, &cond::IOVRange::end))
00213 ;
00214
00215 class_<cond::IOVProxy>("IOV", init<>())
00216 .def("token", &cond::IOVProxy::token, return_value_policy<copy_const_reference>())
00217 .def("head", &cond::IOVProxy::head)
00218 .def("tail", &cond::IOVProxy::tail)
00219 .def("range", &cond::IOVProxy::range)
00220 .def("rangeHead", &cond::IOVProxy::rangeHead)
00221 .def("rangeTail", &cond::IOVProxy::rangeTail)
00222 .def("size", &cond::IOVProxy::size)
00223 .def("timetype", &cond::IOVProxy::timetype)
00224 .def("firstSince", &cond::IOVProxy::firstSince)
00225 .def("lastTill", &cond::IOVProxy::lastTill)
00226 .def("payloadClasses", payloadContainers)
00227 .def("comment", &cond::IOVProxy::comment)
00228 .def("revision",&cond::IOVProxy::revision)
00229 .def("timestamp",&cond::IOVProxy::timestamp)
00230 .add_property("elements", boost::python::range(&cond::IOVProxy::begin, &cond::IOVProxy::end))
00231 ;
00232
00233 class_<cond::FWIncantation>("FWIncantation", init<>());
00234
00235 class_<cond::CondDB>("CondDB", init<>())
00236 .def("allTags", &cond::CondDB::allTags)
00237 .def("iov", &cond::CondDB::iov)
00238 .def("iovToken", &cond::CondDB::iovToken)
00239 .def("iovWithLib", &cond::CondDB::iovWithLib)
00240 .def("payLoad", &cond::CondDB::payLoad)
00241 .def("payloadModules",payloadModules)
00242 .def("lastLogEntry", &cond::CondDB::lastLogEntry)
00243 .def("lastLogEntryOK", &cond::CondDB::lastLogEntryOK)
00244 .def("startTransaction", &cond::CondDB::startTransaction)
00245 .def("startReadOnlyTransaction", &cond::CondDB::startReadOnlyTransaction)
00246 .def("commitTransaction", &cond::CondDB::commitTransaction)
00247 .def("closeSession", &cond::CondDB::closeSession)
00248 ;
00249
00250
00251 class_<cond::RDBMS>("RDBMS", init<>())
00252 .def(init<std::string>())
00253 .def(init<std::string, bool>())
00254 .def(init<std::string, std::string>())
00255 .def("setLogger",&cond::RDBMS::setLogger)
00256 .def("getDB", &cond::RDBMS::getDB)
00257 .def("getReadOnlyDB", &cond::RDBMS::getReadOnlyDB)
00258 .def("globalTag", &cond::RDBMS::globalTag, return_value_policy<copy_const_reference>())
00259 ;
00260
00261
00262 register_exception_translator<std::exception>(exceptionTranslator);
00263
00264
00265 }