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"),
87  false)] = recordToData;
88  }
89  return std::make_unique<EventSetupProvider>(activityRegistry, subProcessIndex, &preferInfo);
90  }
91 
92  // ---------------------------------------------------------------
94  std::vector<std::string> providers = params.getParameter<std::vector<std::string> >("@all_esmodules");
95 
96  for (std::vector<std::string>::iterator itName = providers.begin(), itNameEnd = providers.end();
97  itName != itNameEnd;
98  ++itName) {
99  ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
100  validateEventSetupParameters(*providerPSet);
101  providerPSet->registerIt();
102  ModuleFactory::get()->addTo(esController, cp, *providerPSet);
103  }
104 
105  std::vector<std::string> sources = params.getParameter<std::vector<std::string> >("@all_essources");
106 
107  for (std::vector<std::string>::iterator itName = sources.begin(), itNameEnd = sources.end(); itName != itNameEnd;
108  ++itName) {
109  ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
110  validateEventSetupParameters(*providerPSet);
111  providerPSet->registerIt();
112  SourceFactory::get()->addTo(esController, cp, *providerPSet);
113  }
114  }
115 
116  // ---------------------------------------------------------------
118  std::string modtype;
119  std::string moduleLabel;
120  modtype = pset.getParameter<std::string>("@module_type");
121  moduleLabel = pset.getParameter<std::string>("@module_label");
122  // Check for the "unlabeled" case
123  // This is an artifact left over from the old configuration language
124  // we were using before switching to the python configuration
125  // This is handled in the validation code and python configuration
126  // files by using a label equal to the module typename.
127  if (moduleLabel == std::string("")) {
128  moduleLabel = modtype;
129  }
130 
131  std::unique_ptr<ParameterSetDescriptionFillerBase> filler(
133  ConfigurationDescriptions descriptions(filler->baseType(), modtype);
134  filler->fill(descriptions);
135  try {
136  edm::convertException::wrap([&]() { descriptions.validate(pset, moduleLabel); });
137  } catch (cms::Exception& iException) {
138  std::ostringstream ost;
139  ost << "Validating configuration of ESProducer or ESSource of type " << modtype << " with label: '"
140  << moduleLabel << "'";
141  iException.addContext(ost.str());
142  throw;
143  }
144  }
145  } // namespace eventsetup
146 } // namespace edm
T getParameter(std::string const &) const
def create(alignables, pedeDump, additionalData, outputFile, config)
void append(Exception const &another)
Definition: Exception.cc:153
std::multimap< RecordName, DataKeyInfo > RecordToDataMap
std::map< ComponentDescription, RecordToDataMap > PreferredProviderInfo
void validateEventSetupParameters(ParameterSet &pset)
void fillEventSetupProvider(EventSetupsController &esController, EventSetupProvider &cp, ParameterSet &params)
std::vector< std::string > getParameterNames() const
ParameterSet const & getParameterSet(std::string const &) const
void addContext(std::string const &context)
Definition: Exception.cc:165
HLT enums.
std::unique_ptr< EventSetupProvider > makeEventSetupProvider(ParameterSet const &params, unsigned subProcessIndex, ActivityRegistry *)
static ComponentFactory< T > const * get()
auto wrap(F iFunc) -> decltype(iFunc())
ParameterSet const & registerIt()
T get(const Candidate &c)
Definition: component.h:55
ParameterSet * getPSetForUpdate(std::string const &name, bool &isTracked)