test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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::auto_ptr<EventSetupProvider>
26  makeEventSetupProvider(ParameterSet const& params, unsigned subProcessIndex) {
27  std::vector<std::string> prefers =
28  params.getParameter<std::vector<std::string> >("@all_esprefers");
29 
30  if(prefers.empty()) {
31  return std::auto_ptr<EventSetupProvider>(new EventSetupProvider(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();
43  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(),
49  itRecordNameEnd = recordNames.end();
50  itRecordName != itRecordNameEnd;
51  ++itRecordName) {
52 
53  if((*itRecordName)[0] == '@') {
54  //this is a 'hidden parameter' so skip it
55  continue;
56  }
57 
58  //this should be a record name with its info
59  try {
60  std::vector<std::string> dataInfo =
61  preferPSet.getParameter<std::vector<std::string> >(*itRecordName);
62 
63  if(dataInfo.empty()) {
64  //FUTURE: empty should just mean all data
66  << "The record named "
67  << *itRecordName << " specifies no data items";
68  }
69  //FUTURE: 'any' should be a special name
70  for(std::vector<std::string>::iterator itDatum = dataInfo.begin(),
71  itDatumEnd = dataInfo.end();
72  itDatum != itDatumEnd;
73  ++itDatum){
74  std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
75  std::string labelName;
76 
77  if(itDatum->size() != datumName.size()) {
78  labelName = std::string(*itDatum, datumName.size() + 1);
79  }
80  recordToData.insert(std::make_pair(std::string(*itRecordName),
81  std::make_pair(datumName,
82  labelName)));
83  }
84  } catch(cms::Exception const& iException) {
85  cms::Exception theError("ESPreferConfigurationError");
86  theError << "While parsing the es_prefer statement for type="
87  << preferPSet.getParameter<std::string>("@module_type")
88  << " label=\""
89  << preferPSet.getParameter<std::string>("@module_label")
90  << "\" an error occurred.";
91  theError.append(iException);
92  throw theError;
93  }
94  }
95  preferInfo[ComponentDescription(preferPSet.getParameter<std::string>("@module_type"),
96  preferPSet.getParameter<std::string>("@module_label"),
97  false)] = recordToData;
98  }
99  return std::auto_ptr<EventSetupProvider>(new EventSetupProvider(subProcessIndex, &preferInfo));
100  }
101 
102  // ---------------------------------------------------------------
103  void
106  ParameterSet& params) {
107  std::vector<std::string> providers =
108  params.getParameter<std::vector<std::string> >("@all_esmodules");
109 
110  for(std::vector<std::string>::iterator itName = providers.begin(), itNameEnd = providers.end();
111  itName != itNameEnd;
112  ++itName) {
113  ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
114  validateEventSetupParameters(*providerPSet);
115  providerPSet->registerIt();
116  ModuleFactory::get()->addTo(esController,
117  cp,
118  *providerPSet);
119  }
120 
121  std::vector<std::string> sources =
122  params.getParameter<std::vector<std::string> >("@all_essources");
123 
124  for(std::vector<std::string>::iterator itName = sources.begin(), itNameEnd = sources.end();
125  itName != itNameEnd;
126  ++itName) {
127  ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
128  validateEventSetupParameters(*providerPSet);
129  providerPSet->registerIt();
130  SourceFactory::get()->addTo(esController,
131  cp,
132  *providerPSet);
133  }
134  }
135 
136  // ---------------------------------------------------------------
138  std::string modtype;
139  std::string moduleLabel;
140  modtype = pset.getParameter<std::string>("@module_type");
141  moduleLabel = pset.getParameter<std::string>("@module_label");
142  // Check for the "unlabeled" case
143  // This is an artifact left over from the old configuration language
144  // we were using before switching to the python configuration
145  // This is handled in the validation code and python configuration
146  // files by using a label equal to the module typename.
147  if (moduleLabel == std::string("")) {
148  moduleLabel = modtype;
149  }
150 
151  std::auto_ptr<ParameterSetDescriptionFillerBase> filler(
153  ConfigurationDescriptions descriptions(filler->baseType());
154  filler->fill(descriptions);
155  try {
157  descriptions.validate(pset, moduleLabel);
158  });
159  }
160  catch (cms::Exception & iException) {
161  std::ostringstream ost;
162  ost << "Validating configuration of ESProducer or ESSource of type " << modtype
163  << " with label: '" << moduleLabel << "'";
164  iException.addContext(ost.str());
165  throw;
166  }
167  }
168  }
169 }
T getParameter(std::string const &) const
void append(Exception const &another)
Definition: Exception.cc:203
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:227
static ComponentFactory< T > const * get()
auto wrap(F iFunc) -> decltype(iFunc())
std::auto_ptr< EventSetupProvider > makeEventSetupProvider(ParameterSet const &params, unsigned subProcessIndex)
ParameterSet const & registerIt()
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:55
ParameterSet * getPSetForUpdate(std::string const &name, bool &isTracked)