LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fhicl::ParameterSet Class Reference

#include "ParameterSet.h"

Public Types

using ps_atom_t = fhicl::detail::ps_atom_t
 
using ps_sequence_t = fhicl::detail::ps_sequence_t
 
using annot_t = std::unordered_map< std::string, std::string >
 

Public Member Functions

bool is_empty () const
 
ParameterSetID id () const
 
std::string to_string () const
 
std::string to_compact_string () const
 
std::string to_indented_string () const
 
std::string to_indented_string (unsigned initial_indent_level) const
 
std::string to_indented_string (unsigned initial_indent_level, bool annotate) const
 
std::string to_indented_string (unsigned initial_indent_level, detail::print_mode pm) const
 
std::vector< std::string > get_names () const
 
std::vector< std::string > get_pset_names () const
 
std::vector< std::string > get_all_keys () const
 
bool has_key (std::string const &key) const
 
bool is_key_to_table (std::string const &key) const
 
bool is_key_to_sequence (std::string const &key) const
 
bool is_key_to_atom (std::string const &key) const
 
template<class T >
std::optional< T > get_if_present (std::string const &key) const
 
template<class T , class Via >
std::optional< T > get_if_present (std::string const &key, T convert(Via const &)) const
 
template<class T >
bool get_if_present (std::string const &key, T &value) const
 
template<class T , class Via >
bool get_if_present (std::string const &key, T &value, T convert(Via const &)) const
 
template<class T >
get (std::string const &key) const
 
template<class T , class Via >
get (std::string const &key, T convert(Via const &)) const
 
template<class T >
get (std::string const &key, T const &default_value) const
 
template<class T , class Via >
get (std::string const &key, T const &default_value, T convert(Via const &)) const
 
std::string get_src_info (std::string const &key) const
 
void walk (ParameterSetWalker &psw) const
 
void put (std::string const &key)
 
template<class T >
void put (std::string const &key, T const &value)
 
void put_or_replace (std::string const &key)
 
template<class T >
void put_or_replace (std::string const &key, T const &value)
 
template<class T >
void put_or_replace_compatible (std::string const &key, T const &value)
 
bool erase (std::string const &key)
 
bool operator== (ParameterSet const &other) const
 
bool operator!= (ParameterSet const &other) const
 
template<>
void put (std::string const &key, fhicl::extended_value const &value)
 

Static Public Member Functions

static ParameterSet make (intermediate_table const &tbl)
 
static ParameterSet make (extended_value const &xval)
 
static ParameterSet make (std::string const &str)
 
static ParameterSet make (std::string const &filename, cet::filepath_maker &maker)
 

Private Types

using map_t = std::map< std::string, std::any >
 
using map_iter_t = map_t::const_iterator
 

Private Member Functions

void insert_ (std::string const &key, std::any const &value)
 
void insert_or_replace_ (std::string const &key, std::any const &value)
 
void insert_or_replace_compatible_ (std::string const &key, std::any const &value)
 
std::string to_string_ (bool compact=false) const
 
std::string stringify_ (std::any const &a, bool compact=false) const
 
bool key_is_type_ (std::string const &key, std::function< bool(std::any const &)> func) const
 
template<class T >
std::optional< T > get_one_ (std::string const &key) const
 
bool find_one_ (std::string const &key) const
 
std::optional< ParameterSetdescend_ (std::vector< std::string > const &names) const
 

Private Attributes

map_t mapping_
 
annot_t srcMapping_
 
ParameterSetID id_
 

Detailed Description

Definition at line 36 of file ParameterSet.h.

Member Typedef Documentation

using fhicl::ParameterSet::annot_t = std::unordered_map<std::string, std::string>

Definition at line 40 of file ParameterSet.h.

Definition at line 123 of file ParameterSet.h.

using fhicl::ParameterSet::map_t = std::map<std::string, std::any>
private

Definition at line 122 of file ParameterSet.h.

Member Function Documentation

std::optional< ParameterSet > ParameterSet::descend_ ( std::vector< std::string > const &  names) const
private

Definition at line 223 of file ParameterSet.cc.

References util::empty().

224 {
225  if (empty(names)) {
226  return std::make_optional(*this);
227  }
228  ParameterSet const* p{this};
229  std::optional<ParameterSet> result;
230  for (auto const& name : names) {
231  if (!p->find_one_(name)) {
232  return std::nullopt;
233  }
234  if (!p->is_key_to_table(name)) {
235  return std::nullopt;
236  }
237 
238  if (result = p->get_one_<ParameterSet>(name); not result) {
239  return std::nullopt;
240  }
241  p = &result.value();
242  }
243  return result;
244 }
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
bool ParameterSet::erase ( std::string const &  key)

Definition at line 338 of file ParameterSet.cc.

339 {
340  bool const did_erase{1u == mapping_.erase(key)};
341  id_.invalidate();
342  return did_erase;
343 }
void invalidate() noexcept
ParameterSetID id_
Definition: ParameterSet.h:127
bool ParameterSet::find_one_ ( std::string const &  key) const
private

Definition at line 209 of file ParameterSet.cc.

References fhicl::detail::find_an_any(), and fhicl::detail::get_sequence_indices().

210 {
211  auto skey = detail::get_sequence_indices(simple_key);
212 
213  auto it = mapping_.find(skey.name());
214  if (it == mapping_.end()) {
215  return false;
216  }
217 
218  auto a = it->second;
219  return detail::find_an_any(skey.indices().cbegin(), skey.indices().cend(), a);
220 }
bool find_an_any(std::vector< std::size_t >::const_iterator it, std::vector< std::size_t >::const_iterator const cend, std::any &a)
SequenceKey get_sequence_indices(std::string const &key)
template<class T >
T fhicl::ParameterSet::get ( std::string const &  key) const

Definition at line 314 of file ParameterSet.h.

References fhicl::cant_find.

Referenced by pmtana::AlgoCFD::AlgoCFD(), pmtana::AlgoFixedWindow::AlgoFixedWindow(), pmtana::AlgoSiPM::AlgoSiPM(), pmtana::AlgoSlidingWindow::AlgoSlidingWindow(), pmtana::AlgoThreshold::AlgoThreshold(), artg4tk::artg4tkMain::artg4tkMain(), fhicl::detail::ValuePrinter::before_action(), fhicl::detail::Prettifier::before_action(), artg4tk::CheckDRCalorimeterHits::beginJob(), cluster::BlurredClusteringAlg::BlurredClusteringAlg(), reco_tool::CandHitDerivative::CandHitDerivative(), reco_tool::CandHitMorphological::CandHitMorphological(), wc::CellTree::CellTree(), cheat::CheckBackTracking::CheckBackTracking(), pid::Chi2PIDAlg::Chi2PIDAlg(), cluster::ClusterCrawlerAlg::ClusterCrawlerAlg(), ClusteringValidation::ClusteringValidation::ClusteringValidation(), cluster::ClusterMatchAlg::ClusterMatchAlg(), cluster::ClusterMatchTQ::ClusterMatchTQ(), altns::ExampleAction::Config(), mf::service::ELdestination::Category::Config::Config(), trigger::TriggerAlgoBase::Config(), evwgh::PPFXCVWeightCalc::Configure(), evwgh::PPFXMIPPKaonWeightCalc::Configure(), evwgh::PPFXMIPPPionWeightCalc::Configure(), evwgh::PPFXOtherWeightCalc::Configure(), evwgh::PPFXTargAttenWeightCalc::Configure(), evwgh::PPFXThinKaonWeightCalc::Configure(), evwgh::PPFXThinMesonWeightCalc::Configure(), evwgh::PPFXThinNucAWeightCalc::Configure(), evwgh::PPFXThinNucWeightCalc::Configure(), evwgh::PPFXThinPionWeightCalc::Configure(), evwgh::PPFXTotAbsorpWeightCalc::Configure(), evwgh::PPFXWeightCalc::Configure(), evwgh::PPFXThinNeutronPionWeightCalc::Configure(), evd_tool::ICARUSDrawer::configure(), evd_tool::MicroBooNEDrawer::configure(), evdb_tool::DrawGausHits::configure(), spacecharge::SpaceChargeStandard::Configure(), lar_cluster3d::ClusterParamsBuilder::configure(), evwgh::WeightManager::Configure(), lar_cluster3d::DBScanAlg::configure(), lar_cluster3d::ClusterMergeAlg::configure(), lar_cluster3d::ClusterPathFinder::configure(), lar_cluster3d::ConvexHullPathFinder::configure(), lar_cluster3d::VoronoiPathFinder::configure(), lar_cluster3d::MinSpanTreeAlg::configure(), lar_cluster3d::kdTree::configure(), lar_cluster3d::MSTPathFinder::configure(), lar_cluster3d::SpacePointHit3DBuilder::configure(), evd_tool::ProtoDUNEDrawer::configure(), evd_tool::StandardDrawer::configure(), trk::TrackContainmentAlg::Configure(), detinfo::LArPropertiesStandard::Configure(), lar_cluster3d::StandardHit3DBuilder::configure(), lar_cluster3d::SnippetHit3DBuilder::configure(), rndm::details::PerEventPolicy< SEED >::configure(), evwgh::GenieWeightCalc::Configure(), lar_pandora::LArPandora::ConstructHitCollectionToolParameterSet(), corner::CornerFinderAlg::CornerFinderAlg(), trkf::CosmicTrackerAlg::CosmicTrackerAlg(), art::PathManager::createModulesAndWorkers(), testing::GeometryTesterEnvironment< ConfigurationClass >::CreateNewGeometry(), rndm::details::AutoIncrementPolicy< SEED >::createSeed(), rndm::details::LinearMappingPolicy< SEED >::createSeed(), rndm::details::PredefinedOffsetPolicy< SEED >::createSeed(), evgb::CRYHelper::CRYHelper(), art::EventSelector::data_for(), cluster::DBScanAlg::DBScanAlg(), evgen::Decay0Gen::Decay0Gen(), DECLARE_ART_SERVICE_INTERFACE_IMPL(), fhicl::decompose_parameterset(), apa::DisambigAlg::DisambigAlg(), evd::Display3DPad::Display3DPad(), fhicl::PrinterFor< T >::do_atomic_print(), fhicl::OptionalSequence< T, N >::do_preset_value(), fhicl::Sequence< float, 3u >::do_preset_value(), fhicl::OptionalSequence< T,-1ull >::do_preset_value(), fhicl::Sequence< T,-1ull >::do_preset_value(), fhicl::PrinterFor< T >::do_sequence_print(), fhicl::Atom< T >::do_set_value(), artg4tk::ArtG4tkModelConfig::DoFill(), evdb_tool::DrawSimEnergyDeposit3D::DrawSimEnergyDeposit3D(), cluster::EndPointAlg::EndPointAlg(), art::detail::ensure_only_one_thread(), art::EventProcessor::EventProcessor(), vertex::FeatureVertexFinderAna::FeatureVertexFinderAna(), opdet::FIFOHistogramAna::FIFOHistogramAna(), artg4tk::ArtG4tkModelConfig::Fill(), opdet::SimPhotonCounterAlg::FillRanges(), hit::GausHitFinder::GausHitFinder(), hit::GausHitFinderAna::GausHitFinderAna(), phot::PropagationTimeModel::generateVUVParams(), geo::Geometry::Geometry(), evd::DrawingPad::GeometryDraw(), fhicl::DelegatedParameter::get(), rndm::details::PerInstancePolicy< SEED >::getInstanceParameter(), rndm::details::PerInstancePolicy< SEED >::getInstanceSeed(), artg4tk::RunSettingsService::getSettings(), hit::HitAnaModule::HitAnaModule(), hit::HitFinderAna::HitFinderAna(), cluster::HoughBaseAlg::HoughBaseAlg(), lar_cluster3d::HoughSeedFinderAlg::HoughSeedFinderAlg(), fluxr::DK2NuInterface::Init(), larg4::ISCalcAna::ISCalcAna(), detsim::ISCalculationSeparate::ISCalculationSeparate(), detinfo::DetectorPropertiesServiceStandard::isDetectorPropertiesServiceStandard(), opdet::SimPhotonCounter::isVisible(), trkf::KalmanFilterAlg::KalmanFilterAlg(), larg4::LArG4Ana::LArG4Ana(), larg4::LArG4DetectorService::LArG4DetectorService(), sim::LArG4Parameters::LArG4Parameters(), lar_pandora::LArPandoraEventDump::LArPandoraEventDump(), reco::shower::LArPandoraModularShowerCreation::LArPandoraModularShowerCreation(), detinfo::LArPropertiesStandard::LArPropertiesStandard(), larg::LArSimChannelAna::LArSimChannelAna(), sim::LArVoxelCalculator::LArVoxelCalculator(), opdet::LEDCalibrationAna::LEDCalibrationAna(), hit::MagDriftAna::MagDriftAna(), art::InputSourceFactory::make(), art::make_tool(), art::EmptyEvent::makePlugin_(), rndm::details::makeRandomSeedPolicy(), art::detail::ServiceCacheEntry::makeService(), hit::MCHitAnaExample::MCHitAnaExample(), sim::MCRecoEdep::MCRecoEdep(), sim::MCShowerRecoPart::MCShowerRecoPart(), sim::MCTrackRecoAlg::MCTrackRecoAlg(), art::PathManager::moduleInformation_(), ems::MultiEMShowers::MultiEMShowers(), DUNE::MuonTrackingEff::MuonTrackingEff(), mvapid::MVAAlg::MVAAlg(), DUNE::NeutrinoShowerEff::NeutrinoShowerEff(), DUNE::NeutrinoTrackingEff::NeutrinoTrackingEff(), evgen::NueAr40CCGenerator::NueAr40CCGenerator(), opdet::OpDigiAna::OpDigiAna(), opdet::OpDigiProperties::OpDigiProperties(), opdet::OpFlashAna::OpFlashAna(), opdet::OpFlashMCTruthAna::OpFlashMCTruthAna(), opdet::OpFlashSimpleAna::OpFlashSimpleAna(), opdet::OpHitAna::OpHitAna(), opreco::OpticalRecoAna::OpticalRecoAna(), lar_cluster3d::ParallelHitsSeedFinderAlg::ParallelHitsSeedFinderAlg(), testing::BasicTesterEnvironment< ConfigurationClass >::ParseEnvironmentOptions(), cheat::ParticleInventoryService::ParticleInventoryService(), lar_cluster3d::PCASeedFinderAlg::PCASeedFinderAlg(), phot::PDFastSimPAR::PDFastSimPAR(), reco_tool::PeakFitterGaussElimination::PeakFitterGaussElimination(), pmtana::PedAlgoEdges::PedAlgoEdges(), pmtana::PedAlgoRmsSlider::PedAlgoRmsSlider(), pmtana::PedAlgoRollingMean::PedAlgoRollingMean(), pmtana::PedAlgoUB::PedAlgoUB(), opdet::PhotonInf::PhotonInf(), phot::PhotonLibraryAnalyzer::PhotonLibraryAnalyzer(), phot::PhotonVisibilityService::PhotonVisibilityService(), pmtana::PMTAna::PMTAna(), detinfo::DetectorPropertiesServiceStandard::postOpenFile(), fluxr::PPFXFluxReader::PPFXFluxReader(), lar_cluster3d::PrincipalComponentsAlg::PrincipalComponentsAlg(), art::detail::print_config_summary(), art::detail::print_module_types(), art::detail::print_service_types(), phot::PropagationTimeModel::PropagationTimeModel(), art::ProvenanceDumper< DETAIL, Enable >::ProvenanceDumper(), cheat::RecoCheckAna::RecoCheckAna(), wcls::WireCellToolkit::reconfigure(), evd::AnalysisDrawingOptions::reconfigure(), evd::ColorDrawingOptions::reconfigure(), evd::RecoDrawingOptions::reconfigure(), evd::EvdLayoutOptions::reconfigure(), evd::SimulationDrawingOptions::reconfigure(), evdb::Colors::reconfigure(), nutools::dbi::DBIService::reconfigure(), evdb::EventDisplay::reconfigure(), mag::MagneticFieldStandard::reconfigure(), trkf::StitchAlg::reconfigure(), tss::Segmentation2D::reconfigure(), trkf::SeedFinderAlgorithm::reconfigure(), lar_pandora::PFParticleTrackAna::reconfigure(), lar_pandora::PFParticleValidation::reconfigure(), lar_pandora::PFParticleCosmicAna::reconfigure(), lar_pandora::PFParticleAnalysis::reconfigure(), lar_pandora::PFParticleMonitoring::reconfigure(), lar_pandora::ConsolidatedPFParticleAnalysisTemplate::reconfigure(), lar_pandora::PFParticleHitDumper::reconfigure(), t0::IndirectHitParticleAssns::reconfigure(), lar_cluster3d::SkeletonAlg::reconfigure(), lariov::SIOVPmtGainProvider::Reconfigure(), evd::RawDrawingOptions::reconfigure(), phot::PhotonVisibilityService::reconfigure(), t0::DirectHitParticleAssns::reconfigure(), noisefilteralg::WireCellNoiseFilter::reconfigure(), lariov::SIOVElectronicsCalibProvider::Reconfigure(), lariov::DatabaseRetrievalAlg::Reconfigure(), util::DatabaseUtil::reconfigure(), evd::InfoTransfer::reconfigure(), rwgt::ReweightAna::reconfigure(), lcvn::ICVNZlibMaker::reconfigure(), lcvn::LArNuCVNZlibMaker::reconfigure(), lariov::DetPedestalRetrievalAlg::Reconfigure(), cluster::MergeClusterAlg::reconfigure(), hit::CCHitFinderAlg::reconfigure(), shower::TrackShowerSeparationAlg::reconfigure(), evdb::ServiceTable::RegisterService(), hit::RFFHitFinderAlg::RFFHitFinderAlg(), art::RPManager::RPManager(), art::run_art(), dnn::SavePiMu::SavePiMu(), evdb::ScanOptions::ScanOptions(), phot::ScintTimeLAr::ScintTimeLAr(), fhicl::detail::TableBase::select_pset(), testing::BasicTesterEnvironment< ConfigurationClass >::ServiceParameters(), lar::standalone::SetupGeometry(), lar::standalone::SetupGeometryWithChannelMapping(), lar::standalone::SetupMessageFacility(), ShowerRecoTools::ShowerBayesianTrucatingdEdx::ShowerBayesianTrucatingdEdx(), shower::ShowerEnergyAlg::ShowerEnergyAlg(), ShowerQuality::ShowerQuality(), shwf::ShowerReco::ShowerReco(), detsim::SimDriftedElectronClusterAna::SimDriftedElectronClusterAna(), opdet::SimPhotonCounterAlg::SimPhotonCounterAlg(), lariov::SimpleChannelStatus::SimpleChannelStatus(), detsim::SimWireAna::SimWireAna(), lariov::SIOVChannelStatusProvider::SIOVChannelStatusProvider(), cluster::SmallClusterFinderAlg::SmallClusterFinderAlg(), evdb_tool::SpacePoint3DDrawerHitAsymmetry::SpacePoint3DDrawerHitAsymmetry(), evdb_tool::SpacePoint3DDrawerHitCharge::SpacePoint3DDrawerHitCharge(), trkf::SpacePointAlg::SpacePointAlg(), sppt::SpacePointAlg_TimeSort::SpacePointAlg_TimeSort(), evgen::SpectrumVolumeGen::SpectrumVolumeGen(), rndm::details::AutoIncrementPolicy< SEED >::static_configure(), rndm::details::LinearMappingPolicy< SEED >::static_configure(), rndm::details::PredefinedOffsetPolicy< SEED >::static_configure(), shower::TCShowerElectronLikelihood::TCShowerElectronLikelihood(), testing::BasicTesterEnvironment< ConfigurationClass >::TesterParameters(), phot::TFLoaderMLP::TFLoaderMLP(), trkf::Track3DKalmanHitAlg::Track3DKalmanHitAlg(), calo::TrackCalorimetryAlg::TrackCalorimetryAlg(), trk::TrackContainmentAnalyzer::TrackContainmentAnalyzer(), tca::TrajClusterAlg::TrajClusterAlg(), lartriton::TritonClient::TritonClient(), evdb::Colors::UnpackColorScale(), evdb::ParameterSetEditRow::UnpackParameter(), wavdenoise_tool::WaveformDenoiseTf::WaveformDenoiseTf(), wavrec_tool::WaveformRecogTf::WaveformRecogTf(), wframerec_tool::WireframeRecogTf::WireframeRecogTf(), and cheat::PhotonBackTracker::~PhotonBackTracker().

315 {
316  auto result = get_if_present<T>(key);
317  return result ? *result : throw fhicl::exception(cant_find, key);
318 }
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class T , class Via >
T fhicl::ParameterSet::get ( std::string const &  key,
T   convertVia const & 
) const

Definition at line 322 of file ParameterSet.h.

References fhicl::cant_find.

323 {
324  auto result = get_if_present<T>(key, convert);
325  return result ? *result : throw fhicl::exception(cant_find, key);
326 }
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class T >
T fhicl::ParameterSet::get ( std::string const &  key,
T const &  default_value 
) const

Definition at line 330 of file ParameterSet.h.

331 {
332  auto result = get_if_present<T>(key);
333  return result ? *result : default_value;
334 }
template<class T , class Via >
T fhicl::ParameterSet::get ( std::string const &  key,
T const &  default_value,
T   convertVia const & 
) const

Definition at line 338 of file ParameterSet.h.

341 {
342  auto result = get_if_present<T>(key, convert);
343  return result ? *result : default_value;
344 }
vector< string > ParameterSet::get_all_keys ( ) const

Definition at line 201 of file ParameterSet.cc.

References fhicl::detail::KeyAssembler::result().

Referenced by evwgh::GenieWeightCalc::Configure().

202 {
203  KeyAssembler ka;
204  walk(ka);
205  return ka.result();
206 }
void walk(ParameterSetWalker &psw) const
std::vector< key_t > const & result()
Definition: KeyAssembler.h:75
template<class T >
std::optional< T > fhicl::ParameterSet::get_if_present ( std::string const &  key) const

Definition at line 267 of file ParameterSet.h.

References fhicl::detail::get_names().

Referenced by rndm::details::RangeCheckHelper< SEED >::configure(), rndm::details::RandomPolicy< SEED >::configure(), rndm::details::RandomPolicy< SEED >::createSeed(), rndm::details::LinearMappingPolicy< SEED >::createSeed(), evgen::Decay0Gen::Decay0Gen(), fhicl::Atom< T >::do_set_value(), fhicl::OptionalAtom< T >::do_set_value(), mf::service::ELdestination::ELdestination(), art::detail::ensure_only_one_thread(), evgen::GENIEGen::GENIEGen(), rndm::details::PerInstancePolicy< SEED >::getInstanceParameter(), rndm::details::PerInstancePolicy< SEED >::getInstanceSeed(), fhicl::detail::TableBase::maybe_select_pset(), rndm::NuRandomService::readSeedParameter(), testing::ProviderSetupClass< detinfo::LArPropertiesStandard >::setup(), testing::ProviderSetupClass< detinfo::DetectorClocksStandard >::setup(), testing::ProviderSetupClass< detinfo::DetectorPropertiesStandard >::setup(), testing::BasicTesterEnvironment< ConfigurationClass >::SetupMessageFacility(), evgen::SpectrumVolumeGen::SpectrumVolumeGen(), rndm::details::LinearMappingPolicy< SEED >::static_configure(), and tca::TrajClusterAlg::TrajClusterAlg().

268 {
269  auto keys = detail::get_names(key);
270  if (auto ps = descend_(keys.tables())) {
271  return ps->get_one_<T>(keys.last());
272  }
273  return std::nullopt;
274 }
Keys get_names(std::string const &key)
std::optional< ParameterSet > descend_(std::vector< std::string > const &names) const
template<class T , class Via >
std::optional< T > fhicl::ParameterSet::get_if_present ( std::string const &  key,
T   convertVia const & 
) const

Definition at line 278 of file ParameterSet.h.

280 {
281  auto go_between = get_if_present<Via>(key);
282  if (not go_between) {
283  return std::nullopt;
284  }
285  return std::make_optional(convert(*go_between));
286 } // get_if_present<>()
template<class T >
bool fhicl::ParameterSet::get_if_present ( std::string const &  key,
T &  value 
) const

Definition at line 290 of file ParameterSet.h.

291 {
292  if (auto present_parameter = get_if_present<T>(key)) {
293  value = *present_parameter;
294  return true;
295  }
296  return false;
297 }
double value
Definition: spectrum.C:18
template<class T , class Via >
bool fhicl::ParameterSet::get_if_present ( std::string const &  key,
T &  value,
T   convertVia const & 
) const

Definition at line 301 of file ParameterSet.h.

304 {
305  if (auto present_parameter = get_if_present<T>(key, convert)) {
306  result = *present_parameter;
307  return true;
308  }
309  return false;
310 } // get_if_present<>()
vector< string > ParameterSet::get_names ( ) const
template<class T >
std::optional< T > fhicl::ParameterSet::get_one_ ( std::string const &  key) const
private

Definition at line 364 of file ParameterSet.h.

References fhicl::cant_find, util::quantities::concepts::decode(), e, fhicl::detail::find_an_any(), fhicl::detail::get_sequence_indices(), fhicl::type_mismatch, and value.

365 {
366  T value;
367  try {
368  auto skey = detail::get_sequence_indices(key);
369 
370  map_iter_t it = mapping_.find(skey.name());
371  if (it == mapping_.end()) {
372  return std::nullopt;
373  }
374 
375  auto a = it->second;
376  if (!detail::find_an_any(
377  skey.indices().cbegin(), skey.indices().cend(), a)) {
379  }
380 
381  using detail::decode;
382  decode(a, value);
383  return std::make_optional(value);
384  }
385  catch (fhicl::exception const& e) {
386  std::ostringstream errmsg;
387  errmsg << "\nUnsuccessful attempt to convert FHiCL parameter '" << key
388  << "' to type '" << cet::demangle_symbol(typeid(value).name())
389  << "'.\n\n"
390  << "[Specific error:]";
391  throw fhicl::exception(type_mismatch, errmsg.str(), e);
392  }
393  catch (std::exception const& e) {
394  std::ostringstream errmsg;
395  errmsg << "\nUnsuccessful attempt to convert FHiCL parameter '" << key
396  << "' to type '" << cet::demangle_symbol(typeid(value).name())
397  << "'.\n\n"
398  << "[Specific error:]\n"
399  << e.what() << "\n\n";
400  throw fhicl::exception(type_mismatch, errmsg.str());
401  }
402 }
map_t::const_iterator map_iter_t
Definition: ParameterSet.h:123
void decode(std::any const &, std::string &)
bool find_an_any(std::vector< std::size_t >::const_iterator it, std::vector< std::size_t >::const_iterator const cend, std::any &a)
SequenceKey get_sequence_indices(std::string const &key)
double value
Definition: spectrum.C:18
void decode(std::any const &src, Interval< Args... > &iv)
Decodes an interval.
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
vector< string > ParameterSet::get_pset_names ( ) const

Definition at line 189 of file ParameterSet.cc.

References fhicl::detail::is_table(), and value.

Referenced by evd::Display3DPad::Display3DPad(), mf::service::ELdestination::ELdestination(), and hit::GausHitFinder::GausHitFinder().

190 {
191  vector<string> keys;
192  for (auto const& [key, value] : mapping_) {
193  if (is_table(value)) {
194  keys.push_back(key);
195  }
196  }
197  return keys;
198 }
double value
Definition: spectrum.C:18
bool is_table(par_type const pt)
std::string ParameterSet::get_src_info ( std::string const &  key) const

Definition at line 257 of file ParameterSet.cc.

Referenced by fhicl::detail::PrettifierAnnotated::before_action(), fhicl::detail::PrettifierPrefixAnnotated::before_action(), and fhicl::detail::ValidateThenSet::delegated_parameter().

258 {
259  auto result = srcMapping_.find(key);
260  return result != srcMapping_.cend() ? result->second : "";
261 }
void ParameterSet::insert_ ( std::string const &  key,
std::any const &  value 
)
private

Definition at line 290 of file ParameterSet.cc.

References fhicl::cant_insert.

291 {
292  check_put_local_key(key);
293  if (!mapping_.emplace(key, value).second) {
294  throw exception(cant_insert) << "key " << key << " already exists.";
295  }
296  id_.invalidate();
297 }
double value
Definition: spectrum.C:18
void invalidate() noexcept
ParameterSetID id_
Definition: ParameterSet.h:127
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void ParameterSet::insert_or_replace_ ( std::string const &  key,
std::any const &  value 
)
private

Definition at line 300 of file ParameterSet.cc.

References value.

301 {
302  check_put_local_key(key);
303  mapping_[key] = value;
304  id_.invalidate();
305 }
double value
Definition: spectrum.C:18
void invalidate() noexcept
ParameterSetID id_
Definition: ParameterSet.h:127
void ParameterSet::insert_or_replace_compatible_ ( std::string const &  key,
std::any const &  value 
)
private

Definition at line 308 of file ParameterSet.cc.

References fhicl::cant_insert, fhicl::detail::is_nil(), fhicl::detail::is_sequence(), fhicl::detail::is_table(), and value.

309 {
310  check_put_local_key(key);
311  auto item = mapping_.find(key);
312  if (item == mapping_.end()) {
313  insert_(key, value);
314  return;
315  } else {
316  if (!detail::is_nil(value)) {
317  auto is_non_nil_atom = [](any const& v) {
318  return !(detail::is_sequence(v) || detail::is_table(v) ||
319  detail::is_nil(v));
320  };
321  if (detail::is_sequence(item->second) && !detail::is_sequence(value)) {
322  throw exception(cant_insert)
323  << "can't use non-sequence to replace sequence.";
324  } else if (detail::is_table(item->second) && !detail::is_table(value)) {
325  throw exception(cant_insert) << "can't use non-table to replace table.";
326  } else if (is_non_nil_atom(item->second) &&
328  throw exception(cant_insert)
329  << "can't use non-atom to replace non-nil atom.";
330  }
331  }
332  item->second = value;
333  }
334  id_.invalidate();
335 }
void insert_(std::string const &key, std::any const &value)
bool is_nil(std::any const &val)
Definition: coding.cc:71
double value
Definition: spectrum.C:18
bool is_table(std::any const &val)
Definition: coding.h:55
void invalidate() noexcept
ParameterSetID id_
Definition: ParameterSet.h:127
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool is_sequence(std::any const &val)
Definition: coding.h:49
bool ParameterSet::is_empty ( ) const

Definition at line 147 of file ParameterSet.cc.

148 {
149  return mapping_.empty();
150 }
bool fhicl::ParameterSet::is_key_to_atom ( std::string const &  key) const
inline

Definition at line 220 of file ParameterSet.h.

References fhicl::detail::is_sequence(), and fhicl::detail::is_table().

Referenced by rndm::details::PerInstancePolicy< SEED >::getInstanceParameter(), and rndm::details::PerInstancePolicy< SEED >::getInstanceSeed().

221 {
222  return key_is_type_(key, [](std::any const& a) {
223  return !(detail::is_sequence(a) || detail::is_table(a));
224  });
225 }
bool key_is_type_(std::string const &key, std::function< bool(std::any const &)> func) const
bool is_table(std::any const &val)
Definition: coding.h:55
bool is_sequence(std::any const &val)
Definition: coding.h:49
bool fhicl::ParameterSet::is_key_to_sequence ( std::string const &  key) const
inline

Definition at line 214 of file ParameterSet.h.

References fhicl::detail::is_sequence().

Referenced by fhicl::decompose_parameterset(), and fhicl::detail::ValidateThenSet::enter_sequence().

215 {
216  return key_is_type_(key, &detail::is_sequence);
217 }
bool key_is_type_(std::string const &key, std::function< bool(std::any const &)> func) const
bool is_sequence(std::any const &val)
Definition: coding.h:49
bool fhicl::ParameterSet::is_key_to_table ( std::string const &  key) const
inline

Definition at line 208 of file ParameterSet.h.

References fhicl::detail::is_table().

Referenced by fhicl::decompose_parameterset(), rndm::details::PerInstancePolicy< SEED >::getInstanceParameter(), rndm::details::PerInstancePolicy< SEED >::getInstanceSeed(), and fluxr::DK2NuInterface::Init().

209 {
210  return key_is_type_(key, &detail::is_table);
211 }
bool key_is_type_(std::string const &key, std::function< bool(std::any const &)> func) const
bool is_table(std::any const &val)
Definition: coding.h:55
bool ParameterSet::key_is_type_ ( std::string const &  key,
std::function< bool(std::any const &)>  func 
) const
private

Definition at line 346 of file ParameterSet.cc.

References fhicl::cant_find, fhicl::detail::find_an_any(), fhicl::detail::get_names(), and fhicl::detail::get_sequence_indices().

348 {
349  auto split_keys = detail::get_names(key);
350  auto ps = descend_(split_keys.tables());
351  if (not ps) {
352  throw exception(error::cant_find, key);
353  }
354 
355  auto skey = detail::get_sequence_indices(split_keys.last());
356 
357  auto it = ps->mapping_.find(skey.name());
358  if (it == ps->mapping_.end()) {
359  throw exception(error::cant_find, key);
360  }
361 
362  auto a = it->second;
363  return detail::find_an_any(
364  skey.indices().cbegin(), skey.indices().cend(), a) ?
365  func(a) :
366  throw exception(error::cant_find, key);
367 }
Keys get_names(std::string const &key)
std::optional< ParameterSet > descend_(std::vector< std::string > const &names) const
bool find_an_any(std::vector< std::size_t >::const_iterator it, std::vector< std::size_t >::const_iterator const cend, std::any &a)
SequenceKey get_sequence_indices(std::string const &key)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
fhicl::ParameterSet fhicl::ParameterSet::make ( extended_value const &  xval)
static

Definition at line 81 of file ParameterSet.cc.

References fhicl::extended_value::is_a(), put(), fhicl::TABLE, fhicl::type_mismatch, and value.

82 {
83  if (!xval.is_a(TABLE))
84  throw fhicl::exception(type_mismatch, "extended value not a table");
85 
86  ParameterSet result;
87  auto const& tbl = table_t(xval);
88  for (auto const& [key, value] : tbl) {
89  if (!value.in_prolog)
90  result.put(key, value);
91  }
92  return result;
93 }
intermediate_table::table_t table_t
Definition: ParameterSet.cc:32
double value
Definition: spectrum.C:18
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
fhicl::ParameterSet fhicl::ParameterSet::make ( std::string const &  str)
static

Definition at line 98 of file ParameterSet.cc.

References make(), and fhicl::parse_document().

99 {
100  auto const tbl = parse_document(str);
101  return ParameterSet::make(tbl);
102 }
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:709
fhicl::ParameterSet fhicl::ParameterSet::make ( std::string const &  filename,
cet::filepath_maker &  maker 
)
static

Definition at line 107 of file ParameterSet.cc.

References make(), and fhicl::parse_document().

109 {
110  auto const tbl = parse_document(filename, maker);
111  return ParameterSet::make(tbl);
112 }
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:709
bool fhicl::ParameterSet::operator!= ( ParameterSet const &  other) const
inline

Definition at line 355 of file ParameterSet.h.

References util::details::operator==().

356 {
357  return !operator==(other);
358 }
bool operator==(ParameterSet const &other) const
Definition: ParameterSet.h:349
bool fhicl::ParameterSet::operator== ( ParameterSet const &  other) const
inline

Definition at line 349 of file ParameterSet.h.

References id().

350 {
351  return id() == other.id();
352 }
ParameterSetID id() const
template<class T >
void fhicl::ParameterSet::put ( std::string const &  key,
T const &  value 
)

Definition at line 229 of file ParameterSet.h.

References util::quantities::concepts::encode(), fhicl::detail::try_insert(), and value.

230 {
231  auto insert = [this, &value](auto const& key) {
232  using detail::encode;
233  this->insert_(key, std::any(encode(value)));
234  };
235  detail::try_insert(insert, key);
236 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
void try_insert(L l, std::string const &key)
Definition: try_blocks.h:11
void insert_(std::string const &key, std::any const &value)
double value
Definition: spectrum.C:18
void fhicl::ParameterSet::put ( std::string const &  key,
fhicl::extended_value const &  value 
)

Definition at line 409 of file ParameterSet.cc.

References fhicl::detail::encode(), fhicl::detail::try_insert(), and value.

410  {
411  auto insert = [this, &value](auto const& key) {
412  using detail::encode;
413  this->insert_(key, std::any(encode(value)));
414  fill_src_info(value, key, srcMapping_);
415  };
416  detail::try_insert(insert, key);
417  }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
void try_insert(L l, std::string const &key)
Definition: try_blocks.h:11
void insert_(std::string const &key, std::any const &value)
double value
Definition: spectrum.C:18
void ParameterSet::put_or_replace ( std::string const &  key)

Definition at line 272 of file ParameterSet.cc.

References fhicl::unimplemented.

Referenced by lar_cluster3d::DBScanAlg::configure(), and reco::shower::LArPandoraModularShowerCreation::LArPandoraModularShowerCreation().

273 {
274  put_or_replace(key, nullptr); // Replace with nil is always OK.
275 }
void put_or_replace(std::string const &key)
template<class T >
void fhicl::ParameterSet::put_or_replace ( std::string const &  key,
T const &  value 
)

Definition at line 240 of file ParameterSet.h.

References util::quantities::concepts::encode(), fhicl::detail::try_insert(), and value.

241 {
242  auto insert_or_replace = [this, &value](auto const& key) {
243  using detail::encode;
244  this->insert_or_replace_(key, std::any(encode(value)));
245  srcMapping_.erase(key);
246  };
247  detail::try_insert(insert_or_replace, key);
248 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
void try_insert(L l, std::string const &key)
Definition: try_blocks.h:11
double value
Definition: spectrum.C:18
void insert_or_replace_(std::string const &key, std::any const &value)
template<class T >
void fhicl::ParameterSet::put_or_replace_compatible ( std::string const &  key,
T const &  value 
)

Definition at line 252 of file ParameterSet.h.

References util::quantities::concepts::encode(), fhicl::detail::try_insert(), and value.

254 {
255  auto insert_or_replace_compatible = [this, &value](auto const& key) {
256  using detail::encode;
257  this->insert_or_replace_compatible_(key, std::any(encode(value)));
258  srcMapping_.erase(key);
259  };
260  detail::try_insert(insert_or_replace_compatible, key);
261 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:83
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
void try_insert(L l, std::string const &key)
Definition: try_blocks.h:11
void insert_or_replace_compatible_(std::string const &key, std::any const &value)
double value
Definition: spectrum.C:18
string ParameterSet::stringify_ ( std::any const &  a,
bool  compact = false 
) const
private

Definition at line 117 of file ParameterSet.cc.

References e, fhicl::ParameterSetRegistry::get(), fhicl::detail::is_sequence(), fhicl::detail::is_table(), and fhicl::ParameterSetID::max_str_size().

118 {
119  string result;
120  if (is_table(a)) {
121  auto const& psid = any_cast<ParameterSetID>(a);
122  result = '{' + ParameterSetRegistry::get(psid).to_string() + '}';
123  if (compact && result.size() > (5 + ParameterSetID::max_str_size())) {
124  // Replace with a reference to the ParameterSetID;
125  result = std::string("@id::") + psid.to_string();
126  }
127  } else if (is_sequence(a)) {
128  auto const& seq = any_cast<ps_sequence_t>(a);
129  result = '[';
130  if (!seq.empty()) {
131  result.append(stringify_(*seq.begin(), compact));
132  for (auto it = seq.cbegin(), e = seq.cend(); ++it != e;) {
133  result.append(1, ',').append(stringify_(*it, compact));
134  }
135  }
136  result.append(1, ']');
137  } else { // is_atom(a)
138  ps_atom_t const str = any_cast<ps_atom_t>(a);
139  result = str == string(9, '\0') ? "@nil" : str;
140  }
141  return result;
142 } // stringify_()
static collection_type const & get() noexcept
bool is_sequence(par_type const pt)
std::vector< std::any > ps_sequence_t
Definition: coding.h:45
static constexpr std::size_t max_str_size() noexcept
std::string ps_atom_t
Definition: coding.h:44
std::string stringify_(std::any const &a, bool compact=false) const
bool is_table(par_type const pt)
Float_t e
Definition: plot.C:35
std::string fhicl::ParameterSet::to_compact_string ( ) const
inline

Definition at line 202 of file ParameterSet.h.

Referenced by fhicl::decompose_parameterset().

203 {
204  return to_string_(true);
205 }
std::string to_string_(bool compact=false) const
string ParameterSet::to_indented_string ( ) const
string ParameterSet::to_indented_string ( unsigned  initial_indent_level) const

Definition at line 472 of file ParameterSet.cc.

473 {
474  return to_indented_string(initial_indent_level, false);
475 }
std::string to_indented_string() const
string ParameterSet::to_indented_string ( unsigned  initial_indent_level,
bool  annotate 
) const

Definition at line 478 of file ParameterSet.cc.

References fhicl::detail::annotated, and fhicl::detail::raw.

480 {
481  if (annotate) {
482  return to_indented_string(initial_indent_level, print_mode::annotated);
483  }
484  return to_indented_string(initial_indent_level, print_mode::raw);
485 }
std::string to_indented_string() const
string ParameterSet::to_indented_string ( unsigned  initial_indent_level,
detail::print_mode  pm 
) const

Definition at line 488 of file ParameterSet.cc.

References fhicl::detail::annotated, fhicl::detail::prefix_annotated, fhicl::detail::raw, and fhicl::detail::PrettifierPrefixAnnotated::result().

490 {
491  std::string result;
492  switch (pm) {
493  case print_mode::raw: {
494  Prettifier p{initial_indent_level};
495  walk(p);
496  result = p.result();
497  break;
498  }
499  case print_mode::annotated: {
500  PrettifierAnnotated p{initial_indent_level};
501  walk(p);
502  result = p.result();
503  break;
504  }
505  case print_mode::prefix_annotated: {
507  walk(p);
508  result = p.result();
509  break;
510  }
511  }
512  return result;
513 }
void walk(ParameterSetWalker &psw) const
std::string fhicl::ParameterSet::to_string ( ) const
inline

Definition at line 196 of file ParameterSet.h.

Referenced by fhicl::ParameterSetID::reset(), and evdb::ParameterSetEditRow::UnpackParameter().

197 {
198  return to_string_();
199 }
std::string to_string_(bool compact=false) const
string ParameterSet::to_string_ ( bool  compact = false) const
private

Definition at line 162 of file ParameterSet.cc.

References e.

163 {
164  string result;
165  if (mapping_.empty()) {
166  return result;
167  }
168  auto it = mapping_.begin();
169  result.append(it->first).append(1, ':').append(
170  stringify_(it->second, compact));
171  for (auto const e = mapping_.end(); ++it != e;) {
172  result.append(1, ' ').append(it->first).append(1, ':').append(
173  stringify_(it->second, compact));
174  }
175  return result;
176 }
std::string stringify_(std::any const &a, bool compact=false) const
Float_t e
Definition: plot.C:35
void ParameterSet::walk ( ParameterSetWalker psw) const

Definition at line 423 of file ParameterSet.cc.

References fhicl::ParameterSetWalker::do_after_action(), fhicl::ParameterSetWalker::do_atom(), fhicl::ParameterSetWalker::do_before_action(), fhicl::ParameterSetWalker::do_enter_sequence(), fhicl::ParameterSetWalker::do_enter_table(), fhicl::ParameterSetWalker::do_exit_sequence(), fhicl::ParameterSetWalker::do_exit_table(), fhicl::detail::is_sequence(), fhicl::detail::is_table(), mapping_, util::to_string(), and value.

Referenced by evgen::MARLEYHelper::reconfigure().

424 {
425  std::stack<ParameterSet const*> ps_stack;
426  ps_stack.push(this);
427 
428  std::function<void(std::string const&, std::any const&)> act_on_element =
429  [&psw, &ps_stack, &act_on_element](std::string const& key,
430  std::any const& a) {
431  auto const* ps = ps_stack.top();
432  psw.do_before_action(key, a, ps);
433 
434  if (is_table(a)) {
435  ParameterSet const* ps = &get_pset_via_any(a);
436  ps_stack.push(ps);
437  psw.do_enter_table(key, a);
438  for (auto const& [nested_key, nested_a] : ps->mapping_) {
439  act_on_element(nested_key, nested_a);
440  }
441  psw.do_exit_table(key, a);
442  ps_stack.pop();
443  } else if (is_sequence(a)) {
444  psw.do_enter_sequence(key, a);
445  std::size_t i{};
446  for (auto const& elem : any_cast<ps_sequence_t>(a)) {
447  std::string const new_key = key + "["s + std::to_string(i++) + "]";
448  act_on_element(new_key, elem);
449  }
450  psw.do_exit_sequence(key, a);
451  } else {
452  psw.do_atom(key, a);
453  }
454 
455  psw.do_after_action(key);
456  };
457 
458  for (auto const& [key, value] : mapping_) {
459  act_on_element(key, value);
460  }
461 }
void do_before_action(key_t const &k, any_t const &a, ParameterSet const *ps)
bool is_sequence(par_type const pt)
void do_enter_sequence(key_t const &k, any_t const &a)
void do_exit_table(key_t const &k, any_t const &a)
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
void do_after_action(key_t const &k)
double value
Definition: spectrum.C:18
void do_exit_sequence(key_t const &k, any_t const &a)
bool is_table(par_type const pt)
void do_atom(key_t const &k, any_t const &a)
void do_enter_table(key_t const &k, any_t const &a)

Member Data Documentation

ParameterSetID fhicl::ParameterSet::id_
mutableprivate

Definition at line 127 of file ParameterSet.h.

map_t fhicl::ParameterSet::mapping_
private

Definition at line 125 of file ParameterSet.h.

Referenced by walk().

annot_t fhicl::ParameterSet::srcMapping_
private

Definition at line 126 of file ParameterSet.h.


The documentation for this class was generated from the following files: