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