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 {
99 public:
104  PluginDescription(std::string typeLabel, bool typeLabelIsTracked):
105  typeLabel_{std::move(typeLabel)},
106  typeLabelIsTracked_{typeLabelIsTracked} {}
107 
113  PluginDescription(std::string typeLabel, std::string defaultType, bool typeLabelIsTracked):
114  typeLabel_{std::move(typeLabel)},
115  defaultType_{std::move(defaultType)},
116  typeLabelIsTracked_{typeLabelIsTracked} {}
117 
118  // ---------- const member functions ---------------------
120  return new PluginDescription<T>(*this);
121  }
122 
123 protected:
124 
125  void checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
126  std::set<ParameterTypes>& parameterTypes,
127  std::set<ParameterTypes>& wildcardTypes) const final {
128 
129  }
130 
131 
132 
134  std::set<std::string>& validatedLabels,
135  bool optional) const final {
137  cache_->validate(pset);
138  //all names are good
139  auto n =pset.getParameterNames();
140  validatedLabels.insert(n.begin(),n.end());
141  }
142 
143  void writeCfi_(std::ostream& os,
144  bool& startWithComma,
145  int indentation,
146  bool& wroteSomething) const final {
147  if(not defaultType_.empty()) {
149  auto conf = edmplugin::standard::config();
150  conf.allowNoCache();
152  }
153 
155 
156  cache_->writeCfi(os,startWithComma,indentation);
157  wroteSomething = true;
158  }
159  }
160 
161  bool hasNestedContent_() const final {
162  return true;
163  }
164 
165  void printNestedContent_(std::ostream& os,
166  bool /*optional*/,
167  DocFormatHelper& dfh) const final {
168  int indentation = dfh.indentation();
169 
172 
173  std::stringstream ss;
174  ss << dfh.section() << "." << dfh.counter();
175  std::string newSection = ss.str();
176 
177  printSpaces(os, indentation);
178  os << "Section " << newSection
179  << " " << Factory::get()->category() << " Plugins description:\n";
180  if(!dfh.brief()) os << "\n";
181 
182  DocFormatHelper new_dfh(dfh);
183  new_dfh.init();
184  new_dfh.setSection(newSection);
185 
186  //loop over all possible plugins
187  unsigned int pluginCount = 0;
188  std::string previousName;
189  for(auto const& info: edmplugin::PluginManager::get()->categoryToInfos().find(Factory::get()->category())->second) {
190 
191  // We only want to print the first instance of each plugin name
192  if (previousName == info.name_) {
193  continue;
194  }
195 
196  std::stringstream ss;
197  ss << dfh.section() << "." << dfh.counter();
198  std::string newSection = ss.str();
199  printSpaces(os, indentation);
200  os << "Section " << newSection <<"."<< ++pluginCount
201  << " " << info.name_ << " Plugin description:\n";
202  if(!dfh.brief()) os << "\n";
203 
204  DocFormatHelper new_dfh(dfh);
205  new_dfh.init();
206  new_dfh.setSection(newSection);
207 
208  loadDescription(info.name_)->print(os,new_dfh);
209 
210  previousName = info.name_;
211  }
212  }
213 
214  bool exists_(ParameterSet const& pset) const final {
215  return pset.existsAs<std::string>(typeLabel_, typeLabelIsTracked_);
216  }
217 
218  bool partiallyExists_(ParameterSet const& pset) const final {
219  return exists_(pset);
220  }
221 
222  int howManyXORSubNodesExist_(ParameterSet const& pset) const final {
223  return exists(pset) ? 1 : 0;
224  }
225 
226 private:
227 
228  std::string findType(edm::ParameterSet const& iPSet) const {
229  if(typeLabelIsTracked_) {
230  if(iPSet.existsAs<std::string>(typeLabel_) || defaultType_.empty()) {
231  return iPSet.getParameter<std::string>(typeLabel_);
232  } else {
233  return defaultType_;
234  }
235  }
236  if(defaultType_.empty()) {
238  }
240  }
241 
242  void loadPlugin(std::string const& iName) const {
243  if(not cache_) {
244  cache_ = loadDescription(iName);
245  }
246  }
247 
248  std::shared_ptr<ParameterSetDescription>
249  loadDescription(std::string const& iName) const {
251  std::unique_ptr<CreatedType> a(edmplugin::PluginFactory<CreatedType*()>::get()->create(iName));
252 
253  std::shared_ptr<ParameterSetDescription> desc = std::make_shared<ParameterSetDescription>(a->description());
254 
255  //There is no way to check to see if a node already wants a label
256  if(typeLabelIsTracked_) {
257  if(defaultType_.empty()) {
258  desc->add<std::string>(typeLabel_);
259  } else {
260  desc->add<std::string>(typeLabel_,defaultType_);
261  }
262  } else {
263  if(defaultType_.empty()) {
264  desc->addUntracked<std::string>(typeLabel_);
265  } else {
266  desc->addUntracked<std::string>(typeLabel_,defaultType_);
267  }
268  }
269  return desc;
270  }
271 
272  // ---------- member data --------------------------------
273  mutable std::shared_ptr<ParameterSetDescription> cache_;
277 
278 };
279 }
280 
281 #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:185
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:29
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