CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/FWCore/PythonParameterSet/interface/PythonParameterSet.h

Go to the documentation of this file.
00001 #ifndef FWCore_PythonParameterSet_PythonParameterSet_h
00002 #define FWCore_PythonParameterSet_PythonParameterSet_h
00003 
00004 #include "FWCore/PythonParameterSet/interface/BoostPython.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/PythonParameterSet/src/PythonWrapper.h"
00007 
00008 #include "FWCore/Utilities/interface/InputTag.h"
00009 #include "FWCore/Utilities/interface/ESInputTag.h"
00010 #include "DataFormats/Provenance/interface/EventRange.h"
00011 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
00012 #include "DataFormats/Provenance/interface/LuminosityBlockRange.h"
00013 #include "DataFormats/Provenance/interface/EventID.h"
00014 
00015 #include <string>
00016 #include <vector>
00017 
00018 class PythonParameterSet {
00019 public:
00020   PythonParameterSet();
00021 
00022   PythonParameterSet(edm::ParameterSet const& p)
00023   : theParameterSet(p) {}
00024 
00025   template<typename T>
00026   T
00027   getParameter(bool tracked, std::string const& name) const {
00028     T result;
00029     if(tracked) {
00030       result = theParameterSet.template getParameter<T>(name);
00031     } else {
00032       result = theParameterSet.template getUntrackedParameter<T>(name);
00033     }
00034     return result;
00035   }
00036 
00037 
00038   template<typename T>
00039   void
00040   addParameter(bool tracked, std::string const& name, T const& value) {
00041    if(tracked) {
00042      theParameterSet.template addParameter<T>(name, value);
00043    } else {
00044      theParameterSet.template addUntrackedParameter<T>(name, value);
00045    }
00046   }
00047 
00048 
00050   template<typename T>
00051   boost::python::list
00052   getParameters(bool tracked, std::string const& name) const {
00053     std::vector<T> v = getParameter<std::vector<T> >(tracked, name);
00054     return edm::toPythonList(v);
00055   }
00056 
00058   template<typename T>
00059   void
00060   addParameters(bool tracked, std::string const& name,
00061                 boost::python::list  value) {
00062     std::vector<T> v = edm::toVector<T>(value);
00063     addParameter(tracked, name, v);
00064   }
00065 
00066 
00070   void addPSet(bool tracked, std::string const& name,
00071                PythonParameterSet const& ppset) {
00072     addParameter(tracked, name, ppset.theParameterSet);
00073   }
00074 
00075 
00076   PythonParameterSet getPSet(bool tracked, std::string const& name) const {
00077     return PythonParameterSet(getParameter<edm::ParameterSet>(tracked, name));
00078   }
00079 
00080 
00081   void addVPSet(bool tracked, std::string const& name,
00082                 boost::python::list  value);
00083 
00084   boost::python::list getVPSet(bool tracked, std::string const& name);
00085 
00086   // no way to interface straight into the other python InputTag
00087   edm::InputTag newInputTag(std::string const& label,
00088                             std::string const& instance,
00089                             std::string const& process) {
00090     return edm::InputTag(label, instance, process);
00091   }
00092 
00093    edm::ESInputTag newESInputTag(std::string const& module,
00094                              std::string const& data) {
00095       return edm::ESInputTag(module, data);
00096    }
00097 
00098    edm::EventID newEventID(unsigned int run, unsigned int lumi, unsigned int event) {
00099     return edm::EventID(run, lumi, event);
00100   }
00101 
00102   edm::LuminosityBlockID newLuminosityBlockID(unsigned int run, unsigned int lumi) {
00103     return edm::LuminosityBlockID(run, lumi);
00104   }
00105 
00106   edm::LuminosityBlockRange newLuminosityBlockRange(unsigned int start, unsigned int startSub,
00107                                                     unsigned int end,   unsigned int endSub) {
00108     return edm::LuminosityBlockRange(start, startSub, end, endSub);
00109   }
00110 
00111   edm::EventRange newEventRange(unsigned int start, unsigned int startLumi, unsigned int startSub,
00112                                 unsigned int end,   unsigned int endLumi, unsigned int endSub) {
00113     return edm::EventRange(start, startLumi, startSub, end, endLumi, endSub);
00114   }
00115 
00116   void addNewFileInPath(bool tracked, std::string const& name, std::string const& value);
00117 
00118   PythonParameterSet newPSet() const {return PythonParameterSet();}
00119 
00120   edm::ParameterSet& pset() {return theParameterSet;}
00121 
00122   edm::ParameterSet const& pset() const {return theParameterSet;}
00123 
00124   std::string dump() const {return theParameterSet.dump();}
00125 
00126 private:
00127   edm::ParameterSet theParameterSet;
00128 };
00129 
00130 #endif