CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PythonModule.h
Go to the documentation of this file.
1 #ifndef FWCore_PythonParameterSet_PythonModule_h
2 #define FWCore_PythonParameterSet_PythonModule_h
3 
7 
15 
16 #include <string>
17 
18 // This is to give some special handling to cms::Exceptions thrown
19 // in C++ code called by python. Only at the very top level do
20 // we need the exception message returned by the function "what".
21 // We only need the central message here as this will get converted
22 // back into a cms::Exception again when control rises back into
23 // the C++ code. If necessary it would probably be possible to
24 // improve these messages even more by adding something in the python
25 // to add module type and label context to the messages being caught
26 // here. At this point we did not think it worth the time to implement.
27 namespace {
28  void translator(cms::Exception const& ex) {
29  PyErr_SetString(PyExc_RuntimeError, ex.message().c_str());
30  }
31 }
32 
33 BOOST_PYTHON_MODULE(libFWCoreParameterSet)
34 {
35  boost::python::register_exception_translator<cms::Exception>(translator);
36 
37  boost::python::class_<edm::InputTag>("InputTag", boost::python::init<std::string>())
38  .def(boost::python::init<std::string, std::string, std::string>())
39  .def(boost::python::init<std::string, std::string>())
40  .def("label", &edm::InputTag::label, boost::python::return_value_policy<boost::python::copy_const_reference>())
41  .def("instance", &edm::InputTag::instance, boost::python::return_value_policy<boost::python::copy_const_reference>())
42  .def("process", &edm::InputTag::process, boost::python::return_value_policy<boost::python::copy_const_reference>())
43  ;
44 
45  boost::python::class_<edm::ESInputTag>("ESInputTag", boost::python::init<std::string>())
46  .def(boost::python::init<std::string, std::string>())
47  .def("module", &edm::ESInputTag::module, boost::python::return_value_policy<boost::python::copy_const_reference>())
48  .def("data", &edm::ESInputTag::data, boost::python::return_value_policy<boost::python::copy_const_reference>())
49  ;
50 
51  boost::python::class_<edm::EventID>("EventID", boost::python::init<unsigned int, unsigned int, unsigned int>())
52  .def("run", &edm::EventID::run)
53  .def("luminosityBlock", &edm::EventID::luminosityBlock)
54  .def("event", &edm::EventID::event)
55  ;
56 
57  boost::python::class_<edm::LuminosityBlockID>("LuminosityBlockID", boost::python::init<unsigned int, unsigned int>())
58  .def("run", &edm::LuminosityBlockID::run)
59  .def("luminosityBlock", &edm::LuminosityBlockID::luminosityBlock)
60  ;
61 
62  boost::python::class_<edm::FileInPath>("FileInPath", boost::python::init<std::string>())
63  .def("fullPath", &edm::FileInPath::fullPath)
64  .def("relativePath", &edm::FileInPath::relativePath)
65  ;
66 
67  boost::python::class_<edm::LuminosityBlockRange>("LuminosityBlockRange", boost::python::init<unsigned int, unsigned int, unsigned int, unsigned int>())
69  .def("startSub", &edm::LuminosityBlockRange::startLumi)
71  .def("endSub", &edm::LuminosityBlockRange::endLumi)
72  ;
73 
74  boost::python::class_<edm::EventRange>("EventRange", boost::python::init<unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int>())
75  .def("start", &edm::EventRange::startRun)
76  .def("startLumi", &edm::EventRange::startLumi)
77  .def("startSub", &edm::EventRange::startEvent)
78  .def("end", &edm::EventRange::endRun)
79  .def("endLumi", &edm::EventRange::endLumi)
80  .def("endSub", &edm::EventRange::endEvent)
81  ;
82 
83  boost::python::class_<PythonParameterSet>("ParameterSet")
84  .def("addInt32", &PythonParameterSet::addParameter<int>)
85  .def("getInt32", &PythonParameterSet::getParameter<int>)
86  .def("addVInt32", &PythonParameterSet::addParameters<int>)
87  .def("getVInt32", &PythonParameterSet::getParameters<int>)
88  .def("addUInt32", &PythonParameterSet::addParameter<unsigned int>)
89  .def("getUInt32", &PythonParameterSet::getParameter<unsigned int>)
90  .def("addVUInt32", &PythonParameterSet::addParameters<unsigned int>)
91  .def("getVUInt32", &PythonParameterSet::getParameters<unsigned int>)
92  .def("addInt64", &PythonParameterSet::addParameter<long long>)
93  .def("getInt64", &PythonParameterSet::getParameter<long long>)
94  .def("addUInt64", &PythonParameterSet::addParameter<unsigned long long>)
95  .def("getUInt64", &PythonParameterSet::getParameter<unsigned long long>)
96  .def("addVInt64", &PythonParameterSet::addParameters<long long>)
97  .def("getVInt64", &PythonParameterSet::getParameters<long long>)
98  .def("addVUInt64", &PythonParameterSet::addParameters<unsigned long long>)
99  .def("getVUInt64", &PythonParameterSet::getParameters<unsigned long long>)
100  .def("addDouble", &PythonParameterSet::addParameter<double>)
101  .def("getDouble", &PythonParameterSet::getParameter<double>)
102  .def("addVDouble", &PythonParameterSet::addParameters<double>)
103  .def("getVDouble", &PythonParameterSet::getParameters<double>)
104  .def("addBool", &PythonParameterSet::addParameter<bool>)
105  .def("getBool", &PythonParameterSet::getParameter<bool>)
106  .def("addString", &PythonParameterSet::addParameter<std::string>)
107  .def("getString", &PythonParameterSet::getParameter<std::string>)
108  .def("addVString", &PythonParameterSet::addParameters<std::string>)
109  .def("getVString", &PythonParameterSet::getParameters<std::string>)
110  .def("addInputTag", &PythonParameterSet::addParameter<edm::InputTag>)
111  .def("getInputTag", &PythonParameterSet::getParameter<edm::InputTag>)
112  .def("addVInputTag", &PythonParameterSet::addParameters<edm::InputTag>)
113  .def("getVInputTag", &PythonParameterSet::getParameters<edm::InputTag>)
114  .def("addESInputTag", &PythonParameterSet::addParameter<edm::ESInputTag>)
115  .def("getESInputTag", &PythonParameterSet::getParameter<edm::ESInputTag>)
116  .def("addVESInputTag", &PythonParameterSet::addParameters<edm::ESInputTag>)
117  .def("getVESInputTag", &PythonParameterSet::getParameters<edm::ESInputTag>)
118  .def("addEventID", &PythonParameterSet::addParameter<edm::EventID>)
119  .def("getEventID", &PythonParameterSet::getParameter<edm::EventID>)
120  .def("addVEventID", &PythonParameterSet::addParameters<edm::EventID>)
121  .def("getVEventID", &PythonParameterSet::getParameters<edm::EventID>)
122  .def("addLuminosityBlockID", &PythonParameterSet::addParameter<edm::LuminosityBlockID>)
123  .def("getLuminosityBlockID", &PythonParameterSet::getParameter<edm::LuminosityBlockID>)
124  .def("addVLuminosityBlockID", &PythonParameterSet::addParameters<edm::LuminosityBlockID>)
125  .def("getVLuminosityBlockID", &PythonParameterSet::getParameters<edm::LuminosityBlockID>)
126  .def("addLuminosityBlockRange", &PythonParameterSet::addParameter<edm::LuminosityBlockRange>)
127  .def("getLuminosityBlockRange", &PythonParameterSet::getParameter<edm::LuminosityBlockRange>)
128  .def("addVLuminosityBlockRange", &PythonParameterSet::addParameters<edm::LuminosityBlockRange>)
129  .def("getVLuminosityBlockRange", &PythonParameterSet::getParameters<edm::LuminosityBlockRange>)
130  .def("addEventRange", &PythonParameterSet::addParameter<edm::EventRange>)
131  .def("getEventRange", &PythonParameterSet::getParameter<edm::EventRange>)
132  .def("addVEventRange", &PythonParameterSet::addParameters<edm::EventRange>)
133  .def("getVEventRange", &PythonParameterSet::getParameters<edm::EventRange>)
134  .def("addPSet", &PythonParameterSet::addPSet)
135  .def("getPSet", &PythonParameterSet::getPSet)
136  .def("addVPSet", &PythonParameterSet::addVPSet)
137  .def("getVPSet", &PythonParameterSet::getVPSet)
138  .def("addFileInPath", &PythonParameterSet::addParameter<edm::FileInPath>)
139  .def("getFileInPath", &PythonParameterSet::getParameter<edm::FileInPath>)
140  .def("newInputTag", &PythonParameterSet::newInputTag)
141  .def("newESInputTag", &PythonParameterSet::newESInputTag)
142  .def("newEventID", &PythonParameterSet::newEventID)
143  .def("newLuminosityBlockID", &PythonParameterSet::newLuminosityBlockID)
144  .def("newLuminosityBlockRange", &PythonParameterSet::newLuminosityBlockRange)
145  .def("newEventRange", &PythonParameterSet::newEventRange)
146  .def("addNewFileInPath", &PythonParameterSet::addNewFileInPath)
147  .def("newPSet", &PythonParameterSet::newPSet)
148  .def("dump", &PythonParameterSet::dump)
149  ;
150 
151  boost::python::class_<PythonProcessDesc>("ProcessDesc", boost::python::init<>())
152  .def(boost::python::init<std::string>())
153  .def("newPSet", &PythonProcessDesc::newPSet)
154  .def("dump", &PythonProcessDesc::dump)
155  ;
156 }
157 #endif
RunNumber_t run() const
Definition: EventID.h:42
std::string dump() const
EventNumber_t event() const
Definition: EventID.h:44
edm::EventID newEventID(unsigned int run, unsigned int lumi, unsigned int event)
PythonParameterSet getPSet(bool tracked, std::string const &name) const
LumiNumber_t startLumi() const
Definition: EventRange.h:51
PythonParameterSet newPSet() const
std::string message() const
Definition: Exception.cc:187
RunNumber_t startRun() const
Definition: EventRange.h:49
std::string relativePath() const
Definition: FileInPath.cc:152
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:43
LuminosityBlockNumber_t startLumi() const
BOOST_PYTHON_MODULE(pluginBeamSpotObjectsPyInterface)
RunNumber_t endRun() const
Definition: EventRange.h:50
EventNumber_t endEvent() const
Definition: EventRange.h:54
boost::python::list getVPSet(bool tracked, std::string const &name)
edm::LuminosityBlockID newLuminosityBlockID(unsigned int run, unsigned int lumi)
RunNumber_t run() const
std::string dump() const
edm::ESInputTag newESInputTag(std::string const &module, std::string const &data)
edm::EventRange newEventRange(unsigned int start, unsigned int startLumi, unsigned int startSub, unsigned int end, unsigned int endLumi, unsigned int endSub)
void addPSet(bool tracked, std::string const &name, PythonParameterSet const &ppset)
LumiNumber_t endLumi() const
Definition: EventRange.h:52
const std::string & data() const
Definition: ESInputTag.h:106
edm::LuminosityBlockRange newLuminosityBlockRange(unsigned int start, unsigned int startSub, unsigned int end, unsigned int endSub)
RunNumber_t startRun() const
edm::InputTag newInputTag(std::string const &label, std::string const &instance, std::string const &process)
EventNumber_t startEvent() const
Definition: EventRange.h:53
LuminosityBlockNumber_t luminosityBlock() const
void addNewFileInPath(bool tracked, std::string const &name, std::string const &value)
std::string const & label() const
Definition: InputTag.h:42
std::string const & process() const
Definition: InputTag.h:46
void addVPSet(bool tracked, std::string const &name, boost::python::list value)
RunNumber_t endRun() const
LuminosityBlockNumber_t endLumi() const
std::string fullPath() const
Definition: FileInPath.cc:165
const std::string & module() const
Definition: ESInputTag.h:101
JetCorrectorParameters::Definitions def
Definition: classes.h:6
std::string const & instance() const
Definition: InputTag.h:43
PythonParameterSet newPSet() const