NoBranchErrorThrower

NoProductErrorThrower

UnsetErrorThrower

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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
// -*- C++ -*-
//
// Package:     FWLite
// Class  :     ErrorThrower
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Chris Jones
//         Created:  Tue Sep 23 10:06:39 EDT 2008
//

// system include files

// user include files
#include "DataFormats/FWLite/interface/ErrorThrower.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/TypeID.h"
#include <ostream>

using namespace fwlite;
//
// constants, enums and typedefs
//
namespace {
  class NoProductErrorThrower : public ErrorThrower {
  public:
    NoProductErrorThrower(const std::type_info& iType, const char* iModule, const char* iInstance, const char* iProcess)
        : type_(&iType), module_(iModule), instance_(iInstance), process_(iProcess) {}

    void throwIt() const override {
      edm::TypeID type(*type_);
      throw edm::Exception(edm::errors::ProductNotFound)
          << "A branch was found for \n  type ='" << type.className() << "'\n  module='" << module_
          << "'\n  productInstance='" << ((nullptr != instance_) ? instance_ : "") << "'\n  process='"
          << ((nullptr != process_) ? process_ : "")
          << "'\n"
             "but no data is available for this Event";
    }
    ErrorThrower* clone() const override { return new NoProductErrorThrower(*this); }

  private:
    const std::type_info* type_;
    const char* module_;
    const char* instance_;
    const char* process_;
  };

  class NoBranchErrorThrower : public ErrorThrower {
  public:
    NoBranchErrorThrower(const std::type_info& iType, const char* iModule, const char* iInstance, const char* iProcess)
        : type_(&iType), module_(iModule), instance_(iInstance), process_(iProcess) {}

    void throwIt() const override {
      edm::TypeID type(*type_);
      throw edm::Exception(edm::errors::ProductNotFound)
          << "No branch was found for \n  type ='" << type.className() << "'\n  module='" << module_
          << "'\n  productInstance='" << ((nullptr != instance_) ? instance_ : "") << "'\n  process='"
          << ((nullptr != process_) ? process_ : "") << "'";
    }

    ErrorThrower* clone() const override { return new NoBranchErrorThrower(*this); }

  private:
    const std::type_info* type_;
    const char* module_;
    const char* instance_;
    const char* process_;
  };

  class UnsetErrorThrower : public ErrorThrower {
    void throwIt() const override { throw cms::Exception("UnsetHandle") << "The fwlite::Handle was never set"; }

    ErrorThrower* clone() const override { return new UnsetErrorThrower(*this); }
  };
}  // namespace
//
// static data member definitions
//

//
// constructors and destructor
//
ErrorThrower::ErrorThrower() {}

// ErrorThrower::ErrorThrower(const ErrorThrower& rhs)
// {
//    // do actual copying here;
// }

ErrorThrower::~ErrorThrower() {}

//
// assignment operators
//
// const ErrorThrower& ErrorThrower::operator=(const ErrorThrower& rhs)
// {
//   //An exception safe implementation is
//   ErrorThrower temp(rhs);
//   swap(rhs);
//
//   return *this;
// }

//
// member functions
//

//
// const member functions
//

//
// static member functions
//
ErrorThrower* ErrorThrower::unsetErrorThrower() { return new UnsetErrorThrower(); }

ErrorThrower* ErrorThrower::errorThrowerBranchNotFoundException(const std::type_info& iType,
                                                                const char* iModule,
                                                                const char* iInstance,
                                                                const char* iProcess) {
  return new NoBranchErrorThrower(iType, iModule, iInstance, iProcess);
}

ErrorThrower* ErrorThrower::errorThrowerProductNotFoundException(const std::type_info& iType,
                                                                 const char* iModule,
                                                                 const char* iInstance,
                                                                 const char* iProcess) {
  return new NoProductErrorThrower(iType, iModule, iInstance, iProcess);
}