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:
74  ProcessToken() : index_{undefinedIndex()} {}
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,
123  std::string moduleLabel,
124  std::string instanceLabel,
126  : type_{iType},
127  moduleLabel_{std::move(moduleLabel)},
128  instanceLabel_{std::move(instanceLabel)},
129  processName_{std::move(processName)} {}
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());
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();
205  beginLuminosityBlock();
206  endLuminosityBlock();
207  endRun();
208  endJob();
209  }
210  void setRunNumber(edm::RunNumber_t);
211  void setLuminosityBlockNumber(edm::LuminosityBlockNumber_t);
212  void setEventNumber(edm::EventNumber_t);
213 
214  std::string const& labelOfTestModule() const { return labelOfTestModule_; }
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 
245  edm::test::Event testImpl();
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  }
255  edm::test::LuminosityBlock testBeginLuminosityBlockImpl(edm::LuminosityBlockNumber_t);
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  }
263  edm::test::LuminosityBlock testEndLuminosityBlockImpl();
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  }
272  edm::test::Run testBeginRunImpl(edm::RunNumber_t);
273  template <typename T, typename... U>
275  U&&... iArgs) {
276  put(std::move(iPut));
277  return testEndRunImpl(std::forward<U>(iArgs)...);
278  }
279  edm::test::Run testEndRunImpl();
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 
320  LuminosityBlockNumber_t lumiNumber_ = 1;
321  EventNumber_t eventNumber_ = 1;
322  bool beginJobCalled_ = false;
323  bool beginRunCalled_ = false;
324  bool beginLumiCalled_ = false;
325  };
326  } // namespace test
327 } // namespace edm
328 
329 #endif
static const char runNumber_[]
void put(std::pair< edm::EDPutTokenT< T >, std::unique_ptr< T >> &&iPut)
std::shared_ptr< ActivityRegistry > actReg_
edm::test::LuminosityBlock testBeginLuminosityBlockImpl(edm::LuminosityBlockNumber_t iNum, std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&...iArgs)
std::vector< std::pair< edm::BranchDescription, std::unique_ptr< WrapperBase > > > dataProducts_
edm::test::Run testBeginRun(edm::RunNumber_t iNum, T &&...iArgs)
std::vector< ESProduceEntry > esProduceEntries_
edm::test::Event testImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&...iArgs)
unsigned long long EventNumber_t
edm::EDPutTokenT< T > produces(std::string iModuleLabel, std::string iProductInstanceLabel=std::string(), ProcessToken iToken=ProcessToken())
void put(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut)
ProcessContext processContext_
unsigned int LuminosityBlockNumber_t
PreallocationConfiguration preallocations_
void beginJob()
Definition: Breakpoints.cc:14
void put(edm::Event &evt, double value, const char *instanceName)
std::shared_ptr< BranchIDListHelper > branchIDListHelper_
static int undefinedIndex()
Definition: TestProcessor.h:78
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:90
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
edm::test::Event testImpl(std::pair< edm::EDPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&...iArgs)
ProduceEntry(edm::TypeID const &iType, std::string moduleLabel, std::string instanceLabel, std::string processName)
std::string labelOfTestModule_
std::unique_ptr< eventsetup::EventSetupsController > espController_
std::shared_ptr< eventsetup::EventSetupProvider > esp_
std::vector< ProduceEntry > const & produceEntries() const
edm::test::LuminosityBlock testEndLuminosityBlockImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&...iArgs)
std::vector< ESProduceEntry > const & esProduceEntries() const
std::unique_ptr< Schedule > schedule_
std::shared_ptr< ProcessConfiguration const > processConfiguration_
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::shared_ptr< ModuleRegistry > moduleRegistry_
#define noexcept
edm::test::LuminosityBlock testBeginLuminosityBlock(edm::LuminosityBlockNumber_t iNum, T &&...iArgs)
std::string const & labelOfTestModule() const
ProcessToken addExtraProcess(std::string const &iProcessName)
Definition: TestProcessor.h:94
PrincipalCache principalCache_
edm::test::LuminosityBlock testEndRunImpl(std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&...iArgs)
std::shared_ptr< ProductRegistry > preg_
edm::test::Run testBeginRunImpl(edm::RunNumber_t iNum, std::pair< edm::test::ESPutTokenT< T >, std::unique_ptr< T >> &&iPut, U &&...iArgs)
std::unique_ptr< ExceptionToActionTable const > act_table_
std::vector< std::string > extraProcesses_
HLT enums.
std::unique_ptr< HistoryAppender > historyAppender_
edm::test::LuminosityBlock testEndLuminosityBlock(T &&...iArgs)
Definition: Config.py:1
unsigned int RunNumber_t
TestProcessorConfig(std::string const &iPythonConfiguration)
Definition: TestProcessor.h:88
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
long double T
ProcessHistoryRegistry processHistoryRegistry_
edm::test::Run testEndRun(T &&...iArgs)
std::string const & pythonConfiguration() const
Definition: TestProcessor.h:89
def move(src, dest)
Definition: eostools.py:511
std::string processName(ProcessToken iToken)
std::vector< std::string > const & extraProcesses() const
Definition: TestProcessor.h:99