CMS 3D CMS Logo

TestOneOutput.cc
Go to the documentation of this file.
1 
13 
14 #include "TTree.h"
15 
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 constexpr unsigned int kDoNotTest = 0xffffffff;
21 
22 namespace edm {
23 
24  class TestOneOutput : public one::OutputModule<WatchInputFiles, RunCache<int>, LuminosityBlockCache<int>> {
25  public:
26  explicit TestOneOutput(ParameterSet const& pset);
27  ~TestOneOutput() override;
28  static void fillDescriptions(ConfigurationDescriptions& descriptions);
29 
30  private:
31  void write(EventForOutput const& e) override;
32  void writeLuminosityBlock(LuminosityBlockForOutput const&) override;
33  void writeRun(RunForOutput const&) override;
34  void writeProcessBlock(ProcessBlockForOutput const&) override;
35 
36  void respondToOpenInputFile(FileBlock const&) override;
37  void respondToCloseInputFile(FileBlock const&) override;
38  void testFileBlock(FileBlock const&);
39 
40  std::shared_ptr<int> globalBeginRun(RunForOutput const&) const override;
41  void globalEndRun(RunForOutput const&) override;
42 
43  std::shared_ptr<int> globalBeginLuminosityBlock(LuminosityBlockForOutput const&) const override;
45  void endJob() override;
46 
47  bool verbose_;
50  std::vector<std::string> expectedAddedProcesses_;
51  std::vector<std::string> expectedTopAddedProcesses_;
52  std::vector<unsigned int> expectedTopCacheIndices0_;
53  std::vector<unsigned int> expectedTopCacheIndices1_;
54  std::vector<unsigned int> expectedTopCacheIndices2_;
55  std::vector<std::string> expectedProcessNamesAtWrite_;
58  unsigned int countInputFiles_ = 0;
61  std::vector<unsigned int> expectedCacheIndexSize_;
63  std::vector<unsigned int> expectedCacheIndexVectorsPerFile_;
64  std::vector<unsigned int> expectedNEntries0_;
65  std::vector<unsigned int> expectedNEntries1_;
66  std::vector<unsigned int> expectedNEntries2_;
67  std::vector<unsigned int> expectedCacheEntriesPerFile0_;
68  std::vector<unsigned int> expectedCacheEntriesPerFile1_;
69  std::vector<unsigned int> expectedCacheEntriesPerFile2_;
70  std::vector<unsigned int> expectedOuterOffset_;
71  std::vector<unsigned int> expectedTranslateFromStoredIndex_;
74  };
75 
79  verbose_(pset.getUntrackedParameter<bool>("verbose")),
80  expectedProcessesWithProcessBlockProducts_(
81  pset.getUntrackedParameter<std::vector<std::string>>("expectedProcessesWithProcessBlockProducts")),
82  expectedTopProcessesWithProcessBlockProducts_(
83  pset.getUntrackedParameter<std::vector<std::string>>("expectedTopProcessesWithProcessBlockProducts")),
84  expectedAddedProcesses_(pset.getUntrackedParameter<std::vector<std::string>>("expectedAddedProcesses")),
85  expectedTopAddedProcesses_(pset.getUntrackedParameter<std::vector<std::string>>("expectedTopAddedProcesses")),
86  expectedTopCacheIndices0_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedTopCacheIndices0")),
87  expectedTopCacheIndices1_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedTopCacheIndices1")),
88  expectedTopCacheIndices2_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedTopCacheIndices2")),
89  expectedProcessNamesAtWrite_(
90  pset.getUntrackedParameter<std::vector<std::string>>("expectedProcessNamesAtWrite")),
91  expectedWriteProcessBlockTransitions_(pset.getUntrackedParameter<int>("expectedWriteProcessBlockTransitions")),
92  requireNullTTreesInFileBlock_(pset.getUntrackedParameter<bool>("requireNullTTreesInFileBlock")),
93  testTTreesInFileBlock_(pset.getUntrackedParameter<bool>("testTTreesInFileBlock")),
94  expectedCacheIndexSize_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedCacheIndexSize")),
95  expectedProcessesInFirstFile_(pset.getUntrackedParameter<unsigned int>("expectedProcessesInFirstFile")),
96  expectedCacheIndexVectorsPerFile_(
97  pset.getUntrackedParameter<std::vector<unsigned int>>("expectedCacheIndexVectorsPerFile")),
98  expectedNEntries0_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedNEntries0")),
99  expectedNEntries1_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedNEntries1")),
100  expectedNEntries2_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedNEntries2")),
101  expectedCacheEntriesPerFile0_(
102  pset.getUntrackedParameter<std::vector<unsigned int>>("expectedCacheEntriesPerFile0")),
103  expectedCacheEntriesPerFile1_(
104  pset.getUntrackedParameter<std::vector<unsigned int>>("expectedCacheEntriesPerFile1")),
105  expectedCacheEntriesPerFile2_(
106  pset.getUntrackedParameter<std::vector<unsigned int>>("expectedCacheEntriesPerFile2")),
107  expectedOuterOffset_(pset.getUntrackedParameter<std::vector<unsigned int>>("expectedOuterOffset")),
108  expectedTranslateFromStoredIndex_(
109  pset.getUntrackedParameter<std::vector<unsigned int>>("expectedTranslateFromStoredIndex")),
110  expectedNAddedProcesses_(pset.getUntrackedParameter<unsigned int>("expectedNAddedProcesses")),
111  expectedProductsFromInputKept_(pset.getUntrackedParameter<bool>("expectedProductsFromInputKept")) {}
112 
114 
116  if (verbose_) {
117  LogAbsolute("TestOneOutput") << "one write event";
118  }
119  }
120 
122  if (verbose_) {
123  LogAbsolute("TestOneOutput") << "one writeLuminosityBlock";
124  }
125  }
126 
128  if (verbose_) {
129  LogAbsolute("TestOneOutput") << "one writeRun";
130  }
131  }
132 
134  if (verbose_) {
135  LogAbsolute("TestOneOutput") << "one writeProcessBlock";
136  }
139  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected process name";
140  }
141  }
143  if (verbose_) {
145  LogAbsolute("TestOneOutput") << " " << process;
146  }
147  }
149  outputProcessBlockHelper().processesWithProcessBlockProducts()) {
150  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected process name list";
151  }
152  }
153  if (!(!expectedAddedProcesses_.empty() && expectedAddedProcesses_[0] == "DONOTTEST")) {
155  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected addedProcesses list";
156  }
157  }
158  if (!(!expectedTopAddedProcesses_.empty() && expectedTopAddedProcesses_[0] == "DONOTTEST")) {
161  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected top addedProcesses list";
162  }
163  }
165  // Same test as the previous except check the list of names in
166  // the top level process name list from the EventProcessor
171  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected top process name list";
172  }
173  // Almost the same as the previous test, should get the same result
175  outputProcessBlockHelper().processBlockHelper()->topProcessesWithProcessBlockProducts()) {
176  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected top process name list 2";
177  }
178 
179  std::vector<unsigned int> const* expectedTopCacheIndices = nullptr;
180  if (countInputFiles_ == 1 && !expectedTopCacheIndices0_.empty()) {
181  expectedTopCacheIndices = &expectedTopCacheIndices0_;
182  } else if (countInputFiles_ == 2 && !expectedTopCacheIndices1_.empty()) {
183  expectedTopCacheIndices = &expectedTopCacheIndices1_;
184  } else if (countInputFiles_ == 3 && !expectedTopCacheIndices2_.empty()) {
185  expectedTopCacheIndices = &expectedTopCacheIndices2_;
186  }
187  if (expectedTopCacheIndices != nullptr) {
188  unsigned int expectedInputProcesses =
191 
192  std::vector<std::vector<unsigned int>> const& topProcessBlockCacheIndices =
194  if (expectedTopCacheIndices->size() != expectedInputProcesses * topProcessBlockCacheIndices.size()) {
195  throw cms::Exception("TestFailure")
196  << "TestOneOutput::writeProcessBlock unexpected sizes related to top cache indices on input file "
197  << (countInputFiles_ - 1);
198  }
199  unsigned int iStored = 0;
200  for (unsigned int i = 0; i < topProcessBlockCacheIndices.size(); ++i) {
201  if (topProcessBlockCacheIndices[i].size() != expectedInputProcesses) {
202  throw cms::Exception("TestFailure")
203  << "TestOneOutput::writeProcessBlock unexpected size of inner cache indices vector on input file "
204  << (countInputFiles_ - 1);
205  }
206  for (unsigned int j = 0; j < topProcessBlockCacheIndices[i].size(); ++j) {
207  if (topProcessBlockCacheIndices[i][j] != (*expectedTopCacheIndices)[iStored]) {
208  throw cms::Exception("TestFailure")
209  << "TestOneOutput::writeProcessBlock unexpected cache index value on input file "
210  << (countInputFiles_ - 1);
211  }
212  ++iStored;
213  }
214  }
215  }
216  }
219  throw cms::Exception("TestFailure")
220  << "TestOneOutput::writeProcessBlock unexpected value for nProcessesInFirstFile";
221  }
222  }
223  for (unsigned int i = 0; i < expectedCacheIndexVectorsPerFile_.size(); ++i) {
224  if (i < countInputFiles_) {
227  throw cms::Exception("TestFailure")
228  << "TestOneOutput::writeProcessBlock unexpected value for cacheIndexVectorsPerFile, element " << i;
229  }
230  }
231  }
232  if (countInputFiles_ >= 1 && !expectedNEntries0_.empty()) {
234  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected value for nEntries 0";
235  }
236  }
237  if (countInputFiles_ >= 2 && !expectedNEntries1_.empty()) {
239  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected value for nEntries 1";
240  }
241  }
242  if (countInputFiles_ >= 3 && !expectedNEntries2_.empty()) {
244  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected value for nEntries 2";
245  }
246  }
247 
248  if (countInputFiles_ == 1 && !expectedCacheEntriesPerFile0_.empty()) {
250  throw cms::Exception("TestFailure")
251  << "TestOneOutput::writeProcessBlock unexpected value for cacheEntriesPerFile 0";
252  }
253  } else if (countInputFiles_ == 2 && !expectedCacheEntriesPerFile1_.empty()) {
255  throw cms::Exception("TestFailure")
256  << "TestOneOutput::writeProcessBlock unexpected value for cacheEntriesPerFile 1";
257  }
258  } else if (countInputFiles_ == 3 && !expectedCacheEntriesPerFile2_.empty()) {
260  throw cms::Exception("TestFailure")
261  << "TestOneOutput::writeProcessBlock unexpected value for cacheEntriesPerFile 2";
262  }
263  }
264 
265  if (!expectedOuterOffset_.empty() && (countInputFiles_ - 1) < expectedOuterOffset_.size()) {
268  throw cms::Exception("TestFailure")
269  << "TestOneOutput::writeProcessBlock unexpected value for outerOffset, file " << (countInputFiles_ - 1);
270  }
271  }
275  throw cms::Exception("TestFailure")
276  << "TestOneOutput::writeProcessBlock unexpected cache index size "
278  }
279  }
280  if (!expectedTranslateFromStoredIndex_.empty()) {
282  throw cms::Exception("TestFailure")
283  << "TestOneOutput::writeProcessBlock unexpected value for translateFromStoredIndex";
284  }
285  }
287  if (expectedNAddedProcesses_ != outputProcessBlockHelper().nAddedProcesses()) {
288  throw cms::Exception("TestFailure") << "TestOneOutput::writeProcessBlock unexpected value for nAddedProcesses";
289  }
290  }
291  if (expectedProductsFromInputKept_ != outputProcessBlockHelper().productsFromInputKept()) {
292  throw cms::Exception("TestFailure")
293  << "TestOneOutput::writeProcessBlock unexpected value for productsFromInputKept";
294  }
296  }
297 
299  if (verbose_) {
300  LogAbsolute("TestOneOutput") << "one respondToOpenInputFile";
301  }
302  testFileBlock(fb);
304  }
305 
307  if (verbose_) {
308  LogAbsolute("TestOneOutput") << "one respondToCloseInputFile";
309  }
310  testFileBlock(fb);
311  }
312 
315  if (fb.tree() != nullptr || fb.lumiTree() != nullptr || fb.runTree() != nullptr ||
316  !fb.processBlockTrees().empty() || !fb.processesWithProcessBlockTrees().empty() ||
317  fb.processBlockTree(std::string("DoesNotExist")) != nullptr) {
318  throw cms::Exception("TestFailure")
319  << "TestOneOutput::respondToOpenInputFile expected null TTree pointers in FileBlock";
320  }
321  } else if (testTTreesInFileBlock_) {
322  if (fb.tree() == nullptr || std::string("Events") != fb.tree()->GetName() ||
323  std::string("LuminosityBlocks") != fb.lumiTree()->GetName() ||
324  std::string("Runs") != fb.runTree()->GetName() || fb.processesWithProcessBlockTrees().size() != 2 ||
325  fb.processesWithProcessBlockTrees()[0] != "PROD1" || fb.processesWithProcessBlockTrees()[1] != "MERGE" ||
326  fb.processBlockTrees().size() != 2 ||
327  std::string("ProcessBlocksPROD1") != fb.processBlockTrees()[0]->GetName() ||
328  std::string("ProcessBlocksMERGE") != fb.processBlockTrees()[1]->GetName() ||
329  std::string("ProcessBlocksPROD1") != fb.processBlockTree("PROD1")->GetName() ||
330  std::string("ProcessBlocksMERGE") != fb.processBlockTree("MERGE")->GetName() ||
331  fb.processBlockTree("DOESNOTEXIST") != nullptr) {
332  throw cms::Exception("TestFailure") << "TestOneOutput::testFileBlock failed. Testing tree pointers";
333  }
334  }
335  }
336 
337  std::shared_ptr<int> TestOneOutput::globalBeginRun(RunForOutput const&) const {
338  if (verbose_) {
339  LogAbsolute("TestOneOutput") << "one globalBeginRun";
341  for (auto const& it : reg->productList()) {
342  LogAbsolute("TestOneOutput") << it.second;
343  }
344  }
345  return std::make_shared<int>(0);
346  }
347 
349  if (verbose_) {
350  LogAbsolute("TestOneOutput") << "one globalEndRun";
351  }
352  }
353 
355  if (verbose_) {
356  LogAbsolute("TestOneOutput") << "one globalBeginLuminosityBlock";
357  }
358  return std::make_shared<int>(0);
359  }
360 
362  if (verbose_) {
363  LogAbsolute("TestOneOutput") << "one globalEndLuminosityBlock";
364  }
365  }
366 
370  throw cms::Exception("TestFailure")
371  << "TestOneOutput::writeProcessBlock unexpected number of writeProcessBlock transitions";
372  }
373  }
374  }
375 
378  OutputModule::fillDescription(desc);
379  desc.addUntracked<bool>("verbose", true);
380  desc.addUntracked<std::vector<std::string>>("expectedProcessesWithProcessBlockProducts",
381  std::vector<std::string>());
382  desc.addUntracked<std::vector<std::string>>("expectedTopProcessesWithProcessBlockProducts",
383  std::vector<std::string>());
384  desc.addUntracked<std::vector<std::string>>("expectedAddedProcesses",
385  std::vector<std::string>(1, std::string("DONOTTEST")));
386  desc.addUntracked<std::vector<std::string>>("expectedTopAddedProcesses",
387  std::vector<std::string>(1, std::string("DONOTTEST")));
388  desc.addUntracked<std::vector<unsigned int>>("expectedTopCacheIndices0", std::vector<unsigned int>());
389  desc.addUntracked<std::vector<unsigned int>>("expectedTopCacheIndices1", std::vector<unsigned int>());
390  desc.addUntracked<std::vector<unsigned int>>("expectedTopCacheIndices2", std::vector<unsigned int>());
391  desc.addUntracked<std::vector<std::string>>("expectedProcessNamesAtWrite", std::vector<std::string>());
392  desc.addUntracked<int>("expectedWriteProcessBlockTransitions", -1);
393  desc.addUntracked<bool>("requireNullTTreesInFileBlock", false);
394  desc.addUntracked<bool>("testTTreesInFileBlock", false);
395  desc.addUntracked<std::vector<unsigned int>>("expectedCacheIndexSize", std::vector<unsigned int>());
396  desc.addUntracked<unsigned int>("expectedProcessesInFirstFile", 0);
397  desc.addUntracked<std::vector<unsigned int>>("expectedCacheIndexVectorsPerFile", std::vector<unsigned int>());
398  desc.addUntracked<std::vector<unsigned int>>("expectedNEntries0", std::vector<unsigned int>());
399  desc.addUntracked<std::vector<unsigned int>>("expectedNEntries1", std::vector<unsigned int>());
400  desc.addUntracked<std::vector<unsigned int>>("expectedNEntries2", std::vector<unsigned int>());
401  desc.addUntracked<std::vector<unsigned int>>("expectedCacheEntriesPerFile0", std::vector<unsigned int>());
402  desc.addUntracked<std::vector<unsigned int>>("expectedCacheEntriesPerFile1", std::vector<unsigned int>());
403  desc.addUntracked<std::vector<unsigned int>>("expectedCacheEntriesPerFile2", std::vector<unsigned int>());
404  desc.addUntracked<std::vector<unsigned int>>("expectedOuterOffset", std::vector<unsigned int>());
405  desc.addUntracked<std::vector<unsigned int>>("expectedTranslateFromStoredIndex", std::vector<unsigned int>());
406  desc.addUntracked<unsigned int>("expectedNAddedProcesses", kDoNotTest);
407  desc.addUntracked<bool>("expectedProductsFromInputKept", true);
408 
409  descriptions.addDefault(desc);
410  }
411 } // namespace edm
412 
413 using edm::TestOneOutput;
TestOneOutput(ParameterSet const &pset)
virtual ProcessBlockHelperBase const * topProcessBlockHelper() const =0
std::vector< unsigned int > expectedNEntries0_
std::vector< std::string > expectedTopProcessesWithProcessBlockProducts_
std::vector< unsigned int > expectedCacheEntriesPerFile1_
std::vector< TTree * > const & processBlockTrees() const
Definition: FileBlock.h:125
virtual unsigned int nProcessesInFirstFile() const =0
std::vector< unsigned int > expectedTopCacheIndices0_
bool requireNullTTreesInFileBlock_
void writeRun(RunForOutput const &) override
std::vector< unsigned int > expectedOuterOffset_
OutputProcessBlockHelper const & outputProcessBlockHelper() const
std::vector< unsigned int > expectedTranslateFromStoredIndex_
std::vector< unsigned int > expectedCacheIndexVectorsPerFile_
std::vector< std::string > expectedAddedProcesses_
TTree * processBlockTree(std::string const &processName) const
Definition: FileBlock.cc:24
std::vector< unsigned int > expectedCacheEntriesPerFile2_
TTree * lumiTree() const
Definition: FileBlock.h:119
unsigned int countInputFiles_
std::vector< unsigned int > expectedNEntries1_
unsigned int expectedProcessesInFirstFile_
std::vector< std::string > const & processesWithProcessBlockProducts() const
virtual std::vector< std::string > const & topProcessesWithProcessBlockProducts() const =0
ProductList const & productList() const
std::vector< std::string > expectedProcessesWithProcessBlockProducts_
virtual unsigned int outerOffset() const =0
unsigned int expectedNAddedProcesses_
std::vector< std::string > expectedTopAddedProcesses_
std::vector< std::string > const & addedProcesses() const
virtual std::vector< unsigned int > const & cacheIndexVectorsPerFile() const =0
void writeLuminosityBlock(LuminosityBlockForOutput const &) override
void addDefault(ParameterSetDescription const &psetDescription)
std::shared_ptr< int > globalBeginLuminosityBlock(LuminosityBlockForOutput const &) const override
TTree * tree() const
Definition: FileBlock.h:117
void testFileBlock(FileBlock const &)
int expectedWriteProcessBlockTransitions_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::string const & processName() const
void globalEndLuminosityBlock(LuminosityBlockForOutput const &) override
unsigned int countWriteProcessBlockTransitions_
void respondToCloseInputFile(FileBlock const &) override
std::vector< unsigned int > expectedTopCacheIndices1_
constexpr unsigned int kDoNotTest
void writeProcessBlock(ProcessBlockForOutput const &) override
void globalEndRun(RunForOutput const &) override
std::vector< unsigned int > const & translateFromStoredIndex() const
std::vector< unsigned int > expectedCacheIndexSize_
std::vector< std::string > expectedProcessNamesAtWrite_
~TestOneOutput() override
void write(EventForOutput const &e) override
virtual std::vector< unsigned int > const & cacheEntriesPerFile() const =0
virtual std::vector< std::vector< unsigned int > > const & nEntries() const =0
HLT enums.
void respondToOpenInputFile(FileBlock const &) override
Log< level::System, true > LogAbsolute
bool expectedProductsFromInputKept_
std::vector< std::string > const & processesWithProcessBlockTrees() const
Definition: FileBlock.h:126
virtual std::vector< std::vector< unsigned int > > const & processBlockCacheIndices() const =0
std::shared_ptr< int > globalBeginRun(RunForOutput const &) const override
std::vector< unsigned int > expectedNEntries2_
std::vector< unsigned int > expectedTopCacheIndices2_
ProcessBlockHelperBase const * processBlockHelper() const
std::vector< unsigned int > expectedCacheEntriesPerFile0_
void endJob() override
TTree * runTree() const
Definition: FileBlock.h:121
static void fillDescriptions(ConfigurationDescriptions &descriptions)