File indexing completed on 2024-04-06 12:12:10
0001
0002
0003
0004
0005 #include "FWCore/Framework/src/EventSetupProviderMaker.h"
0006
0007 #include "FWCore/Framework/interface/ComponentDescription.h"
0008 #include "FWCore/Framework/interface/EventSetupProvider.h"
0009 #include "FWCore/Framework/interface/ModuleFactory.h"
0010 #include "FWCore/Framework/interface/SourceFactory.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerBase.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerPluginFactory.h"
0015 #include "FWCore/Utilities/interface/EDMException.h"
0016 #include "FWCore/Utilities/interface/Exception.h"
0017
0018 #include <exception>
0019 #include <string>
0020
0021 namespace edm {
0022 namespace eventsetup {
0023
0024 std::unique_ptr<EventSetupProvider> makeEventSetupProvider(ParameterSet const& params,
0025 unsigned subProcessIndex,
0026 ActivityRegistry* activityRegistry) {
0027 std::vector<std::string> prefers = params.getParameter<std::vector<std::string> >("@all_esprefers");
0028
0029 if (prefers.empty()) {
0030 return std::make_unique<EventSetupProvider>(activityRegistry, subProcessIndex);
0031 }
0032
0033 EventSetupProvider::PreferredProviderInfo preferInfo;
0034 EventSetupProvider::RecordToDataMap recordToData;
0035
0036
0037
0038
0039
0040
0041 for (std::vector<std::string>::iterator itName = prefers.begin(), itNameEnd = prefers.end(); itName != itNameEnd;
0042 ++itName) {
0043 recordToData.clear();
0044 ParameterSet const& preferPSet = params.getParameterSet(*itName);
0045 std::vector<std::string> recordNames = preferPSet.getParameterNames();
0046 for (std::vector<std::string>::iterator itRecordName = recordNames.begin(), itRecordNameEnd = recordNames.end();
0047 itRecordName != itRecordNameEnd;
0048 ++itRecordName) {
0049 if ((*itRecordName)[0] == '@') {
0050
0051 continue;
0052 }
0053
0054
0055 try {
0056 std::vector<std::string> dataInfo = preferPSet.getParameter<std::vector<std::string> >(*itRecordName);
0057
0058 if (dataInfo.empty()) {
0059
0060 throw Exception(errors::Configuration)
0061 << "The record named " << *itRecordName << " specifies no data items";
0062 }
0063
0064 for (std::vector<std::string>::iterator itDatum = dataInfo.begin(), itDatumEnd = dataInfo.end();
0065 itDatum != itDatumEnd;
0066 ++itDatum) {
0067 std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
0068 std::string labelName;
0069
0070 if (itDatum->size() != datumName.size()) {
0071 labelName = std::string(*itDatum, datumName.size() + 1);
0072 }
0073 recordToData.insert(std::make_pair(std::string(*itRecordName), std::make_pair(datumName, labelName)));
0074 }
0075 } catch (cms::Exception const& iException) {
0076 cms::Exception theError("ESPreferConfigurationError");
0077 theError << "While parsing the es_prefer statement for type="
0078 << preferPSet.getParameter<std::string>("@module_type") << " label=\""
0079 << preferPSet.getParameter<std::string>("@module_label") << "\" an error occurred.";
0080 theError.append(iException);
0081 throw theError;
0082 }
0083 }
0084 preferInfo[ComponentDescription(preferPSet.getParameter<std::string>("@module_type"),
0085 preferPSet.getParameter<std::string>("@module_label"),
0086 ComponentDescription::unknownID(),
0087 false)] = recordToData;
0088 }
0089 return std::make_unique<EventSetupProvider>(activityRegistry, subProcessIndex, &preferInfo);
0090 }
0091
0092
0093 void fillEventSetupProvider(ModuleTypeResolverMaker const* resolverMaker,
0094 EventSetupsController& esController,
0095 EventSetupProvider& cp,
0096 ParameterSet& params) {
0097 std::vector<std::string> providers = params.getParameter<std::vector<std::string> >("@all_esmodules");
0098
0099 for (std::vector<std::string>::iterator itName = providers.begin(), itNameEnd = providers.end();
0100 itName != itNameEnd;
0101 ++itName) {
0102 ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
0103 ModuleFactory::get()->addTo(esController, cp, *providerPSet, resolverMaker);
0104 }
0105
0106 std::vector<std::string> sources = params.getParameter<std::vector<std::string> >("@all_essources");
0107
0108 for (std::vector<std::string>::iterator itName = sources.begin(), itNameEnd = sources.end(); itName != itNameEnd;
0109 ++itName) {
0110 ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
0111 SourceFactory::get()->addTo(esController, cp, *providerPSet, resolverMaker);
0112 }
0113 }
0114 }
0115 }