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_(std::ostream& os,
135  bool optional,
136  bool& startWithComma,
137  int indentation,
139  bool& wroteSomething) const final {
140  if (not defaultType_.empty()) {
142  auto conf = edmplugin::standard::config();
143  conf.allowNoCache();
145  }
146  //given each plugin can have very different parameters we should do a full dump
147  CfiOptions ops = cfi::Typed{};
148  loadDescription(defaultType_).writeCfi(os, startWithComma, indentation, ops);
149  wroteSomething = true;
150  }
151  if (std::holds_alternative<cfi::ClassFile>(options)) {
152  std::get<cfi::ClassFile>(options).parameterMustBeTyped();
153  }
154  }
155 
156  bool hasNestedContent_() const final { return true; }
157 
158  void printNestedContent_(std::ostream& os, bool /*optional*/, DocFormatHelper& dfh) const final {
159  int indentation = dfh.indentation();
160 
163 
164  std::string const& pluginCategory = Factory::get()->category();
165 
167  os << "There are multiple possible different descriptions for this ParameterSet\n";
169  os << "because it will be used by a helper plugin object contained inside the top level\n";
171  os << "module plugin object and the type of the helper plugin object is configurable.\n";
173  os << "Or if it is in a vector of ParameterSets it might be used by multiple\n";
175  os << "helper plugin objects and each could be configured with a different plugin type.\n";
177  os << "Each plugin type could allow a different set of configuration parameters.\n";
179  os << "Each subsection of this section has one of the possible descriptions.\n";
181  os << "All of these plugins are from the category \"" << pluginCategory << "\".\n";
183  os << "The plugin type is specified by the parameter named \"" << typeLabel_ << "\".\n";
184 
185  if (!dfh.brief()) {
186  os << "\n";
187  }
188  std::string section = dfh.sectionOfCategoryAlreadyPrinted(pluginCategory);
189  if (!section.empty()) {
191  os << "*** The descriptions for this plugin category already started printing above (see Section " << section
192  << ")! ***\n";
194  os << "*** We might still be in the middle of that printout at this point because it might be recursive. ***\n";
196  os << "*** We'll not duplicate that printout and skip it. ***\n";
198  os << "*** (N.B. If we tried to print it again, we might fall into an infinite recursion.) ***\n";
199 
200  if (!dfh.brief()) {
201  os << "\n";
202  }
203  return;
204  }
205  dfh.addCategory(pluginCategory, dfh.section());
206 
208 
209  //loop over all possible plugins
210  unsigned int pluginCount = 1;
211  std::string previousName;
212  for (auto const& info : edmplugin::PluginManager::get()->categoryToInfos().find(pluginCategory)->second) {
213  // We only want to print the first instance of each plugin name
214  if (previousName == info.name_) {
215  continue;
216  }
217 
218  std::stringstream ss;
219  ss << dfh.section() << "." << pluginCount;
220  ++pluginCount;
221  std::string newSection = ss.str();
223  os << "Section " << newSection << " ParameterSet description for plugin named \"" << info.name_ << "\"\n";
224  if (!dfh.brief())
225  os << "\n";
226 
227  DocFormatHelper new_dfh(dfh);
228  new_dfh.init();
229  new_dfh.setSection(newSection);
230 
231  loadDescription(info.name_).print(os, new_dfh);
232 
233  previousName = info.name_;
234  }
235  }
236 
237  bool exists_(ParameterSet const& pset) const final {
239  }
240 
241  bool partiallyExists_(ParameterSet const& pset) const final { return exists_(pset); }
242 
243  int howManyXORSubNodesExist_(ParameterSet const& pset) const final { return exists(pset) ? 1 : 0; }
244 
245  private:
246  std::string findType(edm::ParameterSet const& iPSet) const {
247  if (typeLabelIsTracked_) {
248  CMS_SA_ALLOW if (iPSet.existsAs<std::string>(typeLabel_) || defaultType_.empty()) {
249  return iPSet.getParameter<std::string>(typeLabel_);
250  }
251  else {
252  return defaultType_;
253  }
254  }
255  if (defaultType_.empty()) {
257  }
259  }
260 
263  std::unique_ptr<CreatedType> a(edmplugin::PluginFactory<CreatedType*()>::get()->create(iName));
264 
265  ParameterSetDescription desc = a->description();
266 
267  //There is no way to check to see if a node already wants a label
268  if (typeLabelIsTracked_) {
269  if (defaultType_.empty()) {
271  } else {
273  }
274  } else {
275  if (defaultType_.empty()) {
276  desc.addUntracked<std::string>(typeLabel_);
277  } else {
278  desc.addUntracked<std::string>(typeLabel_, defaultType_);
279  }
280  }
281  return desc;
282  }
283 
284  // ---------- member data --------------------------------
288  };
289 } // namespace edm
290 
291 #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 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
void parameterMustBeTyped(CfiOptions &iOps) noexcept
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:245
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 writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, CfiOptions &options, bool &wroteSomething) const final
void setSection(std::string const &value)
static PluginManager * get()
void writeCfi(std::ostream &os, bool startWithComma, int indentation, CfiOptions &) const
def move(src, dest)
Definition: eostools.py:511
cfi::CfiOptions CfiOptions