CMS 3D CMS Logo

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