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 
40 
44 
50 
52 
53 // forward declarations
54 
55 namespace edm {
56  class ThinnedAssociationsHelper;
57  class ExceptionToActionTable;
58  class HistoryAppender;
59 
60  namespace eventsetup {
61  class EventSetupProvider;
62  class EventSetupsController;
63  }
64 
65 namespace test {
66  class TestProcessorConfig;
68 
69  class ProcessToken {
71  public:
72  ProcessToken() : index_{undefinedIndex() } {}
73 
74  int index() const { return index_;}
75 
76  static int undefinedIndex() { return -1;}
77  private:
78  explicit ProcessToken(int index): index_{index} {}
79 
80  int index_;
81  };
82 
84  public:
85  TestProcessorConfig(std::string const& iPythonConfiguration):
86  config_(iPythonConfiguration)
87  {}
88  std::string const& pythonConfiguration() const { return config_;}
89  void setPythonConfiguration(std::string iConfig) { config_ = std::move(iConfig);}
90 
93  ProcessToken addExtraProcess(std::string const& iProcessName) {
94  extraProcesses_.emplace_back(iProcessName);
95  return ProcessToken( extraProcesses_.size() -1);
96  }
97 
98  std::vector<std::string> const& extraProcesses() const { return extraProcesses_;}
99 
103  template<typename T>
105  std::string iProductInstanceLabel = std::string(),
106  ProcessToken iToken= ProcessToken()) {
107  produceEntries_.emplace_back(edm::TypeID(typeid(T)), std::move(iModuleLabel),
108  std::move(iProductInstanceLabel),
109  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 {
139  return esProduceEntries_;
140  }
141 
142  private:
144  std::vector<std::string> extraProcesses_;
145  std::vector<ProduceEntry> produceEntries_;
146  std::vector<ESProduceEntry> esProduceEntries_;
147 
149  if(iToken.index() == ProcessToken::undefinedIndex()) {
150  return std::string();
151  }
152  return extraProcesses_[iToken.index()];
153  }
154  };
155 
157 {
158  public:
160 
161  TestProcessor(Config const& iConfig);
163 
167  template< typename... T>
168  edm::test::Event test(T&&... iArgs) {
169  return testImpl(std::forward<T>(iArgs)...);
170  }
171 
175  void testBeginAndEndJobOnly() { beginJob(); endJob();}
176 
178  beginJob();
179  beginRun();
180  endRun();
181  endJob();
182  }
183 
185  beginJob();
186  beginRun();
187  beginLuminosityBlock();
188  endLuminosityBlock();
189  endRun();
190  endJob();
191  }
192  void setRunNumber(edm::RunNumber_t);
193  void setLuminosityBlockNumber(edm::LuminosityBlockNumber_t);
194  void setEventNumber(edm::EventNumber_t);
195 
197  return labelOfTestModule_;
198  }
199 
200  private:
201  TestProcessor(const TestProcessor&) = delete; // stop default
202 
203  const TestProcessor& operator=(const TestProcessor&) = delete; // stop default
204 
205  template< typename T, typename... U>
206  edm::test::Event testImpl(std::pair<edm::EDPutTokenT<T>,std::unique_ptr<T>>&& iPut, U&&... iArgs) {
207  put(std::move(iPut));
208  return testImpl(std::forward<U>(iArgs)...);
209  }
210 
211  template<typename T, typename... U>
212  edm::test::Event testImpl(std::pair<edm::test::ESPutTokenT<T>,std::unique_ptr<T>>&& iPut, U&&... iArgs) {
213  put(std::move(iPut));
214  return testImpl(std::forward<U>(iArgs)...);
215  }
216 
217  template< typename T>
218  void put(std::pair<edm::EDPutTokenT<T>,std::unique_ptr<T>>&& iPut) {
219  put(iPut.first.index(), std::make_unique<edm::Wrapper<T>>(std::move(iPut.second)));
220  }
221 
222  template<typename T>
223  void put(std::pair<edm::test::ESPutTokenT<T>,std::unique_ptr<T>>&& iPut) {
224  dynamic_cast<TestDataProxy<T>*>(esHelper_->getProxy(iPut.first.index()).get())->setData(std::move(iPut.second));
225  }
226 
227  void put(unsigned int, std::unique_ptr<WrapperBase>);
228 
229  edm::test::Event testImpl();
230 
231  void setupProcessing();
232  void teardownProcessing();
233 
234  void beginJob();
235  void beginRun();
236  void beginLuminosityBlock();
237  void event();
238  void endLuminosityBlock();
239  void endRun();
240  void endJob();
241 
242  // ---------- member data --------------------------------
244  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
245  std::shared_ptr<ProductRegistry> preg_;
246  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
247  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
249  std::unique_ptr<eventsetup::EventSetupsController> espController_;
250  std::shared_ptr<eventsetup::EventSetupProvider> esp_;
251  std::shared_ptr<EventSetupTestHelper> esHelper_;
252 
253  std::unique_ptr<ExceptionToActionTable const> act_table_;
254  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
256 
258  std::unique_ptr<HistoryAppender> historyAppender_;
259 
262 
263  std::shared_ptr<ModuleRegistry> moduleRegistry_;
264  std::unique_ptr<Schedule> schedule_;
265  std::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal_;
266 
267  std::vector<std::pair<edm::BranchDescription,std::unique_ptr<WrapperBase>>> dataProducts_;
268 
270  LuminosityBlockNumber_t lumiNumber_=1;
271  EventNumber_t eventNumber_=1;
272  bool beginJobCalled_ = false;
273  bool beginRunCalled_ = false;
274  bool beginLumiCalled_ = false;
275  bool newRun_ = true;
276  bool newLumi_ = true;
277 };
278 }
279 }
280 
281 #endif
static const char runNumber_[]
void put(std::pair< edm::EDPutTokenT< T >, std::unique_ptr< T >> &&iPut)
std::shared_ptr< ActivityRegistry > actReg_
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
#define noexcept
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:15
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:89
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:520
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_
std::string const & labelOfTestModule() const
ProcessToken addExtraProcess(std::string const &iProcessName)
Definition: TestProcessor.h:93
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:85
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
long double T
ProcessHistoryRegistry processHistoryRegistry_
std::vector< std::pair< edm::BranchDescription, std::unique_ptr< WrapperBase > > > dataProducts_
std::string const & pythonConfiguration() const
Definition: TestProcessor.h:88
def move(src, dest)
Definition: eostools.py:511
std::string processName(ProcessToken iToken)
std::vector< std::string > const & extraProcesses() const
Definition: TestProcessor.h:98