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 #include "oneapi/tbb/global_control.h"
26 #include "oneapi/tbb/task_arena.h"
27 #include "oneapi/tbb/task_group.h"
28 
29 // user include files
40 
45 
49 
58 
60 
61 // forward declarations
62 
63 namespace edm {
64  class ThinnedAssociationsHelper;
65  class ExceptionToActionTable;
66  class HistoryAppender;
67  class ModuleTypeResolverMaker;
68 
69  namespace eventsetup {
70  class EventSetupProvider;
71  class EventSetupsController;
72  } // namespace eventsetup
73 
74  namespace test {
75  class TestProcessorConfig;
76  class EventSetupTestHelper;
77 
78  class ProcessToken {
80 
81  public:
83 
84  int index() const { return index_; }
85 
86  static int undefinedIndex() { return -1; }
87 
88  private:
89  explicit ProcessToken(int index) : index_{index} {}
90 
91  int index_;
92  };
93 
95  public:
96  TestProcessorConfig(std::string const& iPythonConfiguration) : config_(iPythonConfiguration) {}
97  std::string const& pythonConfiguration() const { return config_; }
98  void setPythonConfiguration(std::string iConfig) { config_ = std::move(iConfig); }
99 
102  ProcessToken addExtraProcess(std::string const& iProcessName) {
103  extraProcesses_.emplace_back(iProcessName);
104  return ProcessToken(extraProcesses_.size() - 1);
105  }
106 
107  std::vector<std::string> const& extraProcesses() const { return extraProcesses_; }
108 
112  template <typename T>
114  std::string iProductInstanceLabel = std::string(),
115  ProcessToken iToken = ProcessToken()) {
116  produceEntries_.emplace_back(
117  edm::TypeID(typeid(T)), std::move(iModuleLabel), std::move(iProductInstanceLabel), processName(iToken));
118  return edm::EDPutTokenT<T>(produceEntries_.size() - 1);
119  }
120 
121  template <typename REC, typename T>
123  auto rk = eventsetup::EventSetupRecordKey::makeKey<REC>();
124  eventsetup::DataKey dk(eventsetup::DataKey::makeTypeTag<T>(), iLabel.c_str());
125  esProduceEntries_.emplace_back(rk, dk, std::make_shared<TestESProductResolver<T>>());
126  return edm::test::ESPutTokenT<T>(esProduceEntries_.size() - 1);
127  }
128 
129  struct ProduceEntry {
130  ProduceEntry(edm::TypeID const& iType,
132  std::string instanceLabel,
134  : type_{iType},
136  instanceLabel_{std::move(instanceLabel)},
142  };
143 
144  std::vector<ProduceEntry> const& produceEntries() const { return produceEntries_; }
145 
146  std::vector<ESProduceEntry> const& esProduceEntries() const { return esProduceEntries_; }
147 
148  private:
150  std::vector<std::string> extraProcesses_;
151  std::vector<ProduceEntry> produceEntries_;
152  std::vector<ESProduceEntry> esProduceEntries_;
153 
155  if (iToken.index() == ProcessToken::undefinedIndex()) {
156  return std::string();
157  }
158  return extraProcesses_[iToken.index()];
159  }
160  };
161 
163  public:
165 
166  TestProcessor(Config const& iConfig, ServiceToken iToken = ServiceToken());
167  TestProcessor(const TestProcessor&) = delete;
168  const TestProcessor& operator=(const TestProcessor&) = delete;
169  ~TestProcessor() noexcept(false);
170 
174  template <typename... T>
175  edm::test::Event test(T&&... iArgs) {
176  return testImpl(std::forward<T>(iArgs)...);
177  }
178 
179  template <typename... T>
181  return testBeginLuminosityBlockImpl(iNum, std::forward<T>(iArgs)...);
182  }
183  template <typename... T>
185  return testEndLuminosityBlockImpl(std::forward<T>(iArgs)...);
186  }
187 
188  template <typename... T>
190  return testBeginRunImpl(iNum, std::forward<T>(iArgs)...);
191  }
192  template <typename... T>
194  return testEndRunImpl(std::forward<T>(iArgs)...);
195  }
196 
197  // It makes no sense to pass EventSetup products and at least
198  // for now Runs, Lumis, and ProcessBlocks don't allow passing
199  // in other products. So for now these don't need to be templates
200  // for ProcessBlock.
202 
204 
209  arena_.execute([this]() {
210  beginJob();
211  endJob();
212  });
213  }
214 
215  void testWithNoRuns() {
216  arena_.execute([this]() {
217  beginJob();
219  endProcessBlock();
220  endJob();
221  });
222  }
223 
225  arena_.execute([this]() {
226  beginJob();
228  beginRun();
229  endRun();
230  endProcessBlock();
231  endJob();
232  });
233  }
234 
236  arena_.execute([this]() {
237  beginJob();
239  beginRun();
242  endRun();
243  endProcessBlock();
244  endJob();
245  });
246  }
250 
252 
253  private:
254  template <typename T, typename... U>
255  edm::test::Event testImpl(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
256  put(std::move(iPut));
257  return testImpl(std::forward<U>(iArgs)...);
258  }
259 
260  template <typename T, typename... U>
261  edm::test::Event testImpl(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
262  put(std::move(iPut));
263  return testImpl(std::forward<U>(iArgs)...);
264  }
265 
266  template <typename T>
267  void put(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
268  put(iPut.first.index(), std::make_unique<edm::Wrapper<T>>(std::move(iPut.second)));
269  }
270 
271  template <typename T>
272  void put(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
273  dynamic_cast<TestESProductResolver<T>*>(esHelper_->getResolver(iPut.first.index()).get())
274  ->setData(std::move(iPut.second));
275  }
276 
277  void put(unsigned int, std::unique_ptr<WrapperBase>);
278 
280 
281  template <typename T, typename... U>
284  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut,
285  U&&... iArgs) {
286  put(std::move(iPut));
287  return testBeginLuminosityBlockImpl(iNum, std::forward<U>(iArgs)...);
288  }
290 
291  template <typename T, typename... U>
293  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
294  put(std::move(iPut));
295  return testEndLuminosityBlockImpl(std::forward<U>(iArgs)...);
296  }
298 
299  template <typename T, typename... U>
301  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut,
302  U&&... iArgs) {
303  put(std::move(iPut));
304  return testBeginRunImpl(iNum, std::forward<U>(iArgs)...);
305  }
307  template <typename T, typename... U>
309  U&&... iArgs) {
310  put(std::move(iPut));
311  return testEndRunImpl(std::forward<U>(iArgs)...);
312  }
314 
317 
318  void setupProcessing();
319  void teardownProcessing();
320 
321  void beginJob();
322  void respondToOpenInputFile();
323  void openOutputFiles();
324  void beginProcessBlock();
325  void beginRun();
326  void beginLuminosityBlock();
327  void event();
328  std::shared_ptr<LuminosityBlockPrincipal> endLuminosityBlock();
329  std::shared_ptr<RunPrincipal> endRun();
332  void closeOutputFiles();
333  void endJob();
334 
335  // ---------- member data --------------------------------
336  oneapi::tbb::global_control globalControl_;
337  oneapi::tbb::task_group taskGroup_;
338  oneapi::tbb::task_arena arena_;
340  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
341  std::shared_ptr<ProductRegistry> preg_;
342  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
343  std::shared_ptr<ProcessBlockHelper> processBlockHelper_;
344  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
346  std::unique_ptr<ModuleTypeResolverMaker const> moduleTypeResolverMaker_;
347  std::unique_ptr<eventsetup::EventSetupsController> espController_;
348  std::shared_ptr<eventsetup::EventSetupProvider> esp_;
349  std::shared_ptr<EventSetupTestHelper> esHelper_;
350 
351  std::unique_ptr<ExceptionToActionTable const> act_table_;
352  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
354 
356 
359  std::unique_ptr<HistoryAppender> historyAppender_;
360 
363 
364  std::shared_ptr<ModuleRegistry> moduleRegistry_;
365  std::unique_ptr<Schedule> schedule_;
366  std::shared_ptr<RunPrincipal> runPrincipal_;
367  std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
368 
369  std::vector<std::pair<edm::BranchDescription, std::unique_ptr<WrapperBase>>> dataProducts_;
370 
374  bool beginJobCalled_ = false;
377  bool beginRunCalled_ = false;
378  bool beginLumiCalled_ = false;
380  };
381  } // namespace test
382 } // namespace edm
383 
384 #endif
edm::test::LuminosityBlock testBeginLuminosityBlock(edm::LuminosityBlockNumber_t iNum, T &&... iArgs)
void put(std::pair< edm::EDPutTokenT< T >, std::unique_ptr< T >> &&iPut)
std::shared_ptr< LuminosityBlockPrincipal > endLuminosityBlock()
std::shared_ptr< ActivityRegistry > actReg_
edm::test::ProcessBlock testBeginProcessBlockImpl()
edm::test::LuminosityBlock testEndRunImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
std::vector< std::pair< edm::BranchDescription, std::unique_ptr< WrapperBase > > > dataProducts_
std::vector< ESProduceEntry > esProduceEntries_
LuminosityBlockNumber_t lumiNumber_
unsigned long long EventNumber_t
edm::test::LuminosityBlock testEndLuminosityBlockImpl()
edm::EDPutTokenT< T > produces(std::string iModuleLabel, std::string iProductInstanceLabel=std::string(), ProcessToken iToken=ProcessToken())
EventNumber_t eventNumber_
void put(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut)
std::string const & pythonConfiguration() const
Definition: TestProcessor.h:97
oneapi::tbb::global_control globalControl_
std::shared_ptr< RunPrincipal > runPrincipal_
ProcessContext processContext_
edm::test::Run testBeginRunImpl(edm::RunNumber_t iNum, std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
unsigned int LuminosityBlockNumber_t
oneapi::tbb::task_group taskGroup_
PreallocationConfiguration preallocations_
~TestProcessor() noexcept(false)
std::unique_ptr< ModuleTypeResolverMaker const > moduleTypeResolverMaker_
std::vector< std::string > const & extraProcesses() const
void setEventNumber(edm::EventNumber_t)
std::shared_ptr< BranchIDListHelper > branchIDListHelper_
edm::test::LuminosityBlock testEndLuminosityBlockImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
edm::test::Event testImpl(std::pair< edm::EDPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
const TestProcessor & operator=(const TestProcessor &)=delete
static int undefinedIndex()
Definition: TestProcessor.h:86
edm::test::ESPutTokenT< T > esProduces(std::string iLabel=std::string())
std::shared_ptr< EventSetupTestHelper > esHelper_
std::vector< ProduceEntry > produceEntries_
void setPythonConfiguration(std::string iConfig)
Definition: TestProcessor.h:98
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
ProduceEntry(edm::TypeID const &iType, std::string moduleLabel, std::string instanceLabel, std::string processName)
std::string labelOfTestModule_
std::unique_ptr< eventsetup::EventSetupsController > espController_
edm::test::Event testImpl()
std::shared_ptr< eventsetup::EventSetupProvider > esp_
edm::test::Run testBeginRun(edm::RunNumber_t iNum, T &&... iArgs)
std::unique_ptr< Schedule > schedule_
std::shared_ptr< ProcessConfiguration const > processConfiguration_
edm::test::LuminosityBlock testBeginLuminosityBlockImpl(edm::LuminosityBlockNumber_t iNum, std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
edm::test::Event testImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&... iArgs)
edm::test::ProcessBlock testEndProcessBlockImpl()
edm::test::ProcessBlock testBeginProcessBlock()
std::shared_ptr< ModuleRegistry > moduleRegistry_
std::vector< ProduceEntry > const & produceEntries() const
std::vector< ESProduceEntry > const & esProduceEntries() const
edm::test::LuminosityBlock testEndLuminosityBlock(T &&... iArgs)
void setLuminosityBlockNumber(edm::LuminosityBlockNumber_t)
ProcessToken addExtraProcess(std::string const &iProcessName)
PrincipalCache principalCache_
ProcessBlockPrincipal const * endProcessBlock()
std::shared_ptr< ProductRegistry > preg_
edm::test::Run testEndRun(T &&... iArgs)
MergeableRunProductProcesses mergeableRunProductProcesses_
std::unique_ptr< ExceptionToActionTable const > act_table_
ProcessHistory processHistory_
std::vector< std::string > extraProcesses_
edm::test::ProcessBlock testEndProcessBlock()
oneapi::tbb::task_arena arena_
edm::test::Run testEndRunImpl()
void setRunNumber(edm::RunNumber_t)
HLT enums.
std::unique_ptr< HistoryAppender > historyAppender_
std::string const & labelOfTestModule() const
Definition: Config.py:1
TestProcessor(Config const &iConfig, ServiceToken iToken=ServiceToken())
unsigned int RunNumber_t
TestProcessorConfig(std::string const &iPythonConfiguration)
Definition: TestProcessor.h:96
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
long double T
std::shared_ptr< ProcessBlockHelper > processBlockHelper_
ProcessHistoryRegistry processHistoryRegistry_
std::shared_ptr< RunPrincipal > endRun()
def move(src, dest)
Definition: eostools.py:511
std::string processName(ProcessToken iToken)