CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/FWCore/Framework/src/EventSetupProviderMaker.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 
00004 // user include files
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/ConvertException.h"
00017 #include "FWCore/Utilities/interface/EDMException.h"
00018 #include "FWCore/Utilities/interface/Exception.h"
00019 
00020 #include <exception>
00021 #include <string>
00022 
00023 namespace edm {
00024   namespace eventsetup {
00025   // ---------------------------------------------------------------
00026     std::auto_ptr<EventSetupProvider>
00027     makeEventSetupProvider(ParameterSet const& params) {
00028       std::vector<std::string> prefers =
00029         params.getParameter<std::vector<std::string> >("@all_esprefers");
00030 
00031       if(prefers.empty()) {
00032         return std::auto_ptr<EventSetupProvider>(new EventSetupProvider());
00033       }
00034 
00035       EventSetupProvider::PreferredProviderInfo preferInfo;
00036       EventSetupProvider::RecordToDataMap recordToData;
00037 
00038       //recordToData.insert(std::make_pair(std::string("DummyRecord"),
00039       //      std::make_pair(std::string("DummyData"), std::string())));
00040       //preferInfo[ComponentDescription("DummyProxyProvider", "", false)]=
00041       //      recordToData;
00042 
00043       for(std::vector<std::string>::iterator itName = prefers.begin(), itNameEnd = prefers.end();
00044           itName != itNameEnd;
00045           ++itName) {
00046         recordToData.clear();
00047         ParameterSet const& preferPSet = params.getParameterSet(*itName);
00048         std::vector<std::string> recordNames = preferPSet.getParameterNames();
00049         for(std::vector<std::string>::iterator itRecordName = recordNames.begin(),
00050             itRecordNameEnd = recordNames.end();
00051             itRecordName != itRecordNameEnd;
00052             ++itRecordName) {
00053 
00054           if((*itRecordName)[0] == '@') {
00055             //this is a 'hidden parameter' so skip it
00056             continue;
00057           }
00058 
00059           //this should be a record name with its info
00060           try {
00061             std::vector<std::string> dataInfo =
00062               preferPSet.getParameter<std::vector<std::string> >(*itRecordName);
00063 
00064             if(dataInfo.empty()) {
00065               //FUTURE: empty should just mean all data
00066               throw Exception(errors::Configuration)
00067                 << "The record named "
00068                 << *itRecordName << " specifies no data items";
00069             }
00070             //FUTURE: 'any' should be a special name
00071             for(std::vector<std::string>::iterator itDatum = dataInfo.begin(),
00072                 itDatumEnd = dataInfo.end();
00073                 itDatum != itDatumEnd;
00074                 ++itDatum){
00075               std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
00076               std::string labelName;
00077 
00078               if(itDatum->size() != datumName.size()) {
00079                 labelName = std::string(*itDatum, datumName.size() + 1);
00080               }
00081               recordToData.insert(std::make_pair(std::string(*itRecordName),
00082                                                  std::make_pair(datumName,
00083                                                                 labelName)));
00084             }
00085           } catch(cms::Exception const& iException) {
00086             cms::Exception theError("ESPreferConfigurationError");
00087             theError << "While parsing the es_prefer statement for type="
00088                      << preferPSet.getParameter<std::string>("@module_type")
00089                      << " label=\""
00090                      << preferPSet.getParameter<std::string>("@module_label")
00091                      << "\" an error occurred.";
00092             theError.append(iException);
00093             throw theError;
00094           }
00095         }
00096         preferInfo[ComponentDescription(preferPSet.getParameter<std::string>("@module_type"),
00097                                         preferPSet.getParameter<std::string>("@module_label"),
00098                                         false)] = recordToData;
00099       }
00100       return std::auto_ptr<EventSetupProvider>(new EventSetupProvider(&preferInfo));
00101     }
00102 
00103     // ---------------------------------------------------------------
00104     void
00105     fillEventSetupProvider(EventSetupProvider& cp,
00106                            ParameterSet& params,
00107                            CommonParams const& common) {
00108       std::vector<std::string> providers =
00109         params.getParameter<std::vector<std::string> >("@all_esmodules");
00110 
00111       for(std::vector<std::string>::iterator itName = providers.begin(), itNameEnd = providers.end();
00112           itName != itNameEnd;
00113           ++itName) {
00114         ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
00115         validateEventSetupParameters(*providerPSet);
00116         providerPSet->registerIt();
00117         ModuleFactory::get()->addTo(cp,
00118                                     *providerPSet,
00119                                     common.processName_,
00120                                     common.releaseVersion_,
00121                                     common.passID_);
00122       }
00123 
00124       std::vector<std::string> sources =
00125         params.getParameter<std::vector<std::string> >("@all_essources");
00126 
00127       for(std::vector<std::string>::iterator itName = sources.begin(), itNameEnd = sources.end();
00128           itName != itNameEnd;
00129           ++itName) {
00130         ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
00131         validateEventSetupParameters(*providerPSet);
00132         providerPSet->registerIt();
00133         SourceFactory::get()->addTo(cp,
00134                                     *providerPSet,
00135                                     common.processName_,
00136                                     common.releaseVersion_,
00137                                     common.passID_);
00138       }
00139     }
00140 
00141     // ---------------------------------------------------------------
00142     void validateEventSetupParameters(ParameterSet & pset) {
00143       std::string modtype;
00144       std::string moduleLabel;
00145       modtype = pset.getParameter<std::string>("@module_type");
00146       moduleLabel = pset.getParameter<std::string>("@module_label");
00147       // Check for the "unlabeled" case
00148       // This is an artifact left over from the old configuration language
00149       // we were using before switching to the python configuration
00150       // This is handled in the validation code and python configuration
00151       // files by using a label equal to the module typename.
00152       if (moduleLabel == std::string("")) {
00153         moduleLabel = modtype;
00154       }
00155 
00156       std::auto_ptr<ParameterSetDescriptionFillerBase> filler(
00157         ParameterSetDescriptionFillerPluginFactory::get()->create(modtype));
00158       ConfigurationDescriptions descriptions(filler->baseType());
00159       filler->fill(descriptions);
00160       try {
00161         try {
00162           descriptions.validate(pset, moduleLabel);
00163         }
00164         catch (cms::Exception& e) { throw; }
00165         catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
00166         catch (std::exception& e) { convertException::stdToEDM(e); }
00167         catch(std::string& s) { convertException::stringToEDM(s); }
00168         catch(char const* c) { convertException::charPtrToEDM(c); }
00169         catch (...) { convertException::unknownToEDM(); }
00170       }
00171       catch (cms::Exception & iException) {
00172         std::ostringstream ost;
00173         ost << "Validating configuration of ESProducer or ESSource of type " << modtype
00174             << " with label: '" << moduleLabel << "'";
00175         iException.addContext(ost.str());
00176         throw;
00177       }
00178     }
00179   }
00180 }