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
43 
47 
56 
58 
59 // forward declarations
60 
61 namespace edm {
62  class ThinnedAssociationsHelper;
63  class ExceptionToActionTable;
64  class HistoryAppender;
65 
66  namespace eventsetup {
67  class EventSetupProvider;
68  class EventSetupsController;
69  } // namespace eventsetup
70 
71  namespace test {
72  class TestProcessorConfig;
74 
75  class ProcessToken {
77 
78  public:
80 
81  int index() const { return index_; }
82 
83  static int undefinedIndex() { return -1; }
84 
85  private:
86  explicit ProcessToken(int index) : index_{index} {}
87 
88  int index_;
89  };
90 
92  public:
93  TestProcessorConfig(std::string const& iPythonConfiguration) : config_(iPythonConfiguration) {}
94  std::string const& pythonConfiguration() const { return config_; }
95  void setPythonConfiguration(std::string iConfig) { config_ = std::move(iConfig); }
96 
99  ProcessToken addExtraProcess(std::string const& iProcessName) {
100  extraProcesses_.emplace_back(iProcessName);
101  return ProcessToken(extraProcesses_.size() - 1);
102  }
103 
104  std::vector<std::string> const& extraProcesses() const { return extraProcesses_; }
105 
109  template <typename T>
111  std::string iProductInstanceLabel = std::string(),
112  ProcessToken iToken = ProcessToken()) {
113  produceEntries_.emplace_back(
114  edm::TypeID(typeid(T)), std::move(iModuleLabel), std::move(iProductInstanceLabel), processName(iToken));
115  return edm::EDPutTokenT<T>(produceEntries_.size() - 1);
116  }
117 
118  template <typename REC, typename T>
120  auto rk = eventsetup::EventSetupRecordKey::makeKey<REC>();
121  eventsetup::DataKey dk(eventsetup::DataKey::makeTypeTag<T>(), iLabel.c_str());
122  esProduceEntries_.emplace_back(rk, dk, std::make_shared<TestDataProxy<T>>());
123  return edm::test::ESPutTokenT<T>(esProduceEntries_.size() - 1);
124  }
125 
126  struct ProduceEntry {
127  ProduceEntry(edm::TypeID const& iType,
129  std::string instanceLabel,
131  : type_{iType},
133  instanceLabel_{std::move(instanceLabel)},
139  };
140 
141  std::vector<ProduceEntry> const& produceEntries() const { return produceEntries_; }
142 
143  std::vector<ESProduceEntry> const& esProduceEntries() const { return esProduceEntries_; }
144 
145  private:
147  std::vector<std::string> extraProcesses_;
148  std::vector<ProduceEntry> produceEntries_;
149  std::vector<ESProduceEntry> esProduceEntries_;
150 
152  if (iToken.index() == ProcessToken::undefinedIndex()) {
153  return std::string();
154  }
155  return extraProcesses_[iToken.index()];
156  }
157  };
158 
160  public:
162 
163  TestProcessor(Config const& iConfig, ServiceToken iToken = ServiceToken());
164  TestProcessor(const TestProcessor&) = delete;
165  const TestProcessor& operator=(const TestProcessor&) = delete;
166  ~TestProcessor() noexcept(false);
167 
171  template <typename... T>
172  edm::test::Event test(T&&... iArgs) {
173  return testImpl(std::forward<T>(iArgs)...);
174  }
175 
176  template <typename... T>
178  return testBeginLuminosityBlockImpl(iNum, std::forward<T>(iArgs)...);
179  }
180  template <typename... T>
182  return testEndLuminosityBlockImpl(std::forward<T>(iArgs)...);
183  }
184 
185  template <typename... T>
187  return testBeginRunImpl(iNum, std::forward<T>(iArgs)...);
188  }
189  template <typename... T>
191  return testEndRunImpl(std::forward<T>(iArgs)...);
192  }
193 
194  // It makes no sense to pass EventSetup products and at least
195  // for now Runs, Lumis, and ProcessBlocks don't allow passing
196  // in other products. So for now these don't need to be templates
197  // for ProcessBlock.
199 
201 
206  arena_.execute([this]() {
207  beginJob();
208  endJob();
209  });
210  }
211 
212  void testWithNoRuns() {
213  arena_.execute([this]() {
214  beginJob();
216  endProcessBlock();
217  endJob();
218  });
219  }
220 
222  arena_.execute([this]() {
223  beginJob();
225  beginRun();
226  endRun();
227  endProcessBlock();
228  endJob();
229  });
230  }
231 
233  arena_.execute([this]() {
234  beginJob();
236  beginRun();
239  endRun();
240  endProcessBlock();
241  endJob();
242  });
243  }
247 
249 
250  private:
251  template <typename T, typename... U>
252  edm::test::Event testImpl(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
253  put(std::move(iPut));
254  return testImpl(std::forward<U>(iArgs)...);
255  }
256 
257  template <typename T, typename... U>
258  edm::test::Event testImpl(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
259  put(std::move(iPut));
260  return testImpl(std::forward<U>(iArgs)...);
261  }
262 
263  template <typename T>
264  void put(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
265  put(iPut.first.index(), std::make_unique<edm::Wrapper<T>>(std::move(iPut.second)));
266  }
267 
268  template <typename T>
269  void put(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
270  dynamic_cast<TestDataProxy<T>*>(esHelper_->getProxy(iPut.first.index()).get())->setData(std::move(iPut.second));
271  }
272 
273  void put(unsigned int, std::unique_ptr<WrapperBase>);
274 
276 
277  template <typename T, typename... U>
280  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut,
281  U&&... iArgs) {
282  put(std::move(iPut));
283  return testBeginLuminosityBlockImpl(iNum, std::forward<U>(iArgs)...);
284  }
286 
287  template <typename T, typename... U>
289  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
290  put(std::move(iPut));
291  return testEndLuminosityBlockImpl(std::forward<U>(iArgs)...);
292  }
294 
295  template <typename T, typename... U>
297  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut,
298  U&&... iArgs) {
299  put(std::move(iPut));
300  return testBeginRunImpl(iNum, std::forward<U>(iArgs)...);
301  }
303  template <typename T, typename... U>
305  U&&... iArgs) {
306  put(std::move(iPut));
307  return testEndRunImpl(std::forward<U>(iArgs)...);
308  }
310 
313 
314  void setupProcessing();
315  void teardownProcessing();
316 
317  void beginJob();
318  void beginProcessBlock();
319  void beginRun();
320  void beginLuminosityBlock();
321  void event();
322  std::shared_ptr<LuminosityBlockPrincipal> endLuminosityBlock();
323  std::shared_ptr<RunPrincipal> endRun();
325  void endJob();
326 
327  // ---------- member data --------------------------------
328  oneapi::tbb::global_control globalControl_;
329  oneapi::tbb::task_group taskGroup_;
330  oneapi::tbb::task_arena arena_;
332  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
333  std::shared_ptr<ProductRegistry> preg_;
334  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
335  std::shared_ptr<ProcessBlockHelper> processBlockHelper_;
336  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
338  std::unique_ptr<eventsetup::EventSetupsController> espController_;
339  std::shared_ptr<eventsetup::EventSetupProvider> esp_;
340  std::shared_ptr<EventSetupTestHelper> esHelper_;
341 
342  std::unique_ptr<ExceptionToActionTable const> act_table_;
343  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
345 
347  std::unique_ptr<HistoryAppender> historyAppender_;
348 
351 
352  std::shared_ptr<ModuleRegistry> moduleRegistry_;
353  std::unique_ptr<Schedule> schedule_;
354  std::shared_ptr<RunPrincipal> runPrincipal_;
355  std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
356 
357  std::vector<std::pair<edm::BranchDescription, std::unique_ptr<WrapperBase>>> dataProducts_;
358 
362  bool beginJobCalled_ = false;
364  bool beginRunCalled_ = false;
365  bool beginLumiCalled_ = false;
366  };
367  } // namespace test
368 } // namespace edm
369 
370 #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:94
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::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:83
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:95
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)
Definition: TestProcessor.h:99
PrincipalCache principalCache_
ProcessBlockPrincipal const * endProcessBlock()
std::shared_ptr< ProductRegistry > preg_
edm::test::Run testEndRun(T &&... iArgs)
std::unique_ptr< ExceptionToActionTable const > act_table_
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:93
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)