CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EventSetupCacheIdentifierChecker
00004 // Class:      EventSetupCacheIdentifierChecker
00005 // 
00013 //
00014 // Original Author:  Chris Jones
00015 //         Created:  Wed May 30 14:42:16 CDT 2012
00016 // $Id: EventSetupCacheIdentifierChecker.cc,v 1.1 2012/05/30 21:36:10 chrjones Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <map>
00024 #include <vector>
00025 
00026 // user include files
00027 #include "FWCore/Framework/interface/Frameworkfwd.h"
00028 #include "FWCore/Framework/interface/EDAnalyzer.h"
00029 
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 
00035 #include "FWCore/Framework/interface/EventSetup.h"
00036 #include "FWCore/Framework/interface/EventSetupRecord.h"
00037 #include "FWCore/Utilities/interface/Exception.h"
00038 
00039 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00040 //
00041 // class declaration
00042 //
00043 
00044 namespace edm {
00045   class EventSetupCacheIdentifierChecker : public edm::EDAnalyzer {
00046    public:
00047     explicit EventSetupCacheIdentifierChecker(const edm::ParameterSet&);
00048     ~EventSetupCacheIdentifierChecker();
00049 
00050     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00051 
00052 
00053    private:
00054     //virtual void beginJob() ;
00055     virtual void analyze(const edm::Event&, const edm::EventSetup&);
00056     //virtual void endJob() ;
00057 
00058     virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00059     //virtual void endRun(edm::Run const&, edm::EventSetup const&);
00060     virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00061     //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00062 
00063     void check(edm::EventSetup const&);
00064     void initialize();
00065       // ----------member data ---------------------------
00066     ParameterSet m_pset;
00067     std::map<eventsetup::EventSetupRecordKey,std::vector<unsigned int> > m_recordKeysToExpectedCacheIdentifiers;
00068     unsigned int m_index;
00069   };
00070 }
00071 //
00072 // constants, enums and typedefs
00073 //
00074 using namespace edm;
00075 
00076 //
00077 // static data member definitions
00078 //
00079 
00080 //
00081 // constructors and destructor
00082 //
00083 EventSetupCacheIdentifierChecker::EventSetupCacheIdentifierChecker(const edm::ParameterSet& iConfig):
00084 m_pset(iConfig),
00085 m_index(0)
00086 {
00087    //now do what ever initialization is needed
00088 
00089 }
00090 
00091 
00092 EventSetupCacheIdentifierChecker::~EventSetupCacheIdentifierChecker()
00093 {
00094  
00095    // do anything here that needs to be done at desctruction time
00096    // (e.g. close files, deallocate resources etc.)
00097 
00098 }
00099 
00100 
00101 //
00102 // member functions
00103 //
00104 
00105 // ------------ method called for each event  ------------
00106 void
00107 EventSetupCacheIdentifierChecker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00108 {
00109   check(iSetup);
00110 }
00111 
00112 
00113 // ------------ method called once each job just before starting event loop  ------------
00114 //void 
00115 //EventSetupCacheIdentifierChecker::beginJob()
00116 //{
00117 //}
00118 
00119 // ------------ method called once each job just after ending the event loop  ------------
00120 //void 
00121 //EventSetupCacheIdentifierChecker::endJob() 
00122 //{
00123 //}
00124 
00125 // ------------ method called when starting to processes a run  ------------
00126 void 
00127 EventSetupCacheIdentifierChecker::beginRun(edm::Run const&, edm::EventSetup const& iSetup)
00128 {
00129   check(iSetup);
00130 }
00131 
00132 // ------------ method called when ending the processing of a run  ------------
00133 //void 
00134 //EventSetupCacheIdentifierChecker::endRun(edm::Run const&, edm::EventSetup const&)
00135 //{
00136 //}
00137 
00138 // ------------ method called when starting to processes a luminosity block  ------------
00139 void 
00140 EventSetupCacheIdentifierChecker::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const& iSetup)
00141 {
00142   check(iSetup);
00143 }
00144 
00145 // ------------ method called when ending the processing of a luminosity block  ------------
00146 //void 
00147 //EventSetupCacheIdentifierChecker::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00148 //{
00149 //}
00150 
00151 void
00152 EventSetupCacheIdentifierChecker::check(edm::EventSetup const& iSetup)
00153 {
00154   if(0==m_recordKeysToExpectedCacheIdentifiers.size()) {
00155     initialize();
00156   }
00157   using namespace edm::eventsetup;
00158 
00159   
00160   for(auto it = m_recordKeysToExpectedCacheIdentifiers.begin(), itEnd = m_recordKeysToExpectedCacheIdentifiers.end();
00161       it != itEnd;
00162       ++it) {
00163     EventSetupRecord const* pRecord = iSetup.find(it->first);
00164     if(0 == pRecord) {
00165       edm::LogWarning("RecordNotInIOV") <<"The EventSetup Record '"<<it->first.name()<<"' is not available for this IOV.";
00166     }
00167     if(it->second.size() <= m_index) {
00168       throw cms::Exception("TooFewCacheIDs")<<"The vector of cacheIdentifiers for the record "<<it->first.name()<<" is too short";
00169     }
00170     if(0 != pRecord && pRecord->cacheIdentifier() != it->second[m_index]) {
00171       throw cms::Exception("IncorrectCacheID")<<"The Record "<<it->first.name()<<" was supposed to have cacheIdentifier: "<<it->second[m_index]<<" but instead has "<<pRecord->cacheIdentifier();
00172     }
00173   }
00174   ++m_index;
00175 }
00176 
00177 void
00178 EventSetupCacheIdentifierChecker::initialize()
00179 {
00180   std::vector<std::string> recordNames{m_pset.getParameterNamesForType<std::vector<unsigned int> >(false)};
00181 
00182   for(auto const& name: recordNames) {
00183     eventsetup::EventSetupRecordKey recordKey(eventsetup::EventSetupRecordKey::TypeTag::findType(name));
00184     if(recordKey.type() == eventsetup::EventSetupRecordKey::TypeTag()) {
00185       //record not found
00186       edm::LogWarning("DataGetter") <<"Record \""<< name <<"\" does not exist "<<std::endl;
00187       
00188       continue;
00189     }
00190     
00191     m_recordKeysToExpectedCacheIdentifiers.insert(std::make_pair(recordKey, m_pset.getUntrackedParameter<std::vector<unsigned int> >(name)));
00192   }
00193 }
00194 
00195 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00196 void
00197 EventSetupCacheIdentifierChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00198   //The following says we do not know what parameters are allowed so do no validation
00199   // Please change this to state exactly what you do use, even if it is no parameters
00200   edm::ParameterSetDescription desc;
00201   desc.addWildcardUntracked<std::vector<unsigned int> >("*")->setComment("The label is the name of an EventSetup Record while the vector contains the expected cacheIdentifier values for each beginRun, beginLuminosityBlock and event transition");
00202   descriptions.addDefault(desc);
00203 }
00204 
00205 //define this as a plug-in
00206 DEFINE_FWK_MODULE(EventSetupCacheIdentifierChecker);