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()) {
148  auto conf = edmplugin::standard::config();
149  conf.allowNoCache();
151 
153 
154  cache_->writeCfi(os,startWithComma,indentation);
155  wroteSomething = true;
156  }
157  }
158 
159  bool hasNestedContent_() const final {
160  return true;
161  }
162 
163  void printNestedContent_(std::ostream& os,
164  bool /*optional*/,
165  DocFormatHelper& dfh) const final {
166  int indentation = dfh.indentation();
167 
170 
171  std::stringstream ss;
172  ss << dfh.section() << "." << dfh.counter();
173  std::string newSection = ss.str();
174 
175  printSpaces(os, indentation);
176  os << "Section " << newSection
177  << " " << Factory::get()->category() << " Plugins description:\n";
178  if(!dfh.brief()) os << "\n";
179 
180  DocFormatHelper new_dfh(dfh);
181  new_dfh.init();
182  new_dfh.setSection(newSection);
183 
184  //loop over all possible plugins
185  unsigned int pluginCount = 0;
186  std::string previousName;
187  for(auto const& info: edmplugin::PluginManager::get()->categoryToInfos().find(Factory::get()->category())->second) {
188 
189  // We only want to print the first instance of each plugin name
190  if (previousName == info.name_) {
191  continue;
192  }
193 
194  std::stringstream ss;
195  ss << dfh.section() << "." << dfh.counter();
196  std::string newSection = ss.str();
197  printSpaces(os, indentation);
198  os << "Section " << newSection <<"."<< ++pluginCount
199  << " " << info.name_ << " Plugin description:\n";
200  if(!dfh.brief()) os << "\n";
201 
202  DocFormatHelper new_dfh(dfh);
203  new_dfh.init();
204  new_dfh.setSection(newSection);
205 
206  loadDescription(info.name_)->print(os,new_dfh);
207 
208  previousName = info.name_;
209  }
210  }
211 
212  bool exists_(ParameterSet const& pset) const final {
213  return pset.existsAs<std::string>(typeLabel_, typeLabelIsTracked_);
214  }
215 
216  bool partiallyExists_(ParameterSet const& pset) const final {
217  return exists_(pset);
218  }
219 
220  int howManyXORSubNodesExist_(ParameterSet const& pset) const final {
221  return exists(pset) ? 1 : 0;
222  }
223 
224 private:
225 
226  std::string findType(edm::ParameterSet const& iPSet) const {
227  if(typeLabelIsTracked_) {
228  if(iPSet.existsAs<std::string>(typeLabel_) || defaultType_.empty()) {
229  return iPSet.getParameter<std::string>(typeLabel_);
230  } else {
231  return defaultType_;
232  }
233  }
234  if(defaultType_.empty()) {
236  }
238  }
239 
240  void loadPlugin(std::string const& iName) const {
241  if(not cache_) {
242  cache_ = loadDescription(iName);
243  }
244  }
245 
246  std::shared_ptr<ParameterSetDescription>
247  loadDescription(std::string const& iName) const {
249  std::unique_ptr<CreatedType> a(edmplugin::PluginFactory<CreatedType*()>::get()->create(iName));
250 
251  std::shared_ptr<ParameterSetDescription> desc = std::make_shared<ParameterSetDescription>(a->description());
252 
253  //There is no way to check to see if a node already wants a label
254  if(typeLabelIsTracked_) {
255  if(defaultType_.empty()) {
256  desc->add<std::string>(typeLabel_);
257  } else {
258  desc->add<std::string>(typeLabel_,defaultType_);
259  }
260  } else {
261  if(defaultType_.empty()) {
262  desc->addUntracked<std::string>(typeLabel_);
263  } else {
264  desc->addUntracked<std::string>(typeLabel_,defaultType_);
265  }
266  }
267  return desc;
268  }
269 
270  // ---------- member data --------------------------------
271  mutable std::shared_ptr<ParameterSetDescription> cache_;
275 
276 };
277 }
278 
279 #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