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 
17 
18 #include <string>
19 
20 namespace edm {
21  namespace eventsetup {
22  // ---------------------------------------------------------------
23  std::auto_ptr<EventSetupProvider>
25  std::vector<std::string> prefers =
26  params.getParameter<std::vector<std::string> >("@all_esprefers");
27 
28  if(prefers.empty()) {
29  return std::auto_ptr<EventSetupProvider>(new EventSetupProvider());
30  }
31 
34 
35  //recordToData.insert(std::make_pair(std::string("DummyRecord"),
36  // std::make_pair(std::string("DummyData"), std::string())));
37  //preferInfo[ComponentDescription("DummyProxyProvider", "", false)]=
38  // recordToData;
39 
40  for(std::vector<std::string>::iterator itName = prefers.begin(), itNameEnd = prefers.end();
41  itName != itNameEnd;
42  ++itName) {
43  recordToData.clear();
44  ParameterSet const& preferPSet = params.getParameterSet(*itName);
45  std::vector<std::string> recordNames = preferPSet.getParameterNames();
46  for(std::vector<std::string>::iterator itRecordName = recordNames.begin(),
47  itRecordNameEnd = recordNames.end();
48  itRecordName != itRecordNameEnd;
49  ++itRecordName) {
50 
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 =
59  preferPSet.getParameter<std::vector<std::string> >(*itRecordName);
60 
61  if(dataInfo.empty()) {
62  //FUTURE: empty should just mean all data
64  << "The record named "
65  << *itRecordName << " specifies no data items";
66  }
67  //FUTURE: 'any' should be a special name
68  for(std::vector<std::string>::iterator itDatum = dataInfo.begin(),
69  itDatumEnd = dataInfo.end();
70  itDatum != itDatumEnd;
71  ++itDatum){
72  std::string datumName(*itDatum, 0, itDatum->find_first_of("/"));
73  std::string labelName;
74 
75  if(itDatum->size() != datumName.size()) {
76  labelName = std::string(*itDatum, datumName.size() + 1);
77  }
78  recordToData.insert(std::make_pair(std::string(*itRecordName),
79  std::make_pair(datumName,
80  labelName)));
81  }
82  } catch(cms::Exception const& iException) {
83  cms::Exception theError("ESPreferConfigurationError");
84  theError << "While parsing the es_prefer statement for type="
85  << preferPSet.getParameter<std::string>("@module_type")
86  << " label=\""
87  << preferPSet.getParameter<std::string>("@module_label")
88  << "\" an error occurred.";
89  theError.append(iException);
90  throw theError;
91  }
92  }
93  preferInfo[ComponentDescription(preferPSet.getParameter<std::string>("@module_type"),
94  preferPSet.getParameter<std::string>("@module_label"),
95  false)] = recordToData;
96  }
97  return std::auto_ptr<EventSetupProvider>(new EventSetupProvider(&preferInfo));
98  }
99 
100  // ---------------------------------------------------------------
101  void
103  ParameterSet& params,
104  CommonParams const& common) {
105  std::vector<std::string> providers =
106  params.getParameter<std::vector<std::string> >("@all_esmodules");
107 
108  for(std::vector<std::string>::iterator itName = providers.begin(), itNameEnd = providers.end();
109  itName != itNameEnd;
110  ++itName) {
111  ParameterSet* providerPSet = params.getPSetForUpdate(*itName);
112  validateEventSetupParameters(*providerPSet);
113  providerPSet->registerIt();
114  ModuleFactory::get()->addTo(cp,
115  *providerPSet,
116  common.processName_,
117  common.releaseVersion_,
118  common.passID_);
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(cp,
131  *providerPSet,
132  common.processName_,
133  common.releaseVersion_,
134  common.passID_);
135  }
136  }
137 
138  // ---------------------------------------------------------------
140  std::string modtype;
141  std::string moduleLabel;
142  try {
143  modtype = pset.getParameter<std::string>("@module_type");
144  moduleLabel = pset.getParameter<std::string>("@module_label");
145  // Check for the "unlabeled" case
146  // This is an artifact left over from the old configuration language
147  // we were using before switching to the python configuration
148  // This is handled in the validation code and python configuration
149  // files by using a label equal to the module typename.
150  if (moduleLabel == std::string("")) {
151  moduleLabel = modtype;
152  }
153 
154  std::auto_ptr<ParameterSetDescriptionFillerBase> filler(
156  ConfigurationDescriptions descriptions(filler->baseType());
157  filler->fill(descriptions);
158  descriptions.validate(pset, moduleLabel);
159  }
160  catch (cms::Exception& iException) {
161  Exception toThrow(errors::Configuration, "Failed validating configuration of ESProducer or ESSource.");
162  toThrow << "\nThe plugin name is \"" << modtype << "\"\n";
163  toThrow << "The module label is \"" << moduleLabel << "\"\n";
164  toThrow.append(iException);
165  throw toThrow;
166  }
167  }
168  }
169 }
T getParameter(std::string const &) const
void fillEventSetupProvider(EventSetupProvider &cp, ParameterSet &params, CommonParams const &common)
std::string processName_
Definition: CommonParams.h:40
void append(Exception const &another)
Definition: Exception.cc:82
void validateEventSetupParameters(ParameterSet &pset)
ReleaseVersion releaseVersion_
Definition: CommonParams.h:41
tuple pset
Definition: CrabTask.py:85
std::vector< std::string > getParameterNames() const
ParameterSet const & getParameterSet(std::string const &) const
std::auto_ptr< EventSetupProvider > makeEventSetupProvider(ParameterSet const &params)
std::map< ComponentDescription, RecordToDataMap > PreferredProviderInfo
std::multimap< RecordName, DataKeyInfo > RecordToDataMap
void validate(ParameterSet &pset, std::string const &moduleLabel) const
ParameterSet const & registerIt()
static ComponentFactory< T > * get()
SurfaceDeformation * create(int type, const std::vector< double > &params)
T get(const Candidate &c)
Definition: component.h:56
const std::string * moduleLabel() const
Definition: HLTadd.h:40
ParameterSet * getPSetForUpdate(std::string const &name, bool &isTracked)