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  :     ErrorThrower
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Sep 23 10:06:39 EDT 2008
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "DataFormats/FWLite/interface/ErrorThrower.h"
0017 #include "FWCore/Utilities/interface/EDMException.h"
0018 #include "FWCore/Utilities/interface/TypeID.h"
0019 #include <ostream>
0020 
0021 using namespace fwlite;
0022 //
0023 // constants, enums and typedefs
0024 //
0025 namespace {
0026   class NoProductErrorThrower : public ErrorThrower {
0027   public:
0028     NoProductErrorThrower(const std::type_info& iType, const char* iModule, const char* iInstance, const char* iProcess)
0029         : type_(&iType), module_(iModule), instance_(iInstance), process_(iProcess) {}
0030 
0031     void throwIt() const override {
0032       edm::TypeID type(*type_);
0033       throw edm::Exception(edm::errors::ProductNotFound)
0034           << "A branch was found for \n  type ='" << type.className() << "'\n  module='" << module_
0035           << "'\n  productInstance='" << ((nullptr != instance_) ? instance_ : "") << "'\n  process='"
0036           << ((nullptr != process_) ? process_ : "")
0037           << "'\n"
0038              "but no data is available for this Event";
0039     }
0040     ErrorThrower* clone() const override { return new NoProductErrorThrower(*this); }
0041 
0042   private:
0043     const std::type_info* type_;
0044     const char* module_;
0045     const char* instance_;
0046     const char* process_;
0047   };
0048 
0049   class NoBranchErrorThrower : public ErrorThrower {
0050   public:
0051     NoBranchErrorThrower(const std::type_info& iType, const char* iModule, const char* iInstance, const char* iProcess)
0052         : type_(&iType), module_(iModule), instance_(iInstance), process_(iProcess) {}
0053 
0054     void throwIt() const override {
0055       edm::TypeID type(*type_);
0056       throw edm::Exception(edm::errors::ProductNotFound)
0057           << "No branch was found for \n  type ='" << type.className() << "'\n  module='" << module_
0058           << "'\n  productInstance='" << ((nullptr != instance_) ? instance_ : "") << "'\n  process='"
0059           << ((nullptr != process_) ? process_ : "") << "'";
0060     }
0061 
0062     ErrorThrower* clone() const override { return new NoBranchErrorThrower(*this); }
0063 
0064   private:
0065     const std::type_info* type_;
0066     const char* module_;
0067     const char* instance_;
0068     const char* process_;
0069   };
0070 
0071   class UnsetErrorThrower : public ErrorThrower {
0072     void throwIt() const override { throw cms::Exception("UnsetHandle") << "The fwlite::Handle was never set"; }
0073 
0074     ErrorThrower* clone() const override { return new UnsetErrorThrower(*this); }
0075   };
0076 }  // namespace
0077 //
0078 // static data member definitions
0079 //
0080 
0081 //
0082 // constructors and destructor
0083 //
0084 ErrorThrower::ErrorThrower() {}
0085 
0086 // ErrorThrower::ErrorThrower(const ErrorThrower& rhs)
0087 // {
0088 //    // do actual copying here;
0089 // }
0090 
0091 ErrorThrower::~ErrorThrower() {}
0092 
0093 //
0094 // assignment operators
0095 //
0096 // const ErrorThrower& ErrorThrower::operator=(const ErrorThrower& rhs)
0097 // {
0098 //   //An exception safe implementation is
0099 //   ErrorThrower temp(rhs);
0100 //   swap(rhs);
0101 //
0102 //   return *this;
0103 // }
0104 
0105 //
0106 // member functions
0107 //
0108 
0109 //
0110 // const member functions
0111 //
0112 
0113 //
0114 // static member functions
0115 //
0116 ErrorThrower* ErrorThrower::unsetErrorThrower() { return new UnsetErrorThrower(); }
0117 
0118 ErrorThrower* ErrorThrower::errorThrowerBranchNotFoundException(const std::type_info& iType,
0119                                                                 const char* iModule,
0120                                                                 const char* iInstance,
0121                                                                 const char* iProcess) {
0122   return new NoBranchErrorThrower(iType, iModule, iInstance, iProcess);
0123 }
0124 
0125 ErrorThrower* ErrorThrower::errorThrowerProductNotFoundException(const std::type_info& iType,
0126                                                                  const char* iModule,
0127                                                                  const char* iInstance,
0128                                                                  const char* iProcess) {
0129   return new NoProductErrorThrower(iType, iModule, iInstance, iProcess);
0130 }