16 #include "boost/bind.hpp" 36 namespace eventsetup {
41 using Map = std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >;
43 explicit KnownRecordsSupplierImpl( Map
const& iMap) :
map_(iMap) {}
46 return map_.find(iKey) !=
map_.end();
68 knownRecordsSupplier_(
std::make_unique<KnownRecordsSupplierImpl>(providers_)),
69 mustFinishConfiguration_(
true),
70 subProcessIndex_(subProcessIndex),
71 preferredProviderInfo_((0!=iInfo) ? (new PreferredProviderInfo(*iInfo)): 0),
80 eventSetup_.setKnownRecordsSupplier(knownRecordsSupplier_.get());
88 EventSetupProvider::~EventSetupProvider()
110 std::shared_ptr<EventSetupRecordProvider>
temp(iProvider.release());
111 providers_[iKey] =
temp;
118 assert(iProvider.get() != 0);
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() != 0);
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;
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(),
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 itFound = providers_.find(*itKey);
303 itFound->second->addFinder(*itFinder);
311 psetIDToRecordKey_->clear();
312 typedef std::set<EventSetupRecordKey>
Keys;
313 for(std::vector<std::shared_ptr<DataProxyProvider> >::iterator itProvider=dataProviders_->begin(),
314 itEnd = dataProviders_->end();
320 const Keys recordsUsing = (*itProvider)->usingRecords();
322 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
326 if ((*itProvider)->description().isLooper_) {
327 recordsWithALooperProxy_->insert(*itKey);
330 (*psetIDToRecordKey_)[psetID].insert(*itKey);
332 Providers::iterator itFound = providers_.find(*itKey);
333 if(providers_.end() == itFound) {
336 itFound = providers_.find(*itKey);
338 itFound->second->add(*itProvider);
341 dataProviders_.reset();
350 for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
351 itProvider != itProviderEnd;
354 RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(itProvider->first);
355 if(itRecordFound != recordToPreferred_->end()) {
356 preferredInfo = &(itRecordFound->second);
359 itProvider->second->usePreferred(*preferredInfo);
361 std::set<EventSetupRecordKey> records = itProvider->second->dependentRecords();
362 if(records.size() != 0) {
364 std::vector<std::shared_ptr<EventSetupRecordProvider> > depProviders;
365 depProviders.reserve(records.size());
366 bool foundAllProviders =
true;
367 for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
368 itRecordEnd = records.end();
369 itRecord != itRecordEnd;
371 Providers::iterator itFound = providers_.find(*itRecord);
372 if(itFound == providers_.end()) {
373 foundAllProviders =
false;
374 if(missingRecords.size() == 0) {
375 missingRecords = itRecord->name();
377 missingRecords +=
", ";
378 missingRecords += itRecord->name();
382 depProviders.push_back(itFound->second);
386 if(!foundAllProviders) {
387 edm::LogInfo(
"EventSetupDependency")<<
"The EventSetup record "<<itProvider->second->key().name()
388 <<
" depends on at least one Record \n ("<<missingRecords<<
") which is not present in the job." 389 "\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.";
395 itProvider->second->setDependentProviders(depProviders);
398 mustFinishConfiguration_ =
false;
401 typedef std::map<EventSetupRecordKey, std::shared_ptr<EventSetupRecordProvider> >
Providers;
402 typedef Providers::iterator
Itr;
408 std::vector<std::shared_ptr<EventSetupRecordProvider> >& oDependents)
411 for(Itr it = itBegin; it != itEnd; ++it) {
413 const std::set<EventSetupRecordKey>&
deps = it->second->dependentRecords();
414 if(deps.end() != deps.find(iKey)) {
415 oDependents.push_back(it->second);
425 Providers::iterator itFind = providers_.find(iKey);
426 if(itFind == providers_.end()) {
431 std::vector<std::shared_ptr<EventSetupRecordProvider> > dependents;
432 findDependents(iKey, providers_.begin(), providers_.end(), dependents);
434 dependents.erase(
std::unique(dependents.begin(),dependents.end()), dependents.end());
436 itFind->second->resetProxies();
438 boost::bind(&EventSetupRecordProvider::resetProxies,
443 EventSetupProvider::forceCacheClear()
445 for(Providers::iterator it=providers_.begin(), itEnd = providers_.end();
448 it->second->resetProxies();
454 std::set<ParameterSetIDHolder>& sharingCheckDone,
458 edm::LogVerbatim(
"EventSetupSharing") <<
"EventSetupProvider::checkESProducerSharing: Checking processes with SubProcess Indexes " 459 << subProcessIndex() <<
" and " << precedingESProvider.
subProcessIndex();
461 if (referencedESProducers.empty()) {
462 for (
auto const& recordProvider : providers_) {
463 recordProvider.second->getReferencedESProducers(referencedESProducers);
470 std::map<EventSetupRecordKey, bool> allComponentsMatch;
472 std::map<ParameterSetID, bool> candidateNotRejectedYet;
476 for (
auto const& iRecord : referencedESProducers) {
477 for (
auto const& iComponent : iRecord.second) {
481 if (sharingCheckDone.find(psetIDHolder) != sharingCheckDone.end())
continue;
483 bool firstProcessWithThisPSet =
false;
484 bool precedingHasMatchingPSet =
false;
489 firstProcessWithThisPSet,
490 precedingHasMatchingPSet);
492 if (firstProcessWithThisPSet) {
493 sharingCheckDone.insert(psetIDHolder);
494 allComponentsMatch[iRecord.first] =
false;
498 if (!precedingHasMatchingPSet) {
499 allComponentsMatch[iRecord.first] =
false;
516 auto iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
517 if (iCandidateNotRejectedYet == candidateNotRejectedYet.end()) {
518 candidateNotRejectedYet[psetID] =
true;
519 iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
541 if (iCandidateNotRejectedYet->second ==
true) {
543 auto iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
544 if (iAllComponentsMatch == allComponentsMatch.end()) {
549 bool match = doRecordsMatch(precedingESProvider,
553 allComponentsMatch[iRecord.first] =
match;
554 iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
556 if (!iAllComponentsMatch->second) {
557 iCandidateNotRejectedYet->second =
false;
564 for (
auto const& candidate : candidateNotRejectedYet) {
566 bool canBeShared = candidate.second;
569 logInfoWhenSharing(pset);
571 sharingCheckDone.insert(psetIDHolder);
581 std::shared_ptr<DataProxyProvider> dataProxyProvider;
582 std::set<EventSetupRecordKey>
const& keysForPSetID1 = (*precedingESProvider.
psetIDToRecordKey_)[psetIDHolder];
583 for (
auto const&
key : keysForPSetID1) {
584 std::shared_ptr<EventSetupRecordProvider>
const& recordProvider = precedingESProvider.
providers_[
key];
585 dataProxyProvider = recordProvider->proxyProvider(psetIDHolder);
586 assert(dataProxyProvider);
590 std::set<EventSetupRecordKey>
const& keysForPSetID2 = (*psetIDToRecordKey_)[psetIDHolder];
591 for (
auto const&
key : keysForPSetID2) {
592 std::shared_ptr<EventSetupRecordProvider>
const& recordProvider = providers_[
key];
593 recordProvider->resetProxyProvider(psetIDHolder, dataProxyProvider);
615 std::map<EventSetupRecordKey, bool> & allComponentsMatch,
629 if ((*recordToFinders_)[eventSetupRecordKey].size() != (*precedingESProvider.
recordToFinders_)[eventSetupRecordKey].
size()) {
633 for (
auto const&
finder : (*recordToFinders_)[eventSetupRecordKey]) {
643 fillReferencedDataKeys(eventSetupRecordKey);
646 std::map<DataKey, ComponentDescription const*>
const& dataItems = (*referencedDataKeys_)[eventSetupRecordKey];
648 std::map<DataKey, ComponentDescription const*>
const& precedingDataItems = (*precedingESProvider.
referencedDataKeys_)[eventSetupRecordKey];
650 if (dataItems.size() != precedingDataItems.size()) {
654 for (
auto const& dataItem : dataItems) {
655 auto precedingDataItem = precedingDataItems.find(dataItem.first);
656 if (precedingDataItem == precedingDataItems.end()) {
659 if (dataItem.second->pid_ != precedingDataItem->second->pid_) {
665 if (!dataItem.second->isSource_ && !dataItem.second->isLooper_) {
674 Providers::iterator itFound = providers_.find(eventSetupRecordKey);
675 if (itFound != providers_.end()) {
676 std::set<EventSetupRecordKey> dependentRecords = itFound->second->dependentRecords();
677 for (
auto const& dependentRecord : dependentRecords) {
678 auto iter = allComponentsMatch.find(dependentRecord);
679 if (iter != allComponentsMatch.end()) {
686 bool match = doRecordsMatch(precedingESProvider,
690 allComponentsMatch[dependentRecord] =
match;
691 if (!match)
return false;
700 if (referencedDataKeys_->find(eventSetupRecordKey) != referencedDataKeys_->end())
return;
702 auto recordProvider = providers_.find(eventSetupRecordKey);
703 if (recordProvider == providers_.end()) {
704 (*referencedDataKeys_)[eventSetupRecordKey];
707 if (recordProvider->second) {
708 recordProvider->second->fillReferencedDataKeys((*referencedDataKeys_)[eventSetupRecordKey]);
713 EventSetupProvider::resetRecordToProxyPointers() {
714 for (
auto const& recordProvider : providers_) {
717 RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(recordProvider.first);
718 if(itRecordFound != recordToPreferred_->end()) {
719 preferredInfo = &(itRecordFound->second);
721 recordProvider.second->resetRecordToProxyPointers(*preferredInfo);
726 EventSetupProvider::clearInitializationData() {
727 preferredProviderInfo_.reset();
728 referencedDataKeys_.reset();
729 recordToFinders_.reset();
730 psetIDToRecordKey_.reset();
731 recordToPreferred_.reset();
732 recordsWithALooperProxy_.reset();
738 eventSetup_.add(iRecord);
754 if(mustFinishConfiguration_) {
755 finishConfiguration();
758 for(Providers::iterator itProvider = providers_.begin(), itProviderEnd = providers_.end();
759 itProvider != itProviderEnd;
761 itProvider->second->addRecordToIfValid(*
this, iValue);
767 struct InsertAll :
public std::unary_function< const std::set<ComponentDescription>&, void>{
769 typedef std::set<ComponentDescription> Set;
771 InsertAll(Set& iSet) : container_(&iSet) {}
772 void operator()(
const Set& iSet) {
773 container_->insert(iSet.begin(), iSet.end());
777 std::set<ComponentDescription>
778 EventSetupProvider::proxyProviderDescriptions()
const 781 typedef std::set<ComponentDescription> Set;
785 bind(InsertAll(descriptions),
786 bind(&EventSetupRecordProvider::proxyProviderDescriptions,
788 if(dataProviders_.get()) {
789 for(std::vector<std::shared_ptr<DataProxyProvider> >::const_iterator it = dataProviders_->begin(),
790 itEnd = dataProviders_->end();
793 descriptions.insert((*it)->description());
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
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_
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
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
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
U second(std::pair< T, U > const &p)
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_
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)