Go to the documentation of this file.00001
00002
00003
00004
00005 #include "FWCore/Framework/interface/EventSetupProviderMaker.h"
00006
00007 #include "FWCore/Framework/interface/CommonParams.h"
00008 #include "FWCore/Framework/interface/ComponentDescription.h"
00009 #include "FWCore/Framework/interface/EventSetupProvider.h"
00010 #include "FWCore/Framework/interface/ModuleFactory.h"
00011 #include "FWCore/Framework/interface/SourceFactory.h"
00012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerBase.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerPluginFactory.h"
00016 #include "FWCore/Utilities/interface/EDMException.h"
00017
00018 #include <string>
00019
00020 namespace edm {
00021 namespace eventsetup {
00022
00023 std::auto_ptr<EventSetupProvider>
00024 makeEventSetupProvider(ParameterSet const& params) {
00025 std::vector<std::string> prefers =
00026 params.getParameter<std::vector<std::string> >("@all_esprefers");
00027
00028 if(prefers.empty()) {
00029 return std::auto_ptr<EventSetupProvider>(new EventSetupProvider());
00030 }
00031
00032 EventSetupProvider::PreferredProviderInfo preferInfo;
00033 EventSetupProvider::RecordToDataMap recordToData;
00034
00035
00036
00037
00038
00039
00040 for(std::vector<std::string>::iterator itName = prefers.begin(), itNameEnd = prefers.end();
00041 itName != itNameEnd;
00042 ++itName) {
00043 recordToData.clear();
00044 ParameterSet const& preferPSet = params.getParameterSet(*itName);
00045 std::vector<std::string> recordNames = preferPSet.getParameterNames();
00046 for(std::vector<std::string>::iterator itRecordName = recordNames.begin(),
00047 itRecordNameEnd = recordNames.end();
00048 itRecordName != itRecordNameEnd;
00049 ++itRecordName) {
00050
00051 if((*itRecordName)[0] == '@') {
00052
00053 continue;
00054 }
00055
00056
00057 try {
00058 std::vector<std::string> dataInfo =
00059 preferPSet.getParameter<std::vector<std::string> >(*itRecordName);
00060
00061 if(dataInfo.empty()) {
00062
00063 throw Exception(errors::Configuration)
00064 << "The record named "
00065 << *itRecordName << " specifies no data items";
00066 }
00067
00068 for(std::vector<std::string>::iterator itDatum = dataInfo.begin(),
00069 itDatumEnd = dataInfo.end();
00070 itDatum != itDatumEnd;
00071 ++itDatum){
00072 std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
00073 std::string labelName;
00074
00075 if(itDatum->size() != datumName.size()) {
00076 labelName = std::string(*itDatum, datumName.size() + 1);
00077 }
00078 recordToData.insert(std::make_pair(std::string(*itRecordName),
00079 std::make_pair(datumName,
00080 labelName)));
00081 }
00082 } catch(cms::Exception const& iException) {
00083 cms::Exception theError("ESPreferConfigurationError");
00084 theError << "While parsing the es_prefer statement for type="
00085 << preferPSet.getParameter<std::string>("@module_type")
00086 << " label=\""
00087 << preferPSet.getParameter<std::string>("@module_label")
00088 << "\" an error occurred.";
00089 theError.append(iException);
00090 throw theError;
00091 }
00092 }
00093 preferInfo[ComponentDescription(preferPSet.getParameter<std::string>("@module_type"),
00094 preferPSet.getParameter<std::string>("@module_label"),
00095 false)] = recordToData;
00096 }
00097 return std::auto_ptr<EventSetupProvider>(new EventSetupProvider(&preferInfo));
00098 }
00099
00100
00101 void
00102 fillEventSetupProvider(EventSetupProvider& cp,
00103 ParameterSet& params,
00104 CommonParams const& common) {
00105 std::vector<std::string> providers =
00106 params.getParameter<std::vector<std::string> >("@all_esmodules");
00107
00108 for(std::vector<std::string>::iterator itName = providers.begin(), itNameEnd = providers.end();
00109 itName != itNameEnd;
00110 ++itName) {
00111 ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
00112 validateEventSetupParameters(*providerPSet);
00113 providerPSet->registerIt();
00114 ModuleFactory::get()->addTo(cp,
00115 *providerPSet,
00116 common.processName_,
00117 common.releaseVersion_,
00118 common.passID_);
00119 }
00120
00121 std::vector<std::string> sources =
00122 params.getParameter<std::vector<std::string> >("@all_essources");
00123
00124 for(std::vector<std::string>::iterator itName = sources.begin(), itNameEnd = sources.end();
00125 itName != itNameEnd;
00126 ++itName) {
00127 ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
00128 validateEventSetupParameters(*providerPSet);
00129 providerPSet->registerIt();
00130 SourceFactory::get()->addTo(cp,
00131 *providerPSet,
00132 common.processName_,
00133 common.releaseVersion_,
00134 common.passID_);
00135 }
00136 }
00137
00138
00139 void validateEventSetupParameters(ParameterSet & pset) {
00140 std::string modtype;
00141 std::string moduleLabel;
00142 try {
00143 modtype = pset.getParameter<std::string>("@module_type");
00144 moduleLabel = pset.getParameter<std::string>("@module_label");
00145
00146
00147
00148
00149
00150 if (moduleLabel == std::string("")) {
00151 moduleLabel = modtype;
00152 }
00153
00154 std::auto_ptr<ParameterSetDescriptionFillerBase> filler(
00155 ParameterSetDescriptionFillerPluginFactory::get()->create(modtype));
00156 ConfigurationDescriptions descriptions(filler->baseType());
00157 filler->fill(descriptions);
00158 descriptions.validate(pset, moduleLabel);
00159 }
00160 catch (cms::Exception& iException) {
00161 Exception toThrow(errors::Configuration, "Failed validating configuration of ESProducer or ESSource.");
00162 toThrow << "\nThe plugin name is \"" << modtype << "\"\n";
00163 toThrow << "The module label is \"" << moduleLabel << "\"\n";
00164 toThrow.append(iException);
00165 throw toThrow;
00166 }
00167 }
00168 }
00169 }