Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023 #include <map>
00024 #include <vector>
00025
00026
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
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
00055 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00056
00057
00058 virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00059
00060 virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00061
00062
00063 void check(edm::EventSetup const&);
00064 void initialize();
00065
00066 ParameterSet m_pset;
00067 std::map<eventsetup::EventSetupRecordKey,std::vector<unsigned int> > m_recordKeysToExpectedCacheIdentifiers;
00068 unsigned int m_index;
00069 };
00070 }
00071
00072
00073
00074 using namespace edm;
00075
00076
00077
00078
00079
00080
00081
00082
00083 EventSetupCacheIdentifierChecker::EventSetupCacheIdentifierChecker(const edm::ParameterSet& iConfig):
00084 m_pset(iConfig),
00085 m_index(0)
00086 {
00087
00088
00089 }
00090
00091
00092 EventSetupCacheIdentifierChecker::~EventSetupCacheIdentifierChecker()
00093 {
00094
00095
00096
00097
00098 }
00099
00100
00101
00102
00103
00104
00105
00106 void
00107 EventSetupCacheIdentifierChecker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00108 {
00109 check(iSetup);
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 void
00127 EventSetupCacheIdentifierChecker::beginRun(edm::Run const&, edm::EventSetup const& iSetup)
00128 {
00129 check(iSetup);
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139 void
00140 EventSetupCacheIdentifierChecker::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const& iSetup)
00141 {
00142 check(iSetup);
00143 }
00144
00145
00146
00147
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
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
00196 void
00197 EventSetupCacheIdentifierChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00198
00199
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
00206 DEFINE_FWK_MODULE(EventSetupCacheIdentifierChecker);