CMS 3D CMS Logo

EventSetupRecordDataGetter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventSetupRecordDataGetter
4 // Class: EventSetupRecordDataGetter
5 //
13 //
14 // Original Author: Chris Jones
15 // Created: Tue Jun 28 11:10:24 EDT 2005
16 //
17 //
18 
19 // system include files
20 #include <map>
21 #include <vector>
22 #include <memory>
23 #include <set>
24 #include <iostream>
25 
26 // user include files
35 
36 //
37 // class decleration
38 //
39 namespace edm {
41  public:
43  ~EventSetupRecordDataGetter() override;
44 
45  void analyze(Event const&, EventSetup const&) override;
46  void beginRun(Run const&, EventSetup const&) override;
47  void beginLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
48 
49  static void fillDescriptions(ConfigurationDescriptions& descriptions);
50 
51  private:
52  void doGet(EventSetup const&);
53  // ----------member data ---------------------------
55 
56  typedef std::map<eventsetup::EventSetupRecordKey, std::vector<eventsetup::DataKey> > RecordToDataKeys;
57  RecordToDataKeys recordToDataKeys_;
58  std::map<eventsetup::EventSetupRecordKey, unsigned long long> recordToCacheIdentifier_;
59  const bool verbose_;
60  };
61 
62  //
63  // constructors and destructor
64  //
66  : pSet_(iConfig),
69  verbose_(iConfig.getUntrackedParameter<bool>("verbose")) {}
70 
72  // do anything here that needs to be done at desctruction time
73  // (e.g. close files, deallocate resources etc.)
74  }
75 
76  //
77  // member functions
78  //
79 
80  // ------------ method called to produce the data ------------
82  descriptions.setComment("Retrieves specified data from the EventSetup sytem whenever that data changes.");
83 
85  desc.addUntracked<bool>("verbose", false)
86  ->setComment("Print a message to the logger each time a data item is gotten.");
87 
89  toGet.add<std::string>("record")->setComment(
90  "The name of an EventSetup record holding the data you want obtained.");
91  toGet.add<std::vector<std::string> >("data")->setComment(
92  "The identifier for the data you wish to retrieve. "
93  "The identifier is in two parts separated by a backslash '/'. "
94  "The first part is the C++ class name of the data and the "
95  "second part is the label used when getting the data (blank is acceptable). "
96  "If there is no label, the backslash may be omitted.");
97 
98  std::vector<edm::ParameterSet> emptyVect;
99  desc.addVPSet("toGet", toGet, emptyVect)
100  ->setComment(
101  "The contained PSets must have the following structure.\n"
102  "A 'string' named 'record' that holds the name of an EventSetup record holding the data you want to "
103  "obtain.\n"
104  "a 'vstring' named 'data' that holds identifiers for the data you wish to retrieve. "
105  "The identifier is in two parts separated by a backslash '/'. "
106  "The first part is the C++ class name of the data and the "
107  "second part is the label used when getting the data (blank is acceptable). "
108  "If there is no label, the backslash may be omitted.\n"
109  "If the VPSet is empty it means all data in the EventSetup should be retrieved.");
110  descriptions.add("getEventSetupData", desc);
111  }
112 
113  void EventSetupRecordDataGetter::beginRun(Run const&, EventSetup const& iSetup) { doGet(iSetup); }
114 
116  doGet(iSetup);
117  }
118 
119  void EventSetupRecordDataGetter::analyze(edm::Event const& /*iEvent*/, edm::EventSetup const& iSetup) {
120  doGet(iSetup);
121  }
122 
124  if (recordToDataKeys_.empty()) {
125  typedef std::vector<ParameterSet> Parameters;
126  Parameters const& toGet = pSet_.getParameterSetVector("toGet");
127 
128  for (Parameters::const_iterator itToGet = toGet.begin(), itToGetEnd = toGet.end(); itToGet != itToGetEnd;
129  ++itToGet) {
130  std::string recordName = itToGet->getParameter<std::string>("record");
131 
133  if (recordKey.type() == eventsetup::EventSetupRecordKey::TypeTag()) {
134  //record not found
135  edm::LogWarning("DataGetter") << "Record \"" << recordName << "\" does not exist " << std::endl;
136 
137  continue;
138  }
139  typedef std::vector<std::string> Strings;
140  Strings dataNames = itToGet->getParameter<Strings>("data");
141  std::vector<eventsetup::DataKey> dataKeys;
142  for (Strings::iterator itDatum = dataNames.begin(), itDatumEnd = dataNames.end(); itDatum != itDatumEnd;
143  ++itDatum) {
144  std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
145  std::string labelName;
146  if (itDatum->size() != datumName.size()) {
147  labelName = std::string(*itDatum, datumName.size() + 1);
148  }
149  eventsetup::TypeTag datumType = eventsetup::TypeTag::findType(datumName);
150  if (datumType == eventsetup::TypeTag()) {
151  //not found
152  edm::LogWarning("DataGetter") << "data item of type \"" << datumName << "\" does not exist" << std::endl;
153 
154  continue;
155  }
156  eventsetup::DataKey datumKey(datumType, labelName.c_str());
157  dataKeys.push_back(datumKey);
158  }
159  recordToDataKeys_.insert(std::make_pair(recordKey, dataKeys));
160  recordToCacheIdentifier_.insert(std::make_pair(recordKey, 0));
161  }
162  if (toGet.empty()) {
163  //This means we should get everything in the EventSetup
164  std::vector<eventsetup::EventSetupRecordKey> recordKeys;
165  iSetup.fillAvailableRecordKeys(recordKeys);
166  std::vector<eventsetup::DataKey> dataKeys;
167 
168  for (std::vector<eventsetup::EventSetupRecordKey>::iterator itRKey = recordKeys.begin(),
169  itRKeyEnd = recordKeys.end();
170  itRKey != itRKeyEnd;
171  ++itRKey) {
172  auto record = iSetup.find(*itRKey);
173  assert(record);
174  dataKeys.clear();
175  record->fillRegisteredDataKeys(dataKeys);
176  recordToDataKeys_.insert(std::make_pair(*itRKey, dataKeys));
177  recordToCacheIdentifier_.insert(std::make_pair(*itRKey, 0));
178  }
179  }
180  }
181 
182  using namespace edm::eventsetup;
183 
184  //For each requested Record get the requested data only if the Record is in a new IOV
185 
186  for (RecordToDataKeys::iterator itRecord = recordToDataKeys_.begin(), itRecordEnd = recordToDataKeys_.end();
187  itRecord != itRecordEnd;
188  ++itRecord) {
189  auto pRecord = iSetup.find(itRecord->first);
190  if (not pRecord) {
191  edm::LogWarning("RecordNotInIOV")
192  << "The EventSetup Record '" << itRecord->first.name() << "' is not available for this IOV.";
193  }
194  if (pRecord.has_value() && pRecord->cacheIdentifier() != recordToCacheIdentifier_[itRecord->first]) {
195  recordToCacheIdentifier_[itRecord->first] = pRecord->cacheIdentifier();
196  typedef std::vector<DataKey> Keys;
197  Keys const& keys = itRecord->second;
198  for (Keys::const_iterator itKey = keys.begin(), itKeyEnd = keys.end(); itKey != itKeyEnd; ++itKey) {
199  if (!pRecord->doGet(*itKey)) {
200  edm::LogWarning("DataGetter")
201  << "No data of type \"" << itKey->type().name() << "\" with name \"" << itKey->name().value()
202  << "\" in record " << itRecord->first.type().name() << " found " << std::endl;
203  } else {
204  if (verbose_) {
205  edm::LogSystem("DataGetter")
206  << "got data of type \"" << itKey->type().name() << "\" with name \"" << itKey->name().value()
207  << "\" in record " << itRecord->first.type().name() << std::endl;
208  }
209  }
210  }
211  }
212  }
213  }
214 } // namespace edm
std::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &iKey) const
Definition: EventSetup.h:160
void setComment(std::string const &value)
VParameterSet const & getParameterSetVector(std::string const &name) const
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
JetCorrectorParameters::Record record
Definition: classes.h:7
EventSelector::Strings Strings
void beginRun(Run const &, EventSetup const &) override
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
vector< ParameterSet > Parameters
std::map< eventsetup::EventSetupRecordKey, unsigned long long > recordToCacheIdentifier_
static void fillDescriptions(ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void analyze(Event const &, EventSetup const &) override
void setComment(std::string const &value)
std::map< eventsetup::EventSetupRecordKey, std::vector< eventsetup::DataKey > > RecordToDataKeys
std::vector< size_type > Keys
void add(std::string const &label, ParameterSetDescription const &psetDescription)
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.h:165
heterocontainer::HCTypeTag TypeTag
HLT enums.
Definition: Run.h:45