CMS 3D CMS Logo

EventSetupProvider.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Framework
4 // Module: EventSetupProvider
5 //
6 // Description: <one line class summary>
7 //
8 // Implementation:
9 // <Notes on implementation>
10 //
11 // Author: Chris Jones
12 // Created: Thu Mar 24 16:27:14 EST 2005
13 //
14 
15 // system include files
16 #include <algorithm>
17 #include <cassert>
18 
19 // user include files
33 
34 namespace edm {
35  namespace eventsetup {
36 
38  unsigned subProcessIndex,
39  const PreferredProviderInfo* iInfo)
40  : eventSetup_(activityRegistry),
41  mustFinishConfiguration_(true),
42  subProcessIndex_(subProcessIndex),
43  preferredProviderInfo_((nullptr != iInfo) ? (new PreferredProviderInfo(*iInfo)) : nullptr),
44  finders_(new std::vector<std::shared_ptr<EventSetupRecordIntervalFinder>>()),
45  dataProviders_(new std::vector<std::shared_ptr<DataProxyProvider>>()),
46  referencedDataKeys_(new std::map<EventSetupRecordKey, std::map<DataKey, ComponentDescription const*>>),
47  recordToFinders_(
48  new std::map<EventSetupRecordKey, std::vector<std::shared_ptr<EventSetupRecordIntervalFinder>>>),
49  psetIDToRecordKey_(new std::map<ParameterSetIDHolder, std::set<EventSetupRecordKey>>),
50  recordToPreferred_(new std::map<EventSetupRecordKey, std::map<DataKey, ComponentDescription>>),
51  recordsWithALooperProxy_(new std::set<EventSetupRecordKey>) {}
52 
53  EventSetupProvider::~EventSetupProvider() { forceCacheClear(); }
54 
55  std::shared_ptr<EventSetupRecordProvider>& EventSetupProvider::recordProvider(const EventSetupRecordKey& iKey) {
56  auto lb = std::lower_bound(recordKeys_.begin(), recordKeys_.end(), iKey);
57  if (lb == recordKeys_.end() || iKey != *lb) {
58  throw cms::Exception("LogicError") << "EventSetupProvider::recordProvider Could not find key\n"
59  << "Should be impossible. Please contact Framework developer.\n";
60  }
61  auto index = std::distance(recordKeys_.begin(), lb);
62  return recordProviders_[index];
63  }
64 
65  EventSetupRecordProvider* EventSetupProvider::tryToGetRecordProvider(const EventSetupRecordKey& iKey) {
66  auto lb = std::lower_bound(recordKeys_.begin(), recordKeys_.end(), iKey);
67  if (lb == recordKeys_.end() || iKey != *lb) {
68  return nullptr;
69  }
70  auto index = std::distance(recordKeys_.begin(), lb);
71  return recordProviders_[index].get();
72  }
73 
75  std::unique_ptr<EventSetupRecordProvider> iProvider) {
76  auto lb = std::lower_bound(recordKeys_.begin(), recordKeys_.end(), iKey);
77  auto index = std::distance(recordKeys_.begin(), lb);
78  if (lb == recordKeys_.end() || iKey != *lb) {
79  recordKeys_.insert(lb, iKey);
80  recordProviders_.insert(recordProviders_.begin() + index, std::move(iProvider));
81  } else {
82  recordProviders_[index] = std::move(iProvider);
83  }
84  }
85 
86  void EventSetupProvider::add(std::shared_ptr<DataProxyProvider> iProvider) {
87  assert(iProvider.get() != nullptr);
88  dataProviders_->push_back(iProvider);
89  }
90 
91  void EventSetupProvider::replaceExisting(std::shared_ptr<DataProxyProvider> dataProxyProvider) {
92  ParameterSetIDHolder psetID(dataProxyProvider->description().pid_);
93  std::set<EventSetupRecordKey> const& keysForPSetID = (*psetIDToRecordKey_)[psetID];
94  for (auto const& key : keysForPSetID) {
95  recordProvider(key)->resetProxyProvider(psetID, dataProxyProvider);
96  }
97  }
98 
99  void EventSetupProvider::add(std::shared_ptr<EventSetupRecordIntervalFinder> iFinder) {
100  assert(iFinder.get() != nullptr);
101  finders_->push_back(iFinder);
102  }
103 
104  using RecordProviders = std::vector<std::shared_ptr<EventSetupRecordProvider>>;
105  using RecordToPreferred = std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap>;
107  static void preferEverything(const ComponentDescription& iComponent,
108  const RecordProviders& iRecordProviders,
109  RecordToPreferred& iReturnValue) {
110  //need to get our hands on the actual DataProxyProvider
111  bool foundProxyProvider = false;
112  for (auto const& recordProvider : iRecordProviders) {
113  std::set<ComponentDescription> components = recordProvider->proxyProviderDescriptions();
114  if (components.find(iComponent) != components.end()) {
115  std::shared_ptr<DataProxyProvider> proxyProv = recordProvider->proxyProvider(*(components.find(iComponent)));
116  assert(proxyProv.get());
117 
118  std::set<EventSetupRecordKey> records = proxyProv->usingRecords();
119  for (std::set<EventSetupRecordKey>::iterator itRecord = records.begin(), itRecordEnd = records.end();
120  itRecord != itRecordEnd;
121  ++itRecord) {
122  const DataProxyProvider::KeyedProxies& keyedProxies = proxyProv->keyedProxies(*itRecord);
123  if (!keyedProxies.empty()) {
124  //add them to our output
125  EventSetupRecordProvider::DataToPreferredProviderMap& dataToProviderMap = iReturnValue[*itRecord];
126 
127  for (DataProxyProvider::KeyedProxies::const_iterator itProxy = keyedProxies.begin(),
128  itProxyEnd = keyedProxies.end();
129  itProxy != itProxyEnd;
130  ++itProxy) {
131  EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
132  dataToProviderMap.find(itProxy->first);
133  if (itFind != dataToProviderMap.end()) {
134  throw cms::Exception("ESPreferConflict")
135  << "Two providers have been set to be preferred for\n"
136  << itProxy->first.type().name() << " \"" << itProxy->first.name().value() << "\""
137  << "\n the providers are "
138  << "\n 1) type=" << itFind->second.type_ << " label=\"" << itFind->second.label_ << "\""
139  << "\n 2) type=" << iComponent.type_ << " label=\"" << iComponent.label_ << "\""
140  << "\nPlease modify configuration so only one is preferred";
141  }
142  dataToProviderMap.insert(std::make_pair(itProxy->first, iComponent));
143  }
144  }
145  }
146  foundProxyProvider = true;
147  break;
148  }
149  }
150  if (!foundProxyProvider) {
151  throw cms::Exception("ESPreferNoProvider")
152  << "Could not make type=\"" << iComponent.type_ << "\" label=\"" << iComponent.label_
153  << "\" a preferred Provider."
154  << "\n Please check spelling of name, or that it was loaded into the job.";
155  }
156  }
157 
158  void EventSetupProvider::determinePreferred() {
159  using namespace edm::eventsetup;
160  if (preferredProviderInfo_) {
161  for (auto const& itInfo : *preferredProviderInfo_) {
162  if (itInfo.second.empty()) {
163  //want everything
164  preferEverything(itInfo.first, recordProviders_, *recordToPreferred_);
165  } else {
166  for (EventSetupProvider::RecordToDataMap::const_iterator itRecData = itInfo.second.begin(),
167  itRecDataEnd = itInfo.second.end();
168  itRecData != itRecDataEnd;
169  ++itRecData) {
170  std::string recordName = itRecData->first;
172  if (recordKey.type() == eventsetup::EventSetupRecordKey::TypeTag()) {
173  throw cms::Exception("ESPreferUnknownRecord")
174  << "Unknown record \"" << recordName
175  << "\" used in es_prefer statement for type=" << itInfo.first.type_ << " label=\""
176  << itInfo.first.label_ << "\"\n Please check spelling.";
177  //record not found
178  }
179  //See if the ProxyProvider provides something for this Record
180  EventSetupRecordProvider& recordProviderForKey = *recordProvider(recordKey);
181 
182  std::set<ComponentDescription> components = recordProviderForKey.proxyProviderDescriptions();
183  std::set<ComponentDescription>::iterator itProxyProv = components.find(itInfo.first);
184  if (itProxyProv == components.end()) {
185  throw cms::Exception("ESPreferWrongRecord")
186  << "The type=" << itInfo.first.type_ << " label=\"" << itInfo.first.label_
187  << "\" does not provide data for the Record " << recordName;
188  }
189  //Does it data type exist?
190  eventsetup::TypeTag datumType = eventsetup::TypeTag::findType(itRecData->second.first);
191  if (datumType == eventsetup::TypeTag()) {
192  //not found
193  throw cms::Exception("ESPreferWrongDataType")
194  << "The es_prefer statement for type=" << itInfo.first.type_ << " label=\"" << itInfo.first.label_
195  << "\" has the unknown data type \"" << itRecData->second.first << "\""
196  << "\n Please check spelling";
197  }
198  eventsetup::DataKey datumKey(datumType, itRecData->second.second.c_str());
199 
200  //Does the proxyprovider make this?
201  std::shared_ptr<DataProxyProvider> proxyProv = recordProviderForKey.proxyProvider(*itProxyProv);
202  const DataProxyProvider::KeyedProxies& keyedProxies = proxyProv->keyedProxies(recordKey);
203  if (std::find_if(keyedProxies.begin(), keyedProxies.end(), [&datumKey](auto const& kp) {
204  return kp.first == datumKey;
205  }) == keyedProxies.end()) {
206  throw cms::Exception("ESPreferWrongData")
207  << "The es_prefer statement for type=" << itInfo.first.type_ << " label=\"" << itInfo.first.label_
208  << "\" specifies the data item \n"
209  << " type=\"" << itRecData->second.first << "\" label=\"" << itRecData->second.second << "\""
210  << " which is not provided. Please check spelling.";
211  }
212 
214  (*recordToPreferred_)[recordKey];
215  //has another provider already been specified?
216  if (dataToProviderMap.end() != dataToProviderMap.find(datumKey)) {
217  EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
218  dataToProviderMap.find(datumKey);
219  throw cms::Exception("ESPreferConflict")
220  << "Two providers have been set to be preferred for\n"
221  << datumKey.type().name() << " \"" << datumKey.name().value() << "\""
222  << "\n the providers are "
223  << "\n 1) type=" << itFind->second.type_ << " label=\"" << itFind->second.label_ << "\""
224  << "\n 2) type=" << itProxyProv->type_ << " label=\"" << itProxyProv->label_ << "\""
225  << "\nPlease modify configuration so only one is preferred";
226  }
227  dataToProviderMap.insert(std::make_pair(datumKey, *itProxyProv));
228  }
229  }
230  }
231  }
232  }
233 
234  void EventSetupProvider::finishConfiguration() {
235  //we delayed adding finders to the system till here so that everything would be loaded first
236  recordToFinders_->clear();
237  for (std::vector<std::shared_ptr<EventSetupRecordIntervalFinder>>::iterator itFinder = finders_->begin(),
238  itEnd = finders_->end();
239  itFinder != itEnd;
240  ++itFinder) {
241  typedef std::set<EventSetupRecordKey> Keys;
242  const Keys recordsUsing = (*itFinder)->findingForRecords();
243 
244  for (auto const& key : recordsUsing) {
245  (*recordToFinders_)[key].push_back(*itFinder);
246 
247  EventSetupRecordProvider* recProvider = tryToGetRecordProvider(key);
248  if (recProvider == nullptr) {
249  //create a provider for this record
250  insert(key, std::make_unique<EventSetupRecordProvider>(key));
251  recProvider = tryToGetRecordProvider(key);
252  }
253  recProvider->addFinder(*itFinder);
254  }
255  }
256  //we've transfered our ownership so this is no longer needed
257  finders_.reset();
258 
259  //Now handle providers since sources can also be finders and the sources can delay registering
260  // their Records and therefore could delay setting up their Proxies
261  psetIDToRecordKey_->clear();
262  typedef std::set<EventSetupRecordKey> Keys;
263  for (std::vector<std::shared_ptr<DataProxyProvider>>::iterator itProvider = dataProviders_->begin(),
264  itEnd = dataProviders_->end();
265  itProvider != itEnd;
266  ++itProvider) {
267  ParameterSetIDHolder psetID((*itProvider)->description().pid_);
268 
269  const Keys recordsUsing = (*itProvider)->usingRecords();
270 
271  for (auto const& key : recordsUsing) {
272  if ((*itProvider)->description().isLooper_) {
273  recordsWithALooperProxy_->insert(key);
274  }
275 
276  (*psetIDToRecordKey_)[psetID].insert(key);
277 
278  EventSetupRecordProvider* recProvider = tryToGetRecordProvider(key);
279  if (recProvider == nullptr) {
280  //create a provider for this record
281  insert(key, std::make_unique<EventSetupRecordProvider>(key));
282  recProvider = tryToGetRecordProvider(key);
283  }
284  recProvider->add(*itProvider);
285  }
286  }
287 
288  eventSetup_.setKeyIters(recordKeys_.begin(), recordKeys_.end());
289 
290  //used for the case where no preferred Providers have been specified for the Record
292 
293  determinePreferred();
294 
295  //For each Provider, find all the Providers it depends on. If a dependent Provider
296  // can not be found pass in an empty list
297  //CHANGE: now allow for missing Providers
298  for (auto& itRecordProvider : recordProviders_) {
299  const EventSetupRecordProvider::DataToPreferredProviderMap* preferredInfo = &kEmptyMap;
300  RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(itRecordProvider->key());
301  if (itRecordFound != recordToPreferred_->end()) {
302  preferredInfo = &(itRecordFound->second);
303  }
304  //Give it our list of preferred
305  itRecordProvider->usePreferred(*preferredInfo);
306 
307  std::set<EventSetupRecordKey> records = itRecordProvider->dependentRecords();
308  if (!records.empty()) {
309  std::string missingRecords;
310  std::vector<std::shared_ptr<EventSetupRecordProvider>> depProviders;
311  depProviders.reserve(records.size());
312  bool foundAllProviders = true;
313  for (auto const& key : records) {
314  auto lb = std::lower_bound(recordKeys_.begin(), recordKeys_.end(), key);
315  if (lb == recordKeys_.end() || key != *lb) {
316  foundAllProviders = false;
317  if (missingRecords.empty()) {
318  missingRecords = key.name();
319  } else {
320  missingRecords += ", ";
321  missingRecords += key.name();
322  }
323  } else {
324  auto index = std::distance(recordKeys_.begin(), lb);
325  depProviders.push_back(recordProviders_[index]);
326  }
327  }
328 
329  if (!foundAllProviders) {
330  edm::LogInfo("EventSetupDependency")
331  << "The EventSetup record " << itRecordProvider->key().name() << " depends on at least one Record \n ("
332  << missingRecords
333  << ") which is not present in the job."
334  "\n This may lead to an exception begin thrown during event processing.\n If no exception occurs "
335  "during the job than it is usually safe to ignore this message.";
336 
337  //depProviders.clear();
338  //NOTE: should provide a warning
339  }
340 
341  itRecordProvider->setDependentProviders(depProviders);
342  }
343  }
344 
345  auto indices = recordsToProxyIndices();
346  for (auto& provider : *dataProviders_) {
347  provider->updateLookup(indices);
348  }
349  dataProviders_.reset();
350 
351  mustFinishConfiguration_ = false;
352  }
353 
354  using Itr = RecordProviders::iterator;
355  static void findDependents(const EventSetupRecordKey& iKey,
356  Itr itBegin,
357  Itr itEnd,
358  std::vector<std::shared_ptr<EventSetupRecordProvider>>& oDependents) {
359  for (Itr it = itBegin; it != itEnd; ++it) {
360  //does it depend on the record in question?
361  const std::set<EventSetupRecordKey>& deps = (*it)->dependentRecords();
362  if (deps.end() != deps.find(iKey)) {
363  oDependents.push_back(*it);
364  //now see who is dependent on this record since they will be indirectly dependent on iKey
365  findDependents((*it)->key(), itBegin, itEnd, oDependents);
366  }
367  }
368  }
369 
370  void EventSetupProvider::resetRecordPlusDependentRecords(const EventSetupRecordKey& iKey) {
371  EventSetupRecordProvider* recProvider = tryToGetRecordProvider(iKey);
372  if (recProvider == nullptr) {
373  return;
374  }
375 
376  std::vector<std::shared_ptr<EventSetupRecordProvider>> dependents;
377  findDependents(iKey, recordProviders_.begin(), recordProviders_.end(), dependents);
378 
379  dependents.erase(std::unique(dependents.begin(), dependents.end()), dependents.end());
380 
381  recProvider->resetProxies();
382  for (auto& d : dependents) {
383  d->resetProxies();
384  }
385  }
386 
387  void EventSetupProvider::forceCacheClear() {
388  for (auto& recProvider : recordProviders_) {
389  if (recProvider) {
390  recProvider->resetProxies();
391  }
392  }
393  }
394 
395  void EventSetupProvider::checkESProducerSharing(
396  EventSetupProvider& precedingESProvider,
397  std::set<ParameterSetIDHolder>& sharingCheckDone,
398  std::map<EventSetupRecordKey, std::vector<ComponentDescription const*>>& referencedESProducers,
399  EventSetupsController& esController) {
400  edm::LogVerbatim("EventSetupSharing")
401  << "EventSetupProvider::checkESProducerSharing: Checking processes with SubProcess Indexes "
402  << subProcessIndex() << " and " << precedingESProvider.subProcessIndex();
403 
404  if (referencedESProducers.empty()) {
405  for (auto& recProvider : recordProviders_) {
406  recProvider->getReferencedESProducers(referencedESProducers);
407  }
408  }
409 
410  // This records whether the configurations of all the DataProxyProviders
411  // and finders matches for a particular pair of processes and
412  // a particular record and also the records it depends on.
413  std::map<EventSetupRecordKey, bool> allComponentsMatch;
414 
415  std::map<ParameterSetID, bool> candidateNotRejectedYet;
416 
417  // Loop over all the ESProducers which have a DataProxy
418  // referenced by any EventSetupRecord in this EventSetupProvider
419  for (auto const& iRecord : referencedESProducers) {
420  for (auto const& iComponent : iRecord.second) {
421  ParameterSetID const& psetID = iComponent->pid_;
422  ParameterSetIDHolder psetIDHolder(psetID);
423  if (sharingCheckDone.find(psetIDHolder) != sharingCheckDone.end())
424  continue;
425 
426  bool firstProcessWithThisPSet = false;
427  bool precedingHasMatchingPSet = false;
428 
429  esController.lookForMatches(psetID,
430  subProcessIndex_,
431  precedingESProvider.subProcessIndex_,
432  firstProcessWithThisPSet,
433  precedingHasMatchingPSet);
434 
435  if (firstProcessWithThisPSet) {
436  sharingCheckDone.insert(psetIDHolder);
437  allComponentsMatch[iRecord.first] = false;
438  continue;
439  }
440 
441  if (!precedingHasMatchingPSet) {
442  allComponentsMatch[iRecord.first] = false;
443  continue;
444  }
445 
446  // An ESProducer that survives to this point is a candidate.
447  // It was shared with some other process in the first pass where
448  // ESProducers were constructed and one of three possibilities exists:
449  // 1) It should not have been shared and a new ESProducer needs
450  // to be created and the proper pointers set.
451  // 2) It should have been shared with a different preceding process
452  // in which case some pointers need to be modified.
453  // 3) It was originally shared which the correct prior process
454  // in which case nothing needs to be done, but we do need to
455  // do some work to verify that.
456  // Make an entry in a map for each of these ESProducers. We
457  // will set the value to false if and when we determine
458  // the ESProducer cannot be shared between this pair of processes.
459  auto iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
460  if (iCandidateNotRejectedYet == candidateNotRejectedYet.end()) {
461  candidateNotRejectedYet[psetID] = true;
462  iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
463  }
464 
465  // At this point we know that the two processes both
466  // have an ESProducer matching the type and label in
467  // iComponent and also with exactly the same configuration.
468  // And there was not an earlier preceding process
469  // where the same instance of the ESProducer could
470  // have been shared. And this ESProducer was referenced
471  // by the later process's EventSetupRecord (prefered or
472  // or just the only thing that could have made the data).
473  // To determine if sharing is allowed, now we need to
474  // check if all the DataProxyProviders and all the
475  // finders are the same for this record and also for
476  // all records this record depends on. And even
477  // if this is true, we have to wait until the loop
478  // ends because some other DataProxy associated with
479  // the ESProducer could write to a different record where
480  // the same determination will need to be repeated. Only if
481  // all of the the DataProxy's can be shared, can the ESProducer
482  // instance be shared across processes.
483 
484  if (iCandidateNotRejectedYet->second == true) {
485  auto iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
486  if (iAllComponentsMatch == allComponentsMatch.end()) {
487  // We do not know the value in AllComponents yet and
488  // we need it now so we have to do the difficult calculation
489  // now.
490  bool match = doRecordsMatch(precedingESProvider, iRecord.first, allComponentsMatch, esController);
491  allComponentsMatch[iRecord.first] = match;
492  iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
493  }
494  if (!iAllComponentsMatch->second) {
495  iCandidateNotRejectedYet->second = false;
496  }
497  }
498  } // end loop over components used by record
499  } // end loop over records
500 
501  // Loop over candidates
502  for (auto const& candidate : candidateNotRejectedYet) {
503  ParameterSetID const& psetID = candidate.first;
504  bool canBeShared = candidate.second;
505  if (canBeShared) {
506  ParameterSet const& pset = *esController.getESProducerPSet(psetID, subProcessIndex_);
507  logInfoWhenSharing(pset);
508  ParameterSetIDHolder psetIDHolder(psetID);
509  sharingCheckDone.insert(psetIDHolder);
510  if (esController.isFirstMatch(psetID, subProcessIndex_, precedingESProvider.subProcessIndex_)) {
511  continue; // Proper sharing was already done. Nothing more to do.
512  }
513 
514  // Need to reset the pointer from the EventSetupRecordProvider to the
515  // the DataProxyProvider so these two processes share an ESProducer.
516 
517  std::shared_ptr<DataProxyProvider> dataProxyProvider;
518  std::set<EventSetupRecordKey> const& keysForPSetID1 = (*precedingESProvider.psetIDToRecordKey_)[psetIDHolder];
519  for (auto const& key : keysForPSetID1) {
520  dataProxyProvider = precedingESProvider.recordProvider(key)->proxyProvider(psetIDHolder);
521  assert(dataProxyProvider);
522  break;
523  }
524 
525  std::set<EventSetupRecordKey> const& keysForPSetID2 = (*psetIDToRecordKey_)[psetIDHolder];
526  for (auto const& key : keysForPSetID2) {
527  recordProvider(key)->resetProxyProvider(psetIDHolder, dataProxyProvider);
528  }
529  } else {
530  if (esController.isLastMatch(psetID, subProcessIndex_, precedingESProvider.subProcessIndex_)) {
531  ParameterSet const& pset = *esController.getESProducerPSet(psetID, subProcessIndex_);
532  ModuleFactory::get()->addTo(esController, *this, pset, true);
533  }
534  }
535  }
536  }
537 
538  bool EventSetupProvider::doRecordsMatch(EventSetupProvider& precedingESProvider,
539  EventSetupRecordKey const& eventSetupRecordKey,
540  std::map<EventSetupRecordKey, bool>& allComponentsMatch,
541  EventSetupsController const& esController) {
542  // first check if this record matches. If not just return false
543 
544  // then find the directly dependent records and iterate over them
545  // recursively call this function on them. If they return false
546  // set allComponentsMatch to false for them and return false.
547  // if they all return true then set allComponents to true
548  // and return true.
549 
550  if (precedingESProvider.recordsWithALooperProxy_->find(eventSetupRecordKey) !=
551  precedingESProvider.recordsWithALooperProxy_->end()) {
552  return false;
553  }
554 
555  if ((*recordToFinders_)[eventSetupRecordKey].size() !=
556  (*precedingESProvider.recordToFinders_)[eventSetupRecordKey].size()) {
557  return false;
558  }
559 
560  for (auto const& finder : (*recordToFinders_)[eventSetupRecordKey]) {
561  ParameterSetID const& psetID = finder->descriptionForFinder().pid_;
562  bool itMatches =
563  esController.isMatchingESSource(psetID, subProcessIndex_, precedingESProvider.subProcessIndex_);
564  if (!itMatches) {
565  return false;
566  }
567  }
568 
569  fillReferencedDataKeys(eventSetupRecordKey);
570  precedingESProvider.fillReferencedDataKeys(eventSetupRecordKey);
571 
572  std::map<DataKey, ComponentDescription const*> const& dataItems = (*referencedDataKeys_)[eventSetupRecordKey];
573 
574  std::map<DataKey, ComponentDescription const*> const& precedingDataItems =
575  (*precedingESProvider.referencedDataKeys_)[eventSetupRecordKey];
576 
577  if (dataItems.size() != precedingDataItems.size()) {
578  return false;
579  }
580 
581  for (auto const& dataItem : dataItems) {
582  auto precedingDataItem = precedingDataItems.find(dataItem.first);
583  if (precedingDataItem == precedingDataItems.end()) {
584  return false;
585  }
586  if (dataItem.second->pid_ != precedingDataItem->second->pid_) {
587  return false;
588  }
589  // Check that the configurations match exactly for the ESProducers
590  // (We already checked the ESSources above and there should not be
591  // any loopers)
592  if (!dataItem.second->isSource_ && !dataItem.second->isLooper_) {
593  bool itMatches = esController.isMatchingESProducer(
594  dataItem.second->pid_, subProcessIndex_, precedingESProvider.subProcessIndex_);
595  if (!itMatches) {
596  return false;
597  }
598  }
599  }
600  EventSetupRecordProvider* recProvider = tryToGetRecordProvider(eventSetupRecordKey);
601  if (recProvider != nullptr) {
602  std::set<EventSetupRecordKey> dependentRecords = recProvider->dependentRecords();
603  for (auto const& dependentRecord : dependentRecords) {
604  auto iter = allComponentsMatch.find(dependentRecord);
605  if (iter != allComponentsMatch.end()) {
606  if (iter->second) {
607  continue;
608  } else {
609  return false;
610  }
611  }
612  bool match = doRecordsMatch(precedingESProvider, dependentRecord, allComponentsMatch, esController);
613  allComponentsMatch[dependentRecord] = match;
614  if (!match)
615  return false;
616  }
617  }
618  return true;
619  }
620 
621  void EventSetupProvider::fillReferencedDataKeys(EventSetupRecordKey const& eventSetupRecordKey) {
622  if (referencedDataKeys_->find(eventSetupRecordKey) != referencedDataKeys_->end())
623  return;
624 
625  EventSetupRecordProvider* recProvider = tryToGetRecordProvider(eventSetupRecordKey);
626  if (recProvider == nullptr) {
627  (*referencedDataKeys_)[eventSetupRecordKey];
628  return;
629  }
630  recProvider->fillReferencedDataKeys((*referencedDataKeys_)[eventSetupRecordKey]);
631  }
632 
633  void EventSetupProvider::resetRecordToProxyPointers() {
634  for (auto const& recProvider : recordProviders_) {
636  const EventSetupRecordProvider::DataToPreferredProviderMap* preferredInfo = &kEmptyMap;
637  RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(recProvider->key());
638  if (itRecordFound != recordToPreferred_->end()) {
639  preferredInfo = &(itRecordFound->second);
640  }
641  recProvider->resetRecordToProxyPointers(*preferredInfo);
642  }
643  }
644 
645  void EventSetupProvider::clearInitializationData() {
646  preferredProviderInfo_.reset();
647  referencedDataKeys_.reset();
648  recordToFinders_.reset();
649  psetIDToRecordKey_.reset();
650  recordToPreferred_.reset();
651  recordsWithALooperProxy_.reset();
652  }
653 
654  void EventSetupProvider::addRecordToEventSetup(EventSetupRecordImpl& iRecord) {
655  iRecord.setEventSetup(&eventSetup_);
656  eventSetup_.add(iRecord);
657  }
658 
659  void EventSetupProvider::insert(std::unique_ptr<EventSetupRecordProvider> iRecordProvider) {
660  auto key = iRecordProvider->key();
661  insert(key, std::move(iRecordProvider));
662  }
663 
664  //
665  // const member functions
666  //
667  EventSetupImpl const& EventSetupProvider::eventSetupForInstance(const IOVSyncValue& iValue) {
668  eventSetup_.clear();
669 
670  // In a cmsRun job this does nothing because the EventSetupsController
671  // will have already called finishConfiguration, but some tests will
672  // call finishConfiguration here.
673  if (mustFinishConfiguration_) {
674  finishConfiguration();
675  }
676 
677  for (auto const& recProvider : recordProviders_) {
678  recProvider->addRecordToIfValid(*this, iValue);
679  }
680  return eventSetup_;
681  }
682 
683  std::set<ComponentDescription> EventSetupProvider::proxyProviderDescriptions() const {
684  typedef std::set<ComponentDescription> Set;
685  Set descriptions;
686 
687  for (auto const& recProvider : recordProviders_) {
688  auto const& d = recProvider->proxyProviderDescriptions();
689  descriptions.insert(d.begin(), d.end());
690  }
691  if (dataProviders_.get()) {
692  for (auto const& p : *dataProviders_) {
693  descriptions.insert(p->description());
694  }
695  }
696 
697  return descriptions;
698  }
699 
700  bool EventSetupProvider::isWithinValidityInterval(IOVSyncValue const& iSync) const {
701  for (auto const& recProvider : recordProviders_) {
702  auto const& iov = recProvider->validityInterval();
703  if ((iov != ValidityInterval::invalidInterval()) and (not recProvider->validityInterval().validFor(iSync))) {
704  return false;
705  }
706  }
707  return true;
708  }
709 
710  ESRecordsToProxyIndices EventSetupProvider::recordsToProxyIndices() const {
711  ESRecordsToProxyIndices ret(recordKeys_);
712 
713  unsigned int index = 0;
714  for (auto provider : recordProviders_) {
715  index = ret.dataKeysInRecord(
716  index, provider->key(), provider->registeredDataKeys(), provider->componentsForRegisteredDataKeys());
717  }
718 
719  return ret;
720  }
721 
722  //
723  // static member functions
724  //
725  void EventSetupProvider::logInfoWhenSharing(ParameterSet const& iConfiguration) {
726  std::string edmtype = iConfiguration.getParameter<std::string>("@module_edm_type");
727  std::string modtype = iConfiguration.getParameter<std::string>("@module_type");
728  std::string label = iConfiguration.getParameter<std::string>("@module_label");
729  edm::LogVerbatim("EventSetupSharing")
730  << "Sharing " << edmtype << ": class=" << modtype << " label='" << label << "'";
731  }
732 
733  void EventSetupProvider::addRecord(const EventSetupRecordKey& iKey) {
734  insert(iKey, std::unique_ptr<EventSetupRecordProvider>());
735  eventSetup_.setKeyIters(recordKeys_.begin(), recordKeys_.end());
736  }
737 
738  } // namespace eventsetup
739 } // namespace edm
std::shared_ptr< EventSetupRecordProvider > & recordProvider(const EventSetupRecordKey &iKey)
size
Write out results.
std::map< DataKey, ComponentDescription > DataToPreferredProviderMap
static void findDependents(const EventSetupRecordKey &iKey, Itr itBegin, Itr itEnd, std::vector< std::shared_ptr< EventSetupRecordProvider >> &oDependents)
void lookForMatches(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex, bool &firstProcessWithThisPSet, bool &precedingHasMatchingPSet) const
T getParameter(std::string const &) const
void add(std::shared_ptr< DataProxyProvider >)
void insert(const eventsetup::EventSetupRecordKey &, const eventsetup::EventSetupRecordImpl *)
bool isFirstMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
bool isMatchingESProducer(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
unsigned int dataKeysInRecord(unsigned int iRecordIndex, EventSetupRecordKey const &iRecord, std::vector< DataKey > const &iDataKeys, std::vector< ComponentDescription const * > const &iComponents)
int kp
EventSetupProvider(ActivityRegistry *, unsigned subProcessIndex=0U, PreferredProviderInfo const *iInfo=0)
std::unique_ptr< std::map< ParameterSetIDHolder, std::set< EventSetupRecordKey > > > psetIDToRecordKey_
#define nullptr
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
bool isLastMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
std::unique_ptr< std::map< EventSetupRecordKey, std::map< DataKey, ComponentDescription const * > > > referencedDataKeys_
void fillReferencedDataKeys(std::map< DataKey, ComponentDescription const * > &referencedDataKeys) const
void fillReferencedDataKeys(EventSetupRecordKey const &eventSetupRecordKey)
std::vector< std::pair< DataKey, edm::propagate_const< std::shared_ptr< DataProxy > > > > KeyedProxies
ParameterSet const * getESProducerPSet(ParameterSetID const &psetID, unsigned subProcessIndex) const
RecordProviders::iterator Itr
char const * label
void setEventSetup(EventSetupImpl const *iEventSetup)
std::unique_ptr< std::set< EventSetupRecordKey > > recordsWithALooperProxy_
std::vector< std::shared_ptr< EventSetupRecordProvider >> RecordProviders
static void preferEverything(const ComponentDescription &iComponent, const RecordProviders &iRecordProviders, RecordToPreferred &iReturnValue)
find everything made by a DataProxyProvider and add it to the &#39;preferred&#39; list
def unique(seq, keepstr=True)
Definition: tier0.py:25
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50
void addFinder(std::shared_ptr< EventSetupRecordIntervalFinder >)
For now, only use one finder.
std::unique_ptr< std::map< EventSetupRecordKey, std::vector< std::shared_ptr< EventSetupRecordIntervalFinder > > > > recordToFinders_
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
std::shared_ptr< DataProxyProvider > proxyProvider(ComponentDescription const &)
returns the first matching DataProxyProvider or a &#39;null&#39; if not found
std::vector< size_type > Keys
heterocontainer::HCTypeTag TypeTag
std::set< ComponentDescription > proxyProviderDescriptions() const
return information on which DataProxyProviders are supplying information
std::map< EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap > RecordToPreferred
HLT enums.
static const ValidityInterval & invalidInterval()
std::set< EventSetupRecordKey > dependentRecords() const
Returns the list of Records the provided Record depends on (usually none)
bool isMatchingESSource(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
void resetProxies()
This will clear the cache&#39;s of all the Proxies so that next time they are called they will run...
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)