File indexing completed on 2024-04-06 12:12:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <map>
0022 #include <vector>
0023
0024
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
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
0053 void analyze(const edm::Event&, const edm::EventSetup&) override;
0054
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
0064 ParameterSet m_pset;
0065 std::map<eventsetup::EventSetupRecordKey, std::vector<unsigned int> > m_recordKeysToExpectedCacheIdentifiers;
0066 unsigned int m_index;
0067 };
0068 }
0069
0070
0071
0072 using namespace edm;
0073
0074
0075
0076
0077
0078
0079
0080
0081 EventSetupCacheIdentifierChecker::EventSetupCacheIdentifierChecker(const edm::ParameterSet& iConfig)
0082 : m_pset(iConfig), m_index(0) {
0083
0084 }
0085
0086 EventSetupCacheIdentifierChecker::~EventSetupCacheIdentifierChecker() {
0087
0088
0089 }
0090
0091
0092
0093
0094
0095
0096 void EventSetupCacheIdentifierChecker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0097 check(iSetup);
0098 }
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113 void EventSetupCacheIdentifierChecker::beginRun(edm::Run const&, edm::EventSetup const& iSetup) { check(iSetup); }
0114
0115
0116
0117
0118
0119
0120
0121
0122 void EventSetupCacheIdentifierChecker::beginLuminosityBlock(edm::LuminosityBlock const&,
0123 edm::EventSetup const& iSetup) {
0124 check(iSetup);
0125 }
0126
0127
0128
0129
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
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
0178 void EventSetupCacheIdentifierChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0179
0180
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
0189 DEFINE_FWK_MODULE(EventSetupCacheIdentifierChecker);