CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/FWCore/ParameterSet/src/ProcessDesc.cc

Go to the documentation of this file.
00001 
00010 #include "FWCore/ParameterSet/interface/ProcessDesc.h"
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 #include "FWCore/Utilities/interface/EDMException.h"
00013 #include <iostream>
00014 
00015 namespace edm
00016 {
00017 
00018   ProcessDesc::ProcessDesc(ParameterSet const& pset)
00019   : pset_(new ParameterSet(pset)), services_(new std::vector<ParameterSet>())
00020   {
00021   }
00022 
00023   ProcessDesc::~ProcessDesc() {
00024   }
00025 
00026   ProcessDesc::ProcessDesc(std::string const& config)
00027   : pset_(new ParameterSet),
00028     services_(new std::vector<ParameterSet>()) {
00029     throw edm::Exception(errors::Configuration,"Old config strings no longer accepted");
00030   }
00031 
00032   boost::shared_ptr<edm::ParameterSet>  
00033   ProcessDesc::getProcessPSet() const {
00034     return pset_;
00035   }
00036 
00037   boost::shared_ptr<std::vector<ParameterSet> > 
00038   ProcessDesc::getServicesPSets() const {
00039     return services_;
00040   }
00041 
00042   
00043   void ProcessDesc::addService(ParameterSet& pset) {
00044     services_->push_back(pset);
00045   }
00046 
00047 
00048   void ProcessDesc::addService(std::string const& service) {
00049     ParameterSet newpset;
00050     newpset.addParameter<std::string>("@service_type",service);
00051     addService(newpset);
00052   }
00053 
00054   void ProcessDesc::addDefaultService(std::string const& service) {
00055     typedef std::vector<edm::ParameterSet>::iterator Iter;
00056     for(Iter it = services_->begin(), itEnd = services_->end(); it != itEnd; ++it) {
00057         std::string name = it->getParameter<std::string>("@service_type");
00058 
00059         if (name == service) {
00060           // If the service is already there move it to the end so
00061           // it will be created before all the others already there
00062           // This means we use the order from the default services list
00063           // and the parameters from the configuration file
00064           while (true) {
00065             Iter iterNext = it + 1;
00066             if (iterNext == itEnd) return;
00067             iter_swap(it, iterNext);
00068             ++it;
00069           }
00070         }
00071     }
00072     addService(service);
00073   }
00074 
00075 
00076   void ProcessDesc::addServices(std::vector<std::string> const& defaultServices,
00077                                 std::vector<std::string> const& forcedServices) {
00078     // Add the forced and default services to services_.
00079     // In services_, we want the default services first, then the forced
00080     // services, then the services from the configuration.  It is efficient
00081     // and convenient to add them in reverse order.  Then after we are done
00082     // adding, we reverse the std::vector again to get the desired order.
00083     std::reverse(services_->begin(), services_->end());
00084     for(std::vector<std::string>::const_reverse_iterator j = forcedServices.rbegin(),
00085                                             jEnd = forcedServices.rend();
00086          j != jEnd; ++j) {
00087       addService(*j);
00088     }
00089     for(std::vector<std::string>::const_reverse_iterator i = defaultServices.rbegin(),
00090                                             iEnd = defaultServices.rend();
00091          i != iEnd; ++i) {
00092       addDefaultService(*i);
00093     }
00094     std::reverse(services_->begin(), services_->end());
00095   }
00096 
00097   std::string ProcessDesc::dump() const {
00098     std::string out = pset_->dump();
00099     for (std::vector<ParameterSet>::const_iterator it = services_->begin(), itEnd = services_->end(); it != itEnd; ++it) {
00100       out += it->dump();
00101     }
00102     return out;
00103   }
00104 
00105 
00106 } // namespace edm