CMS 3D CMS Logo

SwitchProducerProvenanceAnalyzer.cc
Go to the documentation of this file.
3 #include "DataFormats/TestObjects/interface/ToyProducts.h"
11 
12 namespace edm {
13  class EventSetup;
14  class StreamID;
15 } // namespace edm
16 
17 namespace edmtest {
19  public:
20  explicit SwitchProducerProvenanceAnalyzer(edm::ParameterSet const& iConfig);
21  void analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const& iSetup) const override;
22 
23  private:
24  void testProduct(edm::Handle<IntProduct> const& prod, int mode, edm::Event const& iEvent) const;
25 
29  bool const aliasMode_;
30  };
31 
33  : inputToken1_(consumes(iConfig.getParameter<edm::InputTag>("src1"))),
34  inputToken2_(consumes(iConfig.getParameter<edm::InputTag>("src2"))),
35  producerPrefix_(iConfig.getParameter<std::string>("producerPrefix")),
36  aliasMode_(iConfig.getParameter<bool>("aliasMode")) {}
37 
39  edm::Event const& iEvent,
40  edm::EventSetup const& iSetup) const {
42  iEvent.getByToken(inputToken1_, h);
43  testProduct(h, iEvent.id().luminosityBlock(), iEvent);
44 
45  iEvent.getByToken(inputToken2_, h);
46  testProduct(h, iEvent.id().luminosityBlock(), iEvent);
47  }
48 
50  int mode,
51  edm::Event const& iEvent) const {
52  assert(prod->value == mode);
53 
54  edm::Provenance const* provenance = prod.provenance();
55  assert(provenance != nullptr);
56  auto const* productProvenance = provenance->productProvenance();
57  assert(productProvenance != nullptr);
58  auto const& processHistory = iEvent.processHistory();
59 
60  edm::pset::Registry const* psetRegistry = edm::pset::Registry::instance();
61  assert(psetRegistry != nullptr);
62 
63  auto const& moduleLabel = provenance->moduleLabel();
64 
65  // Switch output should not look like an alias
66  assert(productProvenance->branchID() == provenance->branchID());
67 
68  // Check that the provenance of the Switch itself is recorded correctly
69  for (edm::ProcessConfiguration const& pc : processHistory) {
70  if (pc.processName() == provenance->processName()) {
71  edm::ParameterSetID const& psetID = pc.parameterSetID();
72  edm::ParameterSet const* processPSet = psetRegistry->getMapped(psetID);
73  assert(processPSet);
74  auto const& modPSet = processPSet->getParameterSet(moduleLabel);
75  assert(modPSet.getParameter<std::string>("@module_edm_type") == "EDProducer");
76  assert(modPSet.getParameter<std::string>("@module_type") == "SwitchProducer");
77  assert(modPSet.getParameter<std::string>("@module_label") == moduleLabel);
78  auto const& allCases = modPSet.getParameter<std::vector<std::string>>("@all_cases");
79  assert(allCases.size() == 2);
80  assert(allCases[0] == moduleLabel + "@test1");
81  assert(allCases[1] == moduleLabel + "@test2");
82  assert(modPSet.exists("@chosen_case") == false);
83  }
84  }
85 
86  // Check the parentage (foo -> foo@case -> possible input)
87  auto const& parent = productProvenance->parentage();
88  // Here is where Switch differs from a normal EDProducer: each Switch output branch has exactly one parent
89  assert(parent.parents().size() == 1);
90  auto const& parentProvenance = iEvent.getProvenance(parent.parents()[0]);
91  edm::ProductProvenance const* parentProductProvenance = nullptr;
92  if (not(aliasMode_ and mode == 2)) {
93  // If parent is EDAlias, it is skipped in the provenance, so in
94  // that case the normal grandparent can be found on the place of
95  // the parent.
96 
97  assert(parentProvenance.branchDescription().moduleLabel() == moduleLabel + "@test" + std::to_string(mode));
98 
99  // Check grandparent as well
100  parentProductProvenance = parentProvenance.productProvenance();
101  assert(parentProductProvenance != nullptr);
102  }
103  auto const& grandParent = parentProductProvenance ? parentProductProvenance->parentage() : parent;
104  //auto const& grandParent = parentProductProvenance->parentage();
105  assert(grandParent.parents().size() == 1); // behaviour of the AddIntsProducer
106  auto const& grandParentProvenance = iEvent.getProvenance(grandParent.parents()[0]);
107  int postfix = mode;
108  if (aliasMode_ and mode == 2) {
109  postfix = 3;
110  }
111  assert(grandParentProvenance.branchDescription().moduleLabel() == producerPrefix_ + std::to_string(postfix));
112  }
113 } // namespace edmtest
bool getMapped(key_type const &k, value_type &result) const
Definition: Registry.cc:17
ProductProvenance const * productProvenance() const
Definition: Provenance.cc:24
ParameterSet const & getParameterSet(std::string const &) const
std::string const & processName() const
Definition: Provenance.h:57
void analyze(edm::StreamID, edm::Event const &iEvent, edm::EventSetup const &iSetup) const override
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BranchID const & branchID() const
Definition: Provenance.h:52
void testProduct(edm::Handle< IntProduct > const &prod, int mode, edm::Event const &iEvent) const
HLT enums.
SwitchProducerProvenanceAnalyzer(edm::ParameterSet const &iConfig)
std::string const & moduleLabel() const
Definition: Provenance.h:55
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static Registry * instance()
Definition: Registry.cc:12
Parentage const & parentage() const