CMS 3D CMS Logo

EventSetupCacheIdentifierChecker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventSetupCacheIdentifierChecker
4 // Class: EventSetupCacheIdentifierChecker
5 //
13 //
14 // Original Author: Chris Jones
15 // Created: Wed May 30 14:42:16 CDT 2012
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <map>
23 #include <vector>
24 
25 // user include files
28 
31 
33 
37 
39 //
40 // class declaration
41 //
42 
43 namespace edm {
45  public:
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51 
52  private:
53  //virtual void beginJob() ;
54  void analyze(const edm::Event&, const edm::EventSetup&) override;
55  //virtual void endJob() ;
56 
57  void beginRun(edm::Run const&, edm::EventSetup const&) override;
58  //virtual void endRun(edm::Run const&, edm::EventSetup const&);
59  void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
60  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
61 
62  void check(edm::EventSetup const&);
63  void initialize();
64  // ----------member data ---------------------------
66  std::map<eventsetup::EventSetupRecordKey,std::vector<unsigned int> > m_recordKeysToExpectedCacheIdentifiers;
67  unsigned int m_index;
68  };
69 }
70 //
71 // constants, enums and typedefs
72 //
73 using namespace edm;
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83 m_pset(iConfig),
84 m_index(0)
85 {
86  //now do what ever initialization is needed
87 
88 }
89 
90 
92 {
93 
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 
97 }
98 
99 
100 //
101 // member functions
102 //
103 
104 // ------------ method called for each event ------------
105 void
107 {
108  check(iSetup);
109 }
110 
111 
112 // ------------ method called once each job just before starting event loop ------------
113 //void
114 //EventSetupCacheIdentifierChecker::beginJob()
115 //{
116 //}
117 
118 // ------------ method called once each job just after ending the event loop ------------
119 //void
120 //EventSetupCacheIdentifierChecker::endJob()
121 //{
122 //}
123 
124 // ------------ method called when starting to processes a run ------------
125 void
127 {
128  check(iSetup);
129 }
130 
131 // ------------ method called when ending the processing of a run ------------
132 //void
133 //EventSetupCacheIdentifierChecker::endRun(edm::Run const&, edm::EventSetup const&)
134 //{
135 //}
136 
137 // ------------ method called when starting to processes a luminosity block ------------
138 void
140 {
141  check(iSetup);
142 }
143 
144 // ------------ method called when ending the processing of a luminosity block ------------
145 //void
146 //EventSetupCacheIdentifierChecker::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
147 //{
148 //}
149 
150 void
152 {
154  initialize();
155  }
156  using namespace edm::eventsetup;
157 
158 
160  it != itEnd;
161  ++it) {
162  auto pRecord = iSetup.find(it->first);
163  if(not pRecord) {
164  edm::LogWarning("RecordNotInIOV") <<"The EventSetup Record '"<<it->first.name()<<"' is not available for this IOV.";
165  }
166  if(it->second.size() <= m_index) {
167  throw cms::Exception("TooFewCacheIDs")<<"The vector of cacheIdentifiers for the record "<<it->first.name()<<" is too short";
168  }
169  if(pRecord && pRecord->cacheIdentifier() != it->second[m_index]) {
170  throw cms::Exception("IncorrectCacheID")<<"The Record "<<it->first.name()<<" was supposed to have cacheIdentifier: "<<it->second[m_index]<<" but instead has "<<pRecord->cacheIdentifier();
171  }
172  }
173  ++m_index;
174 }
175 
176 void
178 {
179  std::vector<std::string> recordNames{m_pset.getParameterNamesForType<std::vector<unsigned int> >(false)};
180 
181  for(auto const& name: recordNames) {
183  if(recordKey.type() == eventsetup::EventSetupRecordKey::TypeTag()) {
184  //record not found
185  edm::LogWarning("DataGetter") <<"Record \""<< name <<"\" does not exist "<<std::endl;
186 
187  continue;
188  }
189 
190  m_recordKeysToExpectedCacheIdentifiers.insert(std::make_pair(recordKey, m_pset.getUntrackedParameter<std::vector<unsigned int> >(name)));
191  }
192 }
193 
194 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
195 void
197  //The following says we do not know what parameters are allowed so do no validation
198  // Please change this to state exactly what you do use, even if it is no parameters
200  desc.addWildcardUntracked<std::vector<unsigned int> >("*")->setComment("The label is the name of an EventSetup Record while the vector contains the expected cacheIdentifier values for each beginRun, beginLuminosityBlock and event transition");
201  descriptions.addDefault(desc);
202 }
203 
204 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
ParameterWildcardBase * addWildcardUntracked(U const &pattern)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
std::map< eventsetup::EventSetupRecordKey, std::vector< unsigned int > > m_recordKeysToExpectedCacheIdentifiers
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
heterocontainer::HCTypeTag TypeTag
HLT enums.
boost::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:88
void analyze(const edm::Event &, const edm::EventSetup &) override
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:44