/
EDAnalyzerAdaptor.h
212 lines (184 loc) · 9.37 KB
/
EDAnalyzerAdaptor.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
#ifndef FWCore_Framework_stream_EDAnalyzerAdaptor_h
#define FWCore_Framework_stream_EDAnalyzerAdaptor_h
// -*- C++ -*-
//
// Package: FWCore/Framework
// Class : EDAnalyzerAdaptor
//
/**\class edm::stream::EDAnalyzerAdaptor EDAnalyzerAdaptor.h "EDAnalyzerAdaptor.h"
Description: Adapts an edm::stream::EDAnalyzer<> to work with an edm::Worker
Usage:
<usage>
*/
//
// Original Author: Chris Jones
// Created: Fri, 02 Aug 2013 18:09:18 GMT
//
// system include files
// user include files
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Framework/interface/RunPrincipal.h"
#include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/stream/EDAnalyzerAdaptorBase.h"
#include "FWCore/Framework/interface/stream/callAbilities.h"
#include "FWCore/Framework/interface/stream/dummy_helpers.h"
#include "FWCore/Framework/interface/stream/makeGlobal.h"
#include "FWCore/Framework/src/MakeModuleHelper.h"
// forward declarations
namespace edm {
namespace stream {
template <typename ABase, typename ModType>
struct BaseToAdaptor;
template <typename T>
class EDAnalyzerAdaptor;
template <typename ModType>
struct BaseToAdaptor<EDAnalyzerAdaptorBase, ModType> {
typedef EDAnalyzerAdaptor<ModType> Type;
};
template <typename T>
class EDAnalyzerAdaptor : public EDAnalyzerAdaptorBase {
public:
EDAnalyzerAdaptor(edm::ParameterSet const& iPSet) : m_pset(&iPSet) {
m_runs.resize(1);
m_lumis.resize(1);
m_runSummaries.resize(1);
m_lumiSummaries.resize(1);
typename T::GlobalCache const* dummy = nullptr;
m_global = impl::makeGlobal<T>(iPSet, dummy);
}
~EDAnalyzerAdaptor() override {}
static void fillDescriptions(ConfigurationDescriptions& descriptions) { T::fillDescriptions(descriptions); }
static void prevalidate(ConfigurationDescriptions& descriptions) { T::prevalidate(descriptions); }
bool wantsGlobalRuns() const final { return T::HasAbility::kRunCache or T::HasAbility::kRunSummaryCache; }
bool wantsGlobalLuminosityBlocks() const final {
return T::HasAbility::kLuminosityBlockCache or T::HasAbility::kLuminosityBlockSummaryCache;
}
private:
typedef CallGlobal<T> MyGlobal;
typedef CallGlobalRun<T> MyGlobalRun;
typedef CallGlobalRunSummary<T> MyGlobalRunSummary;
typedef CallGlobalLuminosityBlock<T> MyGlobalLuminosityBlock;
typedef CallGlobalLuminosityBlockSummary<T> MyGlobalLuminosityBlockSummary;
void setupStreamModules() final {
this->createStreamModules([this]() -> EDAnalyzerBase* {
auto tmp = impl::makeStreamModule<T>(*m_pset, m_global.get());
MyGlobal::set(tmp, m_global.get());
return tmp;
});
m_pset = nullptr;
}
void preallocLumis(unsigned int iNLumis) final {
m_lumis.resize(iNLumis);
m_lumiSummaries.resize(iNLumis);
}
void doBeginJob() final { MyGlobal::beginJob(m_global.get()); }
void doEndJob() final { MyGlobal::endJob(m_global.get()); }
void setupRun(EDAnalyzerBase* iProd, RunIndex iIndex) final { MyGlobalRun::set(iProd, m_runs[iIndex].get()); }
void streamEndRunSummary(EDAnalyzerBase* iProd, edm::Run const& iRun, edm::EventSetup const& iES) final {
auto s = m_runSummaries[iRun.index()].get();
std::lock_guard<decltype(m_runSummaryLock)> guard(m_runSummaryLock);
MyGlobalRunSummary::streamEndRunSummary(iProd, iRun, iES, s);
}
void setupLuminosityBlock(EDAnalyzerBase* iProd, LuminosityBlockIndex iIndex) final {
MyGlobalLuminosityBlock::set(iProd, m_lumis[iIndex].get());
}
void streamEndLuminosityBlockSummary(EDAnalyzerBase* iProd,
edm::LuminosityBlock const& iLumi,
edm::EventSetup const& iES) final {
auto s = m_lumiSummaries[iLumi.index()].get();
std::lock_guard<decltype(m_lumiSummaryLock)> guard(m_lumiSummaryLock);
MyGlobalLuminosityBlockSummary::streamEndLuminosityBlockSummary(iProd, iLumi, iES, s);
}
void doBeginRun(RunPrincipal const& rp, EventSetupImpl const& ci, ModuleCallingContext const* mcc) final {
if constexpr (T::HasAbility::kRunCache or T::HasAbility::kRunSummaryCache) {
Run r(rp, moduleDescription(), mcc, false);
r.setConsumer(consumer());
Run const& cnstR = r;
RunIndex ri = rp.index();
const EventSetup c{ci,
static_cast<unsigned int>(Transition::BeginRun),
this->consumer()->esGetTokenIndices(Transition::BeginRun),
false};
MyGlobalRun::beginRun(cnstR, c, m_global.get(), m_runs[ri]);
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
MyGlobalRunSummary::beginRun(cnstR, c, &rc, m_runSummaries[ri]);
}
}
void doEndRun(RunPrincipal const& rp, EventSetupImpl const& ci, ModuleCallingContext const* mcc) final {
if constexpr (T::HasAbility::kRunCache or T::HasAbility::kRunSummaryCache) {
Run r(rp, moduleDescription(), mcc, true);
r.setConsumer(consumer());
RunIndex ri = rp.index();
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::EndRun),
this->consumer()->esGetTokenIndices(Transition::EndRun),
false};
MyGlobalRunSummary::globalEndRun(r, c, &rc, m_runSummaries[ri].get());
MyGlobalRun::endRun(r, c, &rc);
}
}
void doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp,
EventSetupImpl const& ci,
ModuleCallingContext const* mcc) final {
if constexpr (T::HasAbility::kLuminosityBlockCache or T::HasAbility::kLuminosityBlockSummaryCache) {
LuminosityBlock lb(lbp, moduleDescription(), mcc, false);
lb.setConsumer(consumer());
LuminosityBlock const& cnstLb = lb;
LuminosityBlockIndex li = lbp.index();
RunIndex ri = lbp.runPrincipal().index();
typename T::RunContext rc(m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::BeginLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::BeginLuminosityBlock),
false};
MyGlobalLuminosityBlock::beginLuminosityBlock(cnstLb, c, &rc, m_lumis[li]);
typename T::LuminosityBlockContext lc(m_lumis[li].get(), m_runs[ri].get(), m_global.get());
MyGlobalLuminosityBlockSummary::beginLuminosityBlock(cnstLb, c, &lc, m_lumiSummaries[li]);
}
}
void doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp,
EventSetupImpl const& ci,
ModuleCallingContext const* mcc) final {
if constexpr (T::HasAbility::kLuminosityBlockCache or T::HasAbility::kLuminosityBlockSummaryCache) {
LuminosityBlock lb(lbp, moduleDescription(), mcc, true);
lb.setConsumer(consumer());
LuminosityBlockIndex li = lbp.index();
RunIndex ri = lbp.runPrincipal().index();
typename T::LuminosityBlockContext lc(m_lumis[li].get(), m_runs[ri].get(), m_global.get());
const EventSetup c{ci,
static_cast<unsigned int>(Transition::EndLuminosityBlock),
this->consumer()->esGetTokenIndices(Transition::EndLuminosityBlock),
false};
MyGlobalLuminosityBlockSummary::globalEndLuminosityBlock(lb, c, &lc, m_lumiSummaries[li].get());
MyGlobalLuminosityBlock::endLuminosityBlock(lb, c, &lc);
}
}
EDAnalyzerAdaptor(const EDAnalyzerAdaptor&) = delete; // stop default
const EDAnalyzerAdaptor& operator=(const EDAnalyzerAdaptor&) = delete; // stop default
// ---------- member data --------------------------------
typename impl::choose_unique_ptr<typename T::GlobalCache>::type m_global;
typename impl::choose_shared_vec<typename T::RunCache const>::type m_runs;
typename impl::choose_shared_vec<typename T::LuminosityBlockCache const>::type m_lumis;
typename impl::choose_shared_vec<typename T::RunSummaryCache>::type m_runSummaries;
typename impl::choose_mutex<typename T::RunSummaryCache>::type m_runSummaryLock;
typename impl::choose_shared_vec<typename T::LuminosityBlockSummaryCache>::type m_lumiSummaries;
typename impl::choose_mutex<typename T::LuminosityBlockSummaryCache>::type m_lumiSummaryLock;
ParameterSet const* m_pset;
};
} // namespace stream
template <>
class MakeModuleHelper<edm::stream::EDAnalyzerAdaptorBase> {
typedef edm::stream::EDAnalyzerAdaptorBase Base;
public:
template <typename ModType>
static std::unique_ptr<Base> makeModule(ParameterSet const& pset) {
typedef typename stream::BaseToAdaptor<Base, ModType>::Type Adaptor;
auto module = std::make_unique<Adaptor>(pset);
return std::unique_ptr<Base>(module.release());
}
};
} // namespace edm
#endif