35 namespace eventsetup {
38 unsigned subProcessIndex,
39 const PreferredProviderInfo* iInfo)
40 : eventSetup_(activityRegistry),
41 mustFinishConfiguration_(
true),
42 subProcessIndex_(subProcessIndex),
43 preferredProviderInfo_((
nullptr != iInfo) ? (new PreferredProviderInfo(*iInfo)) :
nullptr),
53 EventSetupProvider::~EventSetupProvider() { forceCacheClear(); }
55 std::shared_ptr<EventSetupRecordProvider>& EventSetupProvider::recordProvider(
const EventSetupRecordKey& iKey) {
57 if (lb == recordKeys_.end() || iKey != *lb) {
58 throw cms::Exception(
"LogicError") <<
"EventSetupProvider::recordProvider Could not find key\n" 59 <<
"Should be impossible. Please contact Framework developer.\n";
62 return recordProviders_[
index];
67 if (lb == recordKeys_.end() || iKey != *lb) {
71 return recordProviders_[
index].get();
75 std::unique_ptr<EventSetupRecordProvider> iProvider) {
78 if (lb == recordKeys_.end() || iKey != *lb) {
79 recordKeys_.insert(lb, iKey);
80 recordProviders_.insert(recordProviders_.begin() +
index,
std::move(iProvider));
87 assert(iProvider.get() !=
nullptr);
88 dataProviders_->push_back(iProvider);
91 void EventSetupProvider::replaceExisting(std::shared_ptr<DataProxyProvider> dataProxyProvider) {
93 std::set<EventSetupRecordKey>
const& keysForPSetID = (*psetIDToRecordKey_)[psetID];
94 for (
auto const&
key : keysForPSetID) {
95 recordProvider(
key)->resetProxyProvider(psetID, dataProxyProvider);
100 assert(iFinder.get() !=
nullptr);
101 finders_->push_back(iFinder);
105 using RecordToPreferred = std::map<EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap>;
111 bool foundProxyProvider =
false;
112 for (
auto const& recordProvider : iRecordProviders) {
113 std::set<ComponentDescription>
components = recordProvider->proxyProviderDescriptions();
114 if (components.find(iComponent) != components.end()) {
115 std::shared_ptr<DataProxyProvider> proxyProv = recordProvider->proxyProvider(*(components.find(iComponent)));
116 assert(proxyProv.get());
118 std::set<EventSetupRecordKey> records = proxyProv->usingRecords();
119 for (std::set<EventSetupRecordKey>::iterator itRecord = records.begin(), itRecordEnd = records.end();
120 itRecord != itRecordEnd;
123 if (!keyedProxies.empty()) {
127 for (DataProxyProvider::KeyedProxies::const_iterator itProxy = keyedProxies.begin(),
128 itProxyEnd = keyedProxies.end();
129 itProxy != itProxyEnd;
131 EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
132 dataToProviderMap.find(itProxy->first);
133 if (itFind != dataToProviderMap.end()) {
135 <<
"Two providers have been set to be preferred for\n" 136 << itProxy->first.type().name() <<
" \"" << itProxy->first.name().value() <<
"\"" 137 <<
"\n the providers are " 138 <<
"\n 1) type=" << itFind->second.type_ <<
" label=\"" << itFind->second.label_ <<
"\"" 139 <<
"\n 2) type=" << iComponent.
type_ <<
" label=\"" << iComponent.
label_ <<
"\"" 140 <<
"\nPlease modify configuration so only one is preferred";
142 dataToProviderMap.insert(std::make_pair(itProxy->first, iComponent));
146 foundProxyProvider =
true;
150 if (!foundProxyProvider) {
152 <<
"Could not make type=\"" << iComponent.
type_ <<
"\" label=\"" << iComponent.
label_ 153 <<
"\" a preferred Provider." 154 <<
"\n Please check spelling of name, or that it was loaded into the job.";
158 void EventSetupProvider::determinePreferred() {
160 if (preferredProviderInfo_) {
161 for (
auto const& itInfo : *preferredProviderInfo_) {
162 if (itInfo.second.empty()) {
166 for (EventSetupProvider::RecordToDataMap::const_iterator itRecData = itInfo.second.begin(),
167 itRecDataEnd = itInfo.second.end();
168 itRecData != itRecDataEnd;
174 <<
"Unknown record \"" << recordName
175 <<
"\" used in es_prefer statement for type=" << itInfo.first.type_ <<
" label=\"" 176 << itInfo.first.label_ <<
"\"\n Please check spelling.";
183 std::set<ComponentDescription>::iterator itProxyProv = components.find(itInfo.first);
184 if (itProxyProv == components.end()) {
186 <<
"The type=" << itInfo.first.type_ <<
" label=\"" << itInfo.first.label_
187 <<
"\" does not provide data for the Record " <<
recordName;
194 <<
"The es_prefer statement for type=" << itInfo.first.type_ <<
" label=\"" << itInfo.first.label_
195 <<
"\" has the unknown data type \"" << itRecData->second.first <<
"\"" 196 <<
"\n Please check spelling";
201 std::shared_ptr<DataProxyProvider> proxyProv = recordProviderForKey.
proxyProvider(*itProxyProv);
203 if (std::find_if(keyedProxies.begin(), keyedProxies.end(), [&datumKey](
auto const&
kp) {
204 return kp.first == datumKey;
205 }) == keyedProxies.end()) {
207 <<
"The es_prefer statement for type=" << itInfo.first.type_ <<
" label=\"" << itInfo.first.label_
208 <<
"\" specifies the data item \n" 209 <<
" type=\"" << itRecData->second.first <<
"\" label=\"" << itRecData->second.second <<
"\"" 210 <<
" which is not provided. Please check spelling.";
214 (*recordToPreferred_)[recordKey];
216 if (dataToProviderMap.end() != dataToProviderMap.find(datumKey)) {
217 EventSetupRecordProvider::DataToPreferredProviderMap::iterator itFind =
218 dataToProviderMap.find(datumKey);
220 <<
"Two providers have been set to be preferred for\n" 221 << datumKey.type().name() <<
" \"" << datumKey.name().value() <<
"\"" 222 <<
"\n the providers are " 223 <<
"\n 1) type=" << itFind->second.type_ <<
" label=\"" << itFind->second.label_ <<
"\"" 224 <<
"\n 2) type=" << itProxyProv->type_ <<
" label=\"" << itProxyProv->label_ <<
"\"" 225 <<
"\nPlease modify configuration so only one is preferred";
227 dataToProviderMap.insert(std::make_pair(datumKey, *itProxyProv));
234 void EventSetupProvider::finishConfiguration() {
236 recordToFinders_->clear();
237 for (std::vector<std::shared_ptr<EventSetupRecordIntervalFinder>>::iterator itFinder = finders_->begin(),
238 itEnd = finders_->end();
241 typedef std::set<EventSetupRecordKey>
Keys;
242 const Keys recordsUsing = (*itFinder)->findingForRecords();
244 for (
auto const&
key : recordsUsing) {
245 (*recordToFinders_)[
key].push_back(*itFinder);
248 if (recProvider ==
nullptr) {
250 insert(
key, std::make_unique<EventSetupRecordProvider>(
key));
251 recProvider = tryToGetRecordProvider(
key);
261 psetIDToRecordKey_->clear();
262 typedef std::set<EventSetupRecordKey>
Keys;
263 for (std::vector<std::shared_ptr<DataProxyProvider>>::iterator itProvider = dataProviders_->begin(),
264 itEnd = dataProviders_->end();
269 const Keys recordsUsing = (*itProvider)->usingRecords();
271 for (
auto const&
key : recordsUsing) {
272 if ((*itProvider)->description().isLooper_) {
273 recordsWithALooperProxy_->insert(
key);
276 (*psetIDToRecordKey_)[psetID].insert(
key);
279 if (recProvider ==
nullptr) {
281 insert(
key, std::make_unique<EventSetupRecordProvider>(
key));
282 recProvider = tryToGetRecordProvider(
key);
284 recProvider->
add(*itProvider);
288 eventSetup_.setKeyIters(recordKeys_.begin(), recordKeys_.end());
293 determinePreferred();
298 for (
auto& itRecordProvider : recordProviders_) {
300 RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(itRecordProvider->key());
301 if (itRecordFound != recordToPreferred_->end()) {
302 preferredInfo = &(itRecordFound->second);
305 itRecordProvider->usePreferred(*preferredInfo);
307 std::set<EventSetupRecordKey> records = itRecordProvider->dependentRecords();
308 if (!records.empty()) {
310 std::vector<std::shared_ptr<EventSetupRecordProvider>> depProviders;
311 depProviders.reserve(records.size());
312 bool foundAllProviders =
true;
313 for (
auto const&
key : records) {
315 if (lb == recordKeys_.end() ||
key != *lb) {
316 foundAllProviders =
false;
317 if (missingRecords.empty()) {
318 missingRecords =
key.name();
320 missingRecords +=
", ";
321 missingRecords +=
key.name();
325 depProviders.push_back(recordProviders_[
index]);
329 if (!foundAllProviders) {
331 <<
"The EventSetup record " << itRecordProvider->key().name() <<
" depends on at least one Record \n (" 333 <<
") which is not present in the job." 334 "\n This may lead to an exception begin thrown during event processing.\n If no exception occurs " 335 "during the job than it is usually safe to ignore this message.";
341 itRecordProvider->setDependentProviders(depProviders);
345 auto indices = recordsToProxyIndices();
346 for (
auto& provider : *dataProviders_) {
347 provider->updateLookup(indices);
349 dataProviders_.reset();
351 mustFinishConfiguration_ =
false;
354 using Itr = RecordProviders::iterator;
358 std::vector<std::shared_ptr<EventSetupRecordProvider>>& oDependents) {
359 for (
Itr it = itBegin; it != itEnd; ++it) {
361 const std::set<EventSetupRecordKey>&
deps = (*it)->dependentRecords();
362 if (deps.end() != deps.find(iKey)) {
363 oDependents.push_back(*it);
372 if (recProvider ==
nullptr) {
376 std::vector<std::shared_ptr<EventSetupRecordProvider>> dependents;
377 findDependents(iKey, recordProviders_.begin(), recordProviders_.end(), dependents);
379 dependents.erase(
std::unique(dependents.begin(), dependents.end()), dependents.end());
382 for (
auto&
d : dependents) {
387 void EventSetupProvider::forceCacheClear() {
388 for (
auto& recProvider : recordProviders_) {
390 recProvider->resetProxies();
395 void EventSetupProvider::checkESProducerSharing(
397 std::set<ParameterSetIDHolder>& sharingCheckDone,
401 <<
"EventSetupProvider::checkESProducerSharing: Checking processes with SubProcess Indexes " 402 << subProcessIndex() <<
" and " << precedingESProvider.
subProcessIndex();
404 if (referencedESProducers.empty()) {
405 for (
auto& recProvider : recordProviders_) {
406 recProvider->getReferencedESProducers(referencedESProducers);
413 std::map<EventSetupRecordKey, bool> allComponentsMatch;
415 std::map<ParameterSetID, bool> candidateNotRejectedYet;
419 for (
auto const& iRecord : referencedESProducers) {
420 for (
auto const& iComponent : iRecord.second) {
423 if (sharingCheckDone.find(psetIDHolder) != sharingCheckDone.end())
426 bool firstProcessWithThisPSet =
false;
427 bool precedingHasMatchingPSet =
false;
432 firstProcessWithThisPSet,
433 precedingHasMatchingPSet);
435 if (firstProcessWithThisPSet) {
436 sharingCheckDone.insert(psetIDHolder);
437 allComponentsMatch[iRecord.first] =
false;
441 if (!precedingHasMatchingPSet) {
442 allComponentsMatch[iRecord.first] =
false;
459 auto iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
460 if (iCandidateNotRejectedYet == candidateNotRejectedYet.end()) {
461 candidateNotRejectedYet[psetID] =
true;
462 iCandidateNotRejectedYet = candidateNotRejectedYet.find(psetID);
484 if (iCandidateNotRejectedYet->second ==
true) {
485 auto iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
486 if (iAllComponentsMatch == allComponentsMatch.end()) {
490 bool match = doRecordsMatch(precedingESProvider, iRecord.first, allComponentsMatch, esController);
491 allComponentsMatch[iRecord.first] =
match;
492 iAllComponentsMatch = allComponentsMatch.find(iRecord.first);
494 if (!iAllComponentsMatch->second) {
495 iCandidateNotRejectedYet->second =
false;
502 for (
auto const& candidate : candidateNotRejectedYet) {
504 bool canBeShared = candidate.second;
507 logInfoWhenSharing(pset);
509 sharingCheckDone.insert(psetIDHolder);
517 std::shared_ptr<DataProxyProvider> dataProxyProvider;
518 std::set<EventSetupRecordKey>
const& keysForPSetID1 = (*precedingESProvider.
psetIDToRecordKey_)[psetIDHolder];
519 for (
auto const&
key : keysForPSetID1) {
520 dataProxyProvider = precedingESProvider.
recordProvider(
key)->proxyProvider(psetIDHolder);
521 assert(dataProxyProvider);
525 std::set<EventSetupRecordKey>
const& keysForPSetID2 = (*psetIDToRecordKey_)[psetIDHolder];
526 for (
auto const&
key : keysForPSetID2) {
527 recordProvider(
key)->resetProxyProvider(psetIDHolder, dataProxyProvider);
540 std::map<EventSetupRecordKey, bool>& allComponentsMatch,
555 if ((*recordToFinders_)[eventSetupRecordKey].size() !=
560 for (
auto const&
finder : (*recordToFinders_)[eventSetupRecordKey]) {
569 fillReferencedDataKeys(eventSetupRecordKey);
572 std::map<DataKey, ComponentDescription const*>
const& dataItems = (*referencedDataKeys_)[eventSetupRecordKey];
574 std::map<DataKey, ComponentDescription const*>
const& precedingDataItems =
577 if (dataItems.size() != precedingDataItems.size()) {
581 for (
auto const& dataItem : dataItems) {
582 auto precedingDataItem = precedingDataItems.find(dataItem.first);
583 if (precedingDataItem == precedingDataItems.end()) {
586 if (dataItem.second->pid_ != precedingDataItem->second->pid_) {
592 if (!dataItem.second->isSource_ && !dataItem.second->isLooper_) {
594 dataItem.second->pid_, subProcessIndex_, precedingESProvider.
subProcessIndex_);
601 if (recProvider !=
nullptr) {
602 std::set<EventSetupRecordKey> dependentRecords = recProvider->
dependentRecords();
603 for (
auto const& dependentRecord : dependentRecords) {
604 auto iter = allComponentsMatch.find(dependentRecord);
605 if (iter != allComponentsMatch.end()) {
612 bool match = doRecordsMatch(precedingESProvider, dependentRecord, allComponentsMatch, esController);
613 allComponentsMatch[dependentRecord] =
match;
622 if (referencedDataKeys_->find(eventSetupRecordKey) != referencedDataKeys_->end())
626 if (recProvider ==
nullptr) {
627 (*referencedDataKeys_)[eventSetupRecordKey];
633 void EventSetupProvider::resetRecordToProxyPointers() {
634 for (
auto const& recProvider : recordProviders_) {
637 RecordToPreferred::const_iterator itRecordFound = recordToPreferred_->find(recProvider->key());
638 if (itRecordFound != recordToPreferred_->end()) {
639 preferredInfo = &(itRecordFound->second);
641 recProvider->resetRecordToProxyPointers(*preferredInfo);
645 void EventSetupProvider::clearInitializationData() {
646 preferredProviderInfo_.reset();
647 referencedDataKeys_.reset();
648 recordToFinders_.reset();
649 psetIDToRecordKey_.reset();
650 recordToPreferred_.reset();
651 recordsWithALooperProxy_.reset();
656 eventSetup_.add(iRecord);
660 auto key = iRecordProvider->key();
673 if (mustFinishConfiguration_) {
674 finishConfiguration();
677 for (
auto const& recProvider : recordProviders_) {
678 recProvider->addRecordToIfValid(*
this, iValue);
683 std::set<ComponentDescription> EventSetupProvider::proxyProviderDescriptions()
const {
684 typedef std::set<ComponentDescription> Set;
687 for (
auto const& recProvider : recordProviders_) {
688 auto const&
d = recProvider->proxyProviderDescriptions();
689 descriptions.insert(
d.begin(),
d.end());
691 if (dataProviders_.get()) {
692 for (
auto const&
p : *dataProviders_) {
693 descriptions.insert(
p->description());
700 bool EventSetupProvider::isWithinValidityInterval(
IOVSyncValue const& iSync)
const {
701 for (
auto const& recProvider : recordProviders_) {
702 auto const& iov = recProvider->validityInterval();
713 unsigned int index = 0;
714 for (
auto provider : recordProviders_) {
716 index, provider->key(), provider->registeredDataKeys(), provider->componentsForRegisteredDataKeys());
725 void EventSetupProvider::logInfoWhenSharing(
ParameterSet const& iConfiguration) {
730 <<
"Sharing " << edmtype <<
": class=" << modtype <<
" label='" << label <<
"'";
734 insert(iKey, std::unique_ptr<EventSetupRecordProvider>());
735 eventSetup_.setKeyIters(recordKeys_.begin(), recordKeys_.end());
std::shared_ptr< EventSetupRecordProvider > & recordProvider(const EventSetupRecordKey &iKey)
std::map< DataKey, ComponentDescription > DataToPreferredProviderMap
static void findDependents(const EventSetupRecordKey &iKey, Itr itBegin, Itr itEnd, std::vector< std::shared_ptr< EventSetupRecordProvider >> &oDependents)
void lookForMatches(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex, bool &firstProcessWithThisPSet, bool &precedingHasMatchingPSet) const
T getParameter(std::string const &) const
void add(std::shared_ptr< DataProxyProvider >)
void insert(const eventsetup::EventSetupRecordKey &, const eventsetup::EventSetupRecordImpl *)
bool isFirstMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
bool isMatchingESProducer(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
unsigned int dataKeysInRecord(unsigned int iRecordIndex, EventSetupRecordKey const &iRecord, std::vector< DataKey > const &iDataKeys, std::vector< ComponentDescription const * > const &iComponents)
EventSetupProvider(ActivityRegistry *, unsigned subProcessIndex=0U, PreferredProviderInfo const *iInfo=0)
std::unique_ptr< std::map< ParameterSetIDHolder, std::set< EventSetupRecordKey > > > psetIDToRecordKey_
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
bool isLastMatch(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const
std::unique_ptr< std::map< EventSetupRecordKey, std::map< DataKey, ComponentDescription const * > > > referencedDataKeys_
void fillReferencedDataKeys(std::map< DataKey, ComponentDescription const * > &referencedDataKeys) const
void fillReferencedDataKeys(EventSetupRecordKey const &eventSetupRecordKey)
std::vector< std::pair< DataKey, edm::propagate_const< std::shared_ptr< DataProxy > > > > KeyedProxies
ParameterSet const * getESProducerPSet(ParameterSetID const &psetID, unsigned subProcessIndex) const
RecordProviders::iterator Itr
void setEventSetup(EventSetupImpl const *iEventSetup)
std::unique_ptr< std::set< EventSetupRecordKey > > recordsWithALooperProxy_
std::vector< std::shared_ptr< EventSetupRecordProvider >> RecordProviders
static void preferEverything(const ComponentDescription &iComponent, const RecordProviders &iRecordProviders, RecordToPreferred &iReturnValue)
find everything made by a DataProxyProvider and add it to the 'preferred' list
def unique(seq, keepstr=True)
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
void addFinder(std::shared_ptr< EventSetupRecordIntervalFinder >)
For now, only use one finder.
std::unique_ptr< std::map< EventSetupRecordKey, std::vector< std::shared_ptr< EventSetupRecordIntervalFinder > > > > recordToFinders_
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
std::shared_ptr< DataProxyProvider > proxyProvider(ComponentDescription const &)
returns the first matching DataProxyProvider or a 'null' if not found
std::vector< size_type > Keys
unsigned subProcessIndex() const
heterocontainer::HCTypeTag TypeTag
std::set< ComponentDescription > proxyProviderDescriptions() const
return information on which DataProxyProviders are supplying information
std::map< EventSetupRecordKey, EventSetupRecordProvider::DataToPreferredProviderMap > RecordToPreferred
const TypeTag & type() const
static const ValidityInterval & invalidInterval()
std::set< EventSetupRecordKey > dependentRecords() const
Returns the list of Records the provided Record depends on (usually none)
bool isMatchingESSource(ParameterSetID const &psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) 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_
T get(const Candidate &c)
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)