CMS 3D CMS Logo

EventSetupProviderMaker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 
4 // user include files
6 
18 
19 #include <exception>
20 #include <string>
21 
22 namespace edm {
23  namespace eventsetup {
24  // ---------------------------------------------------------------
25  std::unique_ptr<EventSetupProvider> makeEventSetupProvider(ParameterSet const& params,
26  unsigned subProcessIndex,
27  ActivityRegistry* activityRegistry) {
28  std::vector<std::string> prefers = params.getParameter<std::vector<std::string> >("@all_esprefers");
29 
30  if (prefers.empty()) {
31  return std::make_unique<EventSetupProvider>(activityRegistry, subProcessIndex);
32  }
33 
36 
37  //recordToData.insert(std::make_pair(std::string("DummyRecord"),
38  // std::make_pair(std::string("DummyData"), std::string())));
39  //preferInfo[ComponentDescription("DummyProxyProvider", "", false)]=
40  // recordToData;
41 
42  for (std::vector<std::string>::iterator itName = prefers.begin(), itNameEnd = prefers.end(); itName != itNameEnd;
43  ++itName) {
44  recordToData.clear();
45  ParameterSet const& preferPSet = params.getParameterSet(*itName);
46  std::vector<std::string> recordNames = preferPSet.getParameterNames();
47  for (std::vector<std::string>::iterator itRecordName = recordNames.begin(), itRecordNameEnd = recordNames.end();
48  itRecordName != itRecordNameEnd;
49  ++itRecordName) {
50  if ((*itRecordName)[0] == '@') {
51  //this is a 'hidden parameter' so skip it
52  continue;
53  }
54 
55  //this should be a record name with its info
56  try {
57  std::vector<std::string> dataInfo = preferPSet.getParameter<std::vector<std::string> >(*itRecordName);
58 
59  if (dataInfo.empty()) {
60  //FUTURE: empty should just mean all data
62  << "The record named " << *itRecordName << " specifies no data items";
63  }
64  //FUTURE: 'any' should be a special name
65  for (std::vector<std::string>::iterator itDatum = dataInfo.begin(), itDatumEnd = dataInfo.end();
66  itDatum != itDatumEnd;
67  ++itDatum) {
68  std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
69  std::string labelName;
70 
71  if (itDatum->size() != datumName.size()) {
72  labelName = std::string(*itDatum, datumName.size() + 1);
73  }
74  recordToData.insert(std::make_pair(std::string(*itRecordName), std::make_pair(datumName, labelName)));
75  }
76  } catch (cms::Exception const& iException) {
77  cms::Exception theError("ESPreferConfigurationError");
78  theError << "While parsing the es_prefer statement for type="
79  << preferPSet.getParameter<std::string>("@module_type") << " label=\""
80  << preferPSet.getParameter<std::string>("@module_label") << "\" an error occurred.";
81  theError.append(iException);
82  throw theError;
83  }
84  }
85  preferInfo[ComponentDescription(preferPSet.getParameter<std::string>("@module_type"),
86  preferPSet.getParameter<std::string>("@module_label"),
88  false)] = recordToData;
89  }
90  return std::make_unique<EventSetupProvider>(activityRegistry, subProcessIndex, &preferInfo);
91  }
92 
93  // ---------------------------------------------------------------
95  std::vector<std::string> providers = params.getParameter<std::vector<std::string> >("@all_esmodules");
96 
97  for (std::vector<std::string>::iterator itName = providers.begin(), itNameEnd = providers.end();
98  itName != itNameEnd;
99  ++itName) {
100  ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
101  validateEventSetupParameters(*providerPSet);
102  providerPSet->registerIt();
103  ModuleFactory::get()->addTo(esController, cp, *providerPSet);
104  }
105 
106  std::vector<std::string> sources = params.getParameter<std::vector<std::string> >("@all_essources");
107 
108  for (std::vector<std::string>::iterator itName = sources.begin(), itNameEnd = sources.end(); itName != itNameEnd;
109  ++itName) {
110  ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
111  validateEventSetupParameters(*providerPSet);
112  providerPSet->registerIt();
113  SourceFactory::get()->addTo(esController, cp, *providerPSet);
114  }
115  }
116 
117  // ---------------------------------------------------------------
119  std::string modtype;
121  modtype = pset.getParameter<std::string>("@module_type");
122  moduleLabel = pset.getParameter<std::string>("@module_label");
123  // Check for the "unlabeled" case
124  // This is an artifact left over from the old configuration language
125  // we were using before switching to the python configuration
126  // This is handled in the validation code and python configuration
127  // files by using a label equal to the module typename.
128  if (moduleLabel == std::string("")) {
129  moduleLabel = modtype;
130  }
131 
132  std::unique_ptr<ParameterSetDescriptionFillerBase> filler(
134  ConfigurationDescriptions descriptions(filler->baseType(), modtype);
135  filler->fill(descriptions);
136  try {
137  edm::convertException::wrap([&]() { descriptions.validate(pset, moduleLabel); });
138  } catch (cms::Exception& iException) {
139  std::ostringstream ost;
140  ost << "Validating configuration of ESProducer or ESSource of type " << modtype << " with label: '"
141  << moduleLabel << "'";
142  iException.addContext(ost.str());
143  throw;
144  }
145  }
146  } // namespace eventsetup
147 } // namespace edm
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
def create(alignables, pedeDump, additionalData, outputFile, config)
void append(Exception const &another)
Definition: Exception.cc:153
std::multimap< RecordName, DataKeyInfo > RecordToDataMap
std::unique_ptr< EventSetupProvider > makeEventSetupProvider(ParameterSet const &params, unsigned subProcessIndex, ActivityRegistry *activityRegistry)
std::map< ComponentDescription, RecordToDataMap > PreferredProviderInfo
void validateEventSetupParameters(ParameterSet &pset)
void fillEventSetupProvider(EventSetupsController &esController, EventSetupProvider &cp, ParameterSet &params)
ParameterSet const & registerIt()
void addContext(std::string const &context)
Definition: Exception.cc:165
static constexpr unsigned int unknownID() noexcept
HLT enums.
static ComponentFactory< T > const * get()
auto wrap(F iFunc) -> decltype(iFunc())
#define get
std::vector< std::string > getParameterNames() const