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
90 
91 // user include files
92 #include <string>
93 
94 // forward declarations
95 namespace edm {
96  template <typename T>
98  public:
103  PluginDescription(std::string typeLabel, bool typeLabelIsTracked)
104  : typeLabel_{std::move(typeLabel)}, typeLabelIsTracked_{typeLabelIsTracked} {}
105 
111  PluginDescription(std::string typeLabel, std::string defaultType, bool typeLabelIsTracked)
112  : typeLabel_{std::move(typeLabel)},
113  defaultType_{std::move(defaultType)},
114  typeLabelIsTracked_{typeLabelIsTracked} {}
115 
116  // ---------- const member functions ---------------------
118 
119  protected:
120  void checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
121  std::set<ParameterTypes>& parameterTypes,
122  std::set<ParameterTypes>& wildcardTypes) const final {}
123 
124  void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const final {
126  cache_->validate(pset);
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 
142 
143  cache_->writeCfi(os, startWithComma, indentation);
144  wroteSomething = true;
145  }
146  }
147 
148  bool hasNestedContent_() const final { return true; }
149 
150  void printNestedContent_(std::ostream& os, bool /*optional*/, DocFormatHelper& dfh) const final {
151  int indentation = dfh.indentation();
152 
155 
156  {
157  std::stringstream ss;
158  ss << dfh.section() << "." << dfh.counter();
159  std::string newSection = ss.str();
160 
161  printSpaces(os, indentation);
162  os << "Section " << newSection << " " << Factory::get()->category() << " Plugins description:\n";
163  if (!dfh.brief())
164  os << "\n";
165  }
166 
167  //loop over all possible plugins
168  unsigned int pluginCount = 0;
169  std::string previousName;
170  for (auto const& info :
172  // We only want to print the first instance of each plugin name
173  if (previousName == info.name_) {
174  continue;
175  }
176 
177  std::stringstream ss;
178  ss << dfh.section() << "." << dfh.counter();
179  std::string newSection = ss.str();
180  printSpaces(os, indentation);
181  os << "Section " << newSection << "." << ++pluginCount << " " << info.name_ << " Plugin description:\n";
182  if (!dfh.brief())
183  os << "\n";
184 
185  DocFormatHelper new_dfh(dfh);
186  new_dfh.init();
187  new_dfh.setSection(newSection);
188 
189  loadDescription(info.name_)->print(os, new_dfh);
190 
191  previousName = info.name_;
192  }
193  }
194 
195  bool exists_(ParameterSet const& pset) const final {
196  return pset.existsAs<std::string>(typeLabel_, typeLabelIsTracked_);
197  }
198 
199  bool partiallyExists_(ParameterSet const& pset) const final { return exists_(pset); }
200 
201  int howManyXORSubNodesExist_(ParameterSet const& pset) const final { return exists(pset) ? 1 : 0; }
202 
203  private:
204  std::string findType(edm::ParameterSet const& iPSet) const {
205  if (typeLabelIsTracked_) {
206  if (iPSet.existsAs<std::string>(typeLabel_) || defaultType_.empty()) {
207  return iPSet.getParameter<std::string>(typeLabel_);
208  } else {
209  return defaultType_;
210  }
211  }
212  if (defaultType_.empty()) {
214  }
216  }
217 
218  void loadPlugin(std::string const& iName) const {
219  if (not cache_) {
220  cache_ = loadDescription(iName);
221  }
222  }
223 
224  std::shared_ptr<ParameterSetDescription> loadDescription(std::string const& iName) const {
226  std::unique_ptr<CreatedType> a(edmplugin::PluginFactory<CreatedType*()>::get()->create(iName));
227 
228  std::shared_ptr<ParameterSetDescription> desc = std::make_shared<ParameterSetDescription>(a->description());
229 
230  //There is no way to check to see if a node already wants a label
231  if (typeLabelIsTracked_) {
232  if (defaultType_.empty()) {
233  desc->add<std::string>(typeLabel_);
234  } else {
235  desc->add<std::string>(typeLabel_, defaultType_);
236  }
237  } else {
238  if (defaultType_.empty()) {
239  desc->addUntracked<std::string>(typeLabel_);
240  } else {
241  desc->addUntracked<std::string>(typeLabel_, defaultType_);
242  }
243  }
244  return desc;
245  }
246 
247  // ---------- member data --------------------------------
248  mutable std::shared_ptr<ParameterSetDescription> cache_;
252  };
253 } // namespace edm
254 
255 #endif
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:83
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
static PluginManager & configure(const Config &)
def create(alignables, pedeDump, additionalData, outputFile, config)
bool partiallyExists_(ParameterSet const &pset) const final
std::string findType(edm::ParameterSet const &iPSet) const
PluginDescription(std::string typeLabel, bool typeLabelIsTracked)
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const final
void loadPlugin(std::string const &iName) const
std::shared_ptr< ParameterSetDescription > loadDescription(std::string const &iName) const
PluginManager::Config config()
Definition: standard.cc:21
ParameterDescriptionNode * clone() const final
static Factory const * get()
Definition: Factory.cc:23
optional
Definition: Types.py:167
void printNestedContent_(std::ostream &os, bool, DocFormatHelper &dfh) const final
static void printSpaces(std::ostream &os, int n)
PluginDescription(std::string typeLabel, std::string defaultType, bool typeLabelIsTracked)
bool exists(ParameterSet const &pset) const
bool hasNestedContent_() const final
std::shared_ptr< ParameterSetDescription > cache_
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const final
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const final
HLT enums.
double a
Definition: hdecay.h:119
int howManyXORSubNodesExist_(ParameterSet const &pset) const final
void setSection(std::string const &value)
bool exists_(ParameterSet const &pset) const final
static PluginManager * get()
def move(src, dest)
Definition: eostools.py:511