Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-08 02:27:21

0001 // -*- C++ -*-
0002 //
0003 // Package:    EventSetupCacheIdentifierChecker
0004 // Class:      EventSetupCacheIdentifierChecker
0005 //
0006 /**\class EventSetupCacheIdentifierChecker EventSetupCacheIdentifierChecker.cc FWCore/Modules/src/EventSetupCacheIdentifierChecker.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Chris Jones
0015 //         Created:  Wed May 30 14:42:16 CDT 2012
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <map>
0022 #include <vector>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 
0033 #include "FWCore/Framework/interface/EventSetup.h"
0034 #include "FWCore/Framework/interface/EventSetupRecord.h"
0035 #include "FWCore/Utilities/interface/Exception.h"
0036 
0037 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0038 //
0039 // class declaration
0040 //
0041 
0042 namespace edm {
0043   class EventSetupCacheIdentifierChecker
0044       : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0045   public:
0046     explicit EventSetupCacheIdentifierChecker(const edm::ParameterSet&);
0047     ~EventSetupCacheIdentifierChecker() override;
0048 
0049     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050 
0051   private:
0052     //virtual void beginJob() ;
0053     void analyze(const edm::Event&, const edm::EventSetup&) override;
0054     //virtual void endJob() ;
0055 
0056     void beginRun(edm::Run const&, edm::EventSetup const&) override;
0057     void endRun(edm::Run const&, edm::EventSetup const&) override {}
0058     void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0059     void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
0060 
0061     void check(edm::EventSetup const&);
0062     void initialize();
0063     // ----------member data ---------------------------
0064     ParameterSet m_pset;
0065     std::map<eventsetup::EventSetupRecordKey, std::vector<unsigned int> > m_recordKeysToExpectedCacheIdentifiers;
0066     unsigned int m_index;
0067   };
0068 }  // namespace edm
0069 //
0070 // constants, enums and typedefs
0071 //
0072 using namespace edm;
0073 
0074 //
0075 // static data member definitions
0076 //
0077 
0078 //
0079 // constructors and destructor
0080 //
0081 EventSetupCacheIdentifierChecker::EventSetupCacheIdentifierChecker(const edm::ParameterSet& iConfig)
0082     : m_pset(iConfig), m_index(0) {
0083   //now do what ever initialization is needed
0084 }
0085 
0086 EventSetupCacheIdentifierChecker::~EventSetupCacheIdentifierChecker() {
0087   // do anything here that needs to be done at desctruction time
0088   // (e.g. close files, deallocate resources etc.)
0089 }
0090 
0091 //
0092 // member functions
0093 //
0094 
0095 // ------------ method called for each event  ------------
0096 void EventSetupCacheIdentifierChecker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0097   check(iSetup);
0098 }
0099 
0100 // ------------ method called once each job just before starting event loop  ------------
0101 //void
0102 //EventSetupCacheIdentifierChecker::beginJob()
0103 //{
0104 //}
0105 
0106 // ------------ method called once each job just after ending the event loop  ------------
0107 //void
0108 //EventSetupCacheIdentifierChecker::endJob()
0109 //{
0110 //}
0111 
0112 // ------------ method called when starting to processes a run  ------------
0113 void EventSetupCacheIdentifierChecker::beginRun(edm::Run const&, edm::EventSetup const& iSetup) { check(iSetup); }
0114 
0115 // ------------ method called when ending the processing of a run  ------------
0116 //void
0117 //EventSetupCacheIdentifierChecker::endRun(edm::Run const&, edm::EventSetup const&)
0118 //{
0119 //}
0120 
0121 // ------------ method called when starting to processes a luminosity block  ------------
0122 void EventSetupCacheIdentifierChecker::beginLuminosityBlock(edm::LuminosityBlock const&,
0123                                                             edm::EventSetup const& iSetup) {
0124   check(iSetup);
0125 }
0126 
0127 // ------------ method called when ending the processing of a luminosity block  ------------
0128 //void
0129 //EventSetupCacheIdentifierChecker::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0130 //{
0131 //}
0132 
0133 void EventSetupCacheIdentifierChecker::check(edm::EventSetup const& iSetup) {
0134   if (m_recordKeysToExpectedCacheIdentifiers.empty()) {
0135     initialize();
0136   }
0137   using namespace edm::eventsetup;
0138 
0139   for (auto it = m_recordKeysToExpectedCacheIdentifiers.begin(), itEnd = m_recordKeysToExpectedCacheIdentifiers.end();
0140        it != itEnd;
0141        ++it) {
0142     auto pRecord = iSetup.find(it->first);
0143     if (not pRecord) {
0144       edm::LogWarning("RecordNotInIOV") << "The EventSetup Record '" << it->first.name()
0145                                         << "' is not available for this IOV.";
0146     }
0147     if (it->second.size() <= m_index) {
0148       throw cms::Exception("TooFewCacheIDs")
0149           << "The vector of cacheIdentifiers for the record " << it->first.name() << " is too short";
0150     }
0151     if (pRecord && pRecord->cacheIdentifier() != it->second[m_index]) {
0152       throw cms::Exception("IncorrectCacheID")
0153           << "The Record " << it->first.name() << " was supposed to have cacheIdentifier: " << it->second[m_index]
0154           << " but instead has " << pRecord->cacheIdentifier();
0155     }
0156   }
0157   ++m_index;
0158 }
0159 
0160 void EventSetupCacheIdentifierChecker::initialize() {
0161   std::vector<std::string> recordNames{m_pset.getParameterNamesForType<std::vector<unsigned int> >(false)};
0162 
0163   for (auto const& name : recordNames) {
0164     eventsetup::EventSetupRecordKey recordKey(eventsetup::EventSetupRecordKey::TypeTag::findType(name));
0165     if (recordKey.type() == eventsetup::EventSetupRecordKey::TypeTag()) {
0166       //record not found
0167       edm::LogWarning("DataGetter") << "Record \"" << name << "\" does not exist " << std::endl;
0168 
0169       continue;
0170     }
0171 
0172     m_recordKeysToExpectedCacheIdentifiers.insert(
0173         std::make_pair(recordKey, m_pset.getUntrackedParameter<std::vector<unsigned int> >(name)));
0174   }
0175 }
0176 
0177 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0178 void EventSetupCacheIdentifierChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0179   //The following says we do not know what parameters are allowed so do no validation
0180   // Please change this to state exactly what you do use, even if it is no parameters
0181   edm::ParameterSetDescription desc;
0182   desc.addWildcardUntracked<std::vector<unsigned int> >("*")->setComment(
0183       "The label is the name of an EventSetup Record while the vector contains the expected cacheIdentifier values for "
0184       "each beginRun, beginLuminosityBlock and event transition");
0185   descriptions.addDefault(desc);
0186 }
0187 
0188 //define this as a plug-in
0189 DEFINE_FWK_MODULE(EventSetupCacheIdentifierChecker);