CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 // system include files
20 #include <memory>
21 #include <map>
22 #include <vector>
23 
24 // user include files
27 
30 
32 
36 
38 //
39 // class declaration
40 //
41 
42 namespace edm {
44  : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
45  public:
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51  private:
52  //virtual void beginJob() ;
53  void analyze(const edm::Event&, const edm::EventSetup&) override;
54  //virtual void endJob() ;
55 
56  void beginRun(edm::Run const&, edm::EventSetup const&) override;
57  void endRun(edm::Run const&, edm::EventSetup const&) override {}
58  void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
59  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
60 
61  void check(edm::EventSetup const&);
62  void initialize();
63  // ----------member data ---------------------------
65  std::map<eventsetup::EventSetupRecordKey, std::vector<unsigned int> > m_recordKeysToExpectedCacheIdentifiers;
66  unsigned int m_index;
67  };
68 } // namespace edm
69 //
70 // constants, enums and typedefs
71 //
72 using namespace edm;
73 
74 //
75 // static data member definitions
76 //
77 
78 //
79 // constructors and destructor
80 //
82  : m_pset(iConfig), m_index(0) {
83  //now do what ever initialization is needed
84 }
85 
87  // do anything here that needs to be done at desctruction time
88  // (e.g. close files, deallocate resources etc.)
89 }
90 
91 //
92 // member functions
93 //
94 
95 // ------------ method called for each event ------------
97  check(iSetup);
98 }
99 
100 // ------------ method called once each job just before starting event loop ------------
101 //void
102 //EventSetupCacheIdentifierChecker::beginJob()
103 //{
104 //}
105 
106 // ------------ method called once each job just after ending the event loop ------------
107 //void
108 //EventSetupCacheIdentifierChecker::endJob()
109 //{
110 //}
111 
112 // ------------ method called when starting to processes a run ------------
114 
115 // ------------ method called when ending the processing of a run ------------
116 //void
117 //EventSetupCacheIdentifierChecker::endRun(edm::Run const&, edm::EventSetup const&)
118 //{
119 //}
120 
121 // ------------ method called when starting to processes a luminosity block ------------
123  edm::EventSetup const& iSetup) {
124  check(iSetup);
125 }
126 
127 // ------------ method called when ending the processing of a luminosity block ------------
128 //void
129 //EventSetupCacheIdentifierChecker::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
130 //{
131 //}
132 
135  initialize();
136  }
137  using namespace edm::eventsetup;
138 
140  it != itEnd;
141  ++it) {
142  auto pRecord = iSetup.find(it->first);
143  if (not pRecord) {
144  edm::LogWarning("RecordNotInIOV") << "The EventSetup Record '" << it->first.name()
145  << "' is not available for this IOV.";
146  }
147  if (it->second.size() <= m_index) {
148  throw cms::Exception("TooFewCacheIDs")
149  << "The vector of cacheIdentifiers for the record " << it->first.name() << " is too short";
150  }
151  if (pRecord && pRecord->cacheIdentifier() != it->second[m_index]) {
152  throw cms::Exception("IncorrectCacheID")
153  << "The Record " << it->first.name() << " was supposed to have cacheIdentifier: " << it->second[m_index]
154  << " but instead has " << pRecord->cacheIdentifier();
155  }
156  }
157  ++m_index;
158 }
159 
161  std::vector<std::string> recordNames{m_pset.getParameterNamesForType<std::vector<unsigned int> >(false)};
162 
163  for (auto const& name : recordNames) {
165  if (recordKey.type() == eventsetup::EventSetupRecordKey::TypeTag()) {
166  //record not found
167  edm::LogWarning("DataGetter") << "Record \"" << name << "\" does not exist " << std::endl;
168 
169  continue;
170  }
171 
173  std::make_pair(recordKey, m_pset.getUntrackedParameter<std::vector<unsigned int> >(name)));
174  }
175 }
176 
177 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
179  //The following says we do not know what parameters are allowed so do no validation
180  // Please change this to state exactly what you do use, even if it is no parameters
182  desc.addWildcardUntracked<std::vector<unsigned int> >("*")->setComment(
183  "The label is the name of an EventSetup Record while the vector contains the expected cacheIdentifier values for "
184  "each beginRun, beginLuminosityBlock and event transition");
185  descriptions.addDefault(desc);
186 }
187 
188 //define this as a plug-in
std::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &iKey) const
Definition: EventSetup.h:178
T getUntrackedParameter(std::string const &, T const &) const
m_index(idict.size(), 1)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterWildcardBase * addWildcardUntracked(U const &pattern)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
std::map< eventsetup::EventSetupRecordKey, std::vector< unsigned int > > m_recordKeysToExpectedCacheIdentifiers
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void endRun(edm::Run const &, edm::EventSetup const &) override
heterocontainer::HCTypeTag TypeTag
void analyze(const edm::Event &, const edm::EventSetup &) override
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Log< level::Warning, false > LogWarning
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:45
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
Definition: HCTypeTag.cc:121