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 <string>
94 
95 // forward declarations
96 namespace edm {
97  template <typename T>
99  public:
104  PluginDescription(std::string typeLabel, bool typeLabelIsTracked)
105  : typeLabel_{std::move(typeLabel)}, typeLabelIsTracked_{typeLabelIsTracked} {}
106 
112  PluginDescription(std::string typeLabel, std::string defaultType, bool typeLabelIsTracked)
113  : typeLabel_{std::move(typeLabel)},
114  defaultType_{std::move(defaultType)},
115  typeLabelIsTracked_{typeLabelIsTracked} {}
116 
117  // ---------- const member functions ---------------------
119 
120  protected:
121  void checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
122  std::set<ParameterTypes>& parameterTypes,
123  std::set<ParameterTypes>& wildcardTypes) const final {}
124 
125  void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const final {
127  //all names are good
128  auto n = pset.getParameterNames();
129  validatedLabels.insert(n.begin(), n.end());
130  }
131 
132  void writeCfi_(
133  std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const final {
134  if (not defaultType_.empty()) {
136  auto conf = edmplugin::standard::config();
137  conf.allowNoCache();
139  }
140  loadDescription(defaultType_).writeCfi(os, startWithComma, indentation);
141  wroteSomething = true;
142  }
143  }
144 
145  bool hasNestedContent_() const final { return true; }
146 
147  void printNestedContent_(std::ostream& os, bool /*optional*/, DocFormatHelper& dfh) const final {
148  int indentation = dfh.indentation();
149 
152 
153  {
154  std::stringstream ss;
155  ss << dfh.section() << "." << dfh.counter();
156  std::string newSection = ss.str();
157 
159  os << "Section " << newSection << " " << Factory::get()->category() << " Plugins description:\n";
160  if (!dfh.brief())
161  os << "\n";
162  }
163 
164  //loop over all possible plugins
165  unsigned int pluginCount = 0;
166  std::string previousName;
167  for (auto const& info :
169  // We only want to print the first instance of each plugin name
170  if (previousName == info.name_) {
171  continue;
172  }
173 
174  std::stringstream ss;
175  ss << dfh.section() << "." << dfh.counter();
176  std::string newSection = ss.str();
178  os << "Section " << newSection << "." << ++pluginCount << " " << info.name_ << " Plugin description:\n";
179  if (!dfh.brief())
180  os << "\n";
181 
182  DocFormatHelper new_dfh(dfh);
183  new_dfh.init();
184  new_dfh.setSection(newSection);
185 
186  loadDescription(info.name_).print(os, new_dfh);
187 
188  previousName = info.name_;
189  }
190  }
191 
192  bool exists_(ParameterSet const& pset) const final {
193  return pset.existsAs<std::string>(typeLabel_, typeLabelIsTracked_);
194  }
195 
196  bool partiallyExists_(ParameterSet const& pset) const final { return exists_(pset); }
197 
198  int howManyXORSubNodesExist_(ParameterSet const& pset) const final { return exists(pset) ? 1 : 0; }
199 
200  private:
201  std::string findType(edm::ParameterSet const& iPSet) const {
202  if (typeLabelIsTracked_) {
203  if (iPSet.existsAs<std::string>(typeLabel_) || defaultType_.empty()) {
204  return iPSet.getParameter<std::string>(typeLabel_);
205  } else {
206  return defaultType_;
207  }
208  }
209  if (defaultType_.empty()) {
211  }
213  }
214 
217  std::unique_ptr<CreatedType> a(edmplugin::PluginFactory<CreatedType*()>::get()->create(iName));
218 
219  ParameterSetDescription desc = a->description();
220 
221  //There is no way to check to see if a node already wants a label
222  if (typeLabelIsTracked_) {
223  if (defaultType_.empty()) {
225  } else {
227  }
228  } else {
229  if (defaultType_.empty()) {
230  desc.addUntracked<std::string>(typeLabel_);
231  } else {
232  desc.addUntracked<std::string>(typeLabel_, defaultType_);
233  }
234  }
235  return desc;
236  }
237 
238  // ---------- member data --------------------------------
242  };
243 } // namespace edm
244 
245 #endif
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static const TGPicture * info(bool iBackgroundIsBlack)
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:171
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
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
std::string findType(edm::ParameterSet const &iPSet) const
optional
Definition: Types.py:198
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)
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:119
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