Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:10

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::getByTokenImpl(std::type_info const& iProdInfo, edm::EDGetToken iToken) const {
0068     edm::WrapperBase const* prod = nullptr;
0069     getByTokenImp(iToken, prod);
0070     if (prod == nullptr || !prod->isPresent()) {
0071       edm::TypeID productType(iProdInfo);
0072 
0073       edm::BasicHandle failed(edm::makeHandleExceptionFactory([=]() -> std::shared_ptr<cms::Exception> {
0074         std::shared_ptr<cms::Exception> whyFailed(std::make_shared<edm::Exception>(edm::errors::ProductNotFound));
0075         *whyFailed << "getByToken: Found zero products matching all criteria\n"
0076                    << "Looking for type: " << productType << "\n"
0077                    << "The data is registered in the file but is not available for this event\n";
0078         return whyFailed;
0079       }));
0080       return failed;
0081     }
0082 
0083     edm::BasicHandle value(prod, &s_prov);
0084     return value;
0085   }
0086 
0087   edm::BasicHandle EventBase::getImpl(std::type_info const& iProductInfo, const edm::ProductID& pid) const {
0088     edm::WrapperBase const* prod = getByProductID(pid);
0089     if (prod == nullptr || !prod->isPresent()) {
0090       edm::TypeID productType(iProductInfo);
0091 
0092       edm::BasicHandle failed(edm::makeHandleExceptionFactory([=]() -> std::shared_ptr<cms::Exception> {
0093         std::shared_ptr<cms::Exception> whyFailed(std::make_shared<edm::Exception>(edm::errors::ProductNotFound));
0094         *whyFailed << "EventBase::getImpl: getByProductID found no product with the\n"
0095                    << "requested ProductID " << pid << "\n"
0096                    << "Expected type: " << productType << "\n";
0097         return whyFailed;
0098       }));
0099       return failed;
0100     }
0101     edm::BasicHandle value(prod, &s_prov);
0102     return value;
0103   }
0104 }  // namespace fwlite