Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:00

0001 #ifndef FWCore_PyBind11ParameterSet_PyBind11Wrapper_h
0002 #define FWCore_PyBind11ParameterSet_PyBind11Wrapper_h
0003 
0004 #include <vector>
0005 #include <string>
0006 #include <pybind11/pybind11.h>
0007 #include <pybind11/stl.h>
0008 #include <iostream>
0009 
0010 namespace edm {
0011   void pythonToCppException(const std::string& iType, const std::string& error);
0012 
0013   // utility to translate from an STL vector of strings to
0014   // a Python list
0015 
0016   template <typename T>
0017   pybind11::list toPython11List(const std::vector<T>& v) {
0018     pybind11::list result = pybind11::cast(v);
0019     return result;
0020   }
0021 
0022   // and back.  Destroys the input via pop()s - well probably not
0023   template <typename T>
0024   std::vector<T> toVector(pybind11::list& l) {
0025     std::vector<T> result;
0026     result.reserve(l.size());
0027     for (unsigned i = 0; i < l.size(); ++i) {
0028       result.push_back(l[i].cast<T>());
0029     }
0030     return result;
0031   }
0032 }  // namespace edm
0033 
0034 #endif