16 #include "boost/bind.hpp"
35 namespace eventsetup {
51 mustFinishConfiguration_(
true),
52 subProcessIndex_(subProcessIndex),
91 boost::shared_ptr<EventSetupRecordProvider>
temp(iProvider.release());
99 assert(&(*iProvider) != 0);
107 std::set<EventSetupRecordKey>
const& keysForPSetID = (*psetIDToRecordKey_)[psetID];
108 for (
auto const&
key : keysForPSetID) {
109 boost::shared_ptr<EventSetupRecordProvider>
const& recordProvider =
providers_[
key];
110 recordProvider->resetProxyProvider(psetID, dataProxyProvider);
117 assert(&(*iFinder) != 0);
121 typedef std::map<EventSetupRecordKey, boost::shared_ptr<EventSetupRecordProvider> >
Providers;
122 typedef std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap>
RecordToPreferred;
131 bool foundProxyProvider =
false;
132 for(Providers::const_iterator itProvider = iProviders.begin(), itProviderEnd = iProviders.end();
133 itProvider!= itProviderEnd;
135 std::set<ComponentDescription>
components = itProvider->second->proxyProviderDescriptions();
136 if(components.find(iComponent)!= components.end()) {
137 boost::shared_ptr<DataProxyProvider> proxyProv =
138 itProvider->second->proxyProvider(*(components.find(iComponent)));
139 assert(proxyProv.get());
141 std::set<EventSetupRecordKey> records = proxyProv->usingRecords();
142 for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
143 itRecordEnd = records.end();
144 itRecord != itRecordEnd;
147 if(!keyedProxies.empty()){
150 iReturnValue[*itRecord];
152 for(DataProxyProvider::KeyedProxies::const_iterator itProxy = keyedProxies.begin(),
153 itProxyEnd = keyedProxies.end();
154 itProxy != itProxyEnd;
156 EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
157 dataToProviderMap.find(itProxy->first);
158 if(itFind != dataToProviderMap.end()){
159 throw cms::Exception(
"ESPreferConflict") <<
"Two providers have been set to be preferred for\n"
160 <<itProxy->first.type().name()<<
" \""<<itProxy->first.name().value()<<
"\""
161 <<
"\n the providers are "
162 <<
"\n 1) type="<<itFind->second.type_<<
" label=\""<<itFind->second.label_<<
"\""
163 <<
"\n 2) type="<<iComponent.
type_<<
" label=\""<<iComponent.
label_<<
"\""
164 <<
"\nPlease modify configuration so only one is preferred";
166 dataToProviderMap.insert(std::make_pair(itProxy->first,iComponent));
170 foundProxyProvider=
true;
174 if(!foundProxyProvider) {
176 <<
"\" label=\""<<iComponent.
label_<<
"\" a preferred Provider."<<
177 "\n Please check spelling of name, or that it was loaded into the job.";
184 using namespace edm::eventsetup;
187 for(EventSetupProvider::PreferredProviderInfo::const_iterator itInfo = iInfo->begin(),
188 itInfoEnd = iInfo->end();
191 if(itInfo->second.empty()) {
195 for(EventSetupProvider::RecordToDataMap::const_iterator itRecData = itInfo->second.begin(),
196 itRecDataEnd = itInfo->second.end();
197 itRecData != itRecDataEnd;
202 throw cms::Exception(
"ESPreferUnknownRecord") <<
"Unknown record \""<<recordName
203 <<
"\" used in es_prefer statement for type="
204 <<itInfo->first.type_<<
" label=\""<<itInfo->first.label_
205 <<
"\"\n Please check spelling.";
209 Providers::const_iterator itRecordProvider = iProviders.find(recordKey);
210 assert(itRecordProvider != iProviders.end());
212 std::set<ComponentDescription>
components = itRecordProvider->second->proxyProviderDescriptions();
213 std::set<ComponentDescription>::iterator itProxyProv = components.find(itInfo->first);
214 if(itProxyProv == components.end()){
215 throw cms::Exception(
"ESPreferWrongRecord")<<
"The type="<<itInfo->first.type_<<
" label=\""<<
216 itInfo->first.label_<<
"\" does not provide data for the Record "<<
recordName;
222 throw cms::Exception(
"ESPreferWrongDataType")<<
"The es_prefer statement for type="<<itInfo->first.type_<<
" label=\""<<
223 itInfo->first.label_<<
"\" has the unknown data type \""<<itRecData->second.first<<
"\""
224 <<
"\n Please check spelling";
229 boost::shared_ptr<DataProxyProvider> proxyProv =
230 itRecordProvider->second->proxyProvider(*itProxyProv);
232 if(std::find_if(keyedProxies.begin(), keyedProxies.end(),
235 throw cms::Exception(
"ESPreferWrongData")<<
"The es_prefer statement for type="<<itInfo->first.type_<<
" label=\""<<
236 itInfo->first.label_<<
"\" specifies the data item \n"
237 <<
" type=\""<<itRecData->second.first<<
"\" label=\""<<itRecData->second.second<<
"\""
238 <<
" which is not provided. Please check spelling.";
242 =returnValue[recordKey];
244 if(dataToProviderMap.end() != dataToProviderMap.find(datumKey)) {
245 EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
246 dataToProviderMap.find(datumKey);
247 throw cms::Exception(
"ESPreferConflict") <<
"Two providers have been set to be preferred for\n"
248 <<datumKey.type().name()<<
" \""<<datumKey.name().value()<<
"\""
249 <<
"\n the providers are "
250 <<
"\n 1) type="<<itFind->second.type_<<
" label=\""<<itFind->second.label_<<
"\""
251 <<
"\n 2) type="<<itProxyProv->type_<<
" label=\""<<itProxyProv->label_<<
"\""
252 <<
"\nPlease modify configuration so only one is preferred";
254 dataToProviderMap.insert(std::make_pair(datumKey,*itProxyProv));
267 for(std::vector<boost::shared_ptr<EventSetupRecordIntervalFinder> >::iterator itFinder=
finders_->begin(),
271 typedef std::set<EventSetupRecordKey>
Keys;
272 const Keys recordsUsing = (*itFinder)->findingForRecords();
274 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
277 (*recordToFinders_)[*itKey].push_back(*itFinder);
278 Providers::iterator itFound =
providers_.find(*itKey);
284 itFound->second->addFinder(*itFinder);
293 typedef std::set<EventSetupRecordKey>
Keys;
294 for(std::vector<boost::shared_ptr<DataProxyProvider> >::iterator itProvider=
dataProviders_->begin(),
301 const Keys recordsUsing = (*itProvider)->usingRecords();
303 for(Keys::const_iterator itKey = recordsUsing.begin(), itKeyEnd = recordsUsing.end();
307 if ((*itProvider)->description().isLooper_) {
311 (*psetIDToRecordKey_)[psetID].insert(*itKey);
313 Providers::iterator itFound =
providers_.find(*itKey);
319 itFound->second->add(*itProvider);
332 itProvider != itProviderEnd;
335 RecordToPreferred::const_iterator itRecordFound =
recordToPreferred_->find(itProvider->first);
337 preferredInfo = &(itRecordFound->second);
340 itProvider->second->usePreferred(*preferredInfo);
342 std::set<EventSetupRecordKey> records = itProvider->second->dependentRecords();
343 if(records.size() != 0) {
345 std::vector<boost::shared_ptr<EventSetupRecordProvider> > depProviders;
346 depProviders.reserve(records.size());
347 bool foundAllProviders =
true;
348 for(std::set<EventSetupRecordKey>::iterator itRecord = records.begin(),
349 itRecordEnd = records.end();
350 itRecord != itRecordEnd;
352 Providers::iterator itFound =
providers_.find(*itRecord);
354 foundAllProviders =
false;
355 if(missingRecords.size() == 0) {
356 missingRecords = itRecord->name();
358 missingRecords +=
", ";
359 missingRecords += itRecord->name();
363 depProviders.push_back(itFound->second);
367 if(!foundAllProviders) {
368 edm::LogInfo(
"EventSetupDependency")<<
"The EventSetup record "<<itProvider->second->key().name()
369 <<
" depends on at least one Record \n ("<<missingRecords<<
") which is not present in the job."
370 "\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.";
376 itProvider->second->setDependentProviders(depProviders);
382 typedef std::map<EventSetupRecordKey, boost::shared_ptr<EventSetupRecordProvider> >
Providers;
383 typedef Providers::iterator
Itr;
389 std::vector<boost::shared_ptr<EventSetupRecordProvider> >& oDependents)
392 for(Itr it = itBegin; it != itEnd; ++it) {
394 const std::set<EventSetupRecordKey>& deps = it->second->dependentRecords();
395 if(deps.end() != deps.find(iKey)) {
396 oDependents.push_back(it->second);
406 Providers::iterator itFind =
providers_.find(iKey);
412 std::vector<boost::shared_ptr<EventSetupRecordProvider> > dependents;
415 dependents.erase(std::unique(dependents.begin(),dependents.end()), dependents.end());
417 itFind->second->resetProxies();
429 it->second->resetProxies();
435 std::set<ParameterSetIDHolder>& sharingCheckDone,
439 edm::LogVerbatim(
"EventSetupSharing") <<
"EventSetupProvider::checkESProducerSharing: Checking processes with SubProcess Indexes "
442 if (referencedESProducers.empty()) {
443 for (
auto const& recordProvider :
providers_) {
444 recordProvider.second->getReferencedESProducers(referencedESProducers);
451 std::map<EventSetupRecordKey, bool> allComponentsMatch;
453 std::map<ParameterSetID, bool> candidateNotRejectedYet;
457 for (
auto const& iRecord : referencedESProducers) {
458 for (
auto const& iComponent : iRecord.second) {
462 if (sharingCheckDone.find(psetIDHolder) != sharingCheckDone.end())
continue;
464 bool firstProcessWithThisPSet =
false;
465 bool precedingHasMatchingPSet =
false;
470 firstProcessWithThisPSet,
471 precedingHasMatchingPSet);
473 if (firstProcessWithThisPSet) {
474 sharingCheckDone.insert(psetIDHolder);
475 allComponentsMatch[iRecord.first] =
false;
479 if (!precedingHasMatchingPSet) {
480 allComponentsMatch[iRecord.first] =
false;
497 auto iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
498 if (iCandidateNotRejectedYet == candidateNotRejectedYet.end()) {
499 candidateNotRejectedYet[psetID] =
true;
500 iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
522 if (iCandidateNotRejectedYet->second ==
true) {
524 auto iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
525 if (iAllComponentsMatch == allComponentsMatch.end()) {
534 allComponentsMatch[iRecord.first] =
match;
535 iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
537 if (!iAllComponentsMatch->second) {
538 iCandidateNotRejectedYet->second =
false;
545 for (
auto const& candidate : candidateNotRejectedYet) {
547 bool canBeShared = candidate.second;
552 sharingCheckDone.insert(psetIDHolder);
562 boost::shared_ptr<DataProxyProvider> dataProxyProvider;
563 std::set<EventSetupRecordKey>
const& keysForPSetID1 = (*precedingESProvider.
psetIDToRecordKey_)[psetIDHolder];
564 for (
auto const&
key : keysForPSetID1) {
565 boost::shared_ptr<EventSetupRecordProvider>
const& recordProvider = precedingESProvider.
providers_[
key];
566 dataProxyProvider = recordProvider->proxyProvider(psetIDHolder);
567 assert(dataProxyProvider);
571 std::set<EventSetupRecordKey>
const& keysForPSetID2 = (*psetIDToRecordKey_)[psetIDHolder];
572 for (
auto const&
key : keysForPSetID2) {
573 boost::shared_ptr<EventSetupRecordProvider>
const& recordProvider =
providers_[
key];
574 recordProvider->resetProxyProvider(psetIDHolder, dataProxyProvider);
596 std::map<EventSetupRecordKey, bool> & allComponentsMatch,
615 ParameterSetID const& psetID = finder->descriptionForFinder().pid_;
627 std::map<DataKey, ComponentDescription const*>
const& dataItems = (*referencedDataKeys_)[eventSetupRecordKey];
629 std::map<DataKey, ComponentDescription const*>
const& precedingDataItems = (*precedingESProvider.
referencedDataKeys_)[eventSetupRecordKey];
631 if (dataItems.size() != precedingDataItems.size()) {
635 for (
auto const& dataItem : dataItems) {
636 auto precedingDataItem = precedingDataItems.find(dataItem.first);
637 if (precedingDataItem == precedingDataItems.end()) {
640 if (dataItem.second->pid_ != precedingDataItem->second->pid_) {
646 if (!dataItem.second->isSource_ && !dataItem.second->isLooper_) {
655 Providers::iterator itFound =
providers_.find(eventSetupRecordKey);
657 std::set<EventSetupRecordKey> dependentRecords = itFound->second->dependentRecords();
658 for (
auto const& dependentRecord : dependentRecords) {
659 auto iter = allComponentsMatch.find(dependentRecord);
660 if (iter != allComponentsMatch.end()) {
671 allComponentsMatch[dependentRecord] =
match;
672 if (!match)
return false;
683 auto recordProvider =
providers_.find(eventSetupRecordKey);
685 (*referencedDataKeys_)[eventSetupRecordKey];
688 if (recordProvider->second) {
689 recordProvider->second->fillReferencedDataKeys((*
referencedDataKeys_)[eventSetupRecordKey]);
695 for (
auto const& recordProvider :
providers_) {
698 RecordToPreferred::const_iterator itRecordFound =
recordToPreferred_->find(recordProvider.first);
700 preferredInfo = &(itRecordFound->second);
702 recordProvider.second->resetRecordToProxyPointers(*preferredInfo);
740 itProvider != itProviderEnd;
742 itProvider->second->addRecordToIfValid(*
this, iValue);
748 struct InsertAll :
public std::unary_function< const std::set<ComponentDescription>&, void>{
750 typedef std::set<ComponentDescription> Set;
753 void operator()(
const Set& iSet) {
758 std::set<ComponentDescription>
762 typedef std::set<ComponentDescription> Set;
766 bind(InsertAll(descriptions),
770 for(std::vector<boost::shared_ptr<DataProxyProvider> >::const_iterator it =
dataProviders_->begin(),
774 descriptions.insert((*it)->description());
790 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)
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 >)
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::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)