35 namespace eventsetup {
40 using Map = std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >;
42 explicit KnownRecordsSupplierImpl( Map
const& iMap) :
map_(iMap) {}
45 return map_.find(iKey) !=
map_.end();
65 unsigned subProcessIndex,
66 const PreferredProviderInfo* iInfo) :
67 eventSetup_(activityRegistry),
69 knownRecordsSupplier_(
std::make_unique<KnownRecordsSupplierImpl>(providers_)),
70 mustFinishConfiguration_(
true),
71 subProcessIndex_(subProcessIndex),
72 preferredProviderInfo_((
nullptr!=iInfo) ? (new PreferredProviderInfo(*iInfo)):
nullptr),
81 eventSetup_.setKnownRecordsSupplier(knownRecordsSupplier_.get());
89 EventSetupProvider::~EventSetupProvider()
111 std::shared_ptr<EventSetupRecordProvider>
temp(iProvider.release());
112 providers_[iKey] =
temp;
119 assert(iProvider.get() !=
nullptr);
120 dataProviders_->push_back(iProvider);
124 EventSetupProvider::replaceExisting(std::shared_ptr<DataProxyProvider> dataProxyProvider)
127 std::set<EventSetupRecordKey>
const& keysForPSetID = (*psetIDToRecordKey_)[psetID];
128 for (
auto const&
key : keysForPSetID) {
129 std::shared_ptr<EventSetupRecordProvider>
const& recordProvider = providers_[
key];
130 recordProvider->resetProxyProvider(psetID, dataProxyProvider);
137 assert(iFinder.get() !=
nullptr);
138 finders_->push_back(iFinder);
141 typedef std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >
Providers;
142 typedef std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap>
RecordToPreferred;
147 const Providers& iProviders,
148 RecordToPreferred& iReturnValue)
151 bool foundProxyProvider =
false;
152 for(Providers::const_iterator itProvider = iProviders.begin(), itProviderEnd = iProviders.end();
153 itProvider!= itProviderEnd;
155 std::set<ComponentDescription>
components = itProvider->second->proxyProviderDescriptions();
156 if(components.find(iComponent)!= components.end()) {
157 std::shared_ptr<DataProxyProvider> proxyProv =
158 itProvider->second->proxyProvider(*(components.find(iComponent)));
159 assert(proxyProv.get());
161 std::set<EventSetupRecordKey> records = proxyProv->usingRecords();
162 for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
163 itRecordEnd = records.end();
164 itRecord != itRecordEnd;
167 if(!keyedProxies.empty()){
170 iReturnValue[*itRecord];
172 for(DataProxyProvider::KeyedProxies::const_iterator itProxy = keyedProxies.begin(),
173 itProxyEnd = keyedProxies.end();
174 itProxy != itProxyEnd;
176 EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
177 dataToProviderMap.find(itProxy->first);
178 if(itFind != dataToProviderMap.end()){
179 throw cms::Exception(
"ESPreferConflict") <<
"Two providers have been set to be preferred for\n" 180 <<itProxy->first.type().name()<<
" \""<<itProxy->first.name().value()<<
"\"" 181 <<
"\n the providers are " 182 <<
"\n 1) type="<<itFind->second.type_<<
" label=\""<<itFind->second.label_<<
"\"" 183 <<
"\n 2) type="<<iComponent.
type_<<
" label=\""<<iComponent.
label_<<
"\"" 184 <<
"\nPlease modify configuration so only one is preferred";
186 dataToProviderMap.insert(std::make_pair(itProxy->first,iComponent));
190 foundProxyProvider=
true;
194 if(!foundProxyProvider) {
196 <<
"\" label=\""<<iComponent.
label_<<
"\" a preferred Provider."<<
197 "\n Please check spelling of name, or that it was loaded into the job.";
202 const Providers& iProviders)
205 RecordToPreferred returnValue;
206 if(
nullptr != iInfo){
207 for(EventSetupProvider::PreferredProviderInfo::const_iterator itInfo = iInfo->begin(),
208 itInfoEnd = iInfo->end();
211 if(itInfo->second.empty()) {
215 for(EventSetupProvider::RecordToDataMap::const_iterator itRecData = itInfo->second.begin(),
216 itRecDataEnd = itInfo->second.end();
217 itRecData != itRecDataEnd;
222 throw cms::Exception(
"ESPreferUnknownRecord") <<
"Unknown record \""<<recordName
223 <<
"\" used in es_prefer statement for type=" 224 <<itInfo->first.type_<<
" label=\""<<itInfo->first.label_
225 <<
"\"\n Please check spelling.";
229 Providers::const_iterator itRecordProvider = iProviders.find(recordKey);
230 assert(itRecordProvider != iProviders.end());
232 std::set<ComponentDescription>
components = itRecordProvider->second->proxyProviderDescriptions();
233 std::set<ComponentDescription>::iterator itProxyProv = components.find(itInfo->first);
234 if(itProxyProv == components.end()){
235 throw cms::Exception(
"ESPreferWrongRecord")<<
"The type="<<itInfo->first.type_<<
" label=\""<<
236 itInfo->first.label_<<
"\" does not provide data for the Record "<<
recordName;
242 throw cms::Exception(
"ESPreferWrongDataType")<<
"The es_prefer statement for type="<<itInfo->first.type_<<
" label=\""<<
243 itInfo->first.label_<<
"\" has the unknown data type \""<<itRecData->second.first<<
"\"" 244 <<
"\n Please check spelling";
249 std::shared_ptr<DataProxyProvider> proxyProv =
250 itRecordProvider->second->proxyProvider(*itProxyProv);
252 if(std::find_if(keyedProxies.begin(), keyedProxies.end(),
253 [&datumKey](
auto const& kp) {
return kp.first == datumKey;}) ==
255 throw cms::Exception(
"ESPreferWrongData")<<
"The es_prefer statement for type="<<itInfo->first.type_<<
" label=\""<<
256 itInfo->first.label_<<
"\" specifies the data item \n" 257 <<
" type=\""<<itRecData->second.first<<
"\" label=\""<<itRecData->second.second<<
"\"" 258 <<
" which is not provided. Please check spelling.";
262 =returnValue[recordKey];
264 if(dataToProviderMap.end() != dataToProviderMap.find(datumKey)) {
265 EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
266 dataToProviderMap.find(datumKey);
267 throw cms::Exception(
"ESPreferConflict") <<
"Two providers have been set to be preferred for\n" 268 <<datumKey.type().name()<<
" \""<<datumKey.name().value()<<
"\"" 269 <<
"\n the providers are " 270 <<
"\n 1) type="<<itFind->second.type_<<
" label=\""<<itFind->second.label_<<
"\"" 271 <<
"\n 2) type="<<itProxyProv->type_<<
" label=\""<<itProxyProv->label_<<
"\"" 272 <<
"\nPlease modify configuration so only one is preferred";
274 dataToProviderMap.insert(std::make_pair(datumKey,*itProxyProv));
283 EventSetupProvider::finishConfiguration()
286 recordToFinders_->clear();
287 for(std::vector<std::shared_ptr<EventSetupRecordIntervalFinder> >::iterator itFinder=finders_->begin(),
288 itEnd = finders_->end();
291 typedef std::set<EventSetupRecordKey>
Keys;
292 const Keys recordsUsing = (*itFinder)->findingForRecords();
294 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
297 (*recordToFinders_)[*itKey].push_back(*itFinder);
298 Providers::iterator itFound = providers_.find(*itKey);
299 if(providers_.end() == itFound) {
302 itFound = providers_.find(*itKey);
304 itFound->second->addFinder(*itFinder);
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();
321 const Keys recordsUsing = (*itProvider)->usingRecords();
323 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
327 if ((*itProvider)->description().isLooper_) {
328 recordsWithALooperProxy_->insert(*itKey);
331 (*psetIDToRecordKey_)[psetID].insert(*itKey);
333 Providers::iterator itFound = providers_.find(*itKey);
334 if(providers_.end() == itFound) {
337 itFound = providers_.find(*itKey);
339 itFound->second->add(*itProvider);
342 dataProviders_.reset();
351 for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
352 itProvider != itProviderEnd;
355 RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(itProvider->first);
356 if(itRecordFound != recordToPreferred_->end()) {
357 preferredInfo = &(itRecordFound->second);
360 itProvider->second->usePreferred(*preferredInfo);
362 std::set<EventSetupRecordKey> records = itProvider->second->dependentRecords();
363 if(!records.empty()) {
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;
372 Providers::iterator itFound = providers_.find(*itRecord);
373 if(itFound == providers_.end()) {
374 foundAllProviders =
false;
375 if(missingRecords.empty()) {
376 missingRecords = itRecord->name();
378 missingRecords +=
", ";
379 missingRecords += itRecord->name();
383 depProviders.push_back(itFound->second);
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.";
396 itProvider->second->setDependentProviders(depProviders);
399 mustFinishConfiguration_ =
false;
402 typedef std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >
Providers;
403 typedef Providers::iterator
Itr;
409 std::vector<std::shared_ptr<EventSetupRecordProvider> >& oDependents)
412 for(Itr it = itBegin; it != itEnd; ++it) {
414 const std::set<EventSetupRecordKey>&
deps = it->second->dependentRecords();
415 if(deps.end() != deps.find(iKey)) {
416 oDependents.push_back(it->second);
426 Providers::iterator itFind = providers_.find(iKey);
427 if(itFind == providers_.end()) {
432 std::vector<std::shared_ptr<EventSetupRecordProvider> > dependents;
433 findDependents(iKey, providers_.begin(), providers_.end(), dependents);
435 dependents.erase(
std::unique(dependents.begin(),dependents.end()), dependents.end());
437 itFind->second->resetProxies();
438 for(
auto&
d: dependents) {
444 EventSetupProvider::forceCacheClear()
446 for(Providers::iterator it=providers_.begin(), itEnd = providers_.end();
449 it->second->resetProxies();
455 std::set<ParameterSetIDHolder>& sharingCheckDone,
459 edm::LogVerbatim(
"EventSetupSharing") <<
"EventSetupProvider::checkESProducerSharing: Checking processes with SubProcess Indexes " 460 << subProcessIndex() <<
" and " << precedingESProvider.
subProcessIndex();
462 if (referencedESProducers.empty()) {
463 for (
auto const& recordProvider : providers_) {
464 recordProvider.second->getReferencedESProducers(referencedESProducers);
471 std::map<EventSetupRecordKey, bool> allComponentsMatch;
473 std::map<ParameterSetID, bool> candidateNotRejectedYet;
477 for (
auto const& iRecord : referencedESProducers) {
478 for (
auto const& iComponent : iRecord.second) {
482 if (sharingCheckDone.find(psetIDHolder) != sharingCheckDone.end())
continue;
484 bool firstProcessWithThisPSet =
false;
485 bool precedingHasMatchingPSet =
false;
490 firstProcessWithThisPSet,
491 precedingHasMatchingPSet);
493 if (firstProcessWithThisPSet) {
494 sharingCheckDone.insert(psetIDHolder);
495 allComponentsMatch[iRecord.first] =
false;
499 if (!precedingHasMatchingPSet) {
500 allComponentsMatch[iRecord.first] =
false;
517 auto iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
518 if (iCandidateNotRejectedYet == candidateNotRejectedYet.end()) {
519 candidateNotRejectedYet[psetID] =
true;
520 iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
542 if (iCandidateNotRejectedYet->second ==
true) {
544 auto iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
545 if (iAllComponentsMatch == allComponentsMatch.end()) {
550 bool match = doRecordsMatch(precedingESProvider,
554 allComponentsMatch[iRecord.first] =
match;
555 iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
557 if (!iAllComponentsMatch->second) {
558 iCandidateNotRejectedYet->second =
false;
565 for (
auto const& candidate : candidateNotRejectedYet) {
567 bool canBeShared = candidate.second;
570 logInfoWhenSharing(pset);
572 sharingCheckDone.insert(psetIDHolder);
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);
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);
616 std::map<EventSetupRecordKey, bool> & allComponentsMatch,
630 if ((*recordToFinders_)[eventSetupRecordKey].size() != (*precedingESProvider.
recordToFinders_)[eventSetupRecordKey].
size()) {
634 for (
auto const&
finder : (*recordToFinders_)[eventSetupRecordKey]) {
644 fillReferencedDataKeys(eventSetupRecordKey);
647 std::map<DataKey, ComponentDescription const*>
const& dataItems = (*referencedDataKeys_)[eventSetupRecordKey];
649 std::map<DataKey, ComponentDescription const*>
const& precedingDataItems = (*precedingESProvider.
referencedDataKeys_)[eventSetupRecordKey];
651 if (dataItems.size() != precedingDataItems.size()) {
655 for (
auto const& dataItem : dataItems) {
656 auto precedingDataItem = precedingDataItems.find(dataItem.first);
657 if (precedingDataItem == precedingDataItems.end()) {
660 if (dataItem.second->pid_ != precedingDataItem->second->pid_) {
666 if (!dataItem.second->isSource_ && !dataItem.second->isLooper_) {
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()) {
687 bool match = doRecordsMatch(precedingESProvider,
691 allComponentsMatch[dependentRecord] =
match;
692 if (!match)
return false;
701 if (referencedDataKeys_->find(eventSetupRecordKey) != referencedDataKeys_->end())
return;
703 auto recordProvider = providers_.find(eventSetupRecordKey);
704 if (recordProvider == providers_.end()) {
705 (*referencedDataKeys_)[eventSetupRecordKey];
708 if (recordProvider->second) {
709 recordProvider->second->fillReferencedDataKeys((*referencedDataKeys_)[eventSetupRecordKey]);
714 EventSetupProvider::resetRecordToProxyPointers() {
715 for (
auto const& recordProvider : providers_) {
718 RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(recordProvider.first);
719 if(itRecordFound != recordToPreferred_->end()) {
720 preferredInfo = &(itRecordFound->second);
722 recordProvider.second->resetRecordToProxyPointers(*preferredInfo);
727 EventSetupProvider::clearInitializationData() {
728 preferredProviderInfo_.reset();
729 referencedDataKeys_.reset();
730 recordToFinders_.reset();
731 psetIDToRecordKey_.reset();
732 recordToPreferred_.reset();
733 recordsWithALooperProxy_.reset();
739 eventSetup_.add(iRecord);
753 if(mustFinishConfiguration_) {
754 finishConfiguration();
757 for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
758 itProvider != itProviderEnd;
760 itProvider->second->addRecordToIfValid(*
this, iValue);
765 std::set<ComponentDescription>
766 EventSetupProvider::proxyProviderDescriptions()
const 768 typedef std::set<ComponentDescription> Set;
771 for(
auto const&
p: providers_) {
772 auto const&
d =
p.second->proxyProviderDescriptions();
773 descriptions.insert(
d.begin(),
d.end());
775 if(dataProviders_.get()) {
776 for(
auto const&
p: *dataProviders_) {
777 descriptions.insert(
p->description());
785 EventSetupProvider::isWithinValidityInterval(
IOVSyncValue const& iSync)
const {
786 for(
auto const& provider: providers_) {
787 auto const& iov =provider.second->validityInterval();
788 if( (iov != ValidityInterval::invalidInterval()) and
789 (not provider.second->validityInterval().validFor(iSync)) ) {
798 void EventSetupProvider::logInfoWhenSharing(
ParameterSet const& iConfiguration) {
803 edm::LogVerbatim(
"EventSetupSharing") <<
"Sharing " << edmtype <<
": class=" << modtype <<
" label='" << label <<
"'";
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
std::pair< const char *, const std::type_info * > findType(const char *iClassName)
bool isFirstMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
bool isMatchingESProducer(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
static PFTauRenderPlugin instance
EventSetupProvider(ActivityRegistry *, unsigned subProcessIndex=0U, PreferredProviderInfo const *iInfo=0)
std::unique_ptr< std::map< ParameterSetIDHolder, std::set< EventSetupRecordKey > > > psetIDToRecordKey_
bool isLastMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
std::unique_ptr< std::map< EventSetupRecordKey, std::map< DataKey, ComponentDescription const * > > > referencedDataKeys_
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
std::unique_ptr< std::set< EventSetupRecordKey > > recordsWithALooperProxy_
def unique(seq, keepstr=True)
std::map< EventSetupRecordKey, std::shared_ptr< EventSetupRecordProvider > > Providers
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
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 'preferred' list
std::vector< size_type > Keys
unsigned subProcessIndex() const
const TypeTag & type() const
bool isMatchingESSource(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
void setEventSetup(EventSetup const *iEventSetup)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
unsigned subProcessIndex_
T get(const Candidate &c)