ArtServiceHelper.h
Go to the documentation of this file.
1 // ArtServiceHelper.h
2 
3 #ifndef ArtServiceHelper_H
4 #define ArtServiceHelper_H
5 
6 // =================================================================
7 // The purpose of the 'ArtServiceHelper' class is to construct and
8 // manage a set of art services that normally appear in an art job.
9 // In some circumstances, the available means of testing a new
10 // algorithm may rely on functionality that has been expressed in
11 // terms of an art service. In such a case, the ArtServiceHelper
12 // class can be used to initialize the required services and allow
13 // users to create art::ServiceHandle objects for the configured
14 // services.
15 //
16 // Unlike the art framework's services manager, the ArtServiceHelper
17 // is not aware of framework transitions. Because of that, using some
18 // services outside of the context of the framework will not reflect
19 // the same behavior as using them within it. For that reason, using
20 // such services outside of the framework is circumspect. This must
21 // be taken into account when using this class.
22 //
23 // Initialization
24 // ==============
25 //
26 // The 'ArtServiceHelper' is initialized by specifying the same kind
27 // of configuration one might specify within art (see below under the
28 // Configuration layout section). Allowed initialization patterns
29 // include:
30 //
31 // (1) string-based configuration:
32 //
33 // std::string const config{"MyService: {...}"};
34 // ArtServiceHelper::load_services(config);
35 //
36 // The string is allowed to '#include' any files that will be
37 // accessible via the FHICL_FILE_PATH environment variable.
38 //
39 // (2) filename-based configuration:
40 //
41 // ArtServiceHelper::load_services("config.fcl",
42 // ArtServiceHelper::FileOnPath);
43 //
44 // where 'config.fcl' is a filename relative to one of the
45 // directories on the FHICL_FILE_PATH environment variable.
46 //
47 // (3) stream-based configuration:
48 //
49 // It is permissible to specify an input stream that will be used
50 // to parse the configuration. This can be helpful when a
51 // configuration file is required that is not accessible via
52 // FHICL_FILE_PATH:
53 //
54 // std::ifstream in{"/some/path/to_some_file.fcl"};
55 // ArtServiceHelper::load_services(in);
56 //
57 // Note however, that FHICL_FILE_PATH lookup is *still* enabled in
58 // this mode--i.e. configurations within the file can '#include'
59 // files accessible via FHICL_FILE_PATH. Stream-based
60 // configuration can also be used to assemble more complicated
61 // configurations via an std::stringstream object:
62 //
63 // std::stringstream config;
64 // config << "#include \"some_config.fcl\"\n"
65 // << "PedestalCalibration.some_value: " << 15 << '\n;
66 // ArtServiceHelper::load_services(config);
67 //
68 // (4) ParameterSet-based configuration:
69 //
70 // If a fhicl::ParameterSet object is already available, it can be
71 // used to initialize the ArtServiceHelper:
72 //
73 // auto const pset = get_parameter_set(...);
74 // ArtServiceHelper::load_services(pset);
75 //
76 // Configuration layout
77 // ====================
78 //
79 // The allowed configuration layout is of two forms. The minimal form
80 // lists all desired services by themselves:
81 //
82 // Service1: {...}
83 // Service2: {...}
84 // ServiceN: {...}
85 //
86 // The other form nests these services inside of a 'services' table,
87 // which supports cases when it is desired to use a configuration file
88 // that would be used for an art job:
89 //
90 // services: {
91 // Service1: {...}
92 // Service2: {...}
93 // ServiceN: {...}
94 // }
95 //
96 // As in art, it is not necessary to specify the 'service_type'
97 // parameter for each service--the ArtServiceHelper class inserts
98 // those configuration parameters automatically.
99 //
100 // =================================================================
101 
105 
106 #include <iosfwd>
107 #include <map>
108 #include <string>
109 
111 public:
112  struct FileOnPath_t {};
113  constexpr static FileOnPath_t FileOnPath{};
114 
115  static void load_services(std::string const& config);
116  static void load_services(std::string const& filename, FileOnPath_t);
117  static void load_services(std::istream& config);
118  static void load_services(fhicl::ParameterSet const& pset);
119 
120  // For backward compatibility.
121  static void load(std::string const& filename) { load_services(filename, FileOnPath_t{}); }
122 
123 private:
124  explicit ArtServiceHelper(fhicl::ParameterSet&& pset);
128 };
129 
130 #endif
std::string string
Definition: nybbler.cc:12
static constexpr FileOnPath_t FileOnPath
string filename
Definition: train.py:213
static void load_services(std::string const &config)
art::ActivityRegistry activityRegistry_
static void load(std::string const &filename)
static Config * config
Definition: config.cpp:1054
art::ServicesManager servicesManager_
ArtServiceHelper(fhicl::ParameterSet &&pset)
art::detail::SharedResources sharedResources_