CMS 3D CMS Logo

PrintEventSetupDataRetrieval.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Services
4 // Class : PrintEventSetupDataRetrieval
5 //
6 // Implementation:
7 // A service which prints which data from the EventSetup have been retrieved since the last time it checked
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Jul 9 14:30:13 CDT 2009
11 //
12 
13 // system include files
14 #include <iostream>
15 #include <map>
16 #include <memory>
17 
18 // user include files
30 
31 namespace edm {
33  : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
34  public:
36 
37  void analyze(edm::Event const&, edm::EventSetup const&) override;
38 
39  void beginRun(edm::Run const&, edm::EventSetup const&) override;
40  void endRun(edm::Run const&, edm::EventSetup const&) override;
41 
42  void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
43  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47  private:
48  void check(EventSetup const&);
49  // ---------- member data --------------------------------
51  std::pair<unsigned long long, std::map<eventsetup::DataKey, bool> > >
53 
55  std::vector<eventsetup::EventSetupRecordKey> m_recordKeys;
56  const bool m_printProviders;
59  const bool m_checkDuringEvent;
60  };
61  //
62  // constants, enums and typedefs
63  //
64 
65  //
66  // static data member definitions
67  //
68 
69  //
70  // constructors and destructor
71  //
73  : m_printProviders(iPS.getUntrackedParameter<bool>("printProviders")),
74  m_checkDuringBeginRun(iPS.getUntrackedParameter<bool>("checkDuringBeginRun")),
75  m_checkDuringBeginLumi(iPS.getUntrackedParameter<bool>("checkDuringBeginLumi")),
76  m_checkDuringEvent(iPS.getUntrackedParameter<bool>("checkDuringEvent")) {}
77 
78  // PrintEventSetupDataRetrieval::PrintEventSetupDataRetrieval(const PrintEventSetupDataRetrieval& rhs)
79  // {
80  // // do actual copying here;
81  // }
82 
83  //PrintEventSetupDataRetrieval::~PrintEventSetupDataRetrieval()
84  //{
85  //}
86 
89  desc.addUntracked<bool>("printProviders", false)
90  ->setComment("If 'true' also print which ES module provides the data");
91  desc.addUntracked<bool>("checkDuringBeginRun", false)
92  ->setComment("If 'true' check for retrieved data during each begin run is processed");
93  desc.addUntracked<bool>("checkDuringBeginLumi", false)
94  ->setComment("If 'true' check for retrieved data during each begin lumi is processed");
95  desc.addUntracked<bool>("checkDuringEvent", true)
96  ->setComment("If 'true' check for retrieved data during an event is processed");
97  descriptions.add("PrintEventSetupDataRetrieval", desc);
98  descriptions.setComment("This analyzer reports when EventSetup data is retrieved by a module in the job.");
99  }
100 
101  //
102  // assignment operators
103  //
104  // const PrintEventSetupDataRetrieval& PrintEventSetupDataRetrieval::operator=(const PrintEventSetupDataRetrieval& rhs)
105  // {
106  // //An exception safe implementation is
107  // PrintEventSetupDataRetrieval temp(rhs);
108  // swap(rhs);
109  //
110  // return *this;
111  // }
112 
113  //
114  // member functions
115  //
117  if (m_checkDuringEvent) {
118  check(iES);
119  }
120  }
121 
123  if (m_checkDuringBeginRun) {
124  check(iES);
125  }
126  }
127 
129 
132  check(iES);
133  }
134  }
135 
137 
139  //std::cout <<"postProcessEvent"<<std::endl;
140  m_recordKeys.clear();
142 
143  std::unique_ptr<LogSystem> msg;
144  for (std::vector<eventsetup::EventSetupRecordKey>::const_iterator it = m_recordKeys.begin(),
145  itEnd = m_recordKeys.end();
146  it != itEnd;
147  ++it) {
148  //std::cout <<" "<<it->name()<<std::endl;
149  auto r = iES.find(*it);
150  assert(r);
151 
152  RetrievedDataMap::iterator itRetrievedData = m_retrievedDataMap.find(*it);
153  if (itRetrievedData == m_retrievedDataMap.end()) {
154  itRetrievedData =
156  .insert(std::make_pair(*it, std::pair<unsigned long long, std::map<eventsetup::DataKey, bool> >()))
157  .first;
158  itRetrievedData->second.first = r->cacheIdentifier();
159  std::vector<eventsetup::DataKey> keys;
160  r->fillRegisteredDataKeys(keys);
161  for (std::vector<eventsetup::DataKey>::const_iterator itData = keys.begin(), itDataEnd = keys.end();
162  itData != itDataEnd;
163  ++itData) {
164  itRetrievedData->second.second.insert(std::make_pair(*itData, false));
165  }
166  }
167  RetrievedDataMap::value_type& retrievedData = *itRetrievedData;
168  if (itRetrievedData->second.first != r->cacheIdentifier()) {
169  itRetrievedData->second.first = r->cacheIdentifier();
170  for (std::map<eventsetup::DataKey, bool>::iterator itDatum = retrievedData.second.second.begin(),
171  itDatumEnd = retrievedData.second.second.end();
172  itDatum != itDatumEnd;
173  ++itDatum) {
174  itDatum->second = false;
175  }
176  }
177 
178  for (std::map<eventsetup::DataKey, bool>::iterator itDatum = retrievedData.second.second.begin(),
179  itDatumEnd = retrievedData.second.second.end();
180  itDatum != itDatumEnd;
181  ++itDatum) {
182  bool wasGotten = r->wasGotten(itDatum->first);
183  if (wasGotten != itDatum->second) {
184  if (not msg)
185  msg = std::make_unique<LogSystem>("ESContent");
186  else
187  *msg << "\n";
188  itDatum->second = wasGotten;
189  *msg << "Retrieved> record:" << it->name() << " data:" << itDatum->first.type().name() << " '"
190  << itDatum->first.name().value() << "'";
191  if (m_printProviders) {
192  const edm::eventsetup::ComponentDescription* d = r->providerDescription(itDatum->first);
193  assert(nullptr != d);
194  *msg << " provider:" << d->type_ << " '" << d->label_ << "'";
195  }
196  }
197  }
198  }
199  }
200 
201  //
202  // const member functions
203  //
204 
205  //
206  // static member functions
207  //
208 } // namespace edm
209 
210 //define this as a plug-in
void endRun(edm::Run const &, edm::EventSetup const &) override
assert(be >=bs)
std::map< eventsetup::EventSetupRecordKey, std::pair< unsigned long long, std::map< eventsetup::DataKey, bool > > > RetrievedDataMap
void fillAvailableRecordKeys(std::vector< eventsetup::EventSetupRecordKey > &oToFill) const
clears the oToFill vector and then fills it with the keys for all available records ...
Definition: EventSetup.h:156
std::vector< eventsetup::EventSetupRecordKey > m_recordKeys
void analyze(edm::Event const &, edm::EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
d
Definition: ztail.py:151
PrintEventSetupDataRetrieval(edm::ParameterSet const &)
void setComment(std::string const &value)
std::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &iKey) const
Definition: EventSetup.h:151
void add(std::string const &label, ParameterSetDescription const &psetDescription)
tuple msg
Definition: mps_check.py:286
HLT enums.
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:45