-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
LuminosityBlock.h
282 lines (226 loc) · 9.51 KB
/
LuminosityBlock.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
#ifndef FWCore_Framework_LuminosityBlock_h
#define FWCore_Framework_LuminosityBlock_h
// -*- C++ -*-
//
// Package: Framework
// Class : LuminosityBlock
//
/**\class LuminosityBlock LuminosityBlock.h FWCore/Framework/interface/LuminosityBlock.h
Description: This is the primary interface for accessing per luminosity block EDProducts
and inserting new derived per luminosity block EDProducts.
For its usage, see "FWCore/Framework/interface/PrincipalGetAdapter.h"
*/
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
#include "DataFormats/Common/interface/Wrapper.h"
#include "FWCore/Common/interface/LuminosityBlockBase.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/PrincipalGetAdapter.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/ProductKindOfType.h"
#include "FWCore/Utilities/interface/LuminosityBlockIndex.h"
#include "FWCore/Utilities/interface/propagate_const.h"
#include <memory>
#include <string>
#include <typeinfo>
#include <vector>
namespace edm {
class ModuleCallingContext;
class ProducerBase;
class SharedResourcesAcquirer;
namespace stream {
template< typename T> class ProducingModuleAdaptorBase;
}
class LuminosityBlock : public LuminosityBlockBase {
public:
LuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleDescription const& md,
ModuleCallingContext const*);
~LuminosityBlock();
// AUX functions are defined in LuminosityBlockBase
LuminosityBlockAuxiliary const& luminosityBlockAuxiliary() const {return aux_;}
/**\return Reusable index which can be used to separate data for different simultaneous LuminosityBlocks.
*/
LuminosityBlockIndex index() const;
/**If you are caching data from the LuminosityBlock, you should also keep
this number. If this number changes then you know that
the data you have cached is invalid.
The value of '0' will never be returned so you can use that to
denote that you have not yet checked the value.
*/
typedef unsigned long CacheIdentifier_t;
CacheIdentifier_t
cacheIdentifier() const;
//Used in conjunction with EDGetToken
void setConsumer(EDConsumerBase const* iConsumer);
void setSharedResourcesAcquirer( SharedResourcesAcquirer* iResourceAcquirer);
template <typename PROD>
bool
getByLabel(std::string const& label, Handle<PROD>& result) const;
template <typename PROD>
bool
getByLabel(std::string const& label,
std::string const& productInstanceName,
Handle<PROD>& result) const;
/// same as above, but using the InputTag class
template <typename PROD>
bool
getByLabel(InputTag const& tag, Handle<PROD>& result) const;
template<typename PROD>
bool
getByToken(EDGetToken token, Handle<PROD>& result) const;
template<typename PROD>
bool
getByToken(EDGetTokenT<PROD> token, Handle<PROD>& result) const;
template <typename PROD>
void
getManyByType(std::vector<Handle<PROD> >& results) const;
Run const&
getRun() const {
return *run_;
}
///Put a new product.
template <typename PROD>
void
put(std::auto_ptr<PROD> product) {put<PROD>(product, std::string());}
template <typename PROD>
void
put(std::unique_ptr<PROD> product) {put<PROD>(product, std::string());}
///Put a new product with a 'product instance name'
template <typename PROD>
void
put(std::auto_ptr<PROD> product, std::string const& productInstanceName);
template <typename PROD>
void
put(std::unique_ptr<PROD> product, std::string const& productInstanceName);
Provenance
getProvenance(BranchID const& theID) const;
void
getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
ProcessHistoryID const& processHistoryID() const;
ProcessHistory const&
processHistory() const;
ModuleCallingContext const* moduleCallingContext() const { return moduleCallingContext_; }
void labelsForToken(EDGetToken const& iToken, ProductLabels& oLabels) const { provRecorder_.labelsForToken(iToken, oLabels); }
private:
LuminosityBlockPrincipal const&
luminosityBlockPrincipal() const;
// Override version from LuminosityBlockBase class
virtual BasicHandle getByLabelImpl(std::type_info const& iWrapperType, std::type_info const& iProductType, InputTag const& iTag) const;
typedef std::vector<std::pair<edm::propagate_const<std::unique_ptr<WrapperBase>>, BranchDescription const*>> ProductPtrVec;
ProductPtrVec& putProducts() {return putProducts_;}
ProductPtrVec const& putProducts() const {return putProducts_;}
// commit_() is called to complete the transaction represented by
// this PrincipalGetAdapter. The friendships required seems gross, but any
// alternative is not great either. Putting it into the
// public interface is asking for trouble
friend class InputSource;
friend class RawInputSource;
friend class ProducerBase;
template<typename T> friend class stream::ProducingModuleAdaptorBase;
void commit_();
PrincipalGetAdapter provRecorder_;
ProductPtrVec putProducts_;
LuminosityBlockAuxiliary const& aux_;
std::shared_ptr<Run const> const run_;
ModuleCallingContext const* moduleCallingContext_;
static const std::string emptyString_;
};
template <typename PROD>
void
LuminosityBlock::put(std::auto_ptr<PROD> product, std::string const& productInstanceName) {
put(std::unique_ptr<PROD>(product.release()),productInstanceName);
}
template <typename PROD>
void
LuminosityBlock::put(std::unique_ptr<PROD> product, std::string const& productInstanceName) {
if(product.get() == 0) { // null pointer is illegal
TypeID typeID(typeid(PROD));
principal_get_adapter_detail::throwOnPutOfNullProduct("LuminosityBlock", typeID, productInstanceName);
}
// The following will call post_insert if T has such a function,
// and do nothing if T has no such function.
typename boost::mpl::if_c<detail::has_postinsert<PROD>::value,
DoPostInsert<PROD>,
DoNotPostInsert<PROD> >::type maybe_inserter;
maybe_inserter(product.get());
BranchDescription const& desc =
provRecorder_.getBranchDescription(TypeID(*product), productInstanceName);
std::unique_ptr<Wrapper<PROD> > wp(new Wrapper<PROD>(std::move(product)));
putProducts().emplace_back(std::move(wp), &desc);
// product.release(); // The object has been copied into the Wrapper.
// The old copy must be deleted, so we cannot release ownership.
}
template<typename PROD>
bool
LuminosityBlock::getByLabel(std::string const& label, Handle<PROD>& result) const {
return getByLabel(label, emptyString_, result);
}
template<typename PROD>
bool
LuminosityBlock::getByLabel(std::string const& label,
std::string const& productInstanceName,
Handle<PROD>& result) const {
if(!provRecorder_.checkIfComplete<PROD>()) {
principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), label, productInstanceName);
}
result.clear();
BasicHandle bh = provRecorder_.getByLabel_(TypeID(typeid(PROD)), label, productInstanceName, emptyString_, moduleCallingContext_);
convert_handle(std::move(bh), result); // throws on conversion error
if (result.failedToGet()) {
return false;
}
return true;
}
/// same as above, but using the InputTag class
template<typename PROD>
bool
LuminosityBlock::getByLabel(InputTag const& tag, Handle<PROD>& result) const {
if(!provRecorder_.checkIfComplete<PROD>()) {
principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), tag.label(), tag.instance());
}
result.clear();
BasicHandle bh = provRecorder_.getByLabel_(TypeID(typeid(PROD)), tag, moduleCallingContext_);
convert_handle(std::move(bh), result); // throws on conversion error
if (result.failedToGet()) {
return false;
}
return true;
}
template<typename PROD>
bool
LuminosityBlock::getByToken(EDGetToken token, Handle<PROD>& result) const {
if(!provRecorder_.checkIfComplete<PROD>()) {
principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), token);
}
result.clear();
BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)),PRODUCT_TYPE, token, moduleCallingContext_);
convert_handle(std::move(bh), result); // throws on conversion error
if (result.failedToGet()) {
return false;
}
return true;
}
template<typename PROD>
bool
LuminosityBlock::getByToken(EDGetTokenT<PROD> token, Handle<PROD>& result) const {
if(!provRecorder_.checkIfComplete<PROD>()) {
principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)), token);
}
result.clear();
BasicHandle bh = provRecorder_.getByToken_(TypeID(typeid(PROD)),PRODUCT_TYPE, token, moduleCallingContext_);
convert_handle(std::move(bh), result); // throws on conversion error
if (result.failedToGet()) {
return false;
}
return true;
}
template<typename PROD>
void
LuminosityBlock::getManyByType(std::vector<Handle<PROD> >& results) const {
if(!provRecorder_.checkIfComplete<PROD>()) {
principal_get_adapter_detail::throwOnPrematureRead("Lumi", TypeID(typeid(PROD)));
}
return provRecorder_.getManyByType(results, moduleCallingContext_);
}
}
#endif