File indexing completed on 2024-04-06 12:12:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <iostream>
0015 #include <map>
0016 #include <memory>
0017
0018
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/Framework/interface/EventSetupRecord.h"
0022 #include "FWCore/Framework/interface/ComponentDescription.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0026 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0027 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0028 #include "FWCore/Framework/interface/DataKey.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030
0031 namespace edm {
0032 class PrintEventSetupDataRetrieval
0033 : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0034 public:
0035 PrintEventSetupDataRetrieval(edm::ParameterSet const&);
0036
0037 void analyze(edm::Event const&, edm::EventSetup const&) override;
0038
0039 void beginRun(edm::Run const&, edm::EventSetup const&) override;
0040 void endRun(edm::Run const&, edm::EventSetup const&) override;
0041
0042 void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0043 void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0044
0045 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0046
0047 private:
0048 void check(EventSetup const&);
0049
0050 typedef std::map<eventsetup::EventSetupRecordKey,
0051 std::pair<unsigned long long, std::map<eventsetup::DataKey, bool> > >
0052 RetrievedDataMap;
0053
0054 RetrievedDataMap m_retrievedDataMap;
0055 std::vector<eventsetup::EventSetupRecordKey> m_recordKeys;
0056 const bool m_printProviders;
0057 const bool m_checkDuringBeginRun;
0058 const bool m_checkDuringBeginLumi;
0059 const bool m_checkDuringEvent;
0060 };
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 PrintEventSetupDataRetrieval::PrintEventSetupDataRetrieval(const ParameterSet& iPS)
0073 : m_printProviders(iPS.getUntrackedParameter<bool>("printProviders")),
0074 m_checkDuringBeginRun(iPS.getUntrackedParameter<bool>("checkDuringBeginRun")),
0075 m_checkDuringBeginLumi(iPS.getUntrackedParameter<bool>("checkDuringBeginLumi")),
0076 m_checkDuringEvent(iPS.getUntrackedParameter<bool>("checkDuringEvent")) {}
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 void PrintEventSetupDataRetrieval::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0088 edm::ParameterSetDescription desc;
0089 desc.addUntracked<bool>("printProviders", false)
0090 ->setComment("If 'true' also print which ES module provides the data");
0091 desc.addUntracked<bool>("checkDuringBeginRun", false)
0092 ->setComment("If 'true' check for retrieved data during each begin run is processed");
0093 desc.addUntracked<bool>("checkDuringBeginLumi", false)
0094 ->setComment("If 'true' check for retrieved data during each begin lumi is processed");
0095 desc.addUntracked<bool>("checkDuringEvent", true)
0096 ->setComment("If 'true' check for retrieved data during an event is processed");
0097 descriptions.add("PrintEventSetupDataRetrieval", desc);
0098 descriptions.setComment("This analyzer reports when EventSetup data is retrieved by a module in the job.");
0099 }
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 void PrintEventSetupDataRetrieval::analyze(Event const&, EventSetup const& iES) {
0117 if (m_checkDuringEvent) {
0118 check(iES);
0119 }
0120 }
0121
0122 void PrintEventSetupDataRetrieval::beginRun(Run const&, EventSetup const& iES) {
0123 if (m_checkDuringBeginRun) {
0124 check(iES);
0125 }
0126 }
0127
0128 void PrintEventSetupDataRetrieval::endRun(Run const&, EventSetup const&) {}
0129
0130 void PrintEventSetupDataRetrieval::beginLuminosityBlock(LuminosityBlock const&, EventSetup const& iES) {
0131 if (m_checkDuringBeginLumi) {
0132 check(iES);
0133 }
0134 }
0135
0136 void PrintEventSetupDataRetrieval::endLuminosityBlock(LuminosityBlock const&, EventSetup const&) {}
0137
0138 void PrintEventSetupDataRetrieval::check(EventSetup const& iES) {
0139
0140 m_recordKeys.clear();
0141 iES.fillAvailableRecordKeys(m_recordKeys);
0142
0143 std::unique_ptr<LogSystem> msg;
0144 for (std::vector<eventsetup::EventSetupRecordKey>::const_iterator it = m_recordKeys.begin(),
0145 itEnd = m_recordKeys.end();
0146 it != itEnd;
0147 ++it) {
0148
0149 auto r = iES.find(*it);
0150 assert(r);
0151
0152 RetrievedDataMap::iterator itRetrievedData = m_retrievedDataMap.find(*it);
0153 if (itRetrievedData == m_retrievedDataMap.end()) {
0154 itRetrievedData =
0155 m_retrievedDataMap
0156 .insert(std::make_pair(*it, std::pair<unsigned long long, std::map<eventsetup::DataKey, bool> >()))
0157 .first;
0158 itRetrievedData->second.first = r->cacheIdentifier();
0159 std::vector<eventsetup::DataKey> keys;
0160 r->fillRegisteredDataKeys(keys);
0161 for (std::vector<eventsetup::DataKey>::const_iterator itData = keys.begin(), itDataEnd = keys.end();
0162 itData != itDataEnd;
0163 ++itData) {
0164 itRetrievedData->second.second.insert(std::make_pair(*itData, false));
0165 }
0166 }
0167 RetrievedDataMap::value_type& retrievedData = *itRetrievedData;
0168 if (itRetrievedData->second.first != r->cacheIdentifier()) {
0169 itRetrievedData->second.first = r->cacheIdentifier();
0170 for (std::map<eventsetup::DataKey, bool>::iterator itDatum = retrievedData.second.second.begin(),
0171 itDatumEnd = retrievedData.second.second.end();
0172 itDatum != itDatumEnd;
0173 ++itDatum) {
0174 itDatum->second = false;
0175 }
0176 }
0177
0178 for (std::map<eventsetup::DataKey, bool>::iterator itDatum = retrievedData.second.second.begin(),
0179 itDatumEnd = retrievedData.second.second.end();
0180 itDatum != itDatumEnd;
0181 ++itDatum) {
0182 bool wasGotten = r->wasGotten(itDatum->first);
0183 if (wasGotten != itDatum->second) {
0184 if (not msg)
0185 msg = std::make_unique<LogSystem>("ESContent");
0186 else
0187 *msg << "\n";
0188 itDatum->second = wasGotten;
0189 *msg << "Retrieved> record:" << it->name() << " data:" << itDatum->first.type().name() << " '"
0190 << itDatum->first.name().value() << "'";
0191 if (m_printProviders) {
0192 const edm::eventsetup::ComponentDescription* d = r->providerDescription(itDatum->first);
0193 assert(nullptr != d);
0194 *msg << " provider:" << d->type_ << " '" << d->label_ << "'";
0195 }
0196 }
0197 }
0198 }
0199 }
0200
0201
0202
0203
0204
0205
0206
0207
0208 }
0209
0210
0211 using edm::PrintEventSetupDataRetrieval;
0212 DEFINE_FWK_MODULE(PrintEventSetupDataRetrieval);