CMS 3D CMS Logo

PluginDescription.h
Go to the documentation of this file.
1 #ifndef FWCore_ParameterSet_PluginDescription_h
2 #define FWCore_ParameterSet_PluginDescription_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/ParameterSet
6 // Class : PluginDescription
7 //
79 //
80 // Original Author: Chris Jones
81 // Created: Wed, 19 Sep 2018 19:23:27 GMT
82 //
83 
84 // system include files
91 
92 // user include files
93 #include <ostream>
94 #include <sstream>
95 #include <string>
96 
97 // forward declarations
98 namespace edm {
99  template <typename T>
101  public:
106  PluginDescription(std::string typeLabel, bool typeLabelIsTracked)
107  : typeLabel_{std::move(typeLabel)}, typeLabelIsTracked_{typeLabelIsTracked} {}
108 
114  PluginDescription(std::string typeLabel, std::string defaultType, bool typeLabelIsTracked)
115  : typeLabel_{std::move(typeLabel)},
116  defaultType_{std::move(defaultType)},
117  typeLabelIsTracked_{typeLabelIsTracked} {}
118 
119  // ---------- const member functions ---------------------
121 
122  protected:
123  void checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
124  std::set<ParameterTypes>& parameterTypes,
125  std::set<ParameterTypes>& wildcardTypes) const final {}
126 
127  void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const final {
129  //all names are good
130  auto n = pset.getParameterNames();
131  validatedLabels.insert(n.begin(), n.end());
132  }
133 
134  void writeCfi_(
135  std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const final {
136  if (not defaultType_.empty()) {
138  auto conf = edmplugin::standard::config();
139  conf.allowNoCache();
141  }
142  loadDescription(defaultType_).writeCfi(os, startWithComma, indentation);
143  wroteSomething = true;
144  }
145  }
146 
147  bool hasNestedContent_() const final { return true; }
148 
149  void printNestedContent_(std::ostream& os, bool /*optional*/, DocFormatHelper& dfh) const final {
150  int indentation = dfh.indentation();
151 
154 
155  std::string const& pluginCategory = Factory::get()->category();
156 
158  os << "There are multiple possible different descriptions for this ParameterSet\n";
160  os << "because it will be used by a helper plugin object contained inside the top level\n";
162  os << "module plugin object and the type of the helper plugin object is configurable.\n";
164  os << "Or if it is in a vector of ParameterSets it might be used by multiple\n";
166  os << "helper plugin objects and each could be configured with a different plugin type.\n";
168  os << "Each plugin type could allow a different set of configuration parameters.\n";
170  os << "Each subsection of this section has one of the possible descriptions.\n";
172  os << "All of these plugins are from the category \"" << pluginCategory << "\".\n";
174  os << "The plugin type is specified by the parameter named \"" << typeLabel_ << "\".\n";
175 
176  if (!dfh.brief()) {
177  os << "\n";
178  }
179  std::string section = dfh.sectionOfCategoryAlreadyPrinted(pluginCategory);
180  if (!section.empty()) {
182  os << "*** The descriptions for this plugin category already started printing above (see Section " << section
183  << ")! ***\n";
185  os << "*** We might still be in the middle of that printout at this point because it might be recursive. ***\n";
187  os << "*** We'll not duplicate that printout and skip it. ***\n";
189  os << "*** (N.B. If we tried to print it again, we might fall into an infinite recursion.) ***\n";
190 
191  if (!dfh.brief()) {
192  os << "\n";
193  }
194  return;
195  }
196  dfh.addCategory(pluginCategory, dfh.section());
197 
199 
200  //loop over all possible plugins
201  unsigned int pluginCount = 1;
202  std::string previousName;
203  for (auto const& info : edmplugin::PluginManager::get()->categoryToInfos().find(pluginCategory)->second) {
204  // We only want to print the first instance of each plugin name
205  if (previousName == info.name_) {
206  continue;
207  }
208 
209  std::stringstream ss;
210  ss << dfh.section() << "." << pluginCount;
211  ++pluginCount;
212  std::string newSection = ss.str();
214  os << "Section " << newSection << " ParameterSet description for plugin named \"" << info.name_ << "\"\n";
215  if (!dfh.brief())
216  os << "\n";
217 
218  DocFormatHelper new_dfh(dfh);
219  new_dfh.init();
220  new_dfh.setSection(newSection);
221 
222  loadDescription(info.name_).print(os, new_dfh);
223 
224  previousName = info.name_;
225  }
226  }
227 
228  bool exists_(ParameterSet const& pset) const final {
230  }
231 
232  bool partiallyExists_(ParameterSet const& pset) const final { return exists_(pset); }
233 
234  int howManyXORSubNodesExist_(ParameterSet const& pset) const final { return exists(pset) ? 1 : 0; }
235 
236  private:
237  std::string findType(edm::ParameterSet const& iPSet) const {
238  if (typeLabelIsTracked_) {
239  CMS_SA_ALLOW if (iPSet.existsAs<std::string>(typeLabel_) || defaultType_.empty()) {
240  return iPSet.getParameter<std::string>(typeLabel_);
241  }
242  else {
243  return defaultType_;
244  }
245  }
246  if (defaultType_.empty()) {
248  }
250  }
251 
254  std::unique_ptr<CreatedType> a(edmplugin::PluginFactory<CreatedType*()>::get()->create(iName));
255 
256  ParameterSetDescription desc = a->description();
257 
258  //There is no way to check to see if a node already wants a label
259  if (typeLabelIsTracked_) {
260  if (defaultType_.empty()) {
262  } else {
264  }
265  } else {
266  if (defaultType_.empty()) {
267  desc.addUntracked<std::string>(typeLabel_);
268  } else {
269  desc.addUntracked<std::string>(typeLabel_, defaultType_);
270  }
271  }
272  return desc;
273  }
274 
275  // ---------- member data --------------------------------
279  };
280 } // namespace edm
281 
282 #endif
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const TGPicture * info(bool iBackgroundIsBlack)
#define CMS_SA_ALLOW
void print(std::ostream &os, DocFormatHelper &dfh) const
static PluginManager & configure(const Config &)
def create(alignables, pedeDump, additionalData, outputFile, config)
bool partiallyExists_(ParameterSet const &pset) const final
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
PluginDescription(std::string typeLabel, bool typeLabelIsTracked)
void writeCfi(std::ostream &os, bool startWithComma, int indentation) const
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const final
T getUntrackedParameter(std::string const &, T const &) const
U second(std::pair< T, U > const &p)
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const final
PluginManager::Config config()
Definition: standard.cc:21
bool exists_(ParameterSet const &pset) const final
static int offsetSectionContent()
std::string findType(edm::ParameterSet const &iPSet) const
optional
Definition: Types.py:239
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const final
void printNestedContent_(std::ostream &os, bool, DocFormatHelper &dfh) const final
bool hasNestedContent_() const final
static void printSpaces(std::ostream &os, int n)
ParameterDescriptionNode * clone() const final
PluginDescription(std::string typeLabel, std::string defaultType, bool typeLabelIsTracked)
const char * pluginCategory()
ParameterSetDescription loadDescription(std::string const &iName) const
void validate(ParameterSet &pset) const
bool exists(ParameterSet const &pset) const
int howManyXORSubNodesExist_(ParameterSet const &pset) const final
HLT enums.
double a
Definition: hdecay.h:121
static Factory const * get()
Definition: Factory.cc:21
void setSection(std::string const &value)
static PluginManager * get()
def move(src, dest)
Definition: eostools.py:511