CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DataFormats/FWLite/src/ErrorThrower.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     FWLite
00004 // Class  :     ErrorThrower
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Tue Sep 23 10:06:39 EDT 2008
00011 // $Id: ErrorThrower.cc,v 1.3 2008/11/04 20:38:55 elmer Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "DataFormats/FWLite/interface/ErrorThrower.h"
00018 #include "FWCore/Utilities/interface/EDMException.h"
00019 #include "FWCore/Utilities/interface/TypeID.h"
00020 #include <ostream>
00021 
00022 using namespace fwlite;
00023 //
00024 // constants, enums and typedefs
00025 //
00026 namespace {
00027    class NoProductErrorThrower : public ErrorThrower {
00028    public:
00029       NoProductErrorThrower(const std::type_info& iType, const char*iModule, const char*iInstance, const char*iProcess):
00030       type_(&iType), module_(iModule), instance_(iInstance), process_(iProcess) {}
00031       
00032       void throwIt() const {
00033 
00034          edm::TypeID type(*type_);
00035          throw edm::Exception(edm::errors::ProductNotFound)<<"A branch was found for \n  type ='"<<type.className()<<"'\n  module='"<<module_
00036          <<"'\n  productInstance='"<<((0!=instance_)?instance_:"")<<"'\n  process='"<<((0!=process_)?process_:"")<<"'\n"
00037          "but no data is available for this Event";
00038       }
00039       virtual ErrorThrower* clone() const {
00040          return new NoProductErrorThrower(*this);
00041       }
00042 
00043    private:
00044       const std::type_info* type_;
00045       const char* module_;
00046       const char* instance_;
00047       const char* process_;
00048    };
00049    
00050    class NoBranchErrorThrower : public ErrorThrower {
00051    public:
00052       NoBranchErrorThrower(const std::type_info& iType, const char*iModule, const char*iInstance, const char*iProcess):
00053       type_(&iType), module_(iModule), instance_(iInstance), process_(iProcess) {}
00054       
00055       void throwIt() const {
00056          
00057          edm::TypeID type(*type_);
00058          throw edm::Exception(edm::errors::ProductNotFound)<<"No branch was found for \n  type ='"<<type.className()<<"'\n  module='"<<module_
00059          <<"'\n  productInstance='"<<((0!=instance_)?instance_:"")<<"'\n  process='"<<((0!=process_)?process_:"")<<"'";
00060       }
00061       
00062       virtual ErrorThrower* clone() const {
00063          return new NoBranchErrorThrower(*this);
00064       }
00065       
00066    private:
00067       const std::type_info* type_;
00068       const char* module_;
00069       const char* instance_;
00070       const char* process_;
00071    };
00072    
00073    class UnsetErrorThrower : public ErrorThrower {
00074       void throwIt() const {
00075          throw cms::Exception("UnsetHandle")<<"The fwlite::Handle was never set";
00076       }
00077       
00078       virtual ErrorThrower* clone() const {
00079          return new UnsetErrorThrower(*this);
00080       }
00081       
00082    };
00083 }
00084 //
00085 // static data member definitions
00086 //
00087 
00088 //
00089 // constructors and destructor
00090 //
00091 ErrorThrower::ErrorThrower()
00092 {
00093 }
00094 
00095 // ErrorThrower::ErrorThrower(const ErrorThrower& rhs)
00096 // {
00097 //    // do actual copying here;
00098 // }
00099 
00100 ErrorThrower::~ErrorThrower()
00101 {
00102 }
00103 
00104 //
00105 // assignment operators
00106 //
00107 // const ErrorThrower& ErrorThrower::operator=(const ErrorThrower& rhs)
00108 // {
00109 //   //An exception safe implementation is
00110 //   ErrorThrower temp(rhs);
00111 //   swap(rhs);
00112 //
00113 //   return *this;
00114 // }
00115 
00116 //
00117 // member functions
00118 //
00119 
00120 //
00121 // const member functions
00122 //
00123 
00124 //
00125 // static member functions
00126 //
00127 ErrorThrower* 
00128 ErrorThrower::unsetErrorThrower() {
00129    return new UnsetErrorThrower();
00130 }
00131 
00132 ErrorThrower* 
00133 ErrorThrower::errorThrowerBranchNotFoundException(const std::type_info& iType, const char* iModule, const char* iInstance, const char* iProcess){
00134    return new NoBranchErrorThrower(iType,iModule,iInstance,iProcess);
00135 }
00136 
00137 ErrorThrower* 
00138 ErrorThrower::errorThrowerProductNotFoundException(const std::type_info& iType, const char* iModule, const char* iInstance, const char* iProcess){
00139    return new NoProductErrorThrower(iType,iModule,iInstance,iProcess);
00140 }