PluginSuffixes.h
Go to the documentation of this file.
1 #ifndef art_Utilities_PluginSuffixes_h
2 #define art_Utilities_PluginSuffixes_h
3 
4 /*
5  'PluginSuffixes' is a static-member only class that contains all
6  supported plugins within art (proper).
7 
8  ===============
9  Developer notes
10  ===============
11 
12  This class was introduced to support the '--print-description' art
13  program option, which queries the list of supported plugin suffixes
14  for a given plugin spec as provided by the user. This way users can
15  type:
16 
17  art --print-description EmptyEvent TFileService IntProducer RPTest <MyTool>
18 
19  where
20 
21  EmptyEvent = source
22  TFileService = service
23  IntProducer = module
24  RPTest = plugin
25 
26  without having to tell the system what the expected type of each
27  specification is.
28 
29  Having a container that contains each of these plugin suffixes is
30  thus required. For type-safety reasons, the enum class
31  'suffix_type' is used as the map key.
32 
33  This class is an all-static member class. Wherever the
34  string-rendered suffix is required within art, it is desirable to do
35  something like 'Suffixes::module()'. This could be achieved,
36  clearly, by introducing a "Suffixes" namespace and just using free
37  functions. However, doing so would:
38 
39  1. Introduce potential confusion via a using directive, such as
40  'using namespace art::Suffixes'. A call to 'module()' could be
41  unclear to the developer.
42 
43  2. Require creating a free function that returns the full list of
44  allowed suffixes. Then for each
45 
46  'Suffixes::{module,service,source,plugin,tool,mfPlugin,mfStatsPlugin}()'
47 
48  free function call, the full-list function would be called each
49  time, which seems unnecessary.
50 */
51 
53 
54 #include <map>
55 #include <ostream>
56 #include <string>
57 #include <type_traits>
58 
59 namespace art {
60 
61  enum class suffix_type {
62  module,
63  plugin,
64  service,
65  source,
66  tool,
67  mfPlugin,
69  };
70 
71  inline std::ostream&
72  operator<<(std::ostream& os, suffix_type const st)
73  {
74  return os << static_cast<std::underlying_type_t<suffix_type>>(st);
75  }
76 
77  class Suffixes {
78  public:
79  static std::string const&
81  {
82  return suffixes_[suffix_type::module];
83  }
84  static std::string const&
86  {
87  return suffixes_[suffix_type::plugin];
88  }
89  static std::string const&
91  {
92  return suffixes_[suffix_type::service];
93  }
94  static std::string const&
96  {
97  return suffixes_[suffix_type::source];
98  }
99  static std::string const&
101  {
102  return suffixes_[suffix_type::tool];
103  }
104  static std::string const&
106  {
107  return suffixes_[suffix_type::mfPlugin];
108  }
109  static std::string const&
111  {
112  return suffixes_[suffix_type::mfStatsPlugin];
113  }
114 
115  static std::string const&
116  get(suffix_type st)
117  {
118  return suffixes_[st];
119  }
120 
121  static std::string
123  {
125  for (auto const& pr : suffixes_)
126  result += "\n '" + pr.second + "'";
127  return result;
128  }
129 
130  static suffix_type
131  get(std::string const& suffix)
132  {
133  auto it = rSuffixes_.find(suffix);
134  if (it == rSuffixes_.cend()) {
136  << " The suffix '" << suffix << "' is not supported.\n"
137  << " Please choose from:" << print();
138  }
139  return it->second;
140  }
141 
142  static std::map<suffix_type, std::string> const&
143  all()
144  {
145  return suffixes_;
146  }
147 
148  private:
149  static std::map<suffix_type, std::string> suffixes_;
150  static std::map<std::string, suffix_type> rSuffixes_;
151  };
152 }
153 
154 #endif /* art_Utilities_PluginSuffixes_h */
155 
156 // Local variables:
157 // mode: c++
158 // End:
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
static std::string const & mfStatsPlugin()
set< int >::iterator it
static std::map< suffix_type, std::string > const & all()
static std::string print()
static std::string const & source()
static std::map< suffix_type, std::string > suffixes_
static std::map< std::string, suffix_type > rSuffixes_
bool print
static std::string const & plugin()
static std::string const & tool()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
static std::string const & mfPlugin()
static std::string const & service()
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
static std::string const & module()
enum BeamMode string