CMS 3D CMS Logo

DependentRecordImplementation.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_DependentRecordImplementation_h
2 #define FWCore_Framework_DependentRecordImplementation_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : DependentRecordImplementation
7 //
16 //
17 // Author: Chris Jones
18 // Created: Fri Apr 29 10:03:54 EDT 2005
19 //
20 
21 // system include files
22 #include "boost/mpl/begin_end.hpp"
23 #include "boost/mpl/find.hpp"
24 #include <sstream>
25 #include <type_traits>
26 
27 // user include files
33 
34 //This is here only because too many modules depend no
35 // getting this header from this file (before EventSetupImpl)
37 
38 // forward declarations
39 namespace edm {
40  namespace eventsetup {
41 
42  template <class RecordT, class ListT>
44  public:
46  typedef ListT list_type;
47  //virtual ~DependentRecordImplementation();
48 
49  // ---------- const member functions ---------------------
50  template <class DepRecordT>
51  const DepRecordT getRecord() const {
52  //Make sure that DepRecordT is a type in ListT
53  typedef typename boost::mpl::end<ListT>::type EndItrT;
54  typedef typename boost::mpl::find<ListT, DepRecordT>::type FoundItrT;
55  static_assert(
57  "Trying to get a Record from another Record where the second Record is not dependent on the first Record.");
58  try {
59  EventSetup const eventSetupT{this->eventSetup(), this->transitionID(), this->getTokenIndices()};
60  return eventSetupT.get<DepRecordT>();
61  } catch (cms::Exception& e) {
62  std::ostringstream sstrm;
63  sstrm << "While getting dependent Record from Record " << this->key().type().name();
64  e.addContext(sstrm.str());
65  throw;
66  }
67  }
68 
69  template <class DepRecordT>
70  std::optional<DepRecordT> tryToGetRecord() const {
71  //Make sure that DepRecordT is a type in ListT
72  typedef typename boost::mpl::end<ListT>::type EndItrT;
73  typedef typename boost::mpl::find<ListT, DepRecordT>::type FoundItrT;
74  static_assert(
76  "Trying to get a Record from another Record where the second Record is not dependent on the first Record.");
77  EventSetup const eventSetupT{this->eventSetup(), this->transitionID(), this->getTokenIndices()};
78  return eventSetupT.tryToGet<DepRecordT>();
79  }
80 
82 
83  template <typename ProductT, typename DepRecordT>
85  //Make sure that DepRecordT is a type in ListT
86  using EndItrT = typename boost::mpl::end<ListT>::type;
87  using FoundItrT = typename boost::mpl::find<ListT, DepRecordT>::type;
89  "Trying to get a product with an ESGetToken specifying a Record from another Record where the "
90  "second Record is not dependent on the first Record.");
91  return getRecord<DepRecordT>().getHandle(iToken);
92  }
93 
95 
96  template <typename ProductT, typename DepRecordT>
98  //Make sure that DepRecordT is a type in ListT
99  using EndItrT = typename boost::mpl::end<ListT>::type;
100  using FoundItrT = typename boost::mpl::find<ListT, DepRecordT>::type;
102  "Trying to get a product with an ESGetToken specifying a Record from another Record where the "
103  "second Record is not dependent on the first Record.");
104  return getRecord<DepRecordT>().getTransientHandle(iToken);
105  }
106 
108 
109  template <typename ProductT, typename DepRecordT>
110  ProductT const& get(ESGetToken<ProductT, DepRecordT> const& iToken) const {
111  //Make sure that DepRecordT is a type in ListT
112  using EndItrT = typename boost::mpl::end<ListT>::type;
113  using FoundItrT = typename boost::mpl::find<ListT, DepRecordT>::type;
115  "Trying to get a product with an ESGetToken specifying a Record from another Record where the "
116  "second Record is not dependent on the first Record.");
117  return getRecord<DepRecordT>().get(iToken);
118  }
119 
120  template <typename ProductT, typename DepRecordT>
121  ProductT const& get(ESGetToken<ProductT, DepRecordT>& iToken) const {
122  return get(const_cast<ESGetToken<ProductT, DepRecordT> const&>(iToken));
123  }
124 
125  // ---------- static member functions --------------------
126 
127  // ---------- member functions ---------------------------
128 
129  private:
130  // ---------- member data --------------------------------
131  };
132 
133  } // namespace eventsetup
134 } // namespace edm
135 
136 #endif
type
Definition: HCALResponse.h:21
ESHandle< ProductT > getHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
ESTransientHandle< ProductT > getTransientHandle(ESGetToken< ProductT, DepRecordT > const &iToken) const
unsigned int transitionID() const
EventSetupImpl const & eventSetup() const
void addContext(std::string const &context)
Definition: Exception.cc:165
HLT enums.
ESProxyIndex const * getTokenIndices() const