CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
31 namespace edm {
32  class PrintEventSetupDataRetrieval: 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  private:
46  void check(EventSetup const&);
47  // ---------- member data --------------------------------
48  typedef std::map<eventsetup::EventSetupRecordKey, std::pair<unsigned long long, std::map<eventsetup::DataKey,bool> > > RetrievedDataMap;
49 
51  std::vector<eventsetup::EventSetupRecordKey> m_recordKeys;
52  const bool m_printProviders;
55  const bool m_checkDuringEvent;
56 
57  };
58 //
59 // constants, enums and typedefs
60 //
61 
62 //
63 // static data member definitions
64 //
65 
66 //
67 // constructors and destructor
68 //
70  m_printProviders(iPS.getUntrackedParameter<bool>("printProviders")),
71  m_checkDuringBeginRun(iPS.getUntrackedParameter<bool>("checkDuringBeginRun")),
72  m_checkDuringBeginLumi(iPS.getUntrackedParameter<bool>("checkDuringBeginLumi")),
73  m_checkDuringEvent(iPS.getUntrackedParameter<bool>("checkDuringEvent"))
74  {
75  }
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)->setComment(
89  "If 'true' also print which ES module provides the data");
90  desc.addUntracked<bool>("checkDuringBeginRun",false)->setComment(
91  "If 'true' check for retrieved data during each begin run is processed");
92  desc.addUntracked<bool>("checkDuringBeginLumi",false)->setComment(
93  "If 'true' check for retrieved data during each begin lumi is processed");
94  desc.addUntracked<bool>("checkDuringEvent",true)->setComment(
95  "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 //
115  void
117  if(m_checkDuringEvent) { check(iES); }
118  }
119 
120  void
122  if(m_checkDuringBeginRun) { check(iES); }
123  }
124 
125  void
127  }
128 
129  void
131  if(m_checkDuringBeginLumi) { check(iES); }
132  }
133 
134  void
136  }
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(), itEnd = m_recordKeys.end();
145  it != itEnd;
146  ++it) {
147  //std::cout <<" "<<it->name()<<std::endl;
148  const eventsetup::EventSetupRecord* r = iES.find(*it);
149  assert(r != 0);
150 
151  RetrievedDataMap::iterator itRetrievedData = m_retrievedDataMap.find(*it);
152  if(itRetrievedData == m_retrievedDataMap.end()) {
153  itRetrievedData = m_retrievedDataMap.insert(std::make_pair(*it,std::pair<unsigned long long, std::map<eventsetup::DataKey,bool> >())).first;
154  itRetrievedData->second.first = r->cacheIdentifier();
155  std::vector<eventsetup::DataKey> keys;
156  r->fillRegisteredDataKeys(keys);
157  for(std::vector<eventsetup::DataKey>::const_iterator itData = keys.begin(), itDataEnd = keys.end();
158  itData != itDataEnd;
159  ++itData) {
160  itRetrievedData->second.second.insert(std::make_pair(*itData,false));
161  }
162  }
163  RetrievedDataMap::value_type& retrievedData = *itRetrievedData;
164  if(itRetrievedData->second.first != r->cacheIdentifier()) {
165  itRetrievedData->second.first = r->cacheIdentifier();
166  for(std::map<eventsetup::DataKey,bool>::iterator itDatum = retrievedData.second.second.begin(), itDatumEnd = retrievedData.second.second.end();
167  itDatum != itDatumEnd;
168  ++itDatum) {
169  itDatum->second = false;
170  }
171  }
172 
173  for(std::map<eventsetup::DataKey,bool>::iterator itDatum = retrievedData.second.second.begin(), itDatumEnd = retrievedData.second.second.end();
174  itDatum != itDatumEnd;
175  ++itDatum) {
176  bool wasGotten = r->wasGotten(itDatum->first);
177  if (wasGotten != itDatum->second) {
178  if (not msg)
179  msg.reset(new LogSystem("ESContent"));
180  else
181  *msg << "\n";
182  itDatum->second = wasGotten;
183  *msg << "Retrieved> record:" << it->name() << " data:" << itDatum->first.type().name() << " '" << itDatum->first.name().value() << "'";
184  if (m_printProviders) {
185  const edm::eventsetup::ComponentDescription* d = r->providerDescription(itDatum->first);
186  assert(nullptr != d);
187  *msg << " provider:" << d->type_ << " '" << d->label_ << "'";
188  }
189  }
190  }
191  }
192  }
193 
194 //
195 // const member functions
196 //
197 
198 //
199 // static member functions
200 //
201 }
202 
203 //define this as a plug-in
206 
unsigned long long cacheIdentifier() const
std::map< eventsetup::EventSetupRecordKey, std::pair< unsigned long long, std::map< eventsetup::DataKey, bool > > > RetrievedDataMap
void fillRegisteredDataKeys(std::vector< DataKey > &oToFill) const
clears the oToFill vector and then fills it with the keys for all registered data keys ...
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
bool wasGotten(DataKey const &aKey) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
void endRun(edm::Run const &, edm::EventSetup const &) override
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:91
ComponentDescription const * providerDescription(DataKey const &aKey) const
tuple d
Definition: ztail.py:151
std::vector< eventsetup::EventSetupRecordKey > m_recordKeys
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.cc:102
void analyze(edm::Event const &, edm::EventSetup const &) override
Container::value_type value_type
PrintEventSetupDataRetrieval(edm::ParameterSet const &)
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
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:43