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 ---------------------
117  ParameterDescriptionNode* clone() const final { return new PluginDescription<T>(*this); }
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_(std::ostream& os, bool& startWithComma, int indentation, bool& wroteSomething) const final {
133  if (not defaultType_.empty()) {
135  auto conf = edmplugin::standard::config();
136  conf.allowNoCache();
138  }
139 
141 
142  cache_->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::stringstream ss;
156  ss << dfh.section() << "." << dfh.counter();
157  std::string newSection = ss.str();
158 
159  printSpaces(os, indentation);
160  os << "Section " << newSection << " " << Factory::get()->category() << " Plugins description:\n";
161  if (!dfh.brief())
162  os << "\n";
163 
164  DocFormatHelper new_dfh(dfh);
165  new_dfh.init();
166  new_dfh.setSection(newSection);
167 
168  //loop over all possible plugins
169  unsigned int pluginCount = 0;
170  std::string previousName;
171  for (auto const& info :
172  edmplugin::PluginManager::get()->categoryToInfos().find(Factory::get()->category())->second) {
173  // We only want to print the first instance of each plugin name
174  if (previousName == info.name_) {
175  continue;
176  }
177 
178  std::stringstream ss;
179  ss << dfh.section() << "." << dfh.counter();
180  std::string newSection = ss.str();
181  printSpaces(os, indentation);
182  os << "Section " << newSection << "." << ++pluginCount << " " << info.name_ << " Plugin description:\n";
183  if (!dfh.brief())
184  os << "\n";
185 
186  DocFormatHelper new_dfh(dfh);
187  new_dfh.init();
188  new_dfh.setSection(newSection);
189 
190  loadDescription(info.name_)->print(os, new_dfh);
191 
192  previousName = info.name_;
193  }
194  }
195 
196  bool exists_(ParameterSet const& pset) const final {
197  return pset.existsAs<std::string>(typeLabel_, typeLabelIsTracked_);
198  }
199 
200  bool partiallyExists_(ParameterSet const& pset) const final { return exists_(pset); }
201 
202  int howManyXORSubNodesExist_(ParameterSet const& pset) const final { return exists(pset) ? 1 : 0; }
203 
204  private:
205  std::string findType(edm::ParameterSet const& iPSet) const {
206  if (typeLabelIsTracked_) {
207  if (iPSet.existsAs<std::string>(typeLabel_) || defaultType_.empty()) {
208  return iPSet.getParameter<std::string>(typeLabel_);
209  } else {
210  return defaultType_;
211  }
212  }
213  if (defaultType_.empty()) {
215  }
217  }
218 
219  void loadPlugin(std::string const& iName) const {
220  if (not cache_) {
221  cache_ = loadDescription(iName);
222  }
223  }
224 
225  std::shared_ptr<ParameterSetDescription> loadDescription(std::string const& iName) const {
227  std::unique_ptr<CreatedType> a(edmplugin::PluginFactory<CreatedType*()>::get()->create(iName));
228 
229  std::shared_ptr<ParameterSetDescription> desc = std::make_shared<ParameterSetDescription>(a->description());
230 
231  //There is no way to check to see if a node already wants a label
232  if (typeLabelIsTracked_) {
233  if (defaultType_.empty()) {
234  desc->add<std::string>(typeLabel_);
235  } else {
236  desc->add<std::string>(typeLabel_, defaultType_);
237  }
238  } else {
239  if (defaultType_.empty()) {
240  desc->addUntracked<std::string>(typeLabel_);
241  } else {
242  desc->addUntracked<std::string>(typeLabel_, defaultType_);
243  }
244  }
245  return desc;
246  }
247 
248  // ---------- member data --------------------------------
249  mutable std::shared_ptr<ParameterSetDescription> cache_;
253  };
254 } // namespace edm
255 
256 #endif
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:161
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
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
PluginDescription(std::string typeLabel, bool typeLabelIsTracked)
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const final
U second(std::pair< T, U > const &p)
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
void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const final
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 validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const final
HLT enums.
double a
Definition: hdecay.h:121
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