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 
17 // user include files
29 
30 namespace edm {
32  : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
33  public:
35 
36  void analyze(edm::Event const&, edm::EventSetup const&) override;
37 
38  void beginRun(edm::Run const&, edm::EventSetup const&) override;
39  void endRun(edm::Run const&, edm::EventSetup const&) override;
40 
41  void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
42  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
43 
44  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
45 
46  private:
47  void check(EventSetup const&);
48  // ---------- member data --------------------------------
50  std::pair<unsigned long long, std::map<eventsetup::DataKey, bool> > >
52 
54  std::vector<eventsetup::EventSetupRecordKey> m_recordKeys;
55  const bool m_printProviders;
58  const bool m_checkDuringEvent;
59  };
60  //
61  // constants, enums and typedefs
62  //
63 
64  //
65  // static data member definitions
66  //
67 
68  //
69  // constructors and destructor
70  //
72  : m_printProviders(iPS.getUntrackedParameter<bool>("printProviders")),
73  m_checkDuringBeginRun(iPS.getUntrackedParameter<bool>("checkDuringBeginRun")),
74  m_checkDuringBeginLumi(iPS.getUntrackedParameter<bool>("checkDuringBeginLumi")),
75  m_checkDuringEvent(iPS.getUntrackedParameter<bool>("checkDuringEvent")) {}
76 
77  // PrintEventSetupDataRetrieval::PrintEventSetupDataRetrieval(const PrintEventSetupDataRetrieval& rhs)
78  // {
79  // // do actual copying here;
80  // }
81 
82  //PrintEventSetupDataRetrieval::~PrintEventSetupDataRetrieval()
83  //{
84  //}
85 
88  desc.addUntracked<bool>("printProviders", false)
89  ->setComment("If 'true' also print which ES module provides the data");
90  desc.addUntracked<bool>("checkDuringBeginRun", false)
91  ->setComment("If 'true' check for retrieved data during each begin run is processed");
92  desc.addUntracked<bool>("checkDuringBeginLumi", false)
93  ->setComment("If 'true' check for retrieved data during each begin lumi is processed");
94  desc.addUntracked<bool>("checkDuringEvent", true)
95  ->setComment("If 'true' check for retrieved data during an event is processed");
96  descriptions.add("PrintEventSetupDataRetrieval", desc);
97  descriptions.setComment("This analyzer reports when EventSetup data is retrieved by a module in the job.");
98  }
99 
100  //
101  // assignment operators
102  //
103  // const PrintEventSetupDataRetrieval& PrintEventSetupDataRetrieval::operator=(const PrintEventSetupDataRetrieval& rhs)
104  // {
105  // //An exception safe implementation is
106  // PrintEventSetupDataRetrieval temp(rhs);
107  // swap(rhs);
108  //
109  // return *this;
110  // }
111 
112  //
113  // member functions
114  //
116  if (m_checkDuringEvent) {
117  check(iES);
118  }
119  }
120 
122  if (m_checkDuringBeginRun) {
123  check(iES);
124  }
125  }
126 
128 
131  check(iES);
132  }
133  }
134 
136 
138  //std::cout <<"postProcessEvent"<<std::endl;
139  m_recordKeys.clear();
141 
142  std::unique_ptr<LogSystem> msg;
143  for (std::vector<eventsetup::EventSetupRecordKey>::const_iterator it = m_recordKeys.begin(),
144  itEnd = m_recordKeys.end();
145  it != itEnd;
146  ++it) {
147  //std::cout <<" "<<it->name()<<std::endl;
148  auto r = iES.find(*it);
149  assert(r);
150 
151  RetrievedDataMap::iterator itRetrievedData = m_retrievedDataMap.find(*it);
152  if (itRetrievedData == m_retrievedDataMap.end()) {
153  itRetrievedData =
155  .insert(std::make_pair(*it, std::pair<unsigned long long, std::map<eventsetup::DataKey, bool> >()))
156  .first;
157  itRetrievedData->second.first = r->cacheIdentifier();
158  std::vector<eventsetup::DataKey> keys;
159  r->fillRegisteredDataKeys(keys);
160  for (std::vector<eventsetup::DataKey>::const_iterator itData = keys.begin(), itDataEnd = keys.end();
161  itData != itDataEnd;
162  ++itData) {
163  itRetrievedData->second.second.insert(std::make_pair(*itData, false));
164  }
165  }
166  RetrievedDataMap::value_type& retrievedData = *itRetrievedData;
167  if (itRetrievedData->second.first != r->cacheIdentifier()) {
168  itRetrievedData->second.first = r->cacheIdentifier();
169  for (std::map<eventsetup::DataKey, bool>::iterator itDatum = retrievedData.second.second.begin(),
170  itDatumEnd = retrievedData.second.second.end();
171  itDatum != itDatumEnd;
172  ++itDatum) {
173  itDatum->second = false;
174  }
175  }
176 
177  for (std::map<eventsetup::DataKey, bool>::iterator itDatum = retrievedData.second.second.begin(),
178  itDatumEnd = retrievedData.second.second.end();
179  itDatum != itDatumEnd;
180  ++itDatum) {
181  bool wasGotten = r->wasGotten(itDatum->first);
182  if (wasGotten != itDatum->second) {
183  if (not msg)
184  msg.reset(new LogSystem("ESContent"));
185  else
186  *msg << "\n";
187  itDatum->second = wasGotten;
188  *msg << "Retrieved> record:" << it->name() << " data:" << itDatum->first.type().name() << " '"
189  << itDatum->first.name().value() << "'";
190  if (m_printProviders) {
191  const edm::eventsetup::ComponentDescription* d = r->providerDescription(itDatum->first);
192  assert(nullptr != d);
193  *msg << " provider:" << d->type_ << " '" << d->label_ << "'";
194  }
195  }
196  }
197  }
198  }
199 
200  //
201  // const member functions
202  //
203 
204  //
205  // static member functions
206  //
207 } // namespace edm
208 
209 //define this as a plug-in
std::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &iKey) const
Definition: EventSetup.h:162
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void endRun(edm::Run const &, edm::EventSetup const &) override
std::map< eventsetup::EventSetupRecordKey, std::pair< unsigned long long, std::map< eventsetup::DataKey, bool > > > RetrievedDataMap
std::vector< eventsetup::EventSetupRecordKey > m_recordKeys
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(edm::Event const &, edm::EventSetup const &) override
d
Definition: ztail.py:151
PrintEventSetupDataRetrieval(edm::ParameterSet const &)
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
tuple msg
Definition: mps_check.py:285
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:167
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