34 namespace eventsetup {
39 using Map = std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >;
41 explicit KnownRecordsSupplierImpl( Map
const& iMap) :
map_(iMap) {}
44 return map_.find(iKey) !=
map_.end();
64 unsigned subProcessIndex,
65 const PreferredProviderInfo* iInfo) :
66 eventSetup_(activityRegistry),
68 knownRecordsSupplier_(
std::make_unique<KnownRecordsSupplierImpl>(providers_)),
69 mustFinishConfiguration_(
true),
70 subProcessIndex_(subProcessIndex),
71 preferredProviderInfo_((
nullptr!=iInfo) ? (new PreferredProviderInfo(*iInfo)):
nullptr),
80 eventSetup_.setKnownRecordsSupplier(knownRecordsSupplier_.get());
88 EventSetupProvider::~EventSetupProvider()
110 std::shared_ptr<EventSetupRecordProvider>
temp(iProvider.release());
111 providers_[iKey] =
temp;
118 assert(iProvider.get() !=
nullptr);
119 dataProviders_->push_back(iProvider);
123 EventSetupProvider::replaceExisting(std::shared_ptr<DataProxyProvider> dataProxyProvider)
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);
136 assert(iFinder.get() !=
nullptr);
137 finders_->push_back(iFinder);
140 typedef std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >
Providers;
141 typedef std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap>
RecordToPreferred;
146 const Providers& iProviders,
147 RecordToPreferred& iReturnValue)
150 bool foundProxyProvider =
false;
151 for(Providers::const_iterator itProvider = iProviders.begin(), itProviderEnd = iProviders.end();
152 itProvider!= itProviderEnd;
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());
160 std::set<EventSetupRecordKey> records = proxyProv->usingRecords();
161 for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
162 itRecordEnd = records.end();
163 itRecord != itRecordEnd;
166 if(!keyedProxies.empty()){
169 iReturnValue[*itRecord];
171 for(DataProxyProvider::KeyedProxies::const_iterator itProxy = keyedProxies.begin(),
172 itProxyEnd = keyedProxies.end();
173 itProxy != itProxyEnd;
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";
185 dataToProviderMap.insert(std::make_pair(itProxy->first,iComponent));
189 foundProxyProvider=
true;
193 if(!foundProxyProvider) {
195 <<
"\" label=\""<<iComponent.
label_<<
"\" a preferred Provider."<<
196 "\n Please check spelling of name, or that it was loaded into the job.";
201 const Providers& iProviders)
204 RecordToPreferred returnValue;
205 if(
nullptr != iInfo){
206 for(EventSetupProvider::PreferredProviderInfo::const_iterator itInfo = iInfo->begin(),
207 itInfoEnd = iInfo->end();
210 if(itInfo->second.empty()) {
214 for(EventSetupProvider::RecordToDataMap::const_iterator itRecData = itInfo->second.begin(),
215 itRecDataEnd = itInfo->second.end();
216 itRecData != itRecDataEnd;
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.";
228 Providers::const_iterator itRecordProvider = iProviders.find(recordKey);
229 assert(itRecordProvider != iProviders.end());
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;
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";
248 std::shared_ptr<DataProxyProvider> proxyProv =
249 itRecordProvider->second->proxyProvider(*itProxyProv);
251 if(std::find_if(keyedProxies.begin(), keyedProxies.end(),
252 [&datumKey](
auto const&
kp) {
return kp.first == datumKey;}) ==
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.";
261 =returnValue[recordKey];
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";
273 dataToProviderMap.insert(std::make_pair(datumKey,*itProxyProv));
282 EventSetupProvider::finishConfiguration()
285 recordToFinders_->clear();
286 for(std::vector<std::shared_ptr<EventSetupRecordIntervalFinder> >::iterator itFinder=finders_->begin(),
287 itEnd = finders_->end();
290 typedef std::set<EventSetupRecordKey>
Keys;
291 const Keys recordsUsing = (*itFinder)->findingForRecords();
293 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
296 (*recordToFinders_)[*itKey].push_back(*itFinder);
297 Providers::iterator itFound = providers_.find(*itKey);
298 if(providers_.end() == itFound) {
301 std::make_unique<EventSetupRecordProvider>(*itKey) );
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) {
336 insert(*itKey, std::make_unique<EventSetupRecordProvider>(*itKey));
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);
744 auto key =iRecordProvider->key();
759 if(mustFinishConfiguration_) {
760 finishConfiguration();
763 for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
764 itProvider != itProviderEnd;
766 itProvider->second->addRecordToIfValid(*
this, iValue);
771 std::set<ComponentDescription>
772 EventSetupProvider::proxyProviderDescriptions()
const 774 typedef std::set<ComponentDescription> Set;
777 for(
auto const&
p: providers_) {
778 auto const&
d =
p.second->proxyProviderDescriptions();
779 descriptions.insert(
d.begin(),
d.end());
781 if(dataProviders_.get()) {
782 for(
auto const&
p: *dataProviders_) {
783 descriptions.insert(
p->description());
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)) ) {
804 void EventSetupProvider::logInfoWhenSharing(
ParameterSet const& iConfiguration) {
809 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
void setEventSetup(EventSetup const *iEventSetup)
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
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
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)