/
Principal.h
311 lines (235 loc) · 12.9 KB
/
Principal.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#ifndef FWCore_Framework_Principal_h
#define FWCore_Framework_Principal_h
/*----------------------------------------------------------------------
Principal: This is the implementation of the classes responsible
for management of EDProducts. It is not seen by reconstruction code.
The major internal component of the Principal is the ProductResolver, which
contains an EDProduct and its associated Provenance, along with
ancillary transient information regarding the two. ProductResolvers are handled
through shared pointers.
The Principal returns BasicHandle, rather than a shared
pointer to a ProductResolver, when queried.
(Historical note: prior to April 2007 this class was named DataBlockImpl)
----------------------------------------------------------------------*/
#include "DataFormats/Common/interface/BasicHandle.h"
#include "DataFormats/Common/interface/ConvertHandle.h"
#include "DataFormats/Common/interface/WrapperBase.h"
#include "DataFormats/Common/interface/EDProductGetter.h"
#include "DataFormats/Common/interface/Wrapper.h"
#include "DataFormats/Provenance/interface/ProcessHistory.h"
#include "DataFormats/Provenance/interface/ProvenanceFwd.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/ProductResolverBase.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/ProductKindOfType.h"
#include "FWCore/Utilities/interface/propagate_const.h"
#include "boost/iterator/filter_iterator.hpp"
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
namespace edm {
class HistoryAppender;
class ModuleCallingContext;
class ProcessHistoryRegistry;
class ProductResolverIndexHelper;
class EDConsumerBase;
class SharedResourcesAcquirer;
class InputProductResolver;
class WaitingTask;
struct FilledProductPtr {
bool operator()(propagate_const<std::shared_ptr<ProductResolverBase>> const& iObj) { return bool(iObj);}
};
class Principal : public EDProductGetter {
public:
typedef std::vector<propagate_const<std::shared_ptr<ProductResolverBase>> > ProductResolverCollection;
typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::const_iterator> const_iterator;
typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::iterator> iterator;
typedef ProcessHistory::const_iterator ProcessNameConstIterator;
typedef ProductResolverBase const* ConstProductResolverPtr;
typedef std::vector<BasicHandle> BasicHandleVec;
typedef ProductResolverCollection::size_type size_type;
typedef std::shared_ptr<ProductResolverBase> SharedProductPtr;
typedef std::string ProcessName;
Principal(std::shared_ptr<ProductRegistry const> reg,
std::shared_ptr<ProductResolverIndexHelper const> productLookup,
ProcessConfiguration const& pc,
BranchType bt,
HistoryAppender* historyAppender,
bool isForPrimaryProcess = true);
virtual ~Principal();
bool adjustToNewProductRegistry(ProductRegistry const& reg);
void adjustIndexesAfterProductRegistryAddition();
void fillPrincipal(ProcessHistoryID const& hist, ProcessHistoryRegistry const& phr, DelayedReader* reader);
void clearPrincipal();
void setAtEndTransition(bool iAtEnd);
bool atEndTransition() const {return atEndTransition_;}
void deleteProduct(BranchID const& id) const;
EDProductGetter const* prodGetter() const {return this;}
// Return a BasicHandle to the product which:
// 1. matches the given label, instance, and process
// (if process if empty gets the match from the most recent process)
// 2. If kindOfType is PRODUCT, then the type of the product matches typeID
// 3. If kindOfType is ELEMENT
// a. the product is a sequence,
// b. the sequence has the nested type 'value_type'
// c. typeID is the same as or a public base of
// this value_type,
BasicHandle getByLabel(KindOfType kindOfType,
TypeID const& typeID,
InputTag const& inputTag,
EDConsumerBase const* consumes,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const;
BasicHandle getByLabel(KindOfType kindOfType,
TypeID const& typeID,
std::string const& label,
std::string const& instance,
std::string const& process,
EDConsumerBase const* consumes,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const;
BasicHandle getByToken(KindOfType kindOfType,
TypeID const& typeID,
ProductResolverIndex index,
bool skipCurrentProcess,
bool& ambiguous,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const;
void prefetchAsync(WaitingTask* waitTask,
ProductResolverIndex index,
bool skipCurrentProcess,
ModuleCallingContext const* mcc) const;
void getManyByType(TypeID const& typeID,
BasicHandleVec& results,
EDConsumerBase const* consumes,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const;
ProcessHistory const& processHistory() const {
return *processHistoryPtr_;
}
ProcessHistoryID const& processHistoryID() const {
return processHistoryID_;
}
ProcessConfiguration const& processConfiguration() const {return *processConfiguration_;}
ProductRegistry const& productRegistry() const {return *preg_;}
ProductResolverIndexHelper const& productLookup() const {return *productLookup_;}
// merge Principals containing different products.
void recombine(Principal& other, std::vector<BranchID> const& bids);
ProductResolverBase* getModifiableProductResolver(BranchID const& oid) {
return const_cast<ProductResolverBase*>( const_cast<const Principal*>(this)->getProductResolver(oid));
}
size_t size() const;
// These iterators skip over any null shared pointers
const_iterator begin() const {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());}
const_iterator end() const {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());}
iterator begin() {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());}
iterator end() {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());}
Provenance getProvenance(BranchID const& bid,
ModuleCallingContext const* mcc) const;
void getAllProvenance(std::vector<Provenance const*>& provenances) const;
void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
BranchType const& branchType() const {return branchType_;}
//This will never return 0 so you can use 0 to mean unset
typedef unsigned long CacheIdentifier_t;
CacheIdentifier_t cacheIdentifier() const {return cacheIdentifier_;}
DelayedReader* reader() const {return reader_;}
ConstProductResolverPtr getProductResolver(BranchID const& oid) const;
ProductData const* findProductByTag(TypeID const& typeID, InputTag const& tag, ModuleCallingContext const* mcc) const;
void readAllFromSourceAndMergeImmediately();
//For end Run/Lumi we need to reset products failed in the begin
// transition since they may be put into the Principal at the
// end transition
void resetFailedFromThisProcess();
std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const& oid) const;
bool isComplete() const {return isComplete_();}
protected:
// ----- Add a new ProductResolver
// *this takes ownership of the ProductResolver, which in turn owns its
// data.
void addProduct_(std::unique_ptr<ProductResolverBase> phb);
void addProductOrThrow(std::unique_ptr<ProductResolverBase> phb);
ProductResolverBase* getExistingProduct(BranchID const& branchID);
ProductResolverBase const* getExistingProduct(BranchID const& branchID) const;
ProductResolverBase const* getExistingProduct(ProductResolverBase const& phb) const;
void putOrMerge(BranchDescription const& bd, std::unique_ptr<WrapperBase> edp) const;
//F must take an argument of type ProductResolverBase*
template <typename F>
void applyToResolvers( F iFunc) {
for(auto& resolver: productResolvers_) {
iFunc(resolver.get());
}
}
private:
void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
void addInputProduct(std::shared_ptr<BranchDescription const> bd);
void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);
virtual WrapperBase const* getIt(ProductID const&) const override;
virtual WrapperBase const* getThinnedProduct(ProductID const&, unsigned int&) const override;
virtual void getThinnedProducts(ProductID const&,
std::vector<WrapperBase const*>&,
std::vector<unsigned int>&) const override;
void findProducts(std::vector<ProductResolverBase const*> const& holders,
TypeID const& typeID,
BasicHandleVec& results,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const;
ProductData const* findProductByLabel(KindOfType kindOfType,
TypeID const& typeID,
InputTag const& inputTag,
EDConsumerBase const* consumer,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const;
ProductData const* findProductByLabel(KindOfType kindOfType,
TypeID const& typeID,
std::string const& label,
std::string const& instance,
std::string const& process,
EDConsumerBase const* consumer,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const;
virtual bool isComplete_() const {return true;}
void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductResolverBase const* productResolver) const;
std::shared_ptr<ProcessHistory const> processHistoryPtr_;
ProcessHistoryID processHistoryID_;
ProcessConfiguration const* processConfiguration_;
// A vector of product holders.
ProductResolverCollection productResolvers_; // products and provenances are persistent
// Pointer to the product registry. There is one entry in the registry
// for each EDProduct in the event.
std::shared_ptr<ProductRegistry const> preg_;
std::shared_ptr<ProductResolverIndexHelper const> productLookup_;
std::vector<unsigned int> lookupProcessOrder_;
ProcessHistoryID orderProcessHistoryID_;
// Pointer to the 'source' that will be used to obtain EDProducts
// from the persistent store. This 'source' is owned by the input source.
DelayedReader* reader_;
BranchType branchType_;
// In use cases where the new process should not be appended to
// input ProcessHistory, the following pointer should be null.
// The Principal does not own this object.
edm::propagate_const<HistoryAppender*> historyAppender_;
CacheIdentifier_t cacheIdentifier_;
bool atEndTransition_;
};
template <typename PROD>
inline
std::shared_ptr<Wrapper<PROD> const>
getProductByTag(Principal const& ep, InputTag const& tag, ModuleCallingContext const* mcc) {
TypeID tid = TypeID(typeid(PROD));
ProductData const* result = ep.findProductByTag(tid, tag, mcc);
if(result == nullptr) {
return std::shared_ptr<Wrapper<PROD> const>();
}
if(!(result->wrapper()->dynamicTypeInfo() == typeid(PROD))) {
handleimpl::throwConvertTypeError(typeid(PROD), result->wrapper()->dynamicTypeInfo());
}
return std::static_pointer_cast<Wrapper<PROD> const>(result->sharedConstWrapper());
}
}
#endif