Project

General

Profile

Feature #9079

Feature #9078: ParameterSet validation enhancements

Conditional configuration for fhiclcpp types

Added by Kyle Knoepfel about 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
06/09/2015
Due date:
% Done:

100%

Estimated time:
16.00 h
Spent time:
Duration:

Description

Mu2e and NOvA have expressed interest in supporting conditional configuration, as described in #8773-3. There are a couple different ways this feature could be implemented. The first is to allow some parameters to be unvalidated:

Atom<std::string> value1 { Key("value1"), mode::Unchecked };
Atom<std::string> value2 { Key("value2"), mode::Unchecked };

which would allow users to access type but not require that it be present in the FHiCL configuration file. The code would throw if a retrieval was requested and a value was not provided in the FHiCL file. This option would be a placeholder for something more complete, like:

Atom<int> type { Key("type") };

Atom<std::string> value1 { Key("value1"), If( typeIs, 1 ) };
Atom<std::string> value2 { Key("value2"), If( typeIs, 2 ) };

where typeIs is some user-provided function (pointer) that queries the value of type. The latter option, while most helpful for the user, would require that value checking would need to take place for certain variables before key-checking (current behavior) could resume. One would then need to specify the behavior (and possibly new syntax) for cases when the argument following typeIs is not an allowed value for type.


Related issues

Blocks fhicl-cpp - Feature #10820: Parameter validation based on limitsClosed2015-11-05

History

#1 Updated by Kyle Knoepfel about 4 years ago

  • Related to Feature #8773: Create new types in FHiCL that automatically register allowed parameters. added

#2 Updated by Kyle Knoepfel about 4 years ago

  • Related to deleted (Feature #8773: Create new types in FHiCL that automatically register allowed parameters.)

#3 Updated by Kyle Knoepfel about 4 years ago

  • Parent task set to #9078

#4 Updated by Christopher Green about 4 years ago

  • Category set to Infrastructure
  • Status changed from New to Feedback
  • Assignee set to Kyle Knoepfel
  • Target version set to 2.01.00

Analysis is required for a reasonable time estimate.

#5 Updated by Kyle Knoepfel about 4 years ago

  • Subject changed from Conditional configuration for new FHiCL c++ types to Conditional configuration for fhiclcpp types

#6 Updated by Kyle Knoepfel almost 4 years ago

  • Project changed from art to fhicl-cpp
  • Category deleted (Infrastructure)

#7 Updated by Christopher Green over 3 years ago

#8 Updated by Kyle Knoepfel over 3 years ago

  • Status changed from Feedback to Assigned
  • Estimated time set to 16.00 h

#9 Updated by Kyle Knoepfel over 3 years ago

  • % Done changed from 0 to 40

#10 Updated by Kyle Knoepfel over 3 years ago

  • % Done changed from 40 to 80

#11 Updated by Kyle Knoepfel over 3 years ago

  • Status changed from Assigned to Resolved
  • % Done changed from 80 to 100

Implemented with commit fhicl-cpp:3c8cee0. Documentation will be forthcoming. However, as a preview, the conditional configuration for a given module is specified using an std::function<bool()> object. For example, consider the following configuration:

struct BoxParams { Atom<>... };
struct SphereParams {  Atom<>... };

struct Config {
  Atom<int> someNumber { Name("someNumber") };
  Atom<bool> flag { Name("flag") };
  Sequence<int> list { Name("list") };
  Atom<string> shape { Name("shape") };

  Table<BoxParams> boxParams { Name("boxParams"), 
                               Comment("Use if shape = box."),
                               [this](){ return shape() == "box"; } };

  bool maybeSphere() const
  {
    return someNumber() == 10 && 
           flag() &&
           list().size() == 17 &&
           shape() == "sphere";  
  }

  Table<SphereParams> sphereParams { Name("sphereParams"),
                                     Comment("Use if the member function 'maybeSphere' returns true."),
                                     fhicl::use_if(this, &Config::maybeSphere) };

};

For simple conditions, the lambda closure (as used for boxParams), is the simplest way to create the std::function<bool()> object. For more complicated conditions (as in the horribly contrived sphereParams case), one can use the fhicl::use_if and fhicl::use_unless helpers to create the std::function<bool()> object for you. In both cases, the predicate function (either the anonymous lambda or maybeSphere) must return a bool and it can receive no arguments.

Full documentation is here.

#12 Updated by Kyle Knoepfel over 3 years ago

  • Target version changed from 2.01.00 to 1.17.05

#13 Updated by Kyle Knoepfel over 3 years ago

  • Status changed from Resolved to Closed


Also available in: Atom PDF