File indexing completed on 2024-04-06 12:11:55
0001 #ifndef FWCore_Common_EventBase_h
0002 #define FWCore_Common_EventBase_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "DataFormats/Common/interface/BasicHandle.h"
0025
0026 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0027 #include "DataFormats/Provenance/interface/EventID.h"
0028 #include "DataFormats/Provenance/interface/Timestamp.h"
0029 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0030 #include "DataFormats/Common/interface/ConvertHandle.h"
0031 #include "DataFormats/Common/interface/Handle.h"
0032 #include "FWCore/Common/interface/TriggerResultsByName.h"
0033 #include "FWCore/Utilities/interface/InputTag.h"
0034 #include "FWCore/Utilities/interface/EDGetToken.h"
0035
0036
0037 #include <typeinfo>
0038
0039 namespace edm {
0040
0041 class ProcessHistory;
0042 class ProductID;
0043 class TriggerResults;
0044 class TriggerNames;
0045 class ParameterSet;
0046
0047 class EventBase {
0048 public:
0049 EventBase();
0050 virtual ~EventBase();
0051
0052
0053 template <typename T>
0054 bool getByLabel(InputTag const&, Handle<T>&) const;
0055
0056 template <typename T>
0057 bool getByToken(edm::EDGetTokenT<T> const& token, edm::Handle<T>& result) const;
0058
0059 template <typename T>
0060 bool get(ProductID const&, Handle<T>&) const;
0061
0062
0063 edm::EventID id() const { return eventAuxiliary().id(); }
0064 edm::Timestamp time() const { return eventAuxiliary().time(); }
0065 edm::LuminosityBlockNumber_t luminosityBlock() const { return eventAuxiliary().luminosityBlock(); }
0066 bool isRealData() const { return eventAuxiliary().isRealData(); }
0067 edm::EventAuxiliary::ExperimentType experimentType() const { return eventAuxiliary().experimentType(); }
0068 int bunchCrossing() const { return eventAuxiliary().bunchCrossing(); }
0069 int orbitNumber() const { return eventAuxiliary().orbitNumber(); }
0070 virtual edm::EventAuxiliary const& eventAuxiliary() const = 0;
0071
0072 virtual TriggerNames const& triggerNames(edm::TriggerResults const& triggerResults) const = 0;
0073 virtual TriggerResultsByName triggerResultsByName(edm::TriggerResults const& triggerResults) const = 0;
0074 virtual ProcessHistory const& processHistory() const = 0;
0075
0076 virtual edm::ParameterSet const* parameterSet(edm::ParameterSetID const& psID) const = 0;
0077
0078 protected:
0079 static TriggerNames const* triggerNames_(edm::TriggerResults const& triggerResults);
0080
0081 static edm::ParameterSet const* parameterSetForID_(edm::ParameterSetID const& psID);
0082
0083 private:
0084
0085
0086
0087
0088 virtual BasicHandle getByLabelImpl(std::type_info const& iWrapperType,
0089 std::type_info const& iProductType,
0090 InputTag const& iTag) const = 0;
0091 virtual BasicHandle getByTokenImpl(std::type_info const& iProductType, EDGetToken) const = 0;
0092 virtual BasicHandle getImpl(std::type_info const& iProductType, ProductID const& iTag) const = 0;
0093
0094 };
0095
0096 template <typename T>
0097 bool EventBase::getByLabel(InputTag const& tag, Handle<T>& result) const {
0098 result.clear();
0099 BasicHandle bh = this->getByLabelImpl(typeid(edm::Wrapper<T>), typeid(T), tag);
0100 result = convert_handle<T>(std::move(bh));
0101 if (result.failedToGet()) {
0102 return false;
0103 }
0104 return true;
0105 }
0106
0107 template <typename T>
0108 bool EventBase::getByToken(edm::EDGetTokenT<T> const& token, edm::Handle<T>& result) const {
0109 result.clear();
0110 edm::BasicHandle bh = this->getByTokenImpl(typeid(T), token);
0111 result = edm::convert_handle<T>(std::move(bh));
0112 if (result.failedToGet()) {
0113 return false;
0114 }
0115 return true;
0116 }
0117
0118 template <typename T>
0119 bool EventBase::get(ProductID const& pid, Handle<T>& result) const {
0120 result.clear();
0121 BasicHandle bh = this->getImpl(typeid(T), pid);
0122 result = convert_handle_check_type<T>(std::move(bh));
0123 if (result.failedToGet()) {
0124 return false;
0125 }
0126 return true;
0127 }
0128
0129 }
0130
0131 #endif