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;
53 
57 
58  };
59 //
60 // constants, enums and typedefs
61 //
62 
63 //
64 // static data member definitions
65 //
66 
67 //
68 // constructors and destructor
69 //
71  m_printProviders(iPS.getUntrackedParameter<bool>("printProviders")),
72  m_checkDuringBeginRun(iPS.getUntrackedParameter<bool>("checkDuringBeginRun")),
73  m_checkDuringBeginLumi(iPS.getUntrackedParameter<bool>("checkDuringBeginLumi")),
74  m_checkDuringEvent(iPS.getUntrackedParameter<bool>("checkDuringEvent"))
75  {
76  }
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)->setComment(
90  "If 'true' also print which ES module provides the data");
91  desc.addUntracked<bool>("checkDuringBeginRun",false)->setComment(
92  "If 'true' check for retrieved data during each begin run is processed");
93  desc.addUntracked<bool>("checkDuringBeginLumi",false)->setComment(
94  "If 'true' check for retrieved data during each begin lumi is processed");
95  desc.addUntracked<bool>("checkDuringEvent",true)->setComment(
96  "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 //
116  void
118  if(m_checkDuringEvent) { check(iES); }
119  }
120 
121  void
123  if(m_checkDuringBeginRun) { check(iES); }
124  }
125 
126  void
128  }
129 
130  void
132  if(m_checkDuringBeginLumi) { check(iES); }
133  }
134 
135  void
137  }
138 
140  //std::cout <<"postProcessEvent"<<std::endl;
141  m_recordKeys.clear();
143 
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  //std::cout <<" "<<itDatum->first.type().name()<<" "<<wasGotten<<std::endl;
178  if(wasGotten != itDatum->second) {
179  itDatum->second = wasGotten;
180  if(m_printProviders) {
181  const edm::eventsetup::ComponentDescription* d = r->providerDescription(itDatum->first);
182  assert(0!=d);
183  edm::LogSystem("PrintEventSetupDataRetrieval")<<"Retrieved> Record:"<<it->name()<<" data:"<<itDatum->first.type().name()<<" '"<<itDatum->first.name().value()
184  <<"' provider:"<<d->type_<<" '"<<d->label_<<"'";
185  } else {
186  edm::LogSystem("PrintEventSetupDataRetrieval")<<"Retrieved> Record:"<<it->name()<<" data:"<<itDatum->first.type().name()<<" '"<<itDatum->first.name().value()<<"'";
187  }
188  //std::cout <<"CHANGED"<<std::endl;
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
void endRun(edm::Run const &, edm::EventSetup const &) override
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
ComponentDescription const * providerDescription(DataKey const &aKey) const
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:101
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:41