00001 #ifndef FWCore_Framework_EDConsumerBase_h
00002 #define FWCore_Framework_EDConsumerBase_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020
00021
00022
00023 #include <vector>
00024
00025
00026 #include "FWCore/Utilities/interface/TypeID.h"
00027 #include "FWCore/Utilities/interface/TypeToGet.h"
00028 #include "FWCore/Utilities/interface/InputTag.h"
00029 #include "FWCore/Utilities/interface/EDGetToken.h"
00030 #include "FWCore/Utilities/interface/SoATuple.h"
00031 #include "DataFormats/Provenance/interface/BranchType.h"
00032 #include "FWCore/Utilities/interface/ProductHolderIndex.h"
00033 #include "FWCore/Utilities/interface/ProductKindOfType.h"
00034
00035
00036
00037
00038 namespace edm {
00039 class ProductHolderIndexHelper;
00040 class ConsumesCollector;
00041
00042 class EDConsumerBase
00043 {
00044
00045 public:
00046 EDConsumerBase() {}
00047 virtual ~EDConsumerBase();
00048
00049
00050 ProductHolderIndex indexFrom(EDGetToken, BranchType, TypeID const&) const;
00051
00052 void itemsToGet(BranchType, std::vector<ProductHolderIndex>&) const;
00053 void itemsMayGet(BranchType, std::vector<ProductHolderIndex>&) const;
00054
00055
00056
00057
00058 void updateLookup(BranchType iBranchType,
00059 ProductHolderIndexHelper const&);
00060
00061 struct Labels {
00062 const char* module;
00063 const char* productInstance;
00064 const char* process;
00065 };
00066 void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
00067
00068 protected:
00069 friend class ConsumesCollector;
00071 ConsumesCollector consumesCollector();
00072
00073 template <typename ProductType, BranchType B=InEvent>
00074 EDGetTokenT<ProductType> consumes(edm::InputTag const& tag) {
00075 TypeToGet tid=TypeToGet::make<ProductType>();
00076 return EDGetTokenT<ProductType>{recordConsumes(B,tid, tag,true), tag.willSkipCurrentProcess()};
00077 }
00078
00079 EDGetToken consumes(const TypeToGet& id, edm::InputTag const& tag) {
00080 return EDGetToken{recordConsumes(InEvent,id,tag,true), tag.willSkipCurrentProcess()};
00081 }
00082
00083 template <BranchType B>
00084 EDGetToken consumes(TypeToGet const& id, edm::InputTag const& tag) {
00085 return EDGetToken{recordConsumes(B,id,tag,true), tag.willSkipCurrentProcess()};
00086 }
00087
00088 template <typename ProductType, BranchType B=InEvent>
00089 EDGetTokenT<ProductType> mayConsume(edm::InputTag const& tag) {
00090 TypeToGet tid=TypeToGet::make<ProductType>();
00091 return EDGetTokenT<ProductType>{recordConsumes(B,tid, tag,false), tag.willSkipCurrentProcess()};
00092 }
00093
00094
00095 EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) {
00096 return mayConsume<InEvent>(id,tag);
00097 }
00098
00099 template <BranchType B>
00100 EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) {
00101 return EDGetToken{recordConsumes(B,id,tag,false), tag.willSkipCurrentProcess()};
00102 }
00103
00104 template <typename ProductType, BranchType B=InEvent>
00105 void consumesMany() {
00106 TypeToGet tid=TypeToGet::make<ProductType>();
00107 consumesMany<B>(tid);
00108 }
00109
00110
00111 void consumesMany(const TypeToGet& id) {
00112 consumesMany<InEvent>(id);
00113 }
00114
00115 template <BranchType B>
00116 void consumesMany(const TypeToGet& id) {
00117 recordConsumes(B,id,edm::InputTag{},true);
00118 }
00119
00120 private:
00121 EDConsumerBase(const EDConsumerBase&) = delete;
00122
00123 const EDConsumerBase& operator=(const EDConsumerBase&) = delete;
00124
00125 unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
00126
00127 void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
00128 void throwBranchMismatch(BranchType, EDGetToken) const;
00129 void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
00130
00131
00132 struct TokenLookupInfo {
00133 TokenLookupInfo(edm::TypeID const& iID,
00134 ProductHolderIndex iIndex,
00135 BranchType iBranch):
00136 m_type(iID),m_index(iIndex),m_branchType(iBranch){}
00137 edm::TypeID m_type;
00138 ProductHolderIndex m_index;
00139 BranchType m_branchType;
00140 };
00141
00142 struct LabelPlacement {
00143 LabelPlacement(unsigned int iStartOfModuleLabel,
00144 unsigned short iDeltaToProductInstance,
00145 unsigned short iDeltaToProcessName):
00146 m_startOfModuleLabel(iStartOfModuleLabel),
00147 m_deltaToProductInstance(iDeltaToProductInstance),
00148 m_deltaToProcessName(iDeltaToProcessName) {}
00149 unsigned int m_startOfModuleLabel;
00150 unsigned short m_deltaToProductInstance;
00151 unsigned short m_deltaToProcessName;
00152 };
00153
00154
00155 enum {kLookupInfo,kAlwaysGets,kLabels,kKind};
00156 edm::SoATuple<TokenLookupInfo,bool,LabelPlacement,edm::KindOfType> m_tokenInfo;
00157
00158
00159
00160 std::vector<char> m_tokenLabels;
00161
00162 };
00163 }
00164
00165
00166 #endif