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 
20 
21 #include <set>
22 #include <vector>
23 #include <string>
24 #include <iostream>
25 
26 using namespace boost::python;
27 
28 namespace {
29 
30  // decode token
31 // std::string classID(std::string const & token) {
32 // static std::string const clid("CLID=");
33 // std::string::size_type s = token.find(clid) + clid.size();
34 // std::string::size_type e = token.find(']',s);
35 // return token.substr(s,e-s);
36 // }
37 
38 // // find and return
39 // boost::shared_ptr<cond::ClassInfo> pyInfo(std::string const & token) {
40 // // topinit();
41 // static std::string const prefix = cond::idCategories::pythonIDCategory + "/";
42 // std::string pluginName = prefix + classID(token);
43 // std::cout << "############# pluginName: " << pluginName << std::endl;
44 // return boost::shared_ptr<cond::ClassInfo>(cond::ClassInfoFactory::get()->create(pluginName));
45 // }
46 
47 // std::string moduleNameByTag(cond::CondDB & db, std::string const & tag) {
48 // //topinit();
49 // std::cout << "****************** tag: " << tag << std::endl;
50 // cond::IOVProxy iov = db.iov(tag);
51 // if (0==iov.size()) return std::string();
52 
53 // std::cout << "****************** resource: " << pyInfo(iov.begin()->token())->resource() << std::endl;
54 // return pyInfo(iov.begin()->token())->resource();
55 // }
56 
57 // std::string moduleNameByToken(std::string const & token) {
58 // //topinit();
59 // std::cout << "****************** token: " << token << std::endl;
60 // if (token.empty()) return std::string();
61 // std::cout << "****************** resource: " << pyInfo(token)->resource() << std::endl;
62 // return pyInfo(token)->resource();
63 // }
64 
65 // std::string moduleName(cond::CondDB & db, std::string const & ss) {
66 // //topinit();
67 // //assume tags never start with '['
68 // /*if (ss[0]=='[')*/ return moduleNameByToken(ss);
69 // //return moduleNameByTag(db,ss);
70 // }
71 
72  std::vector<std::string> payloadContainers(cond::IOVProxy & iov) {
73  //topinit();
74  std::vector<std::string> v_classes;
75  v_classes.insert(v_classes.end(),iov.payloadClasses().begin(),iov.payloadClasses().end());
76  return v_classes;
77  }
78 
79  std::vector<std::string> payloadModules(cond::CondDB & db, std::string const & tag) {
80  //topinit();
82  cond::IOVProxy iov = db.iov(tag);
83  std::vector<std::string> v_modules;
84  std::set<std::string>::const_iterator sBegin = iov.payloadClasses().begin();
85  std::set<std::string>::const_iterator sEnd = iov.payloadClasses().end();
86  for(std::set<std::string>::const_iterator s = sBegin; s != sEnd; ++s) {
87  boost::shared_ptr<cond::ClassInfo> cInfo(cond::ClassInfoFactory::get()->create(prefix + (*s)));
88  v_modules.push_back(cInfo->resource());
89  }
90  return v_modules;
91  }
92 
93 
94 // exceptionTranslator(const edm::Exception & e)
95 // {
96 // PyErr_SetString(PyExc_RuntimeError, e.what());
97 // }
98  void exceptionTranslator(const std::exception & e)
99  {
100  PyErr_SetString(PyExc_RuntimeError, e.what());
101  }
102 
103 
104  boost::python::tuple
105  getLogState(cond::LogDBEntry& l)
106  {
107  return boost::python::make_tuple(
108  l.logId,
109  l.destinationDB,
110  l.provenance,
111  l.usertext,
112  l.iovtag,
113  l.iovtimetype,
114  l.payloadIdx,
115  l.payloadClass,
116  l.payloadToken,
117  l.exectime,
118  l.execmessage
119  );
120  }
121 
122  boost::python::tuple
123  getTagState(cond::TagMetadata& l)
124  {
125  return boost::python::make_tuple(
126  l.tag,
127  l.pfn,
128  l.recordname,
129  l.labelname,
130  l.objectname
131  );
132  }
133 
134 
135  void append2VS(std::vector<std::string> & v, std::string s) {
136  v.push_back(s);
137  }
138 
139  boost::python::tuple unpackTime(cond::Time_t iValue) {
141  return boost::python::make_tuple(l.first,l.second);
142  }
143 
144 }
145 
146 BOOST_PYTHON_MODULE(pluginCondDBPyInterface) {
147 
148  def("append2VS",&append2VS);
149 
150  def("unpackTime",&unpackTime);
151 
152  class_<cond::LogDBEntry>("LogDBEntry")
153  .def("getState",getLogState)
154  .def_readonly("logId", &cond::LogDBEntry::logId)
155  .def_readonly("destinationDB", &cond::LogDBEntry::destinationDB)
156  .def_readonly("provenance", &cond::LogDBEntry::provenance)
157  .def_readonly("usertext", &cond::LogDBEntry::usertext)
158  .def_readonly("iovtag", &cond::LogDBEntry::iovtag)
159  .def_readonly("iovtimetype", &cond::LogDBEntry::iovtimetype)
160  .def_readonly("payloadIdx", &cond::LogDBEntry::payloadIdx)
161  .def_readonly("payloadClass", &cond::LogDBEntry::payloadClass)
162  .def_readonly("payloadToken", &cond::LogDBEntry::payloadToken)
163  .def_readonly("exectime", &cond::LogDBEntry::exectime)
164  .def_readonly("execmessage", &cond::LogDBEntry::execmessage)
165  ;
166 
167  class_<cond::TagMetadata>("TagEntry")
168  .def("getState",getTagState)
169  .def_readonly("tag", &cond::TagMetadata::tag)
170  .def_readonly("pfn", &cond::TagMetadata::pfn)
171  .def_readonly("record", &cond::TagMetadata::recordname)
172  .def_readonly("label", &cond::TagMetadata::labelname)
173  .def_readonly("object", &cond::TagMetadata::objectname)
174  ;
175 
176  class_<cond::GlobalTag >("GlobalTag", init<>())
177  .def("size", &cond::GlobalTag::size)
178  .add_property("elements", boost::python::range( &cond::GlobalTag::begin, &cond::GlobalTag::end))
179  ;
180 
181  class_<std::vector<std::string> >("VString")
182  .def(vector_indexing_suite<std::vector<std::string> >())
183  ;
184 
185  class_<std::vector<float> >("VFloat")
186  .def(vector_indexing_suite<std::vector<float> >())
187  ;
188 
189  class_<std::vector<int> >("VInt")
190  .def(vector_indexing_suite<std::vector<int> >())
191  ;
192 
193  enum_<cond::TimeType>("timetype")
194  .value("runnumber",cond::runnumber)
195  .value("timestamp",cond::timestamp)
196  .value("lumiid",cond::lumiid)
197  .value("hash",cond::hash)
198  .value("userid",cond::userid)
199  ;
200 
201  class_<cond::IOVElementProxy>("IOVElement", init<>())
202  .def(init<cond::Time_t, cond::Time_t, std::string>())
203  .def("since", &cond::IOVElementProxy::since)
204  .def("till", &cond::IOVElementProxy::till)
205  .def("payloadToken", &cond::IOVElementProxy::token, return_value_policy<copy_const_reference>())
206  ;
207 
208  class_<cond::IOVRange>("IOVRange", init<>())
209  .def("front", &cond::IOVRange::front)
210  .def("back", &cond::IOVRange::back)
211  .def("size", &cond::IOVRange::size)
212  .add_property("elements", boost::python::range(&cond::IOVRange::begin, &cond::IOVRange::end))
213  ;
214 
215  class_<cond::IOVProxy>("IOV", init<>())
216  .def("token", &cond::IOVProxy::token, return_value_policy<copy_const_reference>())
217  .def("head", &cond::IOVProxy::head)
218  .def("tail", &cond::IOVProxy::tail)
219  .def("range", &cond::IOVProxy::range)
220  .def("rangeHead", &cond::IOVProxy::rangeHead)
221  .def("rangeTail", &cond::IOVProxy::rangeTail)
222  .def("size", &cond::IOVProxy::size)
223  .def("timetype", &cond::IOVProxy::timetype)
224  .def("firstSince", &cond::IOVProxy::firstSince)
225  .def("lastTill", &cond::IOVProxy::lastTill)
226  .def("payloadClasses", payloadContainers)
227  .def("comment", &cond::IOVProxy::comment)
228  .def("revision",&cond::IOVProxy::revision)
229  .def("timestamp",&cond::IOVProxy::timestamp)
230  .add_property("elements", boost::python::range(&cond::IOVProxy::begin, &cond::IOVProxy::end))
231  ;
232 
233  class_<cond::FWIncantation>("FWIncantation", init<>());
234 
235  class_<cond::CondDB>("CondDB", init<>())
236  .def("allTags", &cond::CondDB::allTags)
237  .def("iov", &cond::CondDB::iov)
238  .def("iovToken", &cond::CondDB::iovToken)
239  .def("iovWithLib", &cond::CondDB::iovWithLib)
240  .def("payLoad", &cond::CondDB::payLoad)
241  .def("payloadModules",payloadModules)
242  .def("lastLogEntry", &cond::CondDB::lastLogEntry)
243  .def("lastLogEntryOK", &cond::CondDB::lastLogEntryOK)
244  .def("startTransaction", &cond::CondDB::startTransaction)
245  .def("startReadOnlyTransaction", &cond::CondDB::startReadOnlyTransaction)
246  .def("commitTransaction", &cond::CondDB::commitTransaction)
247  .def("closeSession", &cond::CondDB::closeSession)
248  ;
249 
250 
251  class_<cond::RDBMS>("RDBMS", init<>())
252  .def(init<std::string>())
253  .def(init<std::string, bool>())
254  .def(init<std::string, std::string>())
255  .def("setLogger",&cond::RDBMS::setLogger)
256  .def("getDB", &cond::RDBMS::getDB)
257  .def("getReadOnlyDB", &cond::RDBMS::getReadOnlyDB)
258  .def("globalTag", &cond::RDBMS::globalTag, return_value_policy<copy_const_reference>())
259  ;
260 
261 // register_exception_translator<edm::Exception>(exceptionTranslator);
262  register_exception_translator<std::exception>(exceptionTranslator);
263 
264 
265 }
std::string exectime
Definition: LogDBEntry.h:27
std::string usertext
Definition: LogDBEntry.h:20
std::string iovtimetype
Definition: LogDBEntry.h:22
cond::Time_t firstSince() const
Definition: IOVProxy.cc:284
std::string const pythonIDCategory("CondPythonID")
CondDB getDB(std::string const &db)
IOVRange rangeTail(cond::Time_t since, cond::Time_t till, int n) const
Definition: IOVProxy.cc:250
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:23
std::string comment() const
Definition: IOVProxy.cc:298
IOVProxy iovWithLib(std::string const &tag) const
std::string payloadToken
Definition: LogDBEntry.h:26
cond::Time_t timestamp() const
Definition: IOVProxy.cc:307
unsigned long long logId
Definition: LogDBEntry.h:17
std::string objectname
Definition: TagMetadata.h:12
TimeType timetype() const
Definition: IOVProxy.cc:280
tuple db
Definition: EcalCondDB.py:151
const_iterator begin() const
Definition: IOVProxy.h:128
void commitTransaction() const
IOVRange range(cond::Time_t since, cond::Time_t till) const
Definition: IOVProxy.cc:239
void startTransaction() const
std::string payloadClass
Definition: LogDBEntry.h:25
const_iterator begin() const
Definition: IOVProxy.h:188
cond::Time_t till() const
Definition: IOVProxy.h:71
std::string destinationDB
Definition: LogDBEntry.h:18
std::string allTags() const
const_iterator end() const
Definition: IOVProxy.h:193
cond::LogDBEntry lastLogEntry(std::string const &tag) const
IOVElementProxy front() const
Definition: IOVProxy.cc:152
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
tuple iov
Definition: o2o.py:307
std::string const & token() const
Definition: IOVProxy.h:75
IOVRange rangeHead(cond::Time_t since, cond::Time_t till, int n) const
Definition: IOVProxy.cc:244
std::string execmessage
Definition: LogDBEntry.h:28
#define end
Definition: vmac.h:38
int revision() const
Definition: IOVProxy.cc:303
std::string iovToken(std::string const &tag) const
void closeSession() const
const std::string & token()
Definition: IOVProxy.cc:214
const_iterator end() const
Definition: IOVProxy.h:133
int size() const
Definition: IOVProxy.cc:272
cond::Time_t lastTill() const
Definition: IOVProxy.cc:288
size_t size() const
Definition: IOVProxy.cc:162
cond::Time_t since() const
Definition: IOVProxy.h:67
std::string provenance
Definition: LogDBEntry.h:19
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:67
#define begin
Definition: vmac.h:31
void startReadOnlyTransaction() const
std::set< std::string > const & payloadClasses() const
Definition: IOVProxy.cc:293
IOVRange head(int n) const
Definition: IOVProxy.cc:256
CondDB getReadOnlyDB(std::string const &db)
std::string recordname
Definition: TagMetadata.h:10
JetCorrectorParameters::Definitions def
Definition: classes.h:12
std::string iovtag
Definition: LogDBEntry.h:21
SurfaceDeformation * create(int type, const std::vector< double > &params)
tuple size
Write out results.
T get(const Candidate &c)
Definition: component.h:56
void setLogger(std::string const &connstr)
IOVElementProxy back() const
Definition: IOVProxy.cc:157
IOVRange tail(int n) const
Definition: IOVProxy.cc:260
cond::UnpackedTime unpack(cond::Time_t iValue)