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
31 
32 
33 namespace edm {
34  namespace eventsetup {
35 
36  namespace {
37  class KnownRecordsSupplierImpl : public EventSetupKnownRecordsSupplier {
38  public:
39  using Map = std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >;
40 
41  explicit KnownRecordsSupplierImpl( Map const& iMap) : map_(iMap) {}
42 
43  bool isKnown(EventSetupRecordKey const& iKey) const override {
44  return map_.find(iKey) != map_.end();
45  }
46 
47  private:
48  Map map_;
49  };
50  }
51 
52 //
53 // constants, enums and typedefs
54 //
55 
56 //
57 // static data member definitions
58 //
59 
60 //
61 // constructors and destructor
62 //
64  unsigned subProcessIndex,
65  const PreferredProviderInfo* iInfo) :
66 eventSetup_(activityRegistry),
67 providers_(),
68 knownRecordsSupplier_( std::make_unique<KnownRecordsSupplierImpl>(providers_)),
69 mustFinishConfiguration_(true),
70 subProcessIndex_(subProcessIndex),
71 preferredProviderInfo_((nullptr!=iInfo) ? (new PreferredProviderInfo(*iInfo)): nullptr),
72 finders_(new std::vector<std::shared_ptr<EventSetupRecordIntervalFinder> >() ),
73 dataProviders_(new std::vector<std::shared_ptr<DataProxyProvider> >() ),
74 referencedDataKeys_(new std::map<EventSetupRecordKey, std::map<DataKey, ComponentDescription const*> >),
75 recordToFinders_(new std::map<EventSetupRecordKey, std::vector<std::shared_ptr<EventSetupRecordIntervalFinder> > >),
76 psetIDToRecordKey_(new std::map<ParameterSetIDHolder, std::set<EventSetupRecordKey> >),
77 recordToPreferred_(new std::map<EventSetupRecordKey, std::map<DataKey, ComponentDescription> >),
78 recordsWithALooperProxy_(new std::set<EventSetupRecordKey>)
79 {
80  eventSetup_.setKnownRecordsSupplier(knownRecordsSupplier_.get());
81 }
82 
83 // EventSetupProvider::EventSetupProvider(const EventSetupProvider& rhs)
84 // {
85 // // do actual copying here;
86 // }
87 
88 EventSetupProvider::~EventSetupProvider()
89 {
90 }
91 
92 //
93 // assignment operators
94 //
95 // const EventSetupProvider& EventSetupProvider::operator=(const EventSetupProvider& rhs)
96 // {
97 // //An exception safe implementation is
98 // EventSetupProvider temp(rhs);
99 // swap(rhs);
100 //
101 // return *this;
102 // }
103 
104 //
105 // member functions
106 //
107 void
108 EventSetupProvider::insert(const EventSetupRecordKey& iKey, std::unique_ptr<EventSetupRecordProvider> iProvider)
109 {
110  std::shared_ptr<EventSetupRecordProvider> temp(iProvider.release());
111  providers_[iKey] = temp;
112  //temp->addRecordTo(*this);
113 }
114 
115 void
116 EventSetupProvider::add(std::shared_ptr<DataProxyProvider> iProvider)
117 {
118  assert(iProvider.get() != nullptr);
119  dataProviders_->push_back(iProvider);
120 }
121 
122 void
123 EventSetupProvider::replaceExisting(std::shared_ptr<DataProxyProvider> dataProxyProvider)
124 {
125  ParameterSetIDHolder psetID(dataProxyProvider->description().pid_);
126  std::set<EventSetupRecordKey> const& keysForPSetID = (*psetIDToRecordKey_)[psetID];
127  for (auto const& key : keysForPSetID) {
128  std::shared_ptr<EventSetupRecordProvider> const& recordProvider = providers_[key];
129  recordProvider->resetProxyProvider(psetID, dataProxyProvider);
130  }
131 }
132 
133 void
134 EventSetupProvider::add(std::shared_ptr<EventSetupRecordIntervalFinder> iFinder)
135 {
136  assert(iFinder.get() != nullptr);
137  finders_->push_back(iFinder);
138 }
139 
140 typedef std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> > Providers;
141 typedef std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap> RecordToPreferred;
143 static
144 void
146  const Providers& iProviders,
147  RecordToPreferred& iReturnValue)
148 {
149  //need to get our hands on the actual DataProxyProvider
150  bool foundProxyProvider = false;
151  for(Providers::const_iterator itProvider = iProviders.begin(), itProviderEnd = iProviders.end();
152  itProvider!= itProviderEnd;
153  ++itProvider) {
154  std::set<ComponentDescription> components = itProvider->second->proxyProviderDescriptions();
155  if(components.find(iComponent)!= components.end()) {
156  std::shared_ptr<DataProxyProvider> proxyProv =
157  itProvider->second->proxyProvider(*(components.find(iComponent)));
158  assert(proxyProv.get());
159 
160  std::set<EventSetupRecordKey> records = proxyProv->usingRecords();
161  for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
162  itRecordEnd = records.end();
163  itRecord != itRecordEnd;
164  ++itRecord){
165  const DataProxyProvider::KeyedProxies& keyedProxies = proxyProv->keyedProxies(*itRecord);
166  if(!keyedProxies.empty()){
167  //add them to our output
169  iReturnValue[*itRecord];
170 
171  for(DataProxyProvider::KeyedProxies::const_iterator itProxy = keyedProxies.begin(),
172  itProxyEnd = keyedProxies.end();
173  itProxy != itProxyEnd;
174  ++itProxy) {
175  EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
176  dataToProviderMap.find(itProxy->first);
177  if(itFind != dataToProviderMap.end()){
178  throw cms::Exception("ESPreferConflict") <<"Two providers have been set to be preferred for\n"
179  <<itProxy->first.type().name()<<" \""<<itProxy->first.name().value()<<"\""
180  <<"\n the providers are "
181  <<"\n 1) type="<<itFind->second.type_<<" label=\""<<itFind->second.label_<<"\""
182  <<"\n 2) type="<<iComponent.type_<<" label=\""<<iComponent.label_<<"\""
183  <<"\nPlease modify configuration so only one is preferred";
184  }
185  dataToProviderMap.insert(std::make_pair(itProxy->first,iComponent));
186  }
187  }
188  }
189  foundProxyProvider=true;
190  break;
191  }
192  }
193  if(!foundProxyProvider) {
194  throw cms::Exception("ESPreferNoProvider")<<"Could not make type=\""<<iComponent.type_
195  <<"\" label=\""<<iComponent.label_<<"\" a preferred Provider."<<
196  "\n Please check spelling of name, or that it was loaded into the job.";
197  }
198 }
199 static
201  const Providers& iProviders)
202 {
203  using namespace edm::eventsetup;
204  RecordToPreferred returnValue;
205  if(nullptr != iInfo){
206  for(EventSetupProvider::PreferredProviderInfo::const_iterator itInfo = iInfo->begin(),
207  itInfoEnd = iInfo->end();
208  itInfo != itInfoEnd;
209  ++itInfo) {
210  if(itInfo->second.empty()) {
211  //want everything
212  preferEverything(itInfo->first, iProviders, returnValue);
213  } else {
214  for(EventSetupProvider::RecordToDataMap::const_iterator itRecData = itInfo->second.begin(),
215  itRecDataEnd = itInfo->second.end();
216  itRecData != itRecDataEnd;
217  ++itRecData) {
218  std::string recordName= itRecData->first;
220  if(recordKey.type() == eventsetup::EventSetupRecordKey::TypeTag()) {
221  throw cms::Exception("ESPreferUnknownRecord") <<"Unknown record \""<<recordName
222  <<"\" used in es_prefer statement for type="
223  <<itInfo->first.type_<<" label=\""<<itInfo->first.label_
224  <<"\"\n Please check spelling.";
225  //record not found
226  }
227  //See if the ProxyProvider provides something for this Record
228  Providers::const_iterator itRecordProvider = iProviders.find(recordKey);
229  assert(itRecordProvider != iProviders.end());
230 
231  std::set<ComponentDescription> components = itRecordProvider->second->proxyProviderDescriptions();
232  std::set<ComponentDescription>::iterator itProxyProv = components.find(itInfo->first);
233  if(itProxyProv == components.end()){
234  throw cms::Exception("ESPreferWrongRecord")<<"The type="<<itInfo->first.type_<<" label=\""<<
235  itInfo->first.label_<<"\" does not provide data for the Record "<<recordName;
236  }
237  //Does it data type exist?
238  eventsetup::TypeTag datumType = eventsetup::TypeTag::findType(itRecData->second.first);
239  if(datumType == eventsetup::TypeTag()) {
240  //not found
241  throw cms::Exception("ESPreferWrongDataType")<<"The es_prefer statement for type="<<itInfo->first.type_<<" label=\""<<
242  itInfo->first.label_<<"\" has the unknown data type \""<<itRecData->second.first<<"\""
243  <<"\n Please check spelling";
244  }
245  eventsetup::DataKey datumKey(datumType, itRecData->second.second.c_str());
246 
247  //Does the proxyprovider make this?
248  std::shared_ptr<DataProxyProvider> proxyProv =
249  itRecordProvider->second->proxyProvider(*itProxyProv);
250  const DataProxyProvider::KeyedProxies& keyedProxies = proxyProv->keyedProxies(recordKey);
251  if(std::find_if(keyedProxies.begin(), keyedProxies.end(),
252  [&datumKey](auto const& kp) { return kp.first == datumKey;}) ==
253  keyedProxies.end()){
254  throw cms::Exception("ESPreferWrongData")<<"The es_prefer statement for type="<<itInfo->first.type_<<" label=\""<<
255  itInfo->first.label_<<"\" specifies the data item \n"
256  <<" type=\""<<itRecData->second.first<<"\" label=\""<<itRecData->second.second<<"\""
257  <<" which is not provided. Please check spelling.";
258  }
259 
261  =returnValue[recordKey];
262  //has another provider already been specified?
263  if(dataToProviderMap.end() != dataToProviderMap.find(datumKey)) {
264  EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
265  dataToProviderMap.find(datumKey);
266  throw cms::Exception("ESPreferConflict") <<"Two providers have been set to be preferred for\n"
267  <<datumKey.type().name()<<" \""<<datumKey.name().value()<<"\""
268  <<"\n the providers are "
269  <<"\n 1) type="<<itFind->second.type_<<" label=\""<<itFind->second.label_<<"\""
270  <<"\n 2) type="<<itProxyProv->type_<<" label=\""<<itProxyProv->label_<<"\""
271  <<"\nPlease modify configuration so only one is preferred";
272  }
273  dataToProviderMap.insert(std::make_pair(datumKey,*itProxyProv));
274  }
275  }
276  }
277  }
278  return returnValue;
279 }
280 
281 void
282 EventSetupProvider::finishConfiguration()
283 {
284  //we delayed adding finders to the system till here so that everything would be loaded first
285  recordToFinders_->clear();
286  for(std::vector<std::shared_ptr<EventSetupRecordIntervalFinder> >::iterator itFinder=finders_->begin(),
287  itEnd = finders_->end();
288  itFinder != itEnd;
289  ++itFinder) {
290  typedef std::set<EventSetupRecordKey> Keys;
291  const Keys recordsUsing = (*itFinder)->findingForRecords();
292 
293  for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
294  itKey != itKeyEnd;
295  ++itKey) {
296  (*recordToFinders_)[*itKey].push_back(*itFinder);
297  Providers::iterator itFound = providers_.find(*itKey);
298  if(providers_.end() == itFound) {
299  //create a provider for this record
300  insert(*itKey,
301  std::make_unique<EventSetupRecordProvider>(*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, std::make_unique<EventSetupRecordProvider>(*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(EventSetupRecordImpl& iRecord) {
738  iRecord.setEventSetup(&eventSetup_);
739  eventSetup_.add(iRecord);
740 }
741 
742 void
743 EventSetupProvider::insert(std::unique_ptr<EventSetupRecordProvider> iRecordProvider) {
744  auto key =iRecordProvider->key();
745  insert( key, std::move(iRecordProvider));
746 }
747 
748 //
749 // const member functions
750 //
751 EventSetup const&
752 EventSetupProvider::eventSetupForInstance(const IOVSyncValue& iValue)
753 {
754  eventSetup_.clear();
755 
756  // In a cmsRun job this does nothing because the EventSetupsController
757  // will have already called finishConfiguration, but some tests will
758  // call finishConfiguration here.
759  if(mustFinishConfiguration_) {
760  finishConfiguration();
761  }
762 
763  for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
764  itProvider != itProviderEnd;
765  ++itProvider) {
766  itProvider->second->addRecordToIfValid(*this, iValue);
767  }
768  return eventSetup_;
769 }
770 
771 std::set<ComponentDescription>
772 EventSetupProvider::proxyProviderDescriptions() const
773 {
774  typedef std::set<ComponentDescription> Set;
775  Set descriptions;
776 
777  for(auto const& p: providers_) {
778  auto const& d = p.second->proxyProviderDescriptions();
779  descriptions.insert(d.begin(),d.end());
780  }
781  if(dataProviders_.get()) {
782  for(auto const& p: *dataProviders_) {
783  descriptions.insert(p->description());
784  }
785  }
786 
787  return descriptions;
788 }
789 
790 bool
791 EventSetupProvider::isWithinValidityInterval(IOVSyncValue const& iSync) const {
792  for( auto const& provider: providers_) {
793  auto const& iov =provider.second->validityInterval();
794  if( (iov != ValidityInterval::invalidInterval()) and
795  (not provider.second->validityInterval().validFor(iSync)) ) {
796  return false;
797  }
798  }
799  return true;
800 }
801 //
802 // static member functions
803 //
804 void EventSetupProvider::logInfoWhenSharing(ParameterSet const& iConfiguration) {
805 
806  std::string edmtype = iConfiguration.getParameter<std::string>("@module_edm_type");
807  std::string modtype = iConfiguration.getParameter<std::string>("@module_type");
808  std::string label = iConfiguration.getParameter<std::string>("@module_label");
809  edm::LogVerbatim("EventSetupSharing") << "Sharing " << edmtype << ": class=" << modtype << " label='" << label << "'";
810 }
811  }
812 }
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_
void setEventSetup(EventSetup const *iEventSetup)
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
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
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
def move(src, dest)
Definition: eostools.py:510
T get(const Candidate &c)
Definition: component.h:55
Providers::iterator Itr