Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/Control/Walker/CmdLine/CmdLine.hpp
4 : : \copyright 2012-2015 J. Bakosi,
5 : : 2016-2018 Los Alamos National Security, LLC.,
6 : : 2019-2021 Triad National Security, LLC.
7 : : All rights reserved. See the LICENSE file for details.
8 : : \brief Walker's command line
9 : : \details Walker's command line
10 : : */
11 : : // *****************************************************************************
12 : : #ifndef WalkerCmdLine_h
13 : : #define WalkerCmdLine_h
14 : :
15 : : #include <string>
16 : :
17 : : #include <brigand/algorithms/for_each.hpp>
18 : :
19 : : #include "QuinoaConfig.hpp"
20 : : #include "TaggedTuple.hpp"
21 : : #include "HelpFactory.hpp"
22 : : #include "Keywords.hpp"
23 : : #include "Walker/Types.hpp"
24 : :
25 : : namespace walker {
26 : : //! Walker control facilitating user input to internal data transfer
27 : : namespace ctr {
28 : :
29 : : //! Member data for tagged tuple
30 : : using CmdLineMembers = brigand::list<
31 : : tag::io, ios
32 : : , tag::virtualization, kw::virtualization::info::expect::type
33 : : , tag::verbose, bool
34 : : , tag::chare, bool
35 : : , tag::help, bool
36 : : , tag::helpctr, bool
37 : : , tag::quiescence, bool
38 : : , tag::trace, bool
39 : : , tag::version, bool
40 : : , tag::license, bool
41 : : , tag::cmdinfo, tk::ctr::HelpFactory
42 : : , tag::ctrinfo, tk::ctr::HelpFactory
43 : : , tag::helpkw, tk::ctr::HelpKw
44 : : , tag::error, std::vector< std::string >
45 : : >;
46 : :
47 : : //! CmdLine : Control< specialized to Walker >, see Types.h
48 : 0 : class CmdLine : public tk::TaggedTuple< CmdLineMembers > {
49 : :
50 : : public:
51 : : //! Walker command-line keywords
52 : : using keywords = tk::cmd_keywords< kw::verbose
53 : : , kw::charestate
54 : : , kw::virtualization
55 : : , kw::help
56 : : , kw::helpctr
57 : : , kw::helpkw
58 : : , kw::control
59 : : , kw::screen
60 : : , kw::pdf
61 : : , kw::stat
62 : : , kw::particles
63 : : , kw::quiescence
64 : : , kw::trace
65 : : , kw::version
66 : : , kw::license
67 : : >;
68 : :
69 : : //! Set of tags to ignore when printing this CmdLine
70 : : //! \note It would be misleading to print the data behind 'pdfnames' with
71 : : //! the command line object, since only InputDeck parser populates this
72 : : //! (after the CmdLine parser) into its copy of CmdLine.
73 : : using ignore =
74 : : brigand::set< tag::cmdinfo
75 : : , tag::ctrinfo
76 : : , tag::helpkw
77 : : , tag::pdfnames >; // printed with InputDeck instead
78 : :
79 : : //! \brief Constructor: set all defaults.
80 : : //! \param[in] ctrinfo std::map of control file keywords and their info
81 : : //! \details Anything not set here is initialized by the compiler using the
82 : : //! default constructor for the corresponding type. The ctrinfo map
83 : : //! argument is optional. If not given, it is an empty std::map
84 : : //! constructed in-place and affects nothing. If given, it contains the
85 : : //! control file keywords, all of which are moved into the relevant slot
86 : : //! (tag::ctrinfo). This allows constructing, e.g., a CmdLine object both
87 : : //! with and without this information in place, which are both used at
88 : : //! different stages of the execution. For example, because the
89 : : //! command-line is parsed very early on during runtime while the input
90 : : //! deck is only parsed much later, the control-file keywords and their
91 : : //! information (owned by and generated by the input deck and its
92 : : //! constructor) is not yet available when the CmdLine object is
93 : : //! constructed. However, during command-line parsing it is still possible
94 : : //! to request information on a control file keyword, so it must be
95 : : //! available. The input deck is where all parsed information goes during
96 : : //! control file parsing and is stored at global scope, see, e.g.,
97 : : //! walker::g_inputdeck. This global-scope (still namespace-scope), input
98 : : //! deck object is thus created before command-line parsing. The input
99 : : //! deck object's constructor (working only on type information, available
100 : : //! at compile-time, of all the control file keywords) creates a run-time
101 : : //! map. This is a run-time map, but available before main() starts,
102 : : //! because it is const and it is initialized as a global-scope map. This
103 : : //! map is then passed in here as ctrinfo, and its contents inserted into
104 : : //! the CmdLine object, making the control-file keywords and their info
105 : : //! available during command-line parsing. Since the input deck stack
106 : : //! contains a copy of the command-line stack, the command-line stack must
107 : : //! be possible to be instantiated without passing the ctrinfo map,
108 : : //! otherwise it would be a mutual dependency.
109 : : // cppcheck-suppress noExplicitConstructor
110 : 1218 : CmdLine( tk::ctr::HelpFactory ctrinfo = tk::ctr::HelpFactory() ) {
111 : : get< tag::io, tag::screen >() =
112 [ + - ][ + - ]: 2436 : tk::baselogname( tk::walker_executable() );
[ - + ][ + - ]
113 : : get< tag::io, tag::output >() = "out";
114 : : get< tag::io, tag::pdf >() = "pdf";
115 : : get< tag::io, tag::stat >() = "stat.txt";
116 : : get< tag::io, tag::particles >() = "particles.h5part";
117 : 1218 : get< tag::virtualization >() = 0.0;
118 : 1218 : get< tag::verbose >() = false; // Quiet output by default
119 : 1218 : get< tag::chare >() = false; // No chare state output by default
120 : 1218 : get< tag::trace >() = true; // Output call and stack trace by default
121 : 1218 : get< tag::version >() = false; // Do not display version info by default
122 [ + - ]: 1218 : get< tag::license >() = false; // Do not display license info by default
123 : : // Initialize help: fill from own keywords + add map passed in
124 : 1218 : brigand::for_each< keywords::set >( tk::ctr::Info(get<tag::cmdinfo>()) );
125 : : get< tag::ctrinfo >() = std::move( ctrinfo );
126 : 1218 : }
127 : :
128 : : /** @name Pack/Unpack: Serialize CmdLine object for Charm++ */
129 : : ///@{
130 : : //! \brief Pack/Unpack serialize member function
131 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
132 : : void pup( PUP::er& p ) { tk::TaggedTuple< CmdLineMembers >::pup(p); }
133 : : //! \brief Pack/Unpack serialize operator|
134 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
135 : : //! \param[in,out] c CmdLine object reference
136 : : friend void operator|( PUP::er& p, CmdLine& c ) { c.pup(p); }
137 : : //@}
138 : :
139 : : //! Compute and return log file name
140 : : //! \param[in] def Default log file name (so we don't mess with user's)
141 : : //! \param[in] nrestart Number of times restarted
142 : : //! \return Log file name
143 [ - + ]: 2010 : std::string logname( const std::string& def, int nrestart ) const {
144 [ - + ]: 2010 : if (get< tag::io, tag::screen >() != def)
145 : : return get< tag::io, tag::screen >();
146 : : else
147 [ + - ]: 4020 : return tk::logname( tk::walker_executable(), nrestart );
148 : : }
149 : : };
150 : :
151 : : } // ctr::
152 : : } // walker::
153 : :
154 : : #endif // WalkerCmdLine_h
|