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 
49 
51 
52 // forward declarations
53 
54 namespace edm {
55  class ThinnedAssociationsHelper;
56  class ExceptionToActionTable;
57  class HistoryAppender;
58 
59  namespace eventsetup {
60  class EventSetupProvider;
61  class EventSetupsController;
62  } // namespace eventsetup
63 
64  namespace test {
65  class TestProcessorConfig;
67 
68  class ProcessToken {
70 
71  public:
72  ProcessToken() : index_{undefinedIndex()} {}
73 
74  int index() const { return index_; }
75 
76  static int undefinedIndex() { return -1; }
77 
78  private:
79  explicit ProcessToken(int index) : index_{index} {}
80 
81  int index_;
82  };
83 
85  public:
86  TestProcessorConfig(std::string const& iPythonConfiguration) : config_(iPythonConfiguration) {}
87  std::string const& pythonConfiguration() const { return config_; }
88  void setPythonConfiguration(std::string iConfig) { config_ = std::move(iConfig); }
89 
92  ProcessToken addExtraProcess(std::string const& iProcessName) {
93  extraProcesses_.emplace_back(iProcessName);
94  return ProcessToken(extraProcesses_.size() - 1);
95  }
96 
97  std::vector<std::string> const& extraProcesses() const { return extraProcesses_; }
98 
102  template <typename T>
104  std::string iProductInstanceLabel = std::string(),
105  ProcessToken iToken = ProcessToken()) {
106  produceEntries_.emplace_back(
107  edm::TypeID(typeid(T)), std::move(iModuleLabel), std::move(iProductInstanceLabel), processName(iToken));
108  return edm::EDPutTokenT<T>(produceEntries_.size() - 1);
109  }
110 
111  template <typename REC, typename T>
113  auto rk = eventsetup::EventSetupRecordKey::makeKey<REC>();
114  eventsetup::DataKey dk(eventsetup::DataKey::makeTypeTag<T>(), iLabel.c_str());
115  esProduceEntries_.emplace_back(rk, dk, std::make_shared<TestDataProxy<T>>());
116  return edm::test::ESPutTokenT<T>(esProduceEntries_.size() - 1);
117  }
118 
119  struct ProduceEntry {
120  ProduceEntry(edm::TypeID const& iType,
121  std::string moduleLabel,
122  std::string instanceLabel,
124  : type_{iType},
125  moduleLabel_{std::move(moduleLabel)},
126  instanceLabel_{std::move(instanceLabel)},
127  processName_{std::move(processName)} {}
132  };
133 
134  std::vector<ProduceEntry> const& produceEntries() const { return produceEntries_; }
135 
136  std::vector<ESProduceEntry> const& esProduceEntries() const { return esProduceEntries_; }
137 
138  private:
140  std::vector<std::string> extraProcesses_;
141  std::vector<ProduceEntry> produceEntries_;
142  std::vector<ESProduceEntry> esProduceEntries_;
143 
145  if (iToken.index() == ProcessToken::undefinedIndex()) {
146  return std::string();
147  }
148  return extraProcesses_[iToken.index()];
149  }
150  };
151 
153  public:
155 
156  TestProcessor(Config const& iConfig);
158 
162  template <typename... T>
163  edm::test::Event test(T&&... iArgs) {
164  return testImpl(std::forward<T>(iArgs)...);
165  }
166 
171  beginJob();
172  endJob();
173  }
174 
176  beginJob();
177  beginRun();
178  endRun();
179  endJob();
180  }
181 
183  beginJob();
184  beginRun();
185  beginLuminosityBlock();
186  endLuminosityBlock();
187  endRun();
188  endJob();
189  }
190  void setRunNumber(edm::RunNumber_t);
191  void setLuminosityBlockNumber(edm::LuminosityBlockNumber_t);
192  void setEventNumber(edm::EventNumber_t);
193 
194  std::string const& labelOfTestModule() const { return labelOfTestModule_; }
195 
196  private:
197  TestProcessor(const TestProcessor&) = delete; // stop default
198 
199  const TestProcessor& operator=(const TestProcessor&) = delete; // stop default
200 
201  template <typename T, typename... U>
202  edm::test::Event testImpl(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
203  put(std::move(iPut));
204  return testImpl(std::forward<U>(iArgs)...);
205  }
206 
207  template <typename T, typename... U>
208  edm::test::Event testImpl(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut, U&&... iArgs) {
209  put(std::move(iPut));
210  return testImpl(std::forward<U>(iArgs)...);
211  }
212 
213  template <typename T>
214  void put(std::pair<edm::EDPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
215  put(iPut.first.index(), std::make_unique<edm::Wrapper<T>>(std::move(iPut.second)));
216  }
217 
218  template <typename T>
219  void put(std::pair<edm::test::ESPutTokenT<T>, std::unique_ptr<T>>&& iPut) {
220  dynamic_cast<TestDataProxy<T>*>(esHelper_->getProxy(iPut.first.index()).get())->setData(std::move(iPut.second));
221  }
222 
223  void put(unsigned int, std::unique_ptr<WrapperBase>);
224 
225  edm::test::Event testImpl();
226 
227  void setupProcessing();
228  void teardownProcessing();
229 
230  void beginJob();
231  void beginRun();
232  void beginLuminosityBlock();
233  void event();
234  void endLuminosityBlock();
235  void endRun();
236  void endJob();
237 
238  // ---------- member data --------------------------------
240  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
241  std::shared_ptr<ProductRegistry> preg_;
242  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
243  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
245  std::unique_ptr<eventsetup::EventSetupsController> espController_;
246  std::shared_ptr<eventsetup::EventSetupProvider> esp_;
247  std::shared_ptr<EventSetupTestHelper> esHelper_;
248 
249  std::unique_ptr<ExceptionToActionTable const> act_table_;
250  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
252 
254  std::unique_ptr<HistoryAppender> historyAppender_;
255 
258 
259  std::shared_ptr<ModuleRegistry> moduleRegistry_;
260  std::unique_ptr<Schedule> schedule_;
261  std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
262 
263  std::vector<std::pair<edm::BranchDescription, std::unique_ptr<WrapperBase>>> dataProducts_;
264 
266  LuminosityBlockNumber_t lumiNumber_ = 1;
267  EventNumber_t eventNumber_ = 1;
268  bool beginJobCalled_ = false;
269  bool beginRunCalled_ = false;
270  bool beginLumiCalled_ = false;
271  bool newRun_ = true;
272  bool newLumi_ = true;
273  };
274  } // namespace test
275 } // namespace edm
276 
277 #endif
static const char runNumber_[]
void put(std::pair< edm::EDPutTokenT< T >, std::unique_ptr< T >> &&iPut)
std::shared_ptr< ActivityRegistry > actReg_
std::vector< std::pair< edm::BranchDescription, std::unique_ptr< WrapperBase > > > dataProducts_
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:76
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:88
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
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
std::string const & labelOfTestModule() const
ProcessToken addExtraProcess(std::string const &iProcessName)
Definition: TestProcessor.h:92
PrincipalCache principalCache_
std::shared_ptr< ProductRegistry > preg_
std::unique_ptr< ExceptionToActionTable const > act_table_
std::vector< std::string > extraProcesses_
HLT enums.
std::unique_ptr< HistoryAppender > historyAppender_
Definition: Config.py:1
unsigned int RunNumber_t
TestProcessorConfig(std::string const &iPythonConfiguration)
Definition: TestProcessor.h:86
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
long double T
ProcessHistoryRegistry processHistoryRegistry_
std::string const & pythonConfiguration() const
Definition: TestProcessor.h:87
def move(src, dest)
Definition: eostools.py:511
std::string processName(ProcessToken iToken)
std::vector< std::string > const & extraProcesses() const
Definition: TestProcessor.h:97