CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/FWCore/Modules/src/GetProductCheckerOutputModule.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Modules
00004 // Class  :     GetProductCheckerOutputModule
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  
00010 //         Created:  Wed Oct  7 14:41:26 CDT 2009
00011 //
00012 
00013 // system include files
00014 #include <string>
00015 #include <sstream>
00016 
00017 // user include files
00018 #include "DataFormats/Common/interface/OutputHandle.h"
00019 #include "FWCore/Framework/interface/OutputModule.h"
00020 #include "FWCore/Framework/interface/MakerMacros.h"
00021 #include "FWCore/Framework/interface/EventPrincipal.h"
00022 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
00023 #include "FWCore/Framework/interface/RunPrincipal.h"
00024 #include "FWCore/Utilities/interface/Exception.h"
00025 #include "FWCore/Utilities/interface/ProductKindOfType.h"
00026 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00027 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00028 
00029 namespace edm {
00030    class ParameterSet;
00031    class GetProductCheckerOutputModule : public OutputModule {
00032    public:
00033       // We do not take ownership of passed stream.
00034       explicit GetProductCheckerOutputModule(ParameterSet const& pset);
00035       virtual ~GetProductCheckerOutputModule();
00036       static void fillDescriptions(ConfigurationDescriptions& descriptions);
00037 
00038    private:
00039       virtual void write(EventPrincipal const& e);
00040       virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&);
00041       virtual void writeRun(RunPrincipal const&);
00042    };
00043 
00044 //
00045 // constants, enums and typedefs
00046 //
00047 
00048 //
00049 // static data member definitions
00050 //
00051 
00052 //
00053 // constructors and destructor
00054 //
00055    GetProductCheckerOutputModule::GetProductCheckerOutputModule(ParameterSet const& iPSet):
00056    OutputModule(iPSet) { 
00057    } 
00058 
00059 // GetProductCheckerOutputModule::GetProductCheckerOutputModule(GetProductCheckerOutputModule const& rhs) {
00060 //    // do actual copying here;
00061 // }
00062 
00063    GetProductCheckerOutputModule::~GetProductCheckerOutputModule() {
00064    }
00065 
00066 //
00067 // assignment operators
00068 //
00069 // GetProductCheckerOutputModule const& GetProductCheckerOutputModule::operator=(GetProductCheckerOutputModule const& rhs) {
00070 //   //An exception safe implementation is
00071 //   GetProductCheckerOutputModule temp(rhs);
00072 //   swap(rhs);
00073 //
00074 //   return *this;
00075 // }
00076 
00077 //
00078 // member functions
00079 //
00080    static void check(Principal const& p, std::string const& id) {
00081       for(Principal::const_iterator it = p.begin(), itEnd = p.end();
00082           it != itEnd;
00083           ++it) {
00084          if(*it) {
00085            if (!(*it)->singleProduct()) continue;
00086 
00087             BranchID branchID = (*it)->branchDescription().branchID();
00088             OutputHandle const oh = p.getForOutput(branchID, false);
00089             
00090             if(0 != oh.desc() && oh.desc()->branchID() != branchID) {
00091                throw cms::Exception("BranchIDMissMatch") << "While processing " << id << " request for BranchID " << branchID << " returned BranchID " << oh.desc()->branchID() << "\n";
00092             }
00093             
00094             TypeID const& tid((*it)->branchDescription().unwrappedTypeID());
00095             BasicHandle bh = p.getByLabel(PRODUCT_TYPE, tid,
00096             (*it)->branchDescription().moduleLabel(),
00097             (*it)->branchDescription().productInstanceName(),
00098             (*it)->branchDescription().processName());
00099             
00100             /*This doesn't appear to be an error, it just means the Product isn't available, which can be legitimate
00101             if(!bh.product()) {
00102                throw cms::Exception("GetByLabelFailure") << "While processing " << id << " getByLabel request for " << (*it)->productDescription().moduleLabel()
00103                   << " '" << (*it)->productDescription().productInstanceName() << "' " << (*it)->productDescription().processName() << " failed\n.";
00104             }*/
00105             if(0 != bh.provenance() && bh.provenance()->branchDescription().branchID() != branchID) {
00106                throw cms::Exception("BranchIDMissMatch") << "While processing " << id << " getByLabel request for " << (*it)->branchDescription().moduleLabel()
00107                   << " '" << (*it)->branchDescription().productInstanceName() << "' " << (*it)->branchDescription().processName()
00108                   << "\n should have returned BranchID " << branchID << " but returned BranchID " << bh.provenance()->branchDescription().branchID() << "\n";
00109             }
00110          }
00111       }
00112    }
00113    void GetProductCheckerOutputModule::write(EventPrincipal const& e) {
00114       std::ostringstream str;
00115       str << e.id();
00116       check(e, str.str());
00117    }
00118    void GetProductCheckerOutputModule::writeLuminosityBlock(LuminosityBlockPrincipal const& l) {
00119       std::ostringstream str;
00120       str << l.id();
00121       check(l, str.str());
00122    }
00123    void GetProductCheckerOutputModule::writeRun(RunPrincipal const& r) {
00124       std::ostringstream str;
00125       str << r.id();
00126       check(r, str.str());
00127    }
00128 
00129 //
00130 // const member functions
00131 //
00132 
00133 //
00134 // static member functions
00135 //
00136 
00137   void
00138   GetProductCheckerOutputModule::fillDescriptions(ConfigurationDescriptions& descriptions) {
00139     ParameterSetDescription desc;
00140     OutputModule::fillDescription(desc);
00141     descriptions.add("productChecker", desc);
00142   }
00143 }
00144 
00145 using edm::GetProductCheckerOutputModule;
00146 DEFINE_FWK_MODULE(GetProductCheckerOutputModule);