CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/Framework/src/PrincipalGetAdapter.cc

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------
00002 ----------------------------------------------------------------------*/
00003 
00004 #include <algorithm>
00005 
00006 #include "FWCore/Framework/interface/PrincipalGetAdapter.h"
00007 #include "DataFormats/Provenance/interface/ProductRegistry.h"
00008 #include "FWCore/Framework/interface/Principal.h"
00009 #include "FWCore/Utilities/interface/EDMException.h"
00010 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00011 #include "FWCore/Framework/interface/Selector.h"
00012 
00013 namespace edm {
00014 
00015   PrincipalGetAdapter::PrincipalGetAdapter(Principal & pcpl,
00016         ModuleDescription const& md)  :
00017     //putProducts_(),
00018     principal_(pcpl),
00019     md_(md) {
00020   }
00021 
00022   PrincipalGetAdapter::~PrincipalGetAdapter() {
00023   }
00024 
00025 
00026   void
00027   principal_get_adapter_detail::deleter::operator()(std::pair<EDProduct*, ConstBranchDescription const*> const p) const {
00028     delete p.first;
00029   }
00030 
00031   void
00032   principal_get_adapter_detail::throwOnPutOfNullProduct(
00033         char const* principalType,
00034         TypeID const& productType,
00035         std::string const& productInstanceName) {
00036       throw Exception(errors::NullPointerError)
00037         << principalType
00038         << "::put: A null auto_ptr was passed to 'put'.\n"
00039         << "The pointer is of type "
00040         << productType
00041         << ".\nThe specified productInstanceName was '"
00042         << productInstanceName
00043         << "'.\n";
00044   }
00045 
00046   BranchType const&
00047   PrincipalGetAdapter::branchType() const {
00048     return principal_.branchType();
00049   }
00050 
00051   BasicHandle
00052   PrincipalGetAdapter::get_(TypeID const& tid, SelectorBase const& sel) const {
00053     return principal_.getBySelector(tid, sel);
00054   }
00055 
00056   void
00057   PrincipalGetAdapter::getMany_(TypeID const& tid,
00058                   SelectorBase const& sel,
00059                   BasicHandleVec& results) const {
00060     principal_.getMany(tid, sel, results);
00061   }
00062 
00063   BasicHandle
00064   PrincipalGetAdapter::getByLabel_(TypeID const& tid,
00065                      std::string const& label,
00066                      std::string const& productInstanceName,
00067                      std::string const& processName) const {
00068     size_t cachedOffset = 0;
00069     int fillCount = -1;
00070     return principal_.getByLabel(tid, label, productInstanceName, processName, cachedOffset, fillCount);
00071   }
00072 
00073   BasicHandle
00074   PrincipalGetAdapter::getByLabel_(TypeID const& tid,
00075                      InputTag const& tag) const {
00076 
00077     principal_.maybeFlushCache(tid, tag);
00078     return principal_.getByLabel(tid, tag.label(), tag.instance(), tag.process(), tag.cachedOffset(), tag.fillCount());
00079   }
00080 
00081   BasicHandle
00082   PrincipalGetAdapter::getByType_(TypeID const& tid) const {
00083     return principal_.getByType(tid);
00084   }
00085 
00086   void
00087   PrincipalGetAdapter::getManyByType_(TypeID const& tid,
00088                   BasicHandleVec& results) const {
00089     principal_.getManyByType(tid, results);
00090   }
00091 
00092   int
00093   PrincipalGetAdapter::getMatchingSequence_(TypeID const& typeID,
00094                                      SelectorBase const& selector,
00095                                      BasicHandle& result) const {
00096     return principal_.getMatchingSequence(typeID,
00097                                     selector,
00098                                     result);
00099   }
00100 
00101   int
00102   PrincipalGetAdapter::getMatchingSequenceByLabel_(TypeID const& typeID,
00103                                             std::string const& label,
00104                                             std::string const& productInstanceName,
00105                                             BasicHandle& result) const {
00106     Selector sel(ModuleLabelSelector(label) &&
00107                  ProductInstanceNameSelector(productInstanceName));
00108 
00109     int n = principal_.getMatchingSequence(typeID,
00110                                      sel,
00111                                      result);
00112     return n;
00113   }
00114 
00115   int
00116   PrincipalGetAdapter::getMatchingSequenceByLabel_(TypeID const& typeID,
00117                                             std::string const& label,
00118                                             std::string const& productInstanceName,
00119                                             std::string const& processName,
00120                                             BasicHandle& result) const {
00121     Selector sel(ModuleLabelSelector(label) &&
00122                  ProductInstanceNameSelector(productInstanceName) &&
00123                  ProcessNameSelector(processName) );
00124 
00125     int n = principal_.getMatchingSequence(typeID,
00126                                    sel,
00127                                    result);
00128     return n;
00129   }
00130 
00131   ProcessHistory const&
00132   PrincipalGetAdapter::processHistory() const {
00133     return principal_.processHistory();
00134   }
00135 
00136   ConstBranchDescription const&
00137   PrincipalGetAdapter::getBranchDescription(TypeID const& type,
00138                                      std::string const& productInstanceName) const {
00139     TransientProductLookupMap const& tplm = principal_.productRegistry().productLookup();
00140     std::pair<TransientProductLookupMap::const_iterator, TransientProductLookupMap::const_iterator> range = 
00141      tplm.equal_range(TypeInBranchType(type,branchType()),md_.moduleLabel(),productInstanceName);
00142    
00143     //NOTE: getBranchDescription should only be called by a EDProducer and therefore the processName should
00144     // match the first one returned by equal_range since they are ordered by time. However, there is one test
00145     // which violates this rule (FWCore/Framework/test/Event_t.cpp.  I do not see a go way to 'fix' it so
00146     // I'll allow the same behavior it depends upon
00147     bool foundMatch = false;
00148     if(range.first != range.second) {
00149        foundMatch = true;
00150        while(md_.processName() != range.first->branchDescription()->processName()) {
00151           ++range.first;
00152           if(range.first == range.second || range.first->isFirst()) {
00153              foundMatch = false;
00154              break;
00155           }
00156        }
00157     }
00158     if(!foundMatch) {
00159       throw edm::Exception(edm::errors::InsertFailure)
00160         << "Illegal attempt to 'put' an unregistered product.\n"
00161         << "No product is registered for\n"
00162         << "  process name:                '" << md_.processName() << "'\n"
00163         << "  module label:                '" << md_.moduleLabel() << "'\n"
00164         << "  product friendly class name: '" << type.friendlyClassName() << "'\n"
00165         << "  product instance name:       '" << productInstanceName << "'\n"
00166 
00167         << "The ProductRegistry contains:\n"
00168         << principal_.productRegistry()
00169         << '\n';
00170     }
00171     return *(range.first->branchDescription());
00172   }
00173 
00174   EDProductGetter const*
00175   PrincipalGetAdapter::prodGetter() const{
00176     return principal_.prodGetter();
00177   }
00178 }