File indexing completed on 2024-04-06 12:04:09
0001 #ifndef DataFormats_FWLite_ESHandle_h
0002 #define DataFormats_FWLite_ESHandle_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <memory>
0023 #include <typeinfo>
0024 #include <vector>
0025
0026
0027 #include "FWCore/Utilities/interface/Exception.h"
0028 #include "FWCore/Utilities/interface/propagate_const.h"
0029
0030
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
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
0062
0063
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
0069
0070
0071
0072
0073 const T* m_data;
0074 std::shared_ptr<cms::Exception const> m_exception;
0075 };
0076
0077 }
0078 #endif