Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:26

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWLite
0004 // Class  :     EventBase
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Charles Plager
0010 //         Created:
0011 //
0012 
0013 // system include files
0014 #include <iostream>
0015 #include <memory>
0016 
0017 // user include files
0018 #include "DataFormats/FWLite/interface/EventBase.h"
0019 #include "DataFormats/Common/interface/BasicHandle.h"
0020 #include "DataFormats/Common/interface/FunctorHandleExceptionFactory.h"
0021 #include "DataFormats/Common/interface/WrapperBase.h"
0022 #include "DataFormats/Provenance/interface/ProductID.h"
0023 #include "FWCore/Utilities/interface/do_nothing_deleter.h"
0024 #include "FWCore/Utilities/interface/EDMException.h"
0025 #include "FWCore/Utilities/interface/TypeID.h"
0026 
0027 static const edm::ProductID s_id;
0028 static edm::BranchDescription const s_branch = edm::BranchDescription(edm::BranchDescription());
0029 static const edm::Provenance s_prov(std::shared_ptr<edm::BranchDescription const>(&s_branch, edm::do_nothing_deleter()),
0030                                     s_id);
0031 
0032 namespace fwlite {
0033   EventBase::EventBase() {}
0034 
0035   EventBase::~EventBase() {}
0036 
0037   edm::BasicHandle EventBase::getByLabelImpl(std::type_info const& iWrapperInfo,
0038                                              std::type_info const& /*iProductInfo*/,
0039                                              const edm::InputTag& iTag) const {
0040     edm::WrapperBase const* prod = nullptr;
0041     void* prodPtr = &prod;
0042     getByLabel(iWrapperInfo,
0043                iTag.label().c_str(),
0044                iTag.instance().empty() ? static_cast<char const*>(nullptr) : iTag.instance().c_str(),
0045                iTag.process().empty() ? static_cast<char const*>(nullptr) : iTag.process().c_str(),
0046                prodPtr);
0047     if (prod == nullptr || !prod->isPresent()) {
0048       edm::TypeID productType(iWrapperInfo);
0049 
0050       edm::BasicHandle failed(edm::makeHandleExceptionFactory([=]() -> std::shared_ptr<cms::Exception> {
0051         std::shared_ptr<cms::Exception> whyFailed(std::make_shared<edm::Exception>(edm::errors::ProductNotFound));
0052         *whyFailed << "getByLabel: Found zero products matching all criteria\n"
0053                    << "Looking for type: " << productType << "\n"
0054                    << "Looking for module label: " << iTag.label() << "\n"
0055                    << "Looking for productInstanceName: " << iTag.instance() << "\n"
0056                    << (iTag.process().empty() ? "" : "Looking for process: ") << iTag.process() << "\n"
0057                    << "The data is registered in the file but is not available for this event\n";
0058         return whyFailed;
0059       }));
0060       return failed;
0061     }
0062 
0063     edm::BasicHandle value(prod, &s_prov);
0064     return value;
0065   }
0066 
0067   edm::BasicHandle EventBase::getImpl(std::type_info const& iProductInfo, const edm::ProductID& pid) const {
0068     edm::WrapperBase const* prod = getByProductID(pid);
0069     if (prod == nullptr || !prod->isPresent()) {
0070       edm::TypeID productType(iProductInfo);
0071 
0072       edm::BasicHandle failed(edm::makeHandleExceptionFactory([=]() -> std::shared_ptr<cms::Exception> {
0073         std::shared_ptr<cms::Exception> whyFailed(std::make_shared<edm::Exception>(edm::errors::ProductNotFound));
0074         *whyFailed << "EventBase::getImpl: getByProductID found no product with the\n"
0075                    << "requested ProductID " << pid << "\n"
0076                    << "Expected type: " << productType << "\n";
0077         return whyFailed;
0078       }));
0079       return failed;
0080     }
0081     edm::BasicHandle value(prod, &s_prov);
0082     return value;
0083   }
0084 }  // namespace fwlite