CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

edm::PrincipalGetAdapter Class Reference

#include <PrincipalGetAdapter.h>

List of all members.

Public Types

typedef std::vector< BasicHandleBasicHandleVec

Public Member Functions

template<typename PROD >
bool checkIfComplete () const
ConstBranchDescription const & getBranchDescription (TypeID const &type, std::string const &productInstanceName) const
BasicHandle getByLabel_ (TypeID const &tid, InputTag const &tag) const
BasicHandle getByLabel_ (TypeID const &tid, std::string const &label, std::string const &instance, std::string const &process) const
BasicHandle getByToken_ (TypeID const &id, KindOfType kindOfType, EDGetToken token) const
template<typename PROD >
void getManyByType (std::vector< Handle< PROD > > &results) const
void getManyByType_ (TypeID const &tid, BasicHandleVec &results) const
BasicHandle getMatchingSequenceByLabel_ (TypeID const &typeID, std::string const &label, std::string const &instance, std::string const &process) const
BasicHandle getMatchingSequenceByLabel_ (TypeID const &typeID, InputTag const &tag) const
bool isComplete () const
PrincipalGetAdapteroperator= (PrincipalGetAdapter const &)
Principalprincipal ()
Principal const & principal () const
 PrincipalGetAdapter (Principal &pcpl, ModuleDescription const &md)
 PrincipalGetAdapter (PrincipalGetAdapter const &)
ProcessHistory const & processHistory () const
EDProductGetter const * prodGetter () const
void setConsumer (EDConsumerBase const *iConsumer)
 ~PrincipalGetAdapter ()

Private Member Functions

BranchType const & branchType () const
BasicHandle makeFailToGetException (KindOfType, TypeID const &, EDGetToken) const
void throwAmbiguousException (TypeID const &productType, EDGetToken token) const

Private Attributes

EDConsumerBase const * consumer_
ModuleDescription const & md_
Principalprincipal_

Detailed Description

Definition at line 126 of file PrincipalGetAdapter.h.


Member Typedef Documentation

Definition at line 161 of file PrincipalGetAdapter.h.


Constructor & Destructor Documentation

PrincipalGetAdapter::PrincipalGetAdapter ( Principal pcpl,
ModuleDescription const &  md 
)

Definition at line 19 of file PrincipalGetAdapter.cc.

                                      :
    //putProducts_(),
    principal_(pcpl),
    md_(md) {
  }
PrincipalGetAdapter::~PrincipalGetAdapter ( )

Definition at line 26 of file PrincipalGetAdapter.cc.

                                            {
  }
edm::PrincipalGetAdapter::PrincipalGetAdapter ( PrincipalGetAdapter const &  )

Member Function Documentation

BranchType const & PrincipalGetAdapter::branchType ( ) const [private]

Definition at line 137 of file PrincipalGetAdapter.cc.

                                        {
    return principal_.branchType();
  }
template<typename PROD >
bool PrincipalGetAdapter::checkIfComplete ( ) const [inline]
ConstBranchDescription const & PrincipalGetAdapter::getBranchDescription ( TypeID const &  type,
std::string const &  productInstanceName 
) const

Definition at line 205 of file PrincipalGetAdapter.cc.

References edm::ProductHolderBase::branchDescription(), Exception, edm::TypeID::friendlyClassName(), getHLTprescales::index, edm::ProductHolderIndexHelper::index(), edm::errors::InsertFailure, edm::PRODUCT_TYPE, and edm::ProductHolderIndexInvalid.

Referenced by edm::Event::getRefBeforePut(), edm::Event::put(), edm::LuminosityBlock::put(), and edm::Run::put().

                                                                                 {
    ProductHolderIndexHelper const& productHolderIndexHelper = principal_.productLookup();
    ProductHolderIndex index = productHolderIndexHelper.index(PRODUCT_TYPE, type, md_.moduleLabel().c_str(),productInstanceName.c_str(), md_.processName().c_str());
    if(index == ProductHolderIndexInvalid) {
      throw edm::Exception(edm::errors::InsertFailure)
        << "Illegal attempt to 'put' an unregistered product.\n"
        << "No product is registered for\n"
        << "  process name:                '" << md_.processName() << "'\n"
        << "  module label:                '" << md_.moduleLabel() << "'\n"
        << "  product friendly class name: '" << type.friendlyClassName() << "'\n"
        << "  product instance name:       '" << productInstanceName << "'\n"

        << "The ProductRegistry contains:\n"
        << principal_.productRegistry()
        << '\n';
    }
    ProductHolderBase const*  phb = principal_.getProductByIndex(index, false, false);
    assert(phb != nullptr);
    return phb->branchDescription();
  }
BasicHandle PrincipalGetAdapter::getByLabel_ ( TypeID const &  tid,
InputTag const &  tag 
) const
BasicHandle PrincipalGetAdapter::getByLabel_ ( TypeID const &  tid,
std::string const &  label,
std::string const &  instance,
std::string const &  process 
) const

Definition at line 148 of file PrincipalGetAdapter.cc.

References edm::PRODUCT_TYPE.

                                                                   {
    return principal_.getByLabel(PRODUCT_TYPE, typeID, label, instance, process);
  }
BasicHandle PrincipalGetAdapter::getByToken_ ( TypeID const &  id,
KindOfType  kindOfType,
EDGetToken  token 
) const

Definition at line 156 of file PrincipalGetAdapter.cc.

References h, getHLTprescales::index, edm::InEvent, edm::BasicHandle::isValid(), edm::ProductHolderIndexAmbiguous, edm::ProductHolderIndexInvalid, edm::throwAmbiguousException(), and unlikely.

Referenced by edm::Event::getByToken(), edm::LuminosityBlock::getByToken(), and edm::Run::getByToken().

                                                                                                  {
    ProductHolderIndex index = consumer_->indexFrom(token,InEvent,id);
    if( unlikely(index == ProductHolderIndexInvalid)) {
      return makeFailToGetException(kindOfType,id,token);
    } else if( unlikely(index == ProductHolderIndexAmbiguous)) {
      // This deals with ambiguities where the process is specified
      throwAmbiguousException(id, token);
    }
    bool ambiguous = false;
    BasicHandle h = principal_.getByToken(kindOfType,id,index, token.willSkipCurrentProcess(), ambiguous);
    if (ambiguous) {
      // This deals with ambiguities where the process is not specified
      throwAmbiguousException(id, token);
    } else if(!h.isValid()) {
      return makeFailToGetException(kindOfType,id,token);
    }
    return h;
  }
template<typename PROD >
void PrincipalGetAdapter::getManyByType ( std::vector< Handle< PROD > > &  results) const [inline]

Definition at line 310 of file PrincipalGetAdapter.h.

References edm::convert_handle(), end, getManyByType_(), PROD, edm::es::products(), query::result, and python::entryComment::results.

Referenced by edm::Run::getManyByType(), edm::LuminosityBlock::getManyByType(), and edm::Event::getManyByType().

                                                                            { 
    BasicHandleVec bhv;
    this->getManyByType_(TypeID(typeid(PROD)), bhv);
    
    // Go through the returned handles; for each element,
    //   1. create a Handle<PROD> and
    //
    // This function presents an exception safety difficulty. If an
    // exception is thrown when converting a handle, the "got
    // products" record will be wrong.
    //
    // Since EDProducers are not allowed to use this function,
    // the problem does not seem too severe.
    //
    // Question: do we even need to keep track of the "got products"
    // for this function, since it is *not* to be used by EDProducers?
    std::vector<Handle<PROD> > products;

    typename BasicHandleVec::const_iterator it = bhv.begin();
    typename BasicHandleVec::const_iterator end = bhv.end();

    while (it != end) {
      Handle<PROD> result;
      convert_handle(*it, result);  // throws on conversion error
      products.push_back(result);
      ++it;
    }
    results.swap(products);
  }
void PrincipalGetAdapter::getManyByType_ ( TypeID const &  tid,
BasicHandleVec results 
) const

Definition at line 194 of file PrincipalGetAdapter.cc.

Referenced by getManyByType().

                                                 {
    principal_.getManyByType(tid, results);
  }
BasicHandle PrincipalGetAdapter::getMatchingSequenceByLabel_ ( TypeID const &  typeID,
InputTag const &  tag 
) const

Definition at line 176 of file PrincipalGetAdapter.cc.

References edm::ELEMENT_TYPE.

Referenced by edm::Event::getByLabel().

                                                                              {
    return principal_.getByLabel(ELEMENT_TYPE, typeID, tag);    
  }
BasicHandle PrincipalGetAdapter::getMatchingSequenceByLabel_ ( TypeID const &  typeID,
std::string const &  label,
std::string const &  instance,
std::string const &  process 
) const

Definition at line 182 of file PrincipalGetAdapter.cc.

References edm::ELEMENT_TYPE.

                                                                                   {
    return principal_.getByLabel(ELEMENT_TYPE,
                                 typeID,
                                 label,
                                 instance,
                                 process);
  }
bool PrincipalGetAdapter::isComplete ( ) const

Definition at line 233 of file PrincipalGetAdapter.cc.

Referenced by checkIfComplete().

                                        {
    return principal_.isComplete();
  }
BasicHandle PrincipalGetAdapter::makeFailToGetException ( KindOfType  kindOfType,
TypeID const &  productType,
EDGetToken  token 
) const [private]

Definition at line 104 of file PrincipalGetAdapter.cc.

References exception, Exception, reco_calib_source_client_cfg::labels, edm::EDConsumerBase::Labels::module, edm::EDConsumerBase::Labels::process, edm::PRODUCT_TYPE, edm::EDConsumerBase::Labels::productInstance, and edm::errors::ProductNotFound.

                                                                      {
    EDConsumerBase::Labels labels;
    consumer_->labelsForToken(token,labels);
    boost::shared_ptr<cms::Exception> exception(new Exception(errors::ProductNotFound));
    if (kindOfType == PRODUCT_TYPE) {
      *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for type: " << productType << "\n"
      << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
      << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
    } else {
      *exception << "Principal::getByToken: Found zero products matching all criteria\nLooking for a container with elements of type: " << productType << "\n"
      << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
      << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n";
    }
    return BasicHandle(exception);
  }
PrincipalGetAdapter& edm::PrincipalGetAdapter::operator= ( PrincipalGetAdapter const &  )
Principal& edm::PrincipalGetAdapter::principal ( ) [inline]
Principal const& edm::PrincipalGetAdapter::principal ( ) const [inline]

Definition at line 156 of file PrincipalGetAdapter.h.

References principal_.

{return principal_;}
ProcessHistory const & PrincipalGetAdapter::processHistory ( ) const

Definition at line 200 of file PrincipalGetAdapter.cc.

Referenced by edm::LuminosityBlock::processHistory(), edm::Event::processHistory(), and edm::Run::processHistory().

                                            {
    return principal_.processHistory();
  }
EDProductGetter const * PrincipalGetAdapter::prodGetter ( ) const

Definition at line 228 of file PrincipalGetAdapter.cc.

Referenced by edm::Event::getRefBeforePut().

                                       {
    return principal_.prodGetter();
  }
void edm::PrincipalGetAdapter::setConsumer ( EDConsumerBase const *  iConsumer) [inline]

Definition at line 138 of file PrincipalGetAdapter.h.

References consumer_.

Referenced by edm::Event::setConsumer(), edm::Run::setConsumer(), and edm::LuminosityBlock::setConsumer().

                                                      {
      consumer_ = iConsumer;
    }
void PrincipalGetAdapter::throwAmbiguousException ( TypeID const &  productType,
EDGetToken  token 
) const [private]

Definition at line 123 of file PrincipalGetAdapter.cc.

References exception, reco_calib_source_client_cfg::labels, edm::EDConsumerBase::Labels::module, edm::EDConsumerBase::Labels::process, and edm::EDConsumerBase::Labels::productInstance.

                                                                       {
    EDConsumerBase::Labels labels;
    consumer_->labelsForToken(token,labels);
    cms::Exception exception("AmbiguousProduct");
    exception << "Principal::getByToken: More than 1 product matches all criteria\nLooking for a container with elements of type: " << productType << "\n"
    << "Looking for module label: " << labels.module << "\n" << "Looking for productInstanceName: " << labels.productInstance << "\n"
    << (0==labels.process[0] ? "" : "Looking for process: ") << labels.process << "\n"
    << "This can only occur with get function calls using a Handle<View> argument.\n"
    << "Try a get not using a View or change the instance name of one of the products";
    throw exception;    
  }

Member Data Documentation

Definition at line 223 of file PrincipalGetAdapter.h.

Referenced by setConsumer().

Definition at line 221 of file PrincipalGetAdapter.h.

Definition at line 217 of file PrincipalGetAdapter.h.

Referenced by principal().