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  class ModuleTypeResolverMaker;
66 
67  namespace eventsetup {
68  class EventSetupProvider;
69  class EventSetupsController;
70  } // namespace eventsetup
71 
72  namespace test {
73  class TestProcessorConfig;
75 
76  class ProcessToken {
78 
79  public:
81 
82  int index() const { return index_; }
83 
84  static int undefinedIndex() { return -1; }
85 
86  private:
87  explicit ProcessToken(int index) : index_{index} {}
88 
89  int index_;
90  };
91 
93  public:
94  TestProcessorConfig(std::string const& iPythonConfiguration) : config_(iPythonConfiguration) {}
95  std::string const& pythonConfiguration() const { return config_; }
96  void setPythonConfiguration(std::string iConfig) { config_ = std::move(iConfig); }
97 
100  ProcessToken addExtraProcess(std::string const& iProcessName) {
101  extraProcesses_.emplace_back(iProcessName);
102  return ProcessToken(extraProcesses_.size() - 1);
103  }
104 
105  std::vector<std::string> const& extraProcesses() const { return extraProcesses_; }
106 
110  template <typename T>
112  std::string iProductInstanceLabel = std::string(),
113  ProcessToken iToken = ProcessToken()) {
114  produceEntries_.emplace_back(
115  edm::TypeID(typeid(T)), std::move(iModuleLabel), std::move(iProductInstanceLabel), processName(iToken));
116  return edm::EDPutTokenT<T>(produceEntries_.size() - 1);
117  }
118 
119  template <typename REC, typename T>
121  auto rk = eventsetup::EventSetupRecordKey::makeKey<REC>();
122  eventsetup::DataKey dk(eventsetup::DataKey::makeTypeTag<T>(), iLabel.c_str());
123  esProduceEntries_.emplace_back(rk, dk, std::make_shared<TestESProductResolver<T>>());
124  return edm::test::ESPutTokenT<T>(esProduceEntries_.size() - 1);
125  }
126 
127  struct ProduceEntry {
128  ProduceEntry(edm::TypeID const& iType,
130  std::string instanceLabel,
132  : type_{iType},
134  instanceLabel_{std::move(instanceLabel)},
140  };
141 
142  std::vector<ProduceEntry> const& produceEntries() const { return produceEntries_; }
143 
144  std::vector<ESProduceEntry> const& esProduceEntries() const { return esProduceEntries_; }
145 
146  private:
148  std::vector<std::string> extraProcesses_;
149  std::vector<ProduceEntry> produceEntries_;
150  std::vector<ESProduceEntry> esProduceEntries_;
151 
153  if (iToken.index() == ProcessToken::undefinedIndex()) {
154  return std::string();
155  }
156  return extraProcesses_[iToken.index()];
157  }
158  };
159 
161  public:
163 
164  TestProcessor(Config const& iConfig, ServiceToken iToken = ServiceToken());
165  TestProcessor(const TestProcessor&) = delete;
166  const TestProcessor& operator=(const TestProcessor&) = delete;
167  ~TestProcessor() noexcept(false);
168 
172  template <typename... T>
173  edm::test::Event test(T&&... iArgs) {
174  return testImpl(std::forward<T>(iArgs)...);
175  }
176 
177  template <typename... T>
179  return testBeginLuminosityBlockImpl(iNum, std::forward<T>(iArgs)...);
180  }
181  template <typename... T>
183  return testEndLuminosityBlockImpl(std::forward<T>(iArgs)...);
184  }
185 
186  template <typename... T>
188  return testBeginRunImpl(iNum, std::forward<T>(iArgs)...);
189  }
190  template <typename... T>
192  return testEndRunImpl(std::forward<T>(iArgs)...);
193  }
194 
195  // It makes no sense to pass EventSetup products and at least
196  // for now Runs, Lumis, and ProcessBlocks don't allow passing
197  // in other products. So for now these don't need to be templates
198  // for ProcessBlock.
200 
202 
207  arena_.execute([this]() {
208  beginJob();
209  endJob();
210  });
211  }
212 
213  void testWithNoRuns() {
214  arena_.execute([this]() {
215  beginJob();
217  endProcessBlock();
218  endJob();
219  });
220  }
221 
223  arena_.execute([this]() {
224  beginJob();
226  beginRun();
227  endRun();
228  endProcessBlock();
229  endJob();
230  });
231  }
232 
234  arena_.execute([this]() {
235  beginJob();
237  beginRun();
240  endRun();
241  endProcessBlock();
242  endJob();
243  });
244  }
248 
250 
251  private:
252  template <typename T, typename... U>
253  edm::test::Event testImpl(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
254  put(std::move(iPut));
255  return testImpl(std::forward<U>(iArgs)...);
256  }
257 
258  template <typename T, typename... U>
259  edm::test::Event testImpl(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
260  put(std::move(iPut));
261  return testImpl(std::forward<U>(iArgs)...);
262  }
263 
264  template <typename T>
265  void put(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
266  put(iPut.first.index(), std::make_unique<edm::Wrapper<T>>(std::move(iPut.second)));
267  }
268 
269  template <typename T>
270  void put(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
271  dynamic_cast<TestESProductResolver<T>*>(esHelper_->getResolver(iPut.first.index()).get())
272  ->setData(std::move(iPut.second));
273  }
274 
275  void put(unsigned int, std::unique_ptr<WrapperBase>);
276 
278 
279  template <typename T, typename... U>
282  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut,
283  U&&... iArgs) {
284  put(std::move(iPut));
285  return testBeginLuminosityBlockImpl(iNum, std::forward<U>(iArgs)...);
286  }
288 
289  template <typename T, typename... U>
291  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
292  put(std::move(iPut));
293  return testEndLuminosityBlockImpl(std::forward<U>(iArgs)...);
294  }
296 
297  template <typename T, typename... U>
299  std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut,
300  U&&... iArgs) {
301  put(std::move(iPut));
302  return testBeginRunImpl(iNum, std::forward<U>(iArgs)...);
303  }
305  template <typename T, typename... U>
307  U&&... iArgs) {
308  put(std::move(iPut));
309  return testEndRunImpl(std::forward<U>(iArgs)...);
310  }
312 
315 
316  void setupProcessing();
317  void teardownProcessing();
318 
319  void beginJob();
320  void beginProcessBlock();
321  void beginRun();
322  void beginLuminosityBlock();
323  void event();
324  std::shared_ptr<LuminosityBlockPrincipal> endLuminosityBlock();
325  std::shared_ptr<RunPrincipal> endRun();
327  void endJob();
328 
329  // ---------- member data --------------------------------
330  oneapi::tbb::global_control globalControl_;
331  oneapi::tbb::task_group taskGroup_;
332  oneapi::tbb::task_arena arena_;
334  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
335  std::shared_ptr<ProductRegistry> preg_;
336  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
337  std::shared_ptr<ProcessBlockHelper> processBlockHelper_;
338  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
340  std::unique_ptr<ModuleTypeResolverMaker const> moduleTypeResolverMaker_;
341  std::unique_ptr<eventsetup::EventSetupsController> espController_;
342  std::shared_ptr<eventsetup::EventSetupProvider> esp_;
343  std::shared_ptr<EventSetupTestHelper> esHelper_;
344 
345  std::unique_ptr<ExceptionToActionTable const> act_table_;
346  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
348 
350  std::unique_ptr<HistoryAppender> historyAppender_;
351 
354 
355  std::shared_ptr<ModuleRegistry> moduleRegistry_;
356  std::unique_ptr<Schedule> schedule_;
357  std::shared_ptr<RunPrincipal> runPrincipal_;
358  std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
359 
360  std::vector<std::pair<edm::BranchDescription, std::unique_ptr<WrapperBase>>> dataProducts_;
361 
365  bool beginJobCalled_ = false;
367  bool beginRunCalled_ = false;
368  bool beginLumiCalled_ = false;
369  };
370  } // namespace test
371 } // namespace edm
372 
373 #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:95
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:84
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:96
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)
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:94
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)