CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CondPyWrappers.cc
Go to the documentation of this file.
1 // python wrappers for CondDB
7 
8 
11 
15 
16 #include <boost/python.hpp>
17 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
18 
19 using namespace boost::python;
20 
21 #include<iostream>
22 
23 namespace {
24 
25  // decode token
26  std::string classID(std::string const & token) {
27  static std::string const clid("CLID=");
28  std::string::size_type s = token.find(clid) + clid.size();
29  std::string::size_type e = token.find(']',s);
30  return token.substr(s,e-s);
31 
32  }
33  // find and return
34  boost::shared_ptr<cond::ClassInfo> pyInfo(std::string const & token) {
35  // topinit();
36  static std::string const prefix = cond::idCategories::pythonIDCategory + "/";
37  std::string pluginName = prefix + classID(token);
38  return boost::shared_ptr<cond::ClassInfo>(cond::ClassInfoFactory::get()->create(pluginName));
39  }
40 
41  std::string moduleNameByTag(cond::CondDB & db, std::string const & tag) {
42  //topinit();
43  cond::IOVProxy iov = db.iov(tag);
44  if (0==iov.size()) return std::string();
45  return pyInfo(iov.begin()->wrapperToken())->resource();
46  }
47 
48  std::string moduleNameByToken(std::string const & token) {
49  //topinit();
50  if (token.empty()) return std::string();
51  return pyInfo(token)->resource();
52  }
53 
54  std::string moduleName(cond::CondDB & db, std::string const & ss) {
55  //topinit();
56  //assume tags never start with '['
57  if (ss[0]=='[') return moduleNameByToken(ss);
58  return moduleNameByTag(db,ss);
59  }
60 
61 
62 // exceptionTranslator(const edm::Exception & e)
63 // {
64 // PyErr_SetString(PyExc_RuntimeError, e.what());
65 // }
66  void exceptionTranslator(const std::exception & e)
67  {
68  PyErr_SetString(PyExc_RuntimeError, e.what());
69  }
70 
71 
72  boost::python::tuple
73  getLogState(cond::LogDBEntry& l)
74  {
75  return boost::python::make_tuple(
76  l.logId,
77  l.destinationDB,
78  l.provenance,
79  l.usertext,
80  l.iovtag,
81  l.iovtimetype,
82  l.payloadIdx,
83  l.payloadName,
84  l.payloadToken,
86  l.exectime,
87  l.execmessage
88  );
89  }
90 
91  boost::python::tuple
92  getTagState(cond::TagMetadata& l)
93  {
94  return boost::python::make_tuple(
95  l.tag,
96  l.pfn,
97  l.recordname,
98  l.labelname,
99  l.objectname
100  );
101  }
102 
103 
104  void append2VS(std::vector<std::string> & v, std::string s) {
105  v.push_back(s);
106  }
107 
108  boost::python::tuple unpackTime(cond::Time_t iValue) {
110  return boost::python::make_tuple(l.first,l.second);
111  }
112 
113 }
114 
115 BOOST_PYTHON_MODULE(pluginCondDBPyInterface) {
116 
117  def("append2VS",&append2VS);
118 
119  def("unpackTime",&unpackTime);
120 
121  class_<cond::LogDBEntry>("LogDBEntry")
122  .def("getState",getLogState)
123  .def_readonly("logId", &cond::LogDBEntry::logId)
124  .def_readonly("destinationDB", &cond::LogDBEntry::destinationDB)
125  .def_readonly("provenance", &cond::LogDBEntry::provenance)
126  .def_readonly("usertext", &cond::LogDBEntry::usertext)
127  .def_readonly("iovtag", &cond::LogDBEntry::iovtag)
128  .def_readonly("iovtimetype", &cond::LogDBEntry::iovtimetype)
129  .def_readonly("payloadIdx", &cond::LogDBEntry::payloadIdx)
130  .def_readonly("payloadName", &cond::LogDBEntry::payloadName)
131  .def_readonly("payloadToken", &cond::LogDBEntry::payloadToken)
132  .def_readonly("payloadContainer", &cond::LogDBEntry::payloadContainer)
133  .def_readonly("exectime", &cond::LogDBEntry::exectime)
134  .def_readonly("execmessage", &cond::LogDBEntry::execmessage)
135  ;
136 
137  class_<cond::TagMetadata>("TagEntry")
138  .def("getState",getTagState)
139  .def_readonly("tag", &cond::TagMetadata::tag)
140  .def_readonly("pfn", &cond::TagMetadata::pfn)
141  .def_readonly("record", &cond::TagMetadata::recordname)
142  .def_readonly("label", &cond::TagMetadata::labelname)
143  .def_readonly("object", &cond::TagMetadata::objectname)
144  ;
145 
146  class_<cond::GlobalTag >("GlobalTag", init<>())
147  .def("size", &cond::GlobalTag::size)
148  .add_property("elements", boost::python::range( &cond::GlobalTag::begin, &cond::GlobalTag::end))
149  ;
150 
151  class_<std::vector<std::string> >("VString")
152  .def(vector_indexing_suite<std::vector<std::string> >())
153  ;
154 
155  class_<std::vector<float> >("VFloat")
156  .def(vector_indexing_suite<std::vector<float> >())
157  ;
158 
159  class_<std::vector<int> >("VInt")
160  .def(vector_indexing_suite<std::vector<int> >())
161  ;
162 
163  class_<cond::IOVElementProxy>("IOVElement", init<>())
164  .def("since", &cond::IOVElementProxy::since)
165  .def("till", &cond::IOVElementProxy::till)
166  .def("payloadToken", &cond::IOVElementProxy::wrapperToken, return_value_policy<copy_const_reference>())
167  ;
168 
169  enum_<cond::TimeType>("timetype")
170  .value("runnumber",cond::runnumber)
171  .value("timestamp",cond::timestamp)
172  .value("lumiid",cond::lumiid)
173  .value("userid",cond::userid)
174  ;
175 
176  class_<cond::IOVProxy>("IOV", init<>())
177  .def("size", &cond::IOVProxy::size)
178  .def("resetRange", &cond::IOVProxy::resetRange)
179  .def("setRange", &cond::IOVProxy::setRange)
180  .def("head", &cond::IOVProxy::head)
181  .def("tail", &cond::IOVProxy::tail)
182  .def("timetype", &cond::IOVProxy::timetype)
183  .def("payloadContainerName", &cond::IOVProxy::payloadContainerName)
184  .def("comment", &cond::IOVProxy::comment)
185  .def("revision",&cond::IOVProxy::revision)
186  .def("timestamp",&cond::IOVProxy::timestamp)
187  .add_property("elements", boost::python::range( &cond::IOVProxy::begin, &cond::IOVProxy::end))
188  ;
189 
190 
191  class_<cond::FWIncantation>("FWIncantation", init<>());
192 
193  class_<cond::CondDB>("CondDB", init<>())
194  .def("allTags", &cond::CondDB::allTags)
195  .def("iov", &cond::CondDB::iov)
196  .def("iovWithLib", &cond::CondDB::iovWithLib)
197  .def("payLoad", &cond::CondDB::payLoad)
198  .def("moduleName",moduleName)
199  .def("lastLogEntry", &cond::CondDB::lastLogEntry)
200  .def("lastLogEntryOK", &cond::CondDB::lastLogEntryOK)
201  ;
202 
203 
204  class_<cond::RDBMS>("RDBMS", init<>())
205  .def(init<std::string>())
206  .def(init<std::string, std::string>())
207  .def("setLogger",&cond::RDBMS::setLogger)
208  .def("getDB", &cond::RDBMS::getDB)
209  .def("getReadOnlyDB", &cond::RDBMS::getReadOnlyDB)
210  .def("globalTag", &cond::RDBMS::globalTag, return_value_policy<copy_const_reference>())
211  ;
212 
213 
214 // register_exception_translator<edm::Exception>(exceptionTranslator);
215  register_exception_translator<std::exception>(exceptionTranslator);
216 
217 
218 }
std::string exectime
Definition: LogDBEntry.h:18
std::string usertext
Definition: LogDBEntry.h:10
std::string iovtimetype
Definition: LogDBEntry.h:12
std::string const pythonIDCategory("CondPythonID")
CondDB getDB(std::string const &db)
IOVProxy iov(std::string const &tag) const
cond::LogDBEntry lastLogEntryOK(std::string const &tag) const
GlobalTag const & globalTag(std::string const &connstr, std::string const &gname, std::string const &prefix, std::string const &postfix) const
unsigned int payloadIdx
Definition: LogDBEntry.h:13
std::string comment() const
Definition: IOVProxy.cc:143
IOVProxy iovWithLib(std::string const &tag) const
std::string payloadToken
Definition: LogDBEntry.h:16
cond::Time_t timestamp() const
Definition: IOVProxy.cc:152
unsigned long long logId
Definition: LogDBEntry.h:7
std::string objectname
Definition: TagMetadata.h:12
tuple db
Definition: EcalCondDB.py:151
const_iterator begin() const
Definition: IOVProxy.h:86
std::string payloadName
Definition: LogDBEntry.h:15
cond::Time_t till() const
Definition: IOVProxy.h:39
std::string destinationDB
Definition: LogDBEntry.h:8
std::string allTags() const
uint16_t size_type
std::string payloadContainerName() const
Definition: IOVProxy.cc:135
const_iterator end() const
Definition: IOVProxy.h:91
TimeType timetype() const
Definition: IOVProxy.cc:129
cond::LogDBEntry lastLogEntry(std::string const &tag) const
std::string labelname
Definition: TagMetadata.h:11
IOVElementProxy payLoad(std::string const &token) const
unsigned long long Time_t
Definition: Time.h:16
std::string tag
Definition: TagMetadata.h:8
std::string const & wrapperToken() const
Definition: IOVProxy.h:41
tuple iov
Definition: o2o.py:307
void head(int n) const
Definition: IOVProxy.cc:103
std::string execmessage
Definition: LogDBEntry.h:19
#define end
Definition: vmac.h:38
int revision() const
Definition: IOVProxy.cc:148
void tail(int n) const
Definition: IOVProxy.cc:107
int size() const
Definition: IOVProxy.cc:121
std::string payloadContainer
Definition: LogDBEntry.h:17
void resetRange() const
Definition: IOVProxy.cc:88
cond::Time_t since() const
Definition: IOVProxy.h:38
std::string provenance
Definition: LogDBEntry.h:9
std::string pfn
Definition: TagMetadata.h:9
std::pair< unsigned int, unsigned int > UnpackedTime
Definition: Time.h:17
BOOST_PYTHON_MODULE(pluginEcalPyUtils)
Definition: EcalPyUtils.cc:63
#define begin
Definition: vmac.h:31
void setRange(cond::Time_t since, cond::Time_t till) const
Definition: IOVProxy.cc:94
string s
Definition: asciidump.py:422
CondDB getReadOnlyDB(std::string const &db)
std::string recordname
Definition: TagMetadata.h:10
JetCorrectorParameters::Definitions def
Definition: classes.h:10
std::string iovtag
Definition: LogDBEntry.h:11
tuple size
Write out results.
mathSSE::Vec4< T > v
T get(const Candidate &c)
Definition: component.h:56
void setLogger(std::string const &connstr)
cond::UnpackedTime unpack(cond::Time_t iValue)