CMS 3D CMS Logo

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