CMS 3D CMS Logo

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