CMS 3D CMS Logo

TestProcessor.h
Go to the documentation of this file.
1 #ifndef FWCore_TestProcessor_TestProcessor_h
2 #define FWCore_TestProcessor_TestProcessor_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/TestProcessor
6 // Class : TestProcessor
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Mon, 30 Apr 2018 18:51:00 GMT
19 //
20 
21 // system include files
22 #include <string>
23 #include <utility>
24 #include <memory>
25 
26 // user include files
39 
43 
51 
53 
54 // forward declarations
55 
56 namespace edm {
57  class ThinnedAssociationsHelper;
58  class ExceptionToActionTable;
59  class HistoryAppender;
60 
61  namespace eventsetup {
62  class EventSetupProvider;
63  class EventSetupsController;
64  } // namespace eventsetup
65 
66  namespace test {
67  class TestProcessorConfig;
69 
70  class ProcessToken {
72 
73  public:
75 
76  int index() const { return index_; }
77 
78  static int undefinedIndex() { return -1; }
79 
80  private:
81  explicit ProcessToken(int index) : index_{index} {}
82 
83  int index_;
84  };
85 
87  public:
88  TestProcessorConfig(std::string const& iPythonConfiguration) : config_(iPythonConfiguration) {}
89  std::string const& pythonConfiguration() const { return config_; }
90  void setPythonConfiguration(std::string iConfig) { config_ = std::move(iConfig); }
91 
94  ProcessToken addExtraProcess(std::string const& iProcessName) {
95  extraProcesses_.emplace_back(iProcessName);
96  return ProcessToken(extraProcesses_.size() - 1);
97  }
98 
99  std::vector<std::string> const& extraProcesses() const { return extraProcesses_; }
100 
104  template <typename T>
106  std::string iProductInstanceLabel = std::string(),
107  ProcessToken iToken = ProcessToken()) {
108  produceEntries_.emplace_back(
109  edm::TypeID(typeid(T)), std::move(iModuleLabel), std::move(iProductInstanceLabel), processName(iToken));
110  return edm::EDPutTokenT<T>(produceEntries_.size() - 1);
111  }
112 
113  template <typename REC, typename T>
115  auto rk = eventsetup::EventSetupRecordKey::makeKey<REC>();
116  eventsetup::DataKey dk(eventsetup::DataKey::makeTypeTag<T>(), iLabel.c_str());
117  esProduceEntries_.emplace_back(rk, dk, std::make_shared<TestDataProxy<T>>());
118  return edm::test::ESPutTokenT<T>(esProduceEntries_.size() - 1);
119  }
120 
121  struct ProduceEntry {
122  ProduceEntry(edm::TypeID const& iType,
124  std::string instanceLabel,
126  : type_{iType},
128  instanceLabel_{std::move(instanceLabel)},
134  };
135 
136  std::vector<ProduceEntry> const& produceEntries() const { return produceEntries_; }
137 
138  std::vector<ESProduceEntry> const& esProduceEntries() const { return esProduceEntries_; }
139 
140  private:
142  std::vector<std::string> extraProcesses_;
143  std::vector<ProduceEntry> produceEntries_;
144  std::vector<ESProduceEntry> esProduceEntries_;
145 
147  if (iToken.index() == ProcessToken::undefinedIndex()) {
148  return std::string();
149  }
150  return extraProcesses_[iToken.index()];
151  }
152  };
153 
155  public:
157 
158  TestProcessor(Config const& iConfig, ServiceToken iToken = ServiceToken());
159  ~TestProcessor() noexcept(false);
160 
164  template <typename... T>
165  edm::test::Event test(T&&... iArgs) {
166  return testImpl(std::forward<T>(iArgs)...);
167  }
168 
169  template <typename... T>
171  return testBeginLuminosityBlockImpl(iNum, std::forward<T>(iArgs)...);
172  }
173  template <typename... T>
175  return testEndLuminosityBlockImpl(std::forward<T>(iArgs)...);
176  }
177 
178  template <typename... T>
180  return testBeginRunImpl(iNum, std::forward<T>(iArgs)...);
181  }
182  template <typename... T>
184  return testEndRunImpl(std::forward<T>(iArgs)...);
185  }
186 
191  beginJob();
192  endJob();
193  }
194 
196  beginJob();
197  beginRun();
198  endRun();
199  endJob();
200  }
201 
203  beginJob();
204  beginRun();
207  endRun();
208  endJob();
209  }
213 
215 
216  private:
217  TestProcessor(const TestProcessor&) = delete; // stop default
218 
219  const TestProcessor& operator=(const TestProcessor&) = delete; // stop default
220 
221  template <typename T, typename... U>
222  edm::test::Event testImpl(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
223  put(std::move(iPut));
224  return testImpl(std::forward<U>(iArgs)...);
225  }
226 
227  template <typename T, typename... U>
228  edm::test::Event testImpl(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
229  put(std::move(iPut));
230  return testImpl(std::forward<U>(iArgs)...);
231  }
232 
233  template <typename T>
234  void put(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
235  put(iPut.first.index(), std::make_unique<edm::Wrapper<T>>(std::move(iPut.second)));
236  }
237 
238  template <typename T>
239  void put(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
240  dynamic_cast<TestDataProxy<T>*>(esHelper_->getProxy(iPut.first.index()).get())->setData(std::move(iPut.second));
241  }
242 
243  void put(unsigned int, std::unique_ptr<WrapperBase>);
244 
246 
247  template <typename T, typename... U>
250  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut,
251  U&&... iArgs) {
252  put(std::move(iPut));
253  return testBeginLuminosityBlockImpl(iNum, std::forward<U>(iArgs)...);
254  }
256 
257  template <typename T, typename... U>
259  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
260  put(std::move(iPut));
261  return testEndLuminosityBlockImpl(std::forward<U>(iArgs)...);
262  }
264 
265  template <typename T, typename... U>
267  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut,
268  U&&... iArgs) {
269  put(std::move(iPut));
270  return testBeginRunImpl(iNum, std::forward<U>(iArgs)...);
271  }
273  template <typename T, typename... U>
275  U&&... iArgs) {
276  put(std::move(iPut));
277  return testEndRunImpl(std::forward<U>(iArgs)...);
278  }
280 
281  void setupProcessing();
282  void teardownProcessing();
283 
284  void beginJob();
285  void beginRun();
286  void beginLuminosityBlock();
287  void event();
288  std::shared_ptr<LuminosityBlockPrincipal> endLuminosityBlock();
289  std::shared_ptr<RunPrincipal> endRun();
290  void endJob();
291 
292  // ---------- member data --------------------------------
294  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
295  std::shared_ptr<ProductRegistry> preg_;
296  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
297  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
299  std::unique_ptr<eventsetup::EventSetupsController> espController_;
300  std::shared_ptr<eventsetup::EventSetupProvider> esp_;
301  std::shared_ptr<EventSetupTestHelper> esHelper_;
302 
303  std::unique_ptr<ExceptionToActionTable const> act_table_;
304  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
306 
308  std::unique_ptr<HistoryAppender> historyAppender_;
309 
312 
313  std::shared_ptr<ModuleRegistry> moduleRegistry_;
314  std::unique_ptr<Schedule> schedule_;
315  std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
316 
317  std::vector<std::pair<edm::BranchDescription, std::unique_ptr<WrapperBase>>> dataProducts_;
318 
322  bool beginJobCalled_ = false;
323  bool beginRunCalled_ = false;
324  bool beginLumiCalled_ = false;
325  };
326  } // namespace test
327 } // namespace edm
328 
329 #endif
edm::test::TestProcessor::put
void put(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut)
Definition: TestProcessor.h:239
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
edm::test::TestProcessorConfig::extraProcesses_
std::vector< std::string > extraProcesses_
Definition: TestProcessor.h:142
edm::test::TestProcessor::setLuminosityBlockNumber
void setLuminosityBlockNumber(edm::LuminosityBlockNumber_t)
Definition: TestProcessor.cc:662
edm::test::ProcessToken
Definition: TestProcessor.h:70
edm::test::TestProcessorConfig::addExtraProcess
ProcessToken addExtraProcess(std::string const &iProcessName)
Definition: TestProcessor.h:94
edm::test::TestProcessor::labelOfTestModule
std::string const & labelOfTestModule() const
Definition: TestProcessor.h:214
funct::false
false
Definition: Factorize.h:34
edm::test::TestProcessor::~TestProcessor
~TestProcessor() noexcept(false)
Definition: TestProcessor.cc:196
edm::test::TestProcessor::thinnedAssociationsHelper_
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
Definition: TestProcessor.h:297
edm::test::TestProcessor::TestProcessor
TestProcessor(Config const &iConfig, ServiceToken iToken=ServiceToken())
Definition: TestProcessor.cc:84
edm::test::TestProcessor::testLuminosityBlockWithNoEvents
void testLuminosityBlockWithNoEvents()
Definition: TestProcessor.h:202
edm::test::TestProcessor::testImpl
edm::test::Event testImpl(std::pair< edm::EDPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
Definition: TestProcessor.h:222
edm::test::TestProcessorConfig::ProduceEntry::type_
edm::TypeID type_
Definition: TestProcessor.h:130
edm::test::TestProcessor::setRunNumber
void setRunNumber(edm::RunNumber_t)
Definition: TestProcessor.cc:655
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::test::TestProcessor::testEndRunImpl
edm::test::Run testEndRunImpl()
Definition: TestProcessor.cc:286
edm::test::ProcessToken::ProcessToken
ProcessToken()
Definition: TestProcessor.h:74
edm::EDPutTokenT
Definition: EDPutToken.h:33
edm::ProcessContext
Definition: ProcessContext.h:27
edm::test::TestProcessorConfig::esProduces
edm::test::ESPutTokenT< T > esProduces(std::string iLabel=std::string())
Definition: TestProcessor.h:114
RunLumiEventNumber.h
edm::test::TestProcessor::testBeginLuminosityBlockImpl
edm::test::LuminosityBlock testBeginLuminosityBlockImpl(edm::LuminosityBlockNumber_t iNum, std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
Definition: TestProcessor.h:248
edm::test::TestProcessor::processHistoryRegistry_
ProcessHistoryRegistry processHistoryRegistry_
Definition: TestProcessor.h:307
edm::test::TestProcessorConfig::produceEntries_
std::vector< ProduceEntry > produceEntries_
Definition: TestProcessor.h:143
edm::test::TestProcessorConfig::processName
std::string processName(ProcessToken iToken)
Definition: TestProcessor.h:146
edm::eventsetup::DataKey
Definition: DataKey.h:29
SignallingProductRegistry.h
edm::test::TestProcessor::labelOfTestModule_
std::string labelOfTestModule_
Definition: TestProcessor.h:293
ProcessHistoryRegistry.h
ServiceToken.h
edm::test::Run
Definition: Run.h:35
PreallocationConfiguration.h
edm::test::TestProcessorConfig::produceEntries
std::vector< ProduceEntry > const & produceEntries() const
Definition: TestProcessor.h:136
edm::test::TestProcessor::beginRunCalled_
bool beginRunCalled_
Definition: TestProcessor.h:323
edm::test::TestProcessor::serviceToken_
ServiceToken serviceToken_
Definition: TestProcessor.h:298
edm::test::TestProcessor::testBeginLuminosityBlock
edm::test::LuminosityBlock testBeginLuminosityBlock(edm::LuminosityBlockNumber_t iNum, T &&... iArgs)
Definition: TestProcessor.h:170
edm::test::TestProcessor::processConfiguration_
std::shared_ptr< ProcessConfiguration const > processConfiguration_
Definition: TestProcessor.h:304
edm::LuminosityBlockNumber_t
unsigned int LuminosityBlockNumber_t
Definition: RunLumiEventNumber.h:13
edm::test::TestProcessor::endLuminosityBlock
std::shared_ptr< LuminosityBlockPrincipal > endLuminosityBlock()
Definition: TestProcessor.cc:510
edm::test::TestProcessor::lumiPrincipal_
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
Definition: TestProcessor.h:315
edm::test::ProcessToken::index_
int index_
Definition: TestProcessor.h:83
edm::test::LuminosityBlock
Definition: LuminosityBlock.h:35
edm::test::TestProcessorConfig
Definition: TestProcessor.h:86
edm::test::TestProcessor::testEndLuminosityBlock
edm::test::LuminosityBlock testEndLuminosityBlock(T &&... iArgs)
Definition: TestProcessor.h:174
ESProduceEntry.h
edm::test::ESPutTokenT
Definition: ESPutTokenT.h:31
edm::test::TestProcessor::runNumber_
RunNumber_t runNumber_
Definition: TestProcessor.h:319
ActivityRegistry.h
edm::test::TestProcessor::beginRun
void beginRun()
Definition: TestProcessor.cc:359
SharedResourcesAcquirer.h
edm::ServiceToken
Definition: ServiceToken.h:40
test
Definition: SmallWORMDict.h:13
LuminosityBlock.h
edm::test::ProcessToken::TestProcessorConfig
friend TestProcessorConfig
Definition: TestProcessor.h:71
edm::PrincipalCache
Definition: PrincipalCache.h:47
edm::test::TestProcessor::beginLumiCalled_
bool beginLumiCalled_
Definition: TestProcessor.h:324
edm::test::TestProcessor::setupProcessing
void setupProcessing()
Definition: TestProcessor.cc:303
edm::test::TestProcessorConfig::config_
std::string config_
Definition: TestProcessor.h:141
ESPutTokenT.h
edm::test::TestProcessor::historyAppender_
std::unique_ptr< HistoryAppender > historyAppender_
Definition: TestProcessor.h:308
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
edm::test::TestProcessor::preg_
std::shared_ptr< ProductRegistry > preg_
Definition: TestProcessor.h:295
edm::test::TestProcessor::testEndRun
edm::test::Run testEndRun(T &&... iArgs)
Definition: TestProcessor.h:183
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::test::TestProcessor::dataProducts_
std::vector< std::pair< edm::BranchDescription, std::unique_ptr< WrapperBase > > > dataProducts_
Definition: TestProcessor.h:317
edm::test::TestProcessor::beginJob
void beginJob()
Definition: TestProcessor.cc:329
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::test::ProcessToken::undefinedIndex
static int undefinedIndex()
Definition: TestProcessor.h:78
edm::test::TestProcessorConfig::ProduceEntry::processName_
std::string processName_
Definition: TestProcessor.h:133
edm::test::TestDataProxy
Definition: TestDataProxy.h:33
edm::test::ProcessToken::ProcessToken
ProcessToken(int index)
Definition: TestProcessor.h:81
edm::test::TestProcessorConfig::TestProcessorConfig
TestProcessorConfig(std::string const &iPythonConfiguration)
Definition: TestProcessor.h:88
PrincipalCache.h
edm::test::TestProcessorConfig::ProduceEntry::instanceLabel_
std::string instanceLabel_
Definition: TestProcessor.h:132
edm::test::Event
Definition: Event.h:36
edm::test::TestProcessor::testBeginRunImpl
edm::test::Run testBeginRunImpl(edm::RunNumber_t iNum, std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
Definition: TestProcessor.h:266
EDPutToken.h
EventSetupTestHelper
edm::test::TestProcessor::processContext_
ProcessContext processContext_
Definition: TestProcessor.h:305
edm::test::TestProcessor::endRun
std::shared_ptr< RunPrincipal > endRun()
Definition: TestProcessor.cc:569
DataKey.h
edm::test::TestProcessor::testEndLuminosityBlockImpl
edm::test::LuminosityBlock testEndLuminosityBlockImpl()
Definition: TestProcessor.cc:246
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:669
edm::test::TestProcessor::eventNumber_
EventNumber_t eventNumber_
Definition: TestProcessor.h:321
Schedule.h
edm::test::TestProcessorConfig::pythonConfiguration
std::string const & pythonConfiguration() const
Definition: TestProcessor.h:89
edm::test::TestProcessor::testBeginAndEndJobOnly
void testBeginAndEndJobOnly()
Definition: TestProcessor.h:190
edm::test::TestProcessorConfig::ProduceEntry::moduleLabel_
std::string moduleLabel_
Definition: TestProcessor.h:131
edm::test::TestProcessor::branchIDListHelper_
std::shared_ptr< BranchIDListHelper > branchIDListHelper_
Definition: TestProcessor.h:296
edm::test::TestProcessor::put
void put(std::pair< edm::EDPutTokenT< T >, std::unique_ptr< T >> &&iPut)
Definition: TestProcessor.h:234
edm::test::TestProcessor::beginJobCalled_
bool beginJobCalled_
Definition: TestProcessor.h:322
edm::test::TestProcessor
Definition: TestProcessor.h:154
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
edm::test::TestProcessor::esHelper_
std::shared_ptr< EventSetupTestHelper > esHelper_
Definition: TestProcessor.h:301
edm::test::TestProcessor::actReg_
std::shared_ptr< ActivityRegistry > actReg_
Definition: TestProcessor.h:294
edm::test::TestProcessor::setEventNumber
void setEventNumber(edm::EventNumber_t)
Definition: TestProcessor.cc:667
edm::PreallocationConfiguration
Definition: PreallocationConfiguration.h:27
edm::test::TestProcessor::testEndRunImpl
edm::test::LuminosityBlock testEndRunImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
Definition: TestProcessor.h:274
edm::test::TestProcessorConfig::extraProcesses
std::vector< std::string > const & extraProcesses() const
Definition: TestProcessor.h:99
Run.h
edm::test::TestProcessor::testEndLuminosityBlockImpl
edm::test::LuminosityBlock testEndLuminosityBlockImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
Definition: TestProcessor.h:258
ModuleRegistry.h
edm::TypeID
Definition: TypeID.h:22
edm::test::TestProcessor::testRunWithNoLuminosityBlocks
void testRunWithNoLuminosityBlocks()
Definition: TestProcessor.h:195
Wrapper.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::test::TestProcessor::operator=
const TestProcessor & operator=(const TestProcessor &)=delete
Event.h
edm::test::TestProcessor::esp_
std::shared_ptr< eventsetup::EventSetupProvider > esp_
Definition: TestProcessor.h:300
edm::test::TestProcessor::testImpl
edm::test::Event testImpl()
Definition: TestProcessor.cc:210
edm::test::TestProcessor::schedule_
std::unique_ptr< Schedule > schedule_
Definition: TestProcessor.h:314
T
long double T
Definition: Basic3DVectorLD.h:48
ServiceLegacy.h
edm::test::TestProcessorConfig::setPythonConfiguration
void setPythonConfiguration(std::string iConfig)
Definition: TestProcessor.h:90
edm::test::TestProcessor::espController_
std::unique_ptr< eventsetup::EventSetupsController > espController_
Definition: TestProcessor.h:299
edm::ProcessHistoryRegistry
Definition: ProcessHistoryRegistry.h:18
edm::test::ProcessToken::index
int index() const
Definition: TestProcessor.h:76
edm::test::TestProcessor::teardownProcessing
void teardownProcessing()
Definition: TestProcessor.cc:315
edm::test::TestProcessor::testBeginRun
edm::test::Run testBeginRun(edm::RunNumber_t iNum, T &&... iArgs)
Definition: TestProcessor.h:179
edm::test::TestProcessor::event
void event()
Definition: TestProcessor.cc:472
edm::test::TestProcessorConfig::esProduceEntries_
std::vector< ESProduceEntry > esProduceEntries_
Definition: TestProcessor.h:144
edm::test::TestProcessor::testImpl
edm::test::Event testImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
Definition: TestProcessor.h:228
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
Config
Definition: Config.py:1
EventSetupRecordKey.h
edm::test::TestProcessorConfig::ProduceEntry
Definition: TestProcessor.h:121
edm::test::TestProcessor::endJob
void endJob()
Definition: TestProcessor.cc:634
ProcessContext.h
edm::test::TestProcessor::moduleRegistry_
std::shared_ptr< ModuleRegistry > moduleRegistry_
Definition: TestProcessor.h:313
edm::test::TestProcessor::beginLuminosityBlock
void beginLuminosityBlock()
Definition: TestProcessor.cc:415
edm::test::TestProcessor::principalCache_
PrincipalCache principalCache_
Definition: TestProcessor.h:310
edm::test::TestProcessorConfig::esProduceEntries
std::vector< ESProduceEntry > const & esProduceEntries() const
Definition: TestProcessor.h:138
edm::test::TestProcessor::lumiNumber_
LuminosityBlockNumber_t lumiNumber_
Definition: TestProcessor.h:320
edm::test::TestProcessorConfig::produces
edm::EDPutTokenT< T > produces(std::string iModuleLabel, std::string iProductInstanceLabel=std::string(), ProcessToken iToken=ProcessToken())
Definition: TestProcessor.h:105
EventSetupTestHelper.h
edm::test::TestProcessor::act_table_
std::unique_ptr< ExceptionToActionTable const > act_table_
Definition: TestProcessor.h:303
TestDataProxy.h
edm::test::TestProcessor::preallocations_
PreallocationConfiguration preallocations_
Definition: TestProcessor.h:311
edm::test::TestProcessorConfig::ProduceEntry::ProduceEntry
ProduceEntry(edm::TypeID const &iType, std::string moduleLabel, std::string instanceLabel, std::string processName)
Definition: TestProcessor.h:122