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