/
EDConsumerBase.h
193 lines (152 loc) · 6.92 KB
/
EDConsumerBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#ifndef FWCore_Framework_EDConsumerBase_h
#define FWCore_Framework_EDConsumerBase_h
// -*- C++ -*-
//
// Package: FWCore/Framework
// Class : EDConsumerBase
//
/**\class edm::EDConsumerBase
Description: Allows declaration of what data is being consumed
Usage:
The EDM modules all inherit from this base class
*/
//
// Original Author: Chris Jones
// Created: Tue, 02 Apr 2013 21:35:53 GMT
//
// system include files
#include <map>
#include <string>
#include <vector>
// user include files
#include "FWCore/Framework/interface/ProductResolverIndexAndSkipBit.h"
#include "FWCore/ServiceRegistry/interface/ConsumesInfo.h"
#include "FWCore/Utilities/interface/TypeID.h"
#include "FWCore/Utilities/interface/TypeToGet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/SoATuple.h"
#include "DataFormats/Provenance/interface/BranchType.h"
#include "FWCore/Utilities/interface/ProductResolverIndex.h"
#include "FWCore/Utilities/interface/ProductKindOfType.h"
#include "FWCore/Utilities/interface/ProductLabels.h"
// forward declarations
namespace edm {
class ModuleDescription;
class ProductResolverIndexHelper;
class ProductRegistry;
class ConsumesCollector;
template<typename T> class WillGetIfMatch;
class EDConsumerBase
{
public:
EDConsumerBase() : frozen_(false) {}
virtual ~EDConsumerBase() noexcept(false);
// disallow copying
EDConsumerBase(EDConsumerBase const&) = delete;
EDConsumerBase const& operator=(EDConsumerBase const&) = delete;
// allow moving
EDConsumerBase(EDConsumerBase&&) = default;
EDConsumerBase& operator=(EDConsumerBase&&) = default;
// ---------- const member functions ---------------------
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const&) const;
void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const { return itemsToGetFromBranch_[iType]; }
///\return true if the product corresponding to the index was registered via consumes or mayConsume call
bool registeredToConsume(ProductResolverIndex, bool, BranchType) const;
///\return true of TypeID corresponds to a type specified in a consumesMany call
bool registeredToConsumeMany(TypeID const&, BranchType) const;
// ---------- static member functions --------------------
// ---------- member functions ---------------------------
void updateLookup(BranchType iBranchType,
ProductResolverIndexHelper const&,
bool iPrefetchMayGet);
typedef ProductLabels Labels;
void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
void modulesWhoseProductsAreConsumed(std::vector<ModuleDescription const*>& modules,
ProductRegistry const& preg,
std::map<std::string, ModuleDescription const*> const& labelsToDesc,
std::string const& processName) const;
std::vector<ConsumesInfo> consumesInfo() const;
protected:
friend class ConsumesCollector;
template<typename T> friend class WillGetIfMatch;
///Use a ConsumesCollector to gather consumes information from helper functions
ConsumesCollector consumesCollector();
template <typename ProductType, BranchType B=InEvent>
EDGetTokenT<ProductType> consumes(edm::InputTag const& tag) {
TypeToGet tid=TypeToGet::make<ProductType>();
return EDGetTokenT<ProductType>{recordConsumes(B,tid, checkIfEmpty(tag),true)};
}
EDGetToken consumes(const TypeToGet& id, edm::InputTag const& tag) {
return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
}
template <BranchType B>
EDGetToken consumes(TypeToGet const& id, edm::InputTag const& tag) {
return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
}
template <typename ProductType, BranchType B=InEvent>
EDGetTokenT<ProductType> mayConsume(edm::InputTag const& tag) {
TypeToGet tid=TypeToGet::make<ProductType>();
return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), false)};
}
EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) {
return mayConsume<InEvent>(id,tag);
}
template <BranchType B>
EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) {
return EDGetToken{recordConsumes(B,id,checkIfEmpty(tag),false)};
}
template <typename ProductType, BranchType B=InEvent>
void consumesMany() {
TypeToGet tid=TypeToGet::make<ProductType>();
consumesMany<B>(tid);
}
void consumesMany(const TypeToGet& id) {
consumesMany<InEvent>(id);
}
template <BranchType B>
void consumesMany(const TypeToGet& id) {
recordConsumes(B,id,edm::InputTag{},true);
}
private:
unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
void throwBranchMismatch(BranchType, EDGetToken) const;
void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
edm::InputTag const& checkIfEmpty(edm::InputTag const& tag);
// ---------- member data --------------------------------
struct TokenLookupInfo {
TokenLookupInfo(edm::TypeID const& iID,
ProductResolverIndex iIndex,
bool skipCurrentProcess,
BranchType iBranch):
m_type(iID),m_index(iIndex, skipCurrentProcess), m_branchType(iBranch){}
edm::TypeID m_type;
ProductResolverIndexAndSkipBit m_index;
BranchType m_branchType;
};
struct LabelPlacement {
LabelPlacement(unsigned int iStartOfModuleLabel,
unsigned short iDeltaToProductInstance,
unsigned short iDeltaToProcessName):
m_startOfModuleLabel(iStartOfModuleLabel),
m_deltaToProductInstance(iDeltaToProductInstance),
m_deltaToProcessName(iDeltaToProcessName) {}
unsigned int m_startOfModuleLabel;
unsigned short m_deltaToProductInstance;
unsigned short m_deltaToProcessName;
};
//define the purpose of each 'column' in m_tokenInfo
enum {kLookupInfo,kAlwaysGets,kLabels,kKind};
edm::SoATuple<TokenLookupInfo,bool,LabelPlacement,edm::KindOfType> m_tokenInfo;
//m_tokenStartOfLabels holds the entries into this container
// for each of the 3 labels needed to id the data
std::vector<char> m_tokenLabels;
std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
bool frozen_;
};
}
#endif