00001
00002
00003
00004
00005
00006
00007 #include "FWCore/Framework/interface/ProducerBase.h"
00008 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00009 #include "DataFormats/Provenance/interface/ProductRegistry.h"
00010
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "FWCore/Framework/interface/ConstProductRegistry.h"
00013
00014 #include <sstream>
00015
00016 namespace edm {
00017 ProducerBase::ProducerBase() : ProductRegistryHelper(), callWhenNewProductsRegistered_() {}
00018 ProducerBase::~ProducerBase() { }
00019
00020 boost::function<void(const BranchDescription&)> ProducerBase::registrationCallback() const {
00021 return callWhenNewProductsRegistered_;
00022 }
00023
00024
00025 namespace {
00026 class CallbackWrapper {
00027 public:
00028 CallbackWrapper(boost::shared_ptr<ProducerBase> iProd,
00029 boost::function<void(const BranchDescription&)> iCallback,
00030 ProductRegistry* iReg,
00031 const ModuleDescription& iDesc):
00032 prod_(&(*iProd)), callback_(iCallback), reg_(iReg), mdesc_(iDesc),
00033 lastSize_(iProd->typeLabelList().size()) {}
00034
00035 void operator()(const BranchDescription& iDesc) {
00036 callback_(iDesc);
00037 addToRegistry();
00038 }
00039
00040 void addToRegistry() {
00041 ProducerBase::TypeLabelList const& plist = prod_->typeLabelList();
00042
00043 if(lastSize_!=plist.size()){
00044 ProducerBase::TypeLabelList::const_iterator pStart = plist.begin();
00045 advance(pStart, lastSize_);
00046 ProductRegistryHelper::addToRegistry(pStart, plist.end() ,mdesc_, *reg_);
00047 lastSize_ = plist.size();
00048 }
00049 }
00050
00051 private:
00052 ProducerBase* prod_;
00053 boost::function<void(const BranchDescription&)> callback_;
00054 ProductRegistry* reg_;
00055 ModuleDescription mdesc_;
00056 unsigned int lastSize_;
00057
00058 };
00059 }
00060
00061
00062 void ProducerBase::registerProducts(boost::shared_ptr<ProducerBase> producer,
00063 ProductRegistry* iReg,
00064 ModuleDescription const& md)
00065 {
00066 if (typeLabelList().empty() && registrationCallback().empty()) {
00067 return;
00068 }
00069
00070
00071
00072
00073 bool isListener = false;
00074 if(!(registrationCallback().empty())) {
00075 isListener=true;
00076 iReg->callForEachBranch(registrationCallback());
00077 }
00078 TypeLabelList const& plist = typeLabelList();
00079
00080 ProductRegistryHelper::addToRegistry(plist.begin(), plist.end(), md, *(iReg), isListener);
00081 if(!(registrationCallback().empty())) {
00082 Service<ConstProductRegistry> regService;
00083 regService->watchProductAdditions(CallbackWrapper(producer, registrationCallback(), iReg, md));
00084 }
00085 }
00086 }