CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Framework/src/WorkerMaker.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/Framework/src/WorkerMaker.h"
00003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00004 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/Utilities/interface/ConvertException.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/Utilities/interface/EDMException.h"
00009 
00010 #include <sstream>
00011 #include <exception>
00012 
00013 namespace edm {
00014 
00015 Maker::~Maker() {
00016 }
00017 
00018 ModuleDescription 
00019 Maker::createModuleDescription(WorkerParams const &p) const {
00020   ParameterSet const& conf = *p.pset_;
00021   ModuleDescription md(conf.id(),
00022                        conf.getParameter<std::string>("@module_type"),
00023                        conf.getParameter<std::string>("@module_label"),
00024                        p.processConfiguration_.get());
00025   return md;
00026 }
00027 
00028 void 
00029 Maker::throwValidationException(WorkerParams const& p,
00030                                 cms::Exception & iException) const {
00031   ParameterSet const& conf = *p.pset_;
00032   std::string moduleName = conf.getParameter<std::string>("@module_type");
00033   std::string moduleLabel = conf.getParameter<std::string>("@module_label");
00034 
00035   std::ostringstream ost;
00036   ost << "Validating configuration of module: class=" << moduleName
00037       << " label='" << moduleLabel << "'";
00038   iException.addContext(ost.str());  
00039   throw;
00040 }
00041 
00042 void 
00043 Maker::throwConfigurationException(ModuleDescription const& md, 
00044                                    sigc::signal<void, ModuleDescription const&>& post, 
00045                                    cms::Exception & iException) const {
00046   std::ostringstream ost;
00047   ost << "Constructing module: class=" << md.moduleName() << " label='" << md.moduleLabel() << "'";
00048   iException.addContext(ost.str());
00049   post(md);
00050   throw;
00051 }
00052 
00053 void 
00054 Maker::validateEDMType(std::string const& edmType, WorkerParams const& p) const {
00055   std::string expected = p.pset_->getParameter<std::string>("@module_edm_type");
00056   if (edmType != expected) {
00057     throw Exception(errors::Configuration)
00058       << "The base type in the python configuration is " << expected << ", but the base type\n"
00059       << "for the module's C++ class is " << edmType << ". "
00060       << "Please fix the configuration.\n"
00061       << "It must use the same base type as the C++ class.\n";
00062   }
00063 }
00064   
00065 std::auto_ptr<Worker> 
00066 Maker::makeWorker(WorkerParams const& p,
00067                   sigc::signal<void, ModuleDescription const&>& pre,
00068                   sigc::signal<void, ModuleDescription const&>& post) const {
00069   ConfigurationDescriptions descriptions(baseType());
00070   fillDescriptions(descriptions);
00071   try {
00072     try {
00073       descriptions.validate(*p.pset_, p.pset_->getParameter<std::string>("@module_label"));    
00074       validateEDMType(baseType(), p);
00075     }
00076     catch (cms::Exception& e) { throw; }
00077     catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
00078     catch (std::exception& e) { convertException::stdToEDM(e); }
00079     catch(std::string& s) { convertException::stringToEDM(s); }
00080     catch(char const* c) { convertException::charPtrToEDM(c); }
00081     catch (...) { convertException::unknownToEDM(); }
00082   }
00083   catch (cms::Exception & iException) {
00084     throwValidationException(p, iException);
00085   }
00086   p.pset_->registerIt();
00087 
00088   ModuleDescription md = createModuleDescription(p);
00089   
00090   std::auto_ptr<Worker> worker;
00091   try {
00092     try {
00093       pre(md);    
00094       worker = makeWorker(p,md);
00095       post(md);
00096     }
00097     catch (cms::Exception& e) { throw; }
00098     catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
00099     catch (std::exception& e) { convertException::stdToEDM(e); }
00100     catch(std::string& s) { convertException::stringToEDM(s); }
00101     catch(char const* c) { convertException::charPtrToEDM(c); }
00102     catch (...) { convertException::unknownToEDM(); }
00103   }
00104   catch(cms::Exception & iException){
00105     throwConfigurationException(md, post, iException);
00106   }
00107   return worker;
00108 }
00109   
00110 void 
00111 Maker::swapModule(Worker* w, ParameterSet const& p) {
00112    implSwapModule(w,p);
00113 }
00114 
00115 } // end of edm::