Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-10 02:51:02

0001 // -*- C++ -*-
0002 //
0003 // Package:     Modules
0004 // Class  :     GetProductCheckerOutputModule
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Wed Oct  7 14:41:26 CDT 2009
0011 //
0012 
0013 // system include files
0014 #include <string>
0015 #include <sstream>
0016 
0017 // user include files
0018 #include "FWCore/Framework/interface/one/OutputModule.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/Framework/interface/EventForOutput.h"
0021 #include "FWCore/Framework/interface/LuminosityBlockForOutput.h"
0022 #include "FWCore/Framework/interface/RunForOutput.h"
0023 #include "FWCore/Utilities/interface/Exception.h"
0024 #include "FWCore/Utilities/interface/ProductKindOfType.h"
0025 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 
0029 namespace edm {
0030   class ModuleCallingContext;
0031   class ParameterSet;
0032 
0033   class GetProductCheckerOutputModule : public one::OutputModule<> {
0034   public:
0035     // We do not take ownership of passed stream.
0036     explicit GetProductCheckerOutputModule(ParameterSet const& pset);
0037     ~GetProductCheckerOutputModule() override;
0038     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0039 
0040   private:
0041     void write(EventForOutput const& e) override;
0042     void writeLuminosityBlock(LuminosityBlockForOutput const&) override;
0043     void writeRun(RunForOutput const&) override;
0044     const bool verbose_;
0045   };
0046 
0047   //
0048   // constants, enums and typedefs
0049   //
0050 
0051   //
0052   // static data member definitions
0053   //
0054 
0055   //
0056   // constructors and destructor
0057   //
0058   GetProductCheckerOutputModule::GetProductCheckerOutputModule(ParameterSet const& iPSet)
0059       : one::OutputModuleBase(iPSet),
0060         one::OutputModule<>(iPSet),
0061         verbose_(iPSet.getUntrackedParameter<bool>("verbose")) {}
0062 
0063   // GetProductCheckerOutputModule::GetProductCheckerOutputModule(GetProductCheckerOutputModule const& rhs) {
0064   //    // do actual copying here;
0065   // }
0066 
0067   GetProductCheckerOutputModule::~GetProductCheckerOutputModule() {}
0068 
0069   //
0070   // assignment operators
0071   //
0072   // GetProductCheckerOutputModule const& GetProductCheckerOutputModule::operator=(GetProductCheckerOutputModule const& rhs) {
0073   //   //An exception safe implementation is
0074   //   GetProductCheckerOutputModule temp(rhs);
0075   //   swap(rhs);
0076   //
0077   //   return *this;
0078   // }
0079 
0080   //
0081   // member functions
0082   //
0083   template <typename T>
0084   static void check(T const& p, std::string const& id, SelectedProducts const& iProducts, bool iVerbose) {
0085     for (auto const& product : iProducts) {
0086       BranchDescription const* branchDescription = product.first;
0087       TypeID const& tid = branchDescription->unwrappedTypeID();
0088       EDGetToken const& token = product.second;
0089       BasicHandle bh = p.getByToken(token, tid);
0090       if (iVerbose) {
0091         if (bh.isValid()) {
0092           edm::LogInfo("FoundProduct") << "found " << branchDescription->moduleLabel() << " '"
0093                                        << branchDescription->productInstanceName() << "' "
0094                                        << branchDescription->processName();
0095         } else {
0096           edm::LogInfo("DidNotFindProduct")
0097               << "did not find " << branchDescription->moduleLabel() << " '" << branchDescription->productInstanceName()
0098               << "' " << branchDescription->processName();
0099         }
0100       }
0101       if (nullptr != bh.provenance() &&
0102           bh.provenance()->branchDescription().branchID() != branchDescription->branchID()) {
0103         throw cms::Exception("BranchIDMissMatch")
0104             << "While processing " << id << " getByToken request for " << branchDescription->moduleLabel() << " '"
0105             << branchDescription->productInstanceName() << "' " << branchDescription->processName()
0106             << "\n should have returned BranchID " << branchDescription->branchID() << " but returned BranchID "
0107             << bh.provenance()->branchDescription().branchID() << "\n";
0108       }
0109     }
0110   }
0111   void GetProductCheckerOutputModule::write(EventForOutput const& e) {
0112     std::ostringstream str;
0113     str << e.id();
0114     check(e, str.str(), keptProducts()[InEvent], verbose_);
0115   }
0116   void GetProductCheckerOutputModule::writeLuminosityBlock(LuminosityBlockForOutput const& l) {
0117     std::ostringstream str;
0118     str << l.id();
0119     check(l, str.str(), keptProducts()[InLumi], verbose_);
0120   }
0121   void GetProductCheckerOutputModule::writeRun(RunForOutput const& r) {
0122     std::ostringstream str;
0123     str << r.id();
0124     check(r, str.str(), keptProducts()[InRun], verbose_);
0125   }
0126 
0127   //
0128   // const member functions
0129   //
0130 
0131   //
0132   // static member functions
0133   //
0134 
0135   void GetProductCheckerOutputModule::fillDescriptions(ConfigurationDescriptions& descriptions) {
0136     ParameterSetDescription desc;
0137     one::OutputModule<>::fillDescription(desc);
0138     desc.addUntracked<bool>("verbose", false);
0139     descriptions.add("productChecker", desc);
0140   }
0141 }  // namespace edm
0142 
0143 using edm::GetProductCheckerOutputModule;
0144 DEFINE_FWK_MODULE(GetProductCheckerOutputModule);