CMS 3D CMS Logo

GetProductCheckerOutputModule.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Modules
4 // Class : GetProductCheckerOutputModule
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Wed Oct 7 14:41:26 CDT 2009
11 //
12 
13 // system include files
14 #include <string>
15 #include <sstream>
16 
17 // user include files
28 
29 namespace edm {
30  class ModuleCallingContext;
31  class ParameterSet;
32 
34  public:
35  // We do not take ownership of passed stream.
38  static void fillDescriptions(ConfigurationDescriptions& descriptions);
39 
40  private:
41  void write(EventForOutput const& e) override;
42  void writeLuminosityBlock(LuminosityBlockForOutput const&) override;
43  void writeRun(RunForOutput const&) override;
44  const std::vector<std::string> crosscheck_;
45  const bool verbose_;
46  };
47 
48  //
49  // constants, enums and typedefs
50  //
51 
52  //
53  // static data member definitions
54  //
55 
56  //
57  // constructors and destructor
58  //
60  : one::OutputModuleBase(iPSet),
61  one::OutputModule<>(iPSet),
62  crosscheck_(iPSet.getUntrackedParameter<std::vector<std::string>>("crosscheck")),
63  verbose_(iPSet.getUntrackedParameter<bool>("verbose")) {}
64 
65  // GetProductCheckerOutputModule::GetProductCheckerOutputModule(GetProductCheckerOutputModule const& rhs) {
66  // // do actual copying here;
67  // }
68 
70 
71  //
72  // assignment operators
73  //
74  // GetProductCheckerOutputModule const& GetProductCheckerOutputModule::operator=(GetProductCheckerOutputModule const& rhs) {
75  // //An exception safe implementation is
76  // GetProductCheckerOutputModule temp(rhs);
77  // swap(rhs);
78  //
79  // return *this;
80  // }
81 
82  //
83  // member functions
84  //
85  template <typename T>
86  static void check(T const& p, std::string const& id, SelectedProducts const& iProducts, bool iVerbose) {
87  for (auto const& product : iProducts) {
88  BranchDescription const* branchDescription = product.first;
89  TypeID const& tid = branchDescription->unwrappedTypeID();
90  EDGetToken const& token = product.second;
91  BasicHandle bh = p.getByToken(token, tid);
92  if (iVerbose) {
93  if (bh.isValid()) {
94  edm::LogInfo("FoundProduct") << "found " << branchDescription->moduleLabel() << " '"
95  << branchDescription->productInstanceName() << "' "
96  << branchDescription->processName();
97  } else {
98  edm::LogInfo("DidNotFindProduct")
99  << "did not find " << branchDescription->moduleLabel() << " '" << branchDescription->productInstanceName()
100  << "' " << branchDescription->processName();
101  }
102  }
103  if (nullptr != bh.provenance() &&
104  bh.provenance()->branchDescription().branchID() != branchDescription->branchID()) {
105  throw cms::Exception("BranchIDMissMatch")
106  << "While processing " << id << " getByToken request for " << branchDescription->moduleLabel() << " '"
107  << branchDescription->productInstanceName() << "' " << branchDescription->processName()
108  << "\n should have returned BranchID " << branchDescription->branchID() << " but returned BranchID "
109  << bh.provenance()->branchDescription().branchID() << "\n";
110  }
111  }
112  }
113  namespace {
114  std::string canonicalName(std::string const& iOriginal) {
115  if (iOriginal.empty()) {
116  return iOriginal;
117  }
118  if (iOriginal.back() == '.') {
119  return iOriginal.substr(0, iOriginal.size() - 1);
120  }
121  return iOriginal;
122  }
123  } // namespace
125  std::ostringstream str;
126  str << e.id();
127  check(e, str.str(), keptProducts()[InEvent], verbose_);
128  if (not crosscheck_.empty()) {
129  std::set<std::string> expectedProducts(crosscheck_.begin(), crosscheck_.end());
130  for (auto const& kp : keptProducts()[InEvent]) {
131  auto bn = canonicalName(kp.first->branchName());
132  auto found = expectedProducts.find(bn);
133  if (found == expectedProducts.end()) {
134  throw cms::Exception("CrosscheckFailed") << "unexpected kept product " << bn;
135  }
136  expectedProducts.erase(bn);
137  }
138  if (not expectedProducts.empty()) {
139  cms::Exception e("CrosscheckFailed");
140  e << "Did not find the expected products:\n";
141  for (auto const& p : expectedProducts) {
142  e << p << "\n";
143  }
144  throw e;
145  }
146  }
147  }
149  std::ostringstream str;
150  str << l.id();
151  check(l, str.str(), keptProducts()[InLumi], verbose_);
152  }
154  std::ostringstream str;
155  str << r.id();
156  check(r, str.str(), keptProducts()[InRun], verbose_);
157  }
158 
159  //
160  // const member functions
161  //
162 
163  //
164  // static member functions
165  //
166 
170  desc.addUntracked<std::vector<std::string>>("crosscheck", {})
171  ->setComment("Branch names that should be in the event. If empty no check done.");
172  desc.addUntracked<bool>("verbose", false);
173  descriptions.add("productChecker", desc);
174  }
175 } // namespace edm
176 
const std::vector< std::string > crosscheck_
BranchID const & branchID() const
TypeID unwrappedTypeID() const
std::string const & processName() const
std::vector< std::pair< BranchDescription const *, EDGetToken > > SelectedProducts
std::string const & productInstanceName() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BranchDescription const & branchDescription() const
Definition: Provenance.h:45
bool isValid() const noexcept(true)
Definition: BasicHandle.h:69
Log< level::Info, false > LogInfo
void writeRun(RunForOutput const &) override
SelectedProductsForBranchType const & keptProducts() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
static void check(T const &p, std::string const &id, SelectedProducts const &iProducts, bool iVerbose)
HLT enums.
void writeLuminosityBlock(LuminosityBlockForOutput const &) override
GetProductCheckerOutputModule(ParameterSet const &pset)
#define str(s)
long double T
Provenance const * provenance() const noexcept(true)
Definition: BasicHandle.h:75
static void fillDescription(ParameterSetDescription &desc, std::vector< std::string > const &iDefaultOutputCommands=ProductSelectorRules::defaultSelectionStrings())
std::string const & moduleLabel() const
void write(EventForOutput const &e) override