Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-16 00:05:36

0001 // -*- C++ -*-
0002 //
0003 
0004 // user include files
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/ConvertException.h"
0016 #include "FWCore/Utilities/interface/EDMException.h"
0017 #include "FWCore/Utilities/interface/Exception.h"
0018 
0019 #include <exception>
0020 #include <string>
0021 
0022 namespace edm {
0023   namespace eventsetup {
0024     // ---------------------------------------------------------------
0025     std::unique_ptr<EventSetupProvider> makeEventSetupProvider(ParameterSet const& params,
0026                                                                unsigned subProcessIndex,
0027                                                                ActivityRegistry* activityRegistry) {
0028       std::vector<std::string> prefers = params.getParameter<std::vector<std::string> >("@all_esprefers");
0029 
0030       if (prefers.empty()) {
0031         return std::make_unique<EventSetupProvider>(activityRegistry, subProcessIndex);
0032       }
0033 
0034       EventSetupProvider::PreferredProviderInfo preferInfo;
0035       EventSetupProvider::RecordToDataMap recordToData;
0036 
0037       //recordToData.insert(std::make_pair(std::string("DummyRecord"),
0038       //      std::make_pair(std::string("DummyData"), std::string())));
0039       //preferInfo[ComponentDescription("DummyProxyProvider", "", false)]=
0040       //      recordToData;
0041 
0042       for (std::vector<std::string>::iterator itName = prefers.begin(), itNameEnd = prefers.end(); itName != itNameEnd;
0043            ++itName) {
0044         recordToData.clear();
0045         ParameterSet const& preferPSet = params.getParameterSet(*itName);
0046         std::vector<std::string> recordNames = preferPSet.getParameterNames();
0047         for (std::vector<std::string>::iterator itRecordName = recordNames.begin(), itRecordNameEnd = recordNames.end();
0048              itRecordName != itRecordNameEnd;
0049              ++itRecordName) {
0050           if ((*itRecordName)[0] == '@') {
0051             //this is a 'hidden parameter' so skip it
0052             continue;
0053           }
0054 
0055           //this should be a record name with its info
0056           try {
0057             std::vector<std::string> dataInfo = preferPSet.getParameter<std::vector<std::string> >(*itRecordName);
0058 
0059             if (dataInfo.empty()) {
0060               //FUTURE: empty should just mean all data
0061               throw Exception(errors::Configuration)
0062                   << "The record named " << *itRecordName << " specifies no data items";
0063             }
0064             //FUTURE: 'any' should be a special name
0065             for (std::vector<std::string>::iterator itDatum = dataInfo.begin(), itDatumEnd = dataInfo.end();
0066                  itDatum != itDatumEnd;
0067                  ++itDatum) {
0068               std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
0069               std::string labelName;
0070 
0071               if (itDatum->size() != datumName.size()) {
0072                 labelName = std::string(*itDatum, datumName.size() + 1);
0073               }
0074               recordToData.insert(std::make_pair(std::string(*itRecordName), std::make_pair(datumName, labelName)));
0075             }
0076           } catch (cms::Exception const& iException) {
0077             cms::Exception theError("ESPreferConfigurationError");
0078             theError << "While parsing the es_prefer statement for type="
0079                      << preferPSet.getParameter<std::string>("@module_type") << " label=\""
0080                      << preferPSet.getParameter<std::string>("@module_label") << "\" an error occurred.";
0081             theError.append(iException);
0082             throw theError;
0083           }
0084         }
0085         preferInfo[ComponentDescription(preferPSet.getParameter<std::string>("@module_type"),
0086                                         preferPSet.getParameter<std::string>("@module_label"),
0087                                         ComponentDescription::unknownID(),
0088                                         false)] = recordToData;
0089       }
0090       return std::make_unique<EventSetupProvider>(activityRegistry, subProcessIndex, &preferInfo);
0091     }
0092 
0093     // ---------------------------------------------------------------
0094     void fillEventSetupProvider(ModuleTypeResolverBase const* resolver,
0095                                 EventSetupsController& esController,
0096                                 EventSetupProvider& cp,
0097                                 ParameterSet& params) {
0098       std::vector<std::string> providers = params.getParameter<std::vector<std::string> >("@all_esmodules");
0099 
0100       for (std::vector<std::string>::iterator itName = providers.begin(), itNameEnd = providers.end();
0101            itName != itNameEnd;
0102            ++itName) {
0103         ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
0104         validateEventSetupParameters(*providerPSet);
0105         providerPSet->registerIt();
0106         ModuleFactory::get()->addTo(esController, cp, *providerPSet, resolver);
0107       }
0108 
0109       std::vector<std::string> sources = params.getParameter<std::vector<std::string> >("@all_essources");
0110 
0111       for (std::vector<std::string>::iterator itName = sources.begin(), itNameEnd = sources.end(); itName != itNameEnd;
0112            ++itName) {
0113         ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
0114         validateEventSetupParameters(*providerPSet);
0115         providerPSet->registerIt();
0116         SourceFactory::get()->addTo(esController, cp, *providerPSet, resolver);
0117       }
0118     }
0119 
0120     // ---------------------------------------------------------------
0121     void validateEventSetupParameters(ParameterSet& pset) {
0122       std::string modtype;
0123       std::string moduleLabel;
0124       modtype = pset.getParameter<std::string>("@module_type");
0125       moduleLabel = pset.getParameter<std::string>("@module_label");
0126       // Check for the "unlabeled" case
0127       // This is an artifact left over from the old configuration language
0128       // we were using before switching to the python configuration
0129       // This is handled in the validation code and python configuration
0130       // files by using a label equal to the module typename.
0131       if (moduleLabel == std::string("")) {
0132         moduleLabel = modtype;
0133       }
0134 
0135       std::unique_ptr<ParameterSetDescriptionFillerBase> filler(
0136           ParameterSetDescriptionFillerPluginFactory::get()->create(modtype));
0137       ConfigurationDescriptions descriptions(filler->baseType(), modtype);
0138       filler->fill(descriptions);
0139       try {
0140         edm::convertException::wrap([&]() { descriptions.validate(pset, moduleLabel); });
0141       } catch (cms::Exception& iException) {
0142         std::ostringstream ost;
0143         ost << "Validating configuration of ESProducer or ESSource of type " << modtype << " with label: '"
0144             << moduleLabel << "'";
0145         iException.addContext(ost.str());
0146         throw;
0147       }
0148     }
0149   }  // namespace eventsetup
0150 }  // namespace edm