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();
67 knownRecordsSupplier_(
std::make_unique<KnownRecordsSupplierImpl>(providers_)),
68 mustFinishConfiguration_(
true),
69 subProcessIndex_(subProcessIndex),
70 preferredProviderInfo_((0!=iInfo) ? (new PreferredProviderInfo(*iInfo)): 0),
79 eventSetup_.setKnownRecordsSupplier(knownRecordsSupplier_.get());
87 EventSetupProvider::~EventSetupProvider()
109 std::shared_ptr<EventSetupRecordProvider>
temp(iProvider.release());
110 providers_[iKey] =
temp;
117 assert(iProvider.get() != 0);
118 dataProviders_->push_back(iProvider);
122 EventSetupProvider::replaceExisting(std::shared_ptr<DataProxyProvider> dataProxyProvider)
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);
135 assert(iFinder.get() != 0);
136 finders_->push_back(iFinder);
139 typedef std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >
Providers;
140 typedef std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap>
RecordToPreferred;
145 const Providers& iProviders,
146 RecordToPreferred& iReturnValue)
149 bool foundProxyProvider =
false;
150 for(Providers::const_iterator itProvider = iProviders.begin(), itProviderEnd = iProviders.end();
151 itProvider!= itProviderEnd;
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());
159 std::set<EventSetupRecordKey> records = proxyProv->usingRecords();
160 for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
161 itRecordEnd = records.end();
162 itRecord != itRecordEnd;
165 if(!keyedProxies.empty()){
168 iReturnValue[*itRecord];
170 for(DataProxyProvider::KeyedProxies::const_iterator itProxy = keyedProxies.begin(),
171 itProxyEnd = keyedProxies.end();
172 itProxy != itProxyEnd;
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";
184 dataToProviderMap.insert(std::make_pair(itProxy->first,iComponent));
188 foundProxyProvider=
true;
192 if(!foundProxyProvider) {
194 <<
"\" label=\""<<iComponent.
label_<<
"\" a preferred Provider."<<
195 "\n Please check spelling of name, or that it was loaded into the job.";
200 const Providers& iProviders)
203 RecordToPreferred returnValue;
205 for(EventSetupProvider::PreferredProviderInfo::const_iterator itInfo = iInfo->begin(),
206 itInfoEnd = iInfo->end();
209 if(itInfo->second.empty()) {
213 for(EventSetupProvider::RecordToDataMap::const_iterator itRecData = itInfo->second.begin(),
214 itRecDataEnd = itInfo->second.end();
215 itRecData != itRecDataEnd;
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.";
227 Providers::const_iterator itRecordProvider = iProviders.find(recordKey);
228 assert(itRecordProvider != iProviders.end());
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;
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";
247 std::shared_ptr<DataProxyProvider> proxyProv =
248 itRecordProvider->second->proxyProvider(*itProxyProv);
250 if(std::find_if(keyedProxies.begin(), keyedProxies.end(),
251 [&datumKey](
auto const&
kp) {
return kp.first == datumKey;}) ==
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.";
260 =returnValue[recordKey];
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";
272 dataToProviderMap.insert(std::make_pair(datumKey,*itProxyProv));
281 EventSetupProvider::finishConfiguration()
284 recordToFinders_->clear();
285 for(std::vector<std::shared_ptr<EventSetupRecordIntervalFinder> >::iterator itFinder=finders_->begin(),
286 itEnd = finders_->end();
289 typedef std::set<EventSetupRecordKey>
Keys;
290 const Keys recordsUsing = (*itFinder)->findingForRecords();
292 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
295 (*recordToFinders_)[*itKey].push_back(*itFinder);
296 Providers::iterator itFound = providers_.find(*itKey);
297 if(providers_.end() == itFound) {
300 itFound = providers_.find(*itKey);
302 itFound->second->addFinder(*itFinder);
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();
319 const Keys recordsUsing = (*itProvider)->usingRecords();
321 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
325 if ((*itProvider)->description().isLooper_) {
326 recordsWithALooperProxy_->insert(*itKey);
329 (*psetIDToRecordKey_)[psetID].insert(*itKey);
331 Providers::iterator itFound = providers_.find(*itKey);
332 if(providers_.end() == itFound) {
335 itFound = providers_.find(*itKey);
337 itFound->second->add(*itProvider);
340 dataProviders_.reset();
349 for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
350 itProvider != itProviderEnd;
353 RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(itProvider->first);
354 if(itRecordFound != recordToPreferred_->end()) {
355 preferredInfo = &(itRecordFound->second);
358 itProvider->second->usePreferred(*preferredInfo);
360 std::set<EventSetupRecordKey> records = itProvider->second->dependentRecords();
361 if(records.size() != 0) {
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;
370 Providers::iterator itFound = providers_.find(*itRecord);
371 if(itFound == providers_.end()) {
372 foundAllProviders =
false;
373 if(missingRecords.size() == 0) {
374 missingRecords = itRecord->name();
376 missingRecords +=
", ";
377 missingRecords += itRecord->name();
381 depProviders.push_back(itFound->second);
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.";
394 itProvider->second->setDependentProviders(depProviders);
397 mustFinishConfiguration_ =
false;
400 typedef std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >
Providers;
401 typedef Providers::iterator
Itr;
407 std::vector<std::shared_ptr<EventSetupRecordProvider> >& oDependents)
410 for(Itr it = itBegin; it != itEnd; ++it) {
412 const std::set<EventSetupRecordKey>&
deps = it->second->dependentRecords();
413 if(deps.end() != deps.find(iKey)) {
414 oDependents.push_back(it->second);
424 Providers::iterator itFind = providers_.find(iKey);
425 if(itFind == providers_.end()) {
430 std::vector<std::shared_ptr<EventSetupRecordProvider> > dependents;
431 findDependents(iKey, providers_.begin(), providers_.end(), dependents);
433 dependents.erase(
std::unique(dependents.begin(),dependents.end()), dependents.end());
435 itFind->second->resetProxies();
436 for(
auto&
d: dependents) {
442 EventSetupProvider::forceCacheClear()
444 for(Providers::iterator it=providers_.begin(), itEnd = providers_.end();
447 it->second->resetProxies();
453 std::set<ParameterSetIDHolder>& sharingCheckDone,
457 edm::LogVerbatim(
"EventSetupSharing") <<
"EventSetupProvider::checkESProducerSharing: Checking processes with SubProcess Indexes " 458 << subProcessIndex() <<
" and " << precedingESProvider.
subProcessIndex();
460 if (referencedESProducers.empty()) {
461 for (
auto const& recordProvider : providers_) {
462 recordProvider.second->getReferencedESProducers(referencedESProducers);
469 std::map<EventSetupRecordKey, bool> allComponentsMatch;
471 std::map<ParameterSetID, bool> candidateNotRejectedYet;
475 for (
auto const& iRecord : referencedESProducers) {
476 for (
auto const& iComponent : iRecord.second) {
480 if (sharingCheckDone.find(psetIDHolder) != sharingCheckDone.end())
continue;
482 bool firstProcessWithThisPSet =
false;
483 bool precedingHasMatchingPSet =
false;
488 firstProcessWithThisPSet,
489 precedingHasMatchingPSet);
491 if (firstProcessWithThisPSet) {
492 sharingCheckDone.insert(psetIDHolder);
493 allComponentsMatch[iRecord.first] =
false;
497 if (!precedingHasMatchingPSet) {
498 allComponentsMatch[iRecord.first] =
false;
515 auto iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
516 if (iCandidateNotRejectedYet == candidateNotRejectedYet.end()) {
517 candidateNotRejectedYet[psetID] =
true;
518 iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
540 if (iCandidateNotRejectedYet->second ==
true) {
542 auto iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
543 if (iAllComponentsMatch == allComponentsMatch.end()) {
548 bool match = doRecordsMatch(precedingESProvider,
552 allComponentsMatch[iRecord.first] =
match;
553 iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
555 if (!iAllComponentsMatch->second) {
556 iCandidateNotRejectedYet->second =
false;
563 for (
auto const& candidate : candidateNotRejectedYet) {
565 bool canBeShared = candidate.second;
568 logInfoWhenSharing(pset);
570 sharingCheckDone.insert(psetIDHolder);
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);
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);
614 std::map<EventSetupRecordKey, bool> & allComponentsMatch,
628 if ((*recordToFinders_)[eventSetupRecordKey].size() != (*precedingESProvider.
recordToFinders_)[eventSetupRecordKey].
size()) {
632 for (
auto const&
finder : (*recordToFinders_)[eventSetupRecordKey]) {
642 fillReferencedDataKeys(eventSetupRecordKey);
645 std::map<DataKey, ComponentDescription const*>
const& dataItems = (*referencedDataKeys_)[eventSetupRecordKey];
647 std::map<DataKey, ComponentDescription const*>
const& precedingDataItems = (*precedingESProvider.
referencedDataKeys_)[eventSetupRecordKey];
649 if (dataItems.size() != precedingDataItems.size()) {
653 for (
auto const& dataItem : dataItems) {
654 auto precedingDataItem = precedingDataItems.find(dataItem.first);
655 if (precedingDataItem == precedingDataItems.end()) {
658 if (dataItem.second->pid_ != precedingDataItem->second->pid_) {
664 if (!dataItem.second->isSource_ && !dataItem.second->isLooper_) {
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()) {
685 bool match = doRecordsMatch(precedingESProvider,
689 allComponentsMatch[dependentRecord] =
match;
690 if (!match)
return false;
699 if (referencedDataKeys_->find(eventSetupRecordKey) != referencedDataKeys_->end())
return;
701 auto recordProvider = providers_.find(eventSetupRecordKey);
702 if (recordProvider == providers_.end()) {
703 (*referencedDataKeys_)[eventSetupRecordKey];
706 if (recordProvider->second) {
707 recordProvider->second->fillReferencedDataKeys((*referencedDataKeys_)[eventSetupRecordKey]);
712 EventSetupProvider::resetRecordToProxyPointers() {
713 for (
auto const& recordProvider : providers_) {
716 RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(recordProvider.first);
717 if(itRecordFound != recordToPreferred_->end()) {
718 preferredInfo = &(itRecordFound->second);
720 recordProvider.second->resetRecordToProxyPointers(*preferredInfo);
725 EventSetupProvider::clearInitializationData() {
726 preferredProviderInfo_.reset();
727 referencedDataKeys_.reset();
728 recordToFinders_.reset();
729 psetIDToRecordKey_.reset();
730 recordToPreferred_.reset();
731 recordsWithALooperProxy_.reset();
737 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());
787 void EventSetupProvider::logInfoWhenSharing(
ParameterSet const& iConfiguration) {
792 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
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 setIOVSyncValue(const IOVSyncValue &)
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_
EventSetupProvider(unsigned subProcessIndex=0U, PreferredProviderInfo const *iInfo=0)
T get(const Candidate &c)