Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_FWLite_ESHandle_h
0002 #define DataFormats_FWLite_ESHandle_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWLite
0006 // Class  :     ESHandle
0007 //
0008 /**\class ESHandle ESHandle.h DataFormats/FWLite/interface/ESHandle.h
0009 
0010  Description: Used with fwlite::Record to retrieve conditions information
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Mon Dec 14 15:16:07 CST 2009
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include <typeinfo>
0024 #include <vector>
0025 
0026 // user include files
0027 #include "FWCore/Utilities/interface/Exception.h"
0028 #include "FWCore/Utilities/interface/propagate_const.h"
0029 
0030 // forward declarations
0031 namespace fwlite {
0032   class Record;
0033 
0034   std::shared_ptr<cms::Exception> eshandle_not_set_exception();
0035 
0036   template <class T>
0037   class ESHandle {
0038     friend class fwlite::Record;
0039 
0040   public:
0041     ESHandle() : m_data(nullptr), m_exception(eshandle_not_set_exception()) {}
0042 
0043     // ---------- const member functions ---------------------
0044     bool isValid() const { return nullptr != m_data; }
0045 
0046     const T& operator*() const {
0047       if (nullptr != m_exception.get()) {
0048         throw *m_exception;
0049       }
0050       return *m_data;
0051     }
0052 
0053     const T* operator->() const {
0054       if (nullptr != m_exception.get()) {
0055         throw *m_exception;
0056       }
0057       return m_data;
0058     }
0059 
0060     const std::type_info& typeInfo() const { return typeid(T); }
0061     // ---------- static member functions --------------------
0062 
0063     // ---------- member functions ---------------------------
0064 
0065   private:
0066     ESHandle(const void* iData) : m_data(static_cast<const T*>(iData)), m_exception() {}
0067     ESHandle(cms::Exception* iException) : m_data(nullptr), m_exception(iException) {}
0068     //ESHandle(const ESHandle&); // stop default
0069 
0070     //const ESHandle& operator=(const ESHandle&); // stop default
0071 
0072     // ---------- member data --------------------------------
0073     const T* m_data;
0074     std::shared_ptr<cms::Exception const> m_exception;
0075   };
0076 
0077 }  // namespace fwlite
0078 #endif