CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/FWCore/Framework/src/Factory.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/Framework/src/Factory.h"
00003 #include "FWCore/Utilities/interface/DebugMacros.h"
00004 #include "FWCore/Utilities/interface/EDMException.h"
00005 #include "FWCore/Utilities/interface/Algorithms.h"
00006 
00007 #include <iostream>
00008 
00009 EDM_REGISTER_PLUGINFACTORY(edm::MakerPluginFactory,"CMS EDM Framework Module");
00010 namespace edm {
00011 
00012   static void cleanup(const Factory::MakerMap::value_type& v)
00013   {
00014     delete v.second;
00015   }
00016 
00017   Factory Factory::singleInstance_;
00018   
00019   Factory::~Factory()
00020   {
00021     for_all(makers_, cleanup);
00022   }
00023 
00024   Factory::Factory(): makers_()
00025 
00026   {
00027   }
00028 
00029   Factory* Factory::get()
00030   {
00031     return &singleInstance_;
00032   }
00033 
00034   std::auto_ptr<Worker> Factory::makeWorker(const WorkerParams& p,
00035                                             sigc::signal<void, const ModuleDescription&>& pre,
00036                                             sigc::signal<void, const ModuleDescription&>& post) const
00037   {
00038     std::string modtype = p.pset_->getParameter<std::string>("@module_type");
00039     FDEBUG(1) << "Factory: module_type = " << modtype << std::endl;
00040     MakerMap::iterator it = makers_.find(modtype);
00041 
00042     if(it == makers_.end())
00043       {
00044         std::auto_ptr<Maker> wm(MakerPluginFactory::get()->create(modtype));
00045 
00046         if(wm.get()==0)
00047           throw edm::Exception(errors::Configuration,"UnknownModule")
00048             << "Module " << modtype
00049             << " with version " << p.processConfiguration_->releaseVersion()
00050             << " was not registered.\n"
00051             << "Perhaps your module type is misspelled or is not a "
00052             << "framework plugin.\n"
00053             << "Try running EdmPluginDump to obtain a list of "
00054             << "available Plugins.";
00055           
00056         FDEBUG(1) << "Factory:  created worker of type " << modtype << std::endl;
00057 
00058         std::pair<MakerMap::iterator,bool> ret =
00059           makers_.insert(std::pair<std::string,Maker*>(modtype,wm.get()));
00060 
00061         //      if(ret.second==false)
00062         //        throw runtime_error("Worker Factory map insert failed");
00063 
00064         it = ret.first;
00065         wm.release();
00066       }
00067 
00068     std::auto_ptr<Worker> w(it->second->makeWorker(p,pre,post));
00069     return w;
00070   }
00071 
00072 }