CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  tbb::task_arena* taskArena) {
29  std::vector<std::string> prefers = params.getParameter<std::vector<std::string> >("@all_esprefers");
30 
31  if (prefers.empty()) {
32  return std::make_unique<EventSetupProvider>(activityRegistry, taskArena, subProcessIndex);
33  }
34 
37 
38  //recordToData.insert(std::make_pair(std::string("DummyRecord"),
39  // std::make_pair(std::string("DummyData"), std::string())));
40  //preferInfo[ComponentDescription("DummyProxyProvider", "", false)]=
41  // recordToData;
42 
43  for (std::vector<std::string>::iterator itName = prefers.begin(), itNameEnd = prefers.end(); itName != itNameEnd;
44  ++itName) {
45  recordToData.clear();
46  ParameterSet const& preferPSet = params.getParameterSet(*itName);
47  std::vector<std::string> recordNames = preferPSet.getParameterNames();
48  for (std::vector<std::string>::iterator itRecordName = recordNames.begin(), itRecordNameEnd = recordNames.end();
49  itRecordName != itRecordNameEnd;
50  ++itRecordName) {
51  if ((*itRecordName)[0] == '@') {
52  //this is a 'hidden parameter' so skip it
53  continue;
54  }
55 
56  //this should be a record name with its info
57  try {
58  std::vector<std::string> dataInfo = preferPSet.getParameter<std::vector<std::string> >(*itRecordName);
59 
60  if (dataInfo.empty()) {
61  //FUTURE: empty should just mean all data
63  << "The record named " << *itRecordName << " specifies no data items";
64  }
65  //FUTURE: 'any' should be a special name
66  for (std::vector<std::string>::iterator itDatum = dataInfo.begin(), itDatumEnd = dataInfo.end();
67  itDatum != itDatumEnd;
68  ++itDatum) {
69  std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
70  std::string labelName;
71 
72  if (itDatum->size() != datumName.size()) {
73  labelName = std::string(*itDatum, datumName.size() + 1);
74  }
75  recordToData.insert(std::make_pair(std::string(*itRecordName), std::make_pair(datumName, labelName)));
76  }
77  } catch (cms::Exception const& iException) {
78  cms::Exception theError("ESPreferConfigurationError");
79  theError << "While parsing the es_prefer statement for type="
80  << preferPSet.getParameter<std::string>("@module_type") << " label=\""
81  << preferPSet.getParameter<std::string>("@module_label") << "\" an error occurred.";
82  theError.append(iException);
83  throw theError;
84  }
85  }
86  preferInfo[ComponentDescription(preferPSet.getParameter<std::string>("@module_type"),
87  preferPSet.getParameter<std::string>("@module_label"),
88  false)] = recordToData;
89  }
90  return std::make_unique<EventSetupProvider>(activityRegistry, taskArena, 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;
120  std::string moduleLabel;
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
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, tbb::task_arena *taskArena)
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
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void addContext(std::string const &context)
Definition: Exception.cc:165
static ComponentFactory< T > const * get()
auto wrap(F iFunc) -> decltype(iFunc())
#define get
ParameterSet const & registerIt()
ParameterSet * getPSetForUpdate(std::string const &name, bool &isTracked)