CMS 3D CMS Logo

ProvenanceCheckerOutputModule.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Modules
4 // Class : ProvenanceCheckerOutputModule
5 //
6 // Implementation:
7 // Checks the consistency of provenance stored in the framework
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Sep 11 19:24:13 EDT 2008
11 //
12 
13 // system include files
24 
25 // user include files
26 
27 namespace edm {
28 
29  class ModuleCallingContext;
30  class ParameterSet;
31 
33  public:
34  // We do not take ownership of passed stream.
37  static void fillDescriptions(ConfigurationDescriptions& descriptions);
38 
39  private:
40  void write(EventForOutput const& e) override;
42  void writeRun(RunForOutput const&) override {}
43  };
44 
45  //
46  // constants, enums and typedefs
47  //
48 
49  //
50  // static data member definitions
51  //
52 
53  //
54  // constructors and destructor
55  //
57  : one::OutputModuleBase(pset), one::OutputModule<>(pset) {}
58 
59  // ProvenanceCheckerOutputModule::ProvenanceCheckerOutputModule(ProvenanceCheckerOutputModule const& rhs)
60  // {
61  // // do actual copying here;
62  // }
63 
65 
66  //
67  // assignment operators
68  //
69  // ProvenanceCheckerOutputModule const& ProvenanceCheckerOutputModule::operator=(ProvenanceCheckerOutputModule const& rhs)
70  // {
71  // //An exception safe implementation is
72  // ProvenanceCheckerOutputModule temp(rhs);
73  // swap(rhs);
74  //
75  // return *this;
76  // }
77 
78  namespace {
79  void markAncestors(EventForOutput const& e,
80  ProductProvenance const& iInfo,
81  std::map<BranchID, bool>& oMap,
82  std::set<BranchID>& oMapperMissing) {
83  for (BranchID const id : iInfo.parentage().parents()) {
84  //Don't look for parents if we've previously looked at the parents
85  if (oMap.find(id) == oMap.end()) {
86  //use side effect of calling operator[] which is if the item isn't there it will add it as 'false'
87  oMap[id];
88  ProductProvenance const* pInfo = e.getProvenance(id).productProvenance();
89  if (pInfo) {
90  markAncestors(e, *pInfo, oMap, oMapperMissing);
91  } else {
92  oMapperMissing.insert(id);
93  }
94  }
95  }
96  }
97  } // namespace
98 
100  //check ProductProvenance's parents to see if they are in the ProductProvenance list
101 
102  std::map<BranchID, bool> seenParentInPrincipal;
103  std::set<BranchID> missingFromMapper;
104  std::set<BranchID> missingProductProvenance;
105 
106  std::map<BranchID, const BranchDescription*> idToBranchDescriptions;
107  for (auto const& product : keptProducts()[InEvent]) {
108  BranchDescription const* branchDescription = product.first;
109  BranchID branchID = branchDescription->branchID();
110  idToBranchDescriptions[branchID] = branchDescription;
111  TypeID const& tid(branchDescription->unwrappedTypeID());
112  EDGetToken const& token = product.second;
113  BasicHandle bh = e.getByToken(token, tid);
114  bool cannotFindProductProvenance = false;
115  if (!(bh.provenance() and bh.provenance()->productProvenance())) {
116  missingProductProvenance.insert(branchID);
117  cannotFindProductProvenance = true;
118  }
119  ProductProvenance const* pInfo = e.getProvenance(branchID).productProvenance();
120  if (!pInfo) {
121  missingFromMapper.insert(branchID);
122  continue;
123  }
124  if (cannotFindProductProvenance) {
125  continue;
126  }
127  markAncestors(e, *(bh.provenance()->productProvenance()), seenParentInPrincipal, missingFromMapper);
128  seenParentInPrincipal[branchID] = true;
129  }
130 
131  //Determine what BranchIDs are in the product registry
133  ProductRegistry::ProductList const& prodList = reg->productList();
134  std::set<BranchID> branchesInReg;
135  for (auto const& product : prodList) {
136  branchesInReg.insert(product.second.branchID());
137  idToBranchDescriptions[product.second.branchID()] = &product.second;
138  }
139 
140  std::set<BranchID> missingFromReg;
141  for (auto const& item : seenParentInPrincipal) {
142  if (branchesInReg.find(item.first) == branchesInReg.end()) {
143  missingFromReg.insert(item.first);
144  }
145  }
146 
147  if (!missingFromMapper.empty()) {
148  LogError("ProvenanceChecker") << "Missing the following BranchIDs from ProductProvenanceRetriever\n";
149  for (std::set<BranchID>::iterator it = missingFromMapper.begin(), itEnd = missingFromMapper.end(); it != itEnd;
150  ++it) {
151  LogProblem("ProvenanceChecker") << *it << " " << *(idToBranchDescriptions[*it]);
152  }
153  }
154 
155  if (!missingProductProvenance.empty()) {
156  LogError("ProvenanceChecker") << "The ProductResolvers for the following BranchIDs have no ProductProvenance\n";
157  for (std::set<BranchID>::iterator it = missingProductProvenance.begin(), itEnd = missingProductProvenance.end();
158  it != itEnd;
159  ++it) {
160  LogProblem("ProvenanceChecker") << *it << " " << *(idToBranchDescriptions[*it]);
161  }
162  }
163 
164  if (!missingFromReg.empty()) {
165  LogError("ProvenanceChecker") << "Missing the following BranchIDs from ProductRegistry\n";
166  for (auto const& item : missingFromReg) {
167  LogProblem("ProvenanceChecker") << item << " " << *(idToBranchDescriptions[item]);
168  }
169  }
170 
171  if (!missingFromMapper.empty() || !missingProductProvenance.empty() || !missingFromReg.empty()) {
172  throw cms::Exception("ProvenanceError")
173  << (!missingFromMapper.empty() ? "Having missing ancestors from ProductProvenanceRetriever.\n" : "")
174  << (!missingProductProvenance.empty() ? " Have missing ProductProvenance's from ProductResolver in Event.\n"
175  : "")
176  << (!missingFromReg.empty() ? " Have missing info from ProductRegistry.\n" : "");
177  }
178  }
179 
180  //
181  // const member functions
182  //
183 
184  //
185  // static member functions
186  //
190  descriptions.add("provenanceChecker", desc);
191  }
192 } // namespace edm
ConfigurationDescriptions.h
edm::one::OutputModule
Definition: OutputModule.h:30
ConstProductRegistry.h
edm::Parentage::parents
std::vector< BranchID > const & parents() const
Definition: Parentage.h:44
SiPixelPI::one
Definition: SiPixelPayloadInspectorHelper.h:39
MessageLogger.h
edm::BasicHandle::provenance
Provenance const * provenance() const noexcept(true)
Definition: BasicHandle.h:75
OutputModule.h
edm::BasicHandle
Definition: BasicHandle.h:43
edm::ProvenanceCheckerOutputModule::ProvenanceCheckerOutputModule
ProvenanceCheckerOutputModule(ParameterSet const &pset)
Definition: ProvenanceCheckerOutputModule.cc:56
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Provenance::productProvenance
ProductProvenance const * productProvenance() const
Definition: Provenance.cc:24
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::ProvenanceCheckerOutputModule::~ProvenanceCheckerOutputModule
~ProvenanceCheckerOutputModule() override
Definition: ProvenanceCheckerOutputModule.cc:64
ProductRegistry.h
EventForOutput.h
edm::LuminosityBlockForOutput
Definition: LuminosityBlockForOutput.h:40
edm::RunForOutput
Definition: RunForOutput.h:40
MakerMacros.h
edm::ProductProvenance
Definition: ProductProvenance.h:24
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Service.h
edm::LogProblem
Log< level::Error, true > LogProblem
Definition: MessageLogger.h:131
edm::BranchID
Definition: BranchID.h:14
edm::ProvenanceCheckerOutputModule
Definition: ProvenanceCheckerOutputModule.cc:32
edm::ProvenanceCheckerOutputModule::writeLuminosityBlock
void writeLuminosityBlock(LuminosityBlockForOutput const &) override
Definition: ProvenanceCheckerOutputModule.cc:41
edm::BranchDescription::unwrappedTypeID
TypeID unwrappedTypeID() const
Definition: BranchDescription.h:98
edm::InEvent
Definition: BranchType.h:11
edm::one::OutputModuleBase::fillDescription
static void fillDescription(ParameterSetDescription &desc, std::vector< std::string > const &iDefaultOutputCommands=ProductSelectorRules::defaultSelectionStrings())
Definition: OutputModuleBase.cc:361
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
OutputModuleBase
edm::ProductRegistry::ProductList
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductRegistry.h:39
edm::ParameterSet
Definition: ParameterSet.h:47
ParameterSet
Definition: Functions.h:16
edm::one::OutputModuleBase::keptProducts
SelectedProductsForBranchType const & keptProducts() const
Definition: OutputModuleBase.h:97
edm::Service
Definition: Service.h:30
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
edm::EDGetToken
Definition: EDGetToken.h:35
edm::EventForOutput
Definition: EventForOutput.h:50
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::TypeID
Definition: TypeID.h:22
edm::ProvenanceCheckerOutputModule::fillDescriptions
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: ProvenanceCheckerOutputModule.cc:187
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Exception
Definition: hltDiff.cc:245
edm::ProductProvenance::parentage
Parentage const & parentage() const
Definition: ProductProvenance.cc:39
Exception.h
edm::BranchDescription
Definition: BranchDescription.h:32
edm::ProvenanceCheckerOutputModule::write
void write(EventForOutput const &e) override
Definition: ProvenanceCheckerOutputModule.cc:99
edm::BranchDescription::branchID
BranchID const & branchID() const
Definition: BranchDescription.h:74
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::ProvenanceCheckerOutputModule::writeRun
void writeRun(RunForOutput const &) override
Definition: ProvenanceCheckerOutputModule.cc:42
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316