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  cache_->validate(pset);
128  //all names are good
129  auto n = pset.getParameterNames();
130  validatedLabels.insert(n.begin(), n.end());
131  }
132 
133  void writeCfi_(
134  std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const final {
135  if (not defaultType_.empty()) {
137  auto conf = edmplugin::standard::config();
138  conf.allowNoCache();
140  }
141 
143 
144  cache_->writeCfi(os, startWithComma, indentation);
145  wroteSomething = true;
146  }
147  }
148 
149  bool hasNestedContent_() const final { return true; }
150 
151  void printNestedContent_(std::ostream& os, bool /*optional*/, DocFormatHelper& dfh) const final {
152  int indentation = dfh.indentation();
153 
155  using Factory = edmplugin::PluginFactory<CreatedType*()>;
156 
157  {
158  std::stringstream ss;
159  ss << dfh.section() << "." << dfh.counter();
160  std::string newSection = ss.str();
161 
163  os << "Section " << newSection << " " << Factory::get()->category() << " Plugins description:\n";
164  if (!dfh.brief())
165  os << "\n";
166  }
167 
168  //loop over all possible plugins
169  unsigned int pluginCount = 0;
170  std::string previousName;
171  for (auto const& info :
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();
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 {
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  //Validation of plugins is only done on one thread at a time
250  CMS_SA_ALLOW mutable std::shared_ptr<ParameterSetDescription> cache_;
254  };
255 } // namespace edm
256 
257 #endif
edm::PluginDescription::clone
ParameterDescriptionNode * clone() const final
Definition: PluginDescription.h:118
edm::PluginDescription::PluginDescription
PluginDescription(std::string typeLabel, bool typeLabelIsTracked)
Definition: PluginDescription.h:104
edm::PluginDescription::printNestedContent_
void printNestedContent_(std::ostream &os, bool, DocFormatHelper &dfh) const final
Definition: PluginDescription.h:151
edm::Factory
Definition: Factory.h:19
edm::PluginDescription::loadPlugin
void loadPlugin(std::string const &iName) const
Definition: PluginDescription.h:219
PluginFactory.h
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:31
edm::DocFormatHelper::init
void init()
Definition: DocFormatHelper.cc:113
edm::ParameterDescriptionNode::exists
bool exists(ParameterSet const &pset) const
Definition: ParameterDescriptionNode.h:134
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::PluginDescription::cache_
std::shared_ptr< ParameterSetDescription > cache_
Definition: PluginDescription.h:250
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::DocFormatHelper::setSection
void setSection(std::string const &value)
Definition: DocFormatHelper.h:44
edm::PluginDescription
Definition: PluginDescription.h:98
Types.optional
optional
Definition: Types.py:199
PluginDescriptionAdaptorBase.h
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
watchdog.const
const
Definition: watchdog.py:83
edmplugin::PluginManager::get
static PluginManager * get()
Definition: PluginManager.cc:306
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
edmplugin::PluginManager::categoryToInfos
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
edm::PluginDescription::defaultType_
std::string defaultType_
Definition: PluginDescription.h:252
edm::PluginDescription::PluginDescription
PluginDescription(std::string typeLabel, std::string defaultType, bool typeLabelIsTracked)
Definition: PluginDescription.h:112
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::DocFormatHelper
Definition: DocFormatHelper.h:15
edm::PluginDescriptionAdaptorBase
Definition: PluginDescriptionAdaptorBase.h:30
edm::PluginDescription::loadDescription
std::shared_ptr< ParameterSetDescription > loadDescription(std::string const &iName) const
Definition: PluginDescription.h:225
ParameterDescriptionNode.h
edm::PluginDescription::howManyXORSubNodesExist_
int howManyXORSubNodesExist_(ParameterSet const &pset) const final
Definition: PluginDescription.h:202
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::PluginDescription::exists_
bool exists_(ParameterSet const &pset) const final
Definition: PluginDescription.h:196
standard.h
edm::PluginDescription::partiallyExists_
bool partiallyExists_(ParameterSet const &pset) const final
Definition: PluginDescription.h:200
edm::PluginDescription::hasNestedContent_
bool hasNestedContent_() const final
Definition: PluginDescription.h:149
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
edm::PluginDescription::typeLabel_
std::string typeLabel_
Definition: PluginDescription.h:251
edmplugin::PluginManager::configure
static PluginManager & configure(const Config &)
Definition: PluginManager.cc:315
edm::PluginDescription::checkAndGetLabelsAndTypes_
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const final
Definition: PluginDescription.h:121
edmplugin::PluginFactory
Definition: PluginFactory.h:34
edm::PluginDescription::typeLabelIsTracked_
bool typeLabelIsTracked_
Definition: PluginDescription.h:253
thread_safety_macros.h
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:675
edm::PluginDescription::writeCfi_
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const final
Definition: PluginDescription.h:133
edmplugin::standard::config
PluginManager::Config config()
Definition: standard.cc:21
edm::PluginDescription::findType
std::string findType(edm::ParameterSet const &iPSet) const
Definition: PluginDescription.h:205
edm::ParameterDescriptionNode::printSpaces
static void printSpaces(std::ostream &os, int n)
Definition: ParameterDescriptionNode.cc:124
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
PluginManager.h
edm::Factory::get
static Factory const * get()
Definition: Factory.cc:23
printContent_cfi.indentation
indentation
Definition: printContent_cfi.py:10
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::PluginDescription::validate_
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const final
Definition: PluginDescription.h:125
edm::ParameterDescriptionNode
Definition: ParameterDescriptionNode.h:82
edmplugin::PluginManager::isAvailable
static bool isAvailable()
Definition: PluginManager.cc:346
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27