Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
// -*- C++ -*-
//
// Package:     FWLite
// Class  :     EventBase
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Charles Plager
//         Created:
//

// system include files
#include <iostream>
#include <memory>

// user include files
#include "DataFormats/FWLite/interface/EventBase.h"
#include "DataFormats/Common/interface/BasicHandle.h"
#include "DataFormats/Common/interface/FunctorHandleExceptionFactory.h"
#include "DataFormats/Common/interface/WrapperBase.h"
#include "DataFormats/Provenance/interface/ProductID.h"
#include "FWCore/Utilities/interface/do_nothing_deleter.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/TypeID.h"

static const edm::ProductID s_id;
static edm::ProductDescription const s_branch = edm::ProductDescription(edm::ProductDescription());
static const edm::Provenance s_prov(std::shared_ptr<edm::ProductDescription const>(&s_branch,
                                                                                   edm::do_nothing_deleter()),
                                    s_id);

namespace fwlite {
  EventBase::EventBase() {}

  EventBase::~EventBase() {}

  edm::BasicHandle EventBase::getByLabelImpl(std::type_info const& iWrapperInfo,
                                             std::type_info const& /*iProductInfo*/,
                                             const edm::InputTag& iTag) const {
    edm::WrapperBase const* prod = nullptr;
    void* prodPtr = &prod;
    getByLabel(iWrapperInfo,
               iTag.label().c_str(),
               iTag.instance().empty() ? static_cast<char const*>(nullptr) : iTag.instance().c_str(),
               iTag.process().empty() ? static_cast<char const*>(nullptr) : iTag.process().c_str(),
               prodPtr);
    if (prod == nullptr || !prod->isPresent()) {
      edm::TypeID productType(iWrapperInfo);

      edm::BasicHandle failed(edm::makeHandleExceptionFactory([=]() -> std::shared_ptr<cms::Exception> {
        std::shared_ptr<cms::Exception> whyFailed(std::make_shared<edm::Exception>(edm::errors::ProductNotFound));
        *whyFailed << "getByLabel: Found zero products matching all criteria\n"
                   << "Looking for type: " << productType << "\n"
                   << "Looking for module label: " << iTag.label() << "\n"
                   << "Looking for productInstanceName: " << iTag.instance() << "\n"
                   << (iTag.process().empty() ? "" : "Looking for process: ") << iTag.process() << "\n"
                   << "The data is registered in the file but is not available for this event\n";
        return whyFailed;
      }));
      return failed;
    }

    edm::BasicHandle value(prod, &s_prov);
    return value;
  }

  edm::BasicHandle EventBase::getByTokenImpl(std::type_info const& iProdInfo, edm::EDGetToken iToken) const {
    edm::WrapperBase const* prod = nullptr;
    getByTokenImp(iToken, prod);
    if (prod == nullptr || !prod->isPresent()) {
      edm::TypeID productType(iProdInfo);

      edm::BasicHandle failed(edm::makeHandleExceptionFactory([=]() -> std::shared_ptr<cms::Exception> {
        std::shared_ptr<cms::Exception> whyFailed(std::make_shared<edm::Exception>(edm::errors::ProductNotFound));
        *whyFailed << "getByToken: Found zero products matching all criteria\n"
                   << "Looking for type: " << productType << "\n"
                   << "The data is registered in the file but is not available for this event\n";
        return whyFailed;
      }));
      return failed;
    }

    edm::BasicHandle value(prod, &s_prov);
    return value;
  }

  edm::BasicHandle EventBase::getImpl(std::type_info const& iProductInfo, const edm::ProductID& pid) const {
    edm::WrapperBase const* prod = getByProductID(pid);
    if (prod == nullptr || !prod->isPresent()) {
      edm::TypeID productType(iProductInfo);

      edm::BasicHandle failed(edm::makeHandleExceptionFactory([=]() -> std::shared_ptr<cms::Exception> {
        std::shared_ptr<cms::Exception> whyFailed(std::make_shared<edm::Exception>(edm::errors::ProductNotFound));
        *whyFailed << "EventBase::getImpl: getByProductID found no product with the\n"
                   << "requested ProductID " << pid << "\n"
                   << "Expected type: " << productType << "\n";
        return whyFailed;
      }));
      return failed;
    }
    edm::BasicHandle value(prod, &s_prov);
    return value;
  }
}  // namespace fwlite