Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:29

0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 #include "FWCore/ParameterSet/interface/ProcessDesc.h"
0003 #include "FWCore/Utilities/interface/EDMException.h"
0004 
0005 namespace edm {
0006 
0007   ProcessDesc::ProcessDesc(std::shared_ptr<ParameterSet> pset)
0008       : pset_(pset), services_(pset_->popVParameterSet(std::string("services"))) {}
0009 
0010   ProcessDesc::ProcessDesc(std::unique_ptr<ParameterSet> pset)
0011       : pset_(std::move(pset)), services_(pset_->popVParameterSet(std::string("services"))) {}
0012 
0013   ProcessDesc::ProcessDesc(std::string const&) : pset_(new ParameterSet), services_{} {
0014     throw Exception(errors::Configuration, "Old config strings no longer accepted");
0015   }
0016 
0017   ProcessDesc::~ProcessDesc() {}
0018 
0019   void ProcessDesc::addService(ParameterSet& pset) {
0020     // The standard services should be initialized first.
0021     services_.insert(services_.begin(), pset);
0022   }
0023 
0024   void ProcessDesc::addService(std::string const& service) {
0025     ParameterSet newpset;
0026     newpset.addParameter<std::string>("@service_type", service);
0027     addService(newpset);
0028   }
0029 
0030   void ProcessDesc::addDefaultService(std::string const& service) {
0031     for (auto it = services_.begin(), itEnd = services_.end(); it != itEnd; ++it) {
0032       std::string name = it->getParameter<std::string>("@service_type");
0033       if (name == service) {
0034         // Use the configured service.  Don't add a default.
0035         // However, the service needs to be moved to the front because it is a standard service.
0036         ParameterSet pset = *it;
0037         services_.erase(it);
0038         addService(pset);
0039         return;
0040       }
0041     }
0042     addService(service);
0043   }
0044 
0045   void ProcessDesc::addForcedService(std::string const& service) {
0046     for (auto it = services_.begin(), itEnd = services_.end(); it != itEnd; ++it) {
0047       std::string name = it->getParameter<std::string>("@service_type");
0048       if (name == service) {
0049         // Remove the configured service before adding the default.
0050         services_.erase(it);
0051         break;
0052       }
0053     }
0054     addService(service);
0055   }
0056 
0057   void ProcessDesc::addServices(std::vector<std::string> const& defaultServices,
0058                                 std::vector<std::string> const& forcedServices) {
0059     // Add the default services to services_.
0060     for (auto const& service : defaultServices) {
0061       addDefaultService(service);
0062     }
0063     // Add the forced services to services_.
0064     for (auto const& service : forcedServices) {
0065       addForcedService(service);
0066     }
0067   }
0068 
0069   std::string ProcessDesc::dump() const {
0070     std::string out = pset_->dump();
0071     for (auto const& service : services_) {
0072       out += service.dump();
0073     }
0074     return out;
0075   }
0076 }  // namespace edm