All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StandaloneBasicSetup.h
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/StandaloneBasicSetup.h
3  * @brief Collection of functions for quick setup of basic facilities.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date June 22, 2017
6  *
7  * Currently the following functionality is provided:
8  * * configuration parsing (`ParseConfiguration()`)
9  * * message facility service setup (`SetupMessageFacility()`)
10  *
11  * A complete basic setup for `my test` may look like:
12  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
13  * using namespace lar::standalone;
14  *
15  * // parse the configuration file taken from the first command line argument:
16  * fhicl::ParameterSet pset = ParseConfiguration(argv[1]);
17  *
18  * // set up the message facility service
19  * SetupMessageFacility(pset, "my test");
20  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21  *
22  * Additional setup utilities may be available in `lar::standalone` namespace.
23  * Also, some service providers can be set up using `testing`setupProvider()`
24  * functions (the function itself is defined in `ProviderTestHelpers.h`).
25  *
26  * Currently this is a header-only library.
27  *
28  */
29 
30 #ifndef LARCOREALG_GEOMETRY_STANDALONEBASICSETUP_H
31 #define LARCOREALG_GEOMETRY_STANDALONEBASICSETUP_H
32 
33 // utility libraries
34 #include "messagefacility/MessageLogger/MessageLogger.h"
35 #include "fhiclcpp/ParameterSet.h"
36 #include "cetlib/filepath_maker.h" // cet::filepath_lookup_after1
37 
38 // C/C++ standard libraries
39 #include <string>
40 
41 
42 namespace lar {
43 
44  /// Utilities for use in an environment without _art_.
45  namespace standalone {
46 
47  //--------------------------------------------------------------------------
48  /**
49  * @brief Parses a FHiCL configuration file.
50  * @param configPath the path to the configuration file to be parsed
51  * @param lookupPolicy class performing the proper lookup for FHiCL files
52  * @return a parameter set containing the whole configuration from the file
53  *
54  * Some lookup policies are provided in cetlib (see
55  * `cetlib/filepath_maker.h` file).
56  */
57  fhicl::ParameterSet ParseConfiguration
58  (std::string configPath, cet::filepath_maker& lookupPolicy);
59 
60 
61  //--------------------------------------------------------------------------
62  /**
63  * @brief Parses a FHiCL configuration file.
64  * @param configPath the path to the configuration file to be parsed
65  * @return a parameter set containing the whole configuration from the file
66  *
67  * The lookup policy for finding the FHiCL files is such that:
68  * * `configPath` must be readily available: no special lookup is performed
69  * * FHiCL files included (directly or indirectly) by `configPath` are
70  * searched for in the path list specified in the environment variable
71  * `FHICL_FILE_PATH`
72  *
73  */
74  fhicl::ParameterSet ParseConfiguration(std::string configPath);
75 
76 
77  //--------------------------------------------------------------------------
78  /**
79  * @brief Sets up the message facility service.
80  * @param pset global configuration parameter set
81  * @param applName (default: `"standalone"`) name of running the application
82  *
83  * The configuration is read from the path `services.message` (as for the
84  * standard _art_ behaviour). Any configuration working in _art_ is expected
85  * to work here as well.
86  *
87  * Technical details:
88  * * "context singlet" is set to `main` (`mf::SetContextSinglet()`)
89  * * "context iteration" is set to empty (`mf::SetContextIteration()`)
90  */
92  (fhicl::ParameterSet const& pset, std::string applName = "standalone");
93 
94 
95  //--------------------------------------------------------------------------
96 
97  } // namespace standalone
98 } // namespace lar
99 
100 
101 //------------------------------------------------------------------------------
102 //--- inline implementation
103 //---
104 //------------------------------------------------------------------------------
105 inline fhicl::ParameterSet lar::standalone::ParseConfiguration
106  (std::string configPath, cet::filepath_maker& lookupPolicy)
107 {
108  fhicl::ParameterSet pset;
109  pset = fhicl::ParameterSet::make(configPath, lookupPolicy);
110  return pset;
111 } // ParseConfiguration(string, filepath_maker)
112 
113 
114 //------------------------------------------------------------------------------
115 inline fhicl::ParameterSet lar::standalone::ParseConfiguration
116  (std::string configPath)
117 {
118  cet::filepath_lookup_after1 policy("FHICL_FILE_PATH");
119  return ParseConfiguration(configPath, policy);
120 } // ParseConfiguration(string)
121 
122 
123 //------------------------------------------------------------------------------
125  (fhicl::ParameterSet const& pset, std::string applName /* = "standalone" */)
126 {
127  mf::StartMessageFacility(pset.get<fhicl::ParameterSet>("services.message"));
128  mf::SetApplicationName(applName);
129  mf::SetContextSinglet("main");
130  mf::SetContextIteration("");
131 } // lar::standalone::SetupMessageFacility()
132 
133 
134 //------------------------------------------------------------------------------
135 
136 #endif // LARCOREALG_GEOMETRY_STANDALONEBASICSETUP_H
void SetupMessageFacility(fhicl::ParameterSet const &pset, std::string applName="standalone")
Sets up the message facility service.
fhicl::ParameterSet ParseConfiguration(std::string configPath, cet::filepath_maker &lookupPolicy)
Parses a FHiCL configuration file.