16 #include "boost/bind.hpp"
36 namespace eventsetup {
41 using Map = std::map<EventSetupRecordKey, boost::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),
110 boost::shared_ptr<EventSetupRecordProvider>
temp(iProvider.release());
118 assert(iProvider.get() != 0);
126 std::set<EventSetupRecordKey>
const& keysForPSetID = (*psetIDToRecordKey_)[psetID];
127 for (
auto const&
key : keysForPSetID) {
128 boost::shared_ptr<EventSetupRecordProvider>
const& recordProvider =
providers_[
key];
129 recordProvider->resetProxyProvider(psetID, dataProxyProvider);
136 assert(iFinder.get() != 0);
140 typedef std::map<EventSetupRecordKey, boost::shared_ptr<EventSetupRecordProvider> >
Providers;
141 typedef std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap>
RecordToPreferred;
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 boost::shared_ptr<DataProxyProvider> proxyProv =
157 itProvider->second->proxyProvider(*(components.find(iComponent)));
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.";
203 using namespace edm::eventsetup;
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 boost::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));
286 for(std::vector<boost::shared_ptr<EventSetupRecordIntervalFinder> >::iterator itFinder=
finders_->begin(),
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);
303 itFound->second->addFinder(*itFinder);
312 typedef std::set<EventSetupRecordKey>
Keys;
313 for(std::vector<boost::shared_ptr<DataProxyProvider> >::iterator itProvider=
dataProviders_->begin(),
320 const Keys recordsUsing = (*itProvider)->usingRecords();
322 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
326 if ((*itProvider)->description().isLooper_) {
330 (*psetIDToRecordKey_)[psetID].insert(*itKey);
332 Providers::iterator itFound =
providers_.find(*itKey);
338 itFound->second->add(*itProvider);
351 itProvider != itProviderEnd;
354 RecordToPreferred::const_iterator itRecordFound =
recordToPreferred_->find(itProvider->first);
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<boost::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);
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);
401 typedef std::map<EventSetupRecordKey, boost::shared_ptr<EventSetupRecordProvider> >
Providers;
402 typedef Providers::iterator
Itr;
408 std::vector<boost::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);
431 std::vector<boost::shared_ptr<EventSetupRecordProvider> > dependents;
434 dependents.erase(std::unique(dependents.begin(),dependents.end()), dependents.end());
436 itFind->second->resetProxies();
448 it->second->resetProxies();
454 std::set<ParameterSetIDHolder>& sharingCheckDone,
458 edm::LogVerbatim(
"EventSetupSharing") <<
"EventSetupProvider::checkESProducerSharing: Checking processes with SubProcess Indexes "
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()) {
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;
571 sharingCheckDone.insert(psetIDHolder);
581 boost::shared_ptr<DataProxyProvider> dataProxyProvider;
582 std::set<EventSetupRecordKey>
const& keysForPSetID1 = (*precedingESProvider.
psetIDToRecordKey_)[psetIDHolder];
583 for (
auto const&
key : keysForPSetID1) {
584 boost::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 boost::shared_ptr<EventSetupRecordProvider>
const& recordProvider =
providers_[
key];
593 recordProvider->resetProxyProvider(psetIDHolder, dataProxyProvider);
615 std::map<EventSetupRecordKey, bool> & allComponentsMatch,
634 ParameterSetID const& psetID = finder->descriptionForFinder().pid_;
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);
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()) {
690 allComponentsMatch[dependentRecord] =
match;
691 if (!match)
return false;
702 auto recordProvider =
providers_.find(eventSetupRecordKey);
704 (*referencedDataKeys_)[eventSetupRecordKey];
707 if (recordProvider->second) {
708 recordProvider->second->fillReferencedDataKeys((*
referencedDataKeys_)[eventSetupRecordKey]);
714 for (
auto const& recordProvider :
providers_) {
717 RecordToPreferred::const_iterator itRecordFound =
recordToPreferred_->find(recordProvider.first);
719 preferredInfo = &(itRecordFound->second);
721 recordProvider.second->resetRecordToProxyPointers(*preferredInfo);
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;
772 void operator()(
const Set& iSet) {
777 std::set<ComponentDescription>
781 typedef std::set<ComponentDescription> Set;
785 bind(InsertAll(descriptions),
789 for(std::vector<boost::shared_ptr<DataProxyProvider> >::const_iterator it =
dataProviders_->begin(),
793 descriptions.insert((*it)->description());
809 edm::LogVerbatim(
"EventSetupSharing") <<
"Sharing " << edmtype <<
": class=" << modtype <<
" label='" << label <<
"'";
EventSetup const & eventSetupForInstance(IOVSyncValue const &)
void finishConfiguration()
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 EventSetupRecordProviderFactoryManager & instance()
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.
bool mustFinishConfiguration_
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
U second(std::pair< T, U > const &p)
void setKnownRecordsSupplier(eventsetup::EventSetupKnownRecordsSupplier const *iSupplier)
virtual ~EventSetupProvider()
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 >)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
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 'preferred' list
void resetRecordToProxyPointers()
std::vector< size_type > Keys
void add(const eventsetup::EventSetupRecord &iRecord)
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)
unsigned subProcessIndex() const
heterocontainer::HCTypeTag TypeTag
std::unique_ptr< EventSetupKnownRecordsSupplier > knownRecordsSupplier_
std::set< ComponentDescription > proxyProviderDescriptions() const
return information on which DataProxyProviders are supplying information
const TypeTag & type() const
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 &)
std::unique_ptr< std::map< EventSetupRecordKey, std::map< DataKey, ComponentDescription > > > recordToPreferred_
void clearInitializationData()
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's of all the Proxies so that next time they are called they will run...
unsigned subProcessIndex_
std::unique_ptr< std::vector< boost::shared_ptr< EventSetupRecordIntervalFinder > > > finders_
tuple size
Write out results.
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
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)