Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef FWCore_PyBind11ParameterSet_PyBind11ProcessDesc_h
0002 #define FWCore_PyBind11ParameterSet_PyBind11ProcessDesc_h
0003 
0004 #include "FWCore/PythonParameterSet/interface/Python11ParameterSet.h"
0005 
0006 #include <memory>
0007 #include <string>
0008 #include <vector>
0009 
0010 namespace edm {
0011   class ParameterSet;
0012   class ProcessDesc;
0013 }  // namespace edm
0014 
0015 class PyBind11InterpreterSentry {
0016 public:
0017   PyBind11InterpreterSentry(bool ownsInterpreter);
0018   ~PyBind11InterpreterSentry();
0019 
0020   pybind11::object mainModule;
0021 
0022 private:
0023   bool const ownsInterpreter_;
0024 };
0025 
0026 class PyBind11ProcessDesc {
0027 public:
0028   PyBind11ProcessDesc();
0029   /** This constructor will parse the given file or string
0030       and create two objects in python-land:
0031     * a PythonProcessDesc named 'processDesc'
0032     * a PythonParameterSet named 'processPSet'
0033     It decides whether it's a file or string by seeing if
0034     it ends in '.py'
0035   */
0036   PyBind11ProcessDesc(std::string const& config, bool isFile);
0037 
0038   PyBind11ProcessDesc(std::string const& config, bool isFile, const std::vector<std::string>& args);
0039 
0040   ~PyBind11ProcessDesc();
0041 
0042   Python11ParameterSet newPSet() const { return Python11ParameterSet(); }
0043 
0044   Python11ParameterSet& pset() { return theProcessPSet; }
0045 
0046   std::string dump() const;
0047 
0048   // makes a new (copy) of the ParameterSet
0049   std::unique_ptr<edm::ParameterSet> parameterSet() const;
0050 
0051   // makes a new (copy) of a ProcessDesc
0052   // For backward compatibility only.  Remove when no longer needed.
0053   std::unique_ptr<edm::ProcessDesc> processDesc() const;
0054 
0055 private:
0056   void prepareToRead();
0057   void read(std::string const& config, bool isFile);
0058   void readFile(std::string const& fileName);
0059   void readString(std::string const& pyConfig);
0060 
0061   Python11ParameterSet theProcessPSet;
0062   PyBind11InterpreterSentry theInterpreter;
0063 };
0064 
0065 #endif