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