18#include "boost/algorithm/string/trim.hpp"
19#include "boost/algorithm/string/split.hpp"
37 const std::string& the_docstring,
38 const std::vector<std::string>& the_labels,
39 const std::vector<std::string>& the_label_classes,
40 const std::string& the_defstring,
49 std::string firstName;
52 assert (the_labels.size() == the_label_classes.size());
53 for (
size_t i = 0; i < the_labels.size(); i++) {
54 SG::auxid_t auxid = reg.findAuxID (the_labels[i], the_label_classes[i]);
56 accessors.emplace_back (the_labels[i], the_label_classes[i]);
58 std::string
name = the_label_classes[i] +
"::" + the_labels[i];
65 ti = reg.getType (auxid);
66 type.init (reg.getTypeName (auxid));
67 firstName = std::move(
name);
71 if (
ti != reg.getType (auxid)) {
72 std::string errstr =
"Inconsistent types for aux data: " +
73 firstName +
" (" + reg.getTypeName (firstId) +
") vs " +
74 name +
" (" + reg.getTypeName (auxid) +
")";
75 throw std::runtime_error (errstr);
81 if (the_has_default && !the_defstring.empty()) {
111 const std::string& name,
112 const IInterface* parent)
116 "Prefix to add to aux data names.");
119 "Specify variables to fill. "
120 "Each is of the form VAR[=AUXVAR][<DEF][#DOCSTRING].\n"
121 "VAR is the D3PD variable name. "
122 "AUXVAR is the aux data item name. It may contain a class "
123 "name before a ::. If omitted, it defaults to VAR. "
124 "It may also be a comma-separated string of variable "
125 "names; the first one found to be present will be used. "
126 "If the < is present, then it is not an error for this "
127 "variable to be missing. If not empty, DEF specifies the "
128 "default value to use (works only for basic types). "
129 "DEF may be preceded with a type name: `TYPE: DEF' to "
130 "specify a type in the case the type of this aux variable "
132 "An optional documentation string may be given after a #.");
152 std::string docstring =
"[AuxData: ";
153 docstring += v->label;
155 docstring += v->docstring;
158 return StatusCode::SUCCESS;
173 const void*
aux = v->access(p);
175 v->type.assign (v->ptr,
aux);
176 else if (!v->has_default) {
182 return StatusCode::SUCCESS;
192 std::string docstring;
193 std::string::size_type ipos = name.find (
'#');
194 if (ipos != std::string::npos) {
195 docstring = name.substr (ipos+1, std::string::npos);
199 std::string defstring;
200 bool has_default =
false;
201 ipos = name.find (
'<');
202 if (ipos != std::string::npos) {
203 defstring = name.substr (ipos+1, std::string::npos);
204 name.erase (ipos, std::string::npos);
208 std::string
label = name;
209 ipos = name.find (
'=');
210 if (ipos != std::string::npos) {
211 name.erase (ipos, std::string::npos);
212 label.erase (0, ipos+1);
215 std::vector<std::string> labels;
216 boost::algorithm::split (labels,
label, boost::algorithm::is_any_of(
","));
217 std::vector<std::string> label_classes;
218 for (std::string& l : labels) {
219 std::string label_class;
220 ipos = l.find (
"::");
221 if (ipos != std::string::npos) {
222 label_class = l.substr (0, ipos);
225 boost::algorithm::trim (l);
227 boost::algorithm::trim (label_class);
228 label_classes.push_back (std::move(label_class));
231 boost::algorithm::trim (name);
232 boost::algorithm::trim (docstring);
233 boost::algorithm::trim (defstring);
237 if (!defstring.empty()) {
238 ipos = defstring.find (
':');
239 if (ipos != std::string::npos) {
240 std::string typname = defstring.substr (0, ipos);
241 boost::algorithm::trim (typname);
242 defstring.erase (0, ipos+1);
248 for (
size_t i = 0; i < labels.size(); i++){
249 auto auxid = reg.getAuxID (*ti, labels[i], label_classes[i]);
252 <<
"AuxDataFillerTool::parseVars: auxid is invalid for "<<labels[i]<<
"\n";
260 m_vars.push_back (std::make_unique<Var>
261 (name, docstring, labels, label_classes,
262 defstring, has_default));
264 catch (
const std::runtime_error& e) {
266 <<
"Can't find aux data item(s) " <<
label
267 <<
" [" << e.what() <<
"]";
268 return StatusCode::FAILURE;
271 if (
m_vars.back()->accessors.empty()) {
273 <<
"Can't find aux data item(s) " <<
label;
274 return StatusCode::FAILURE;
277 return StatusCode::SUCCESS;
Base class for elements of a container that can have aux data.
Handle mappings between names and auxid_t.
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
virtual StatusCode addVariable(const std::string &name, const std::type_info &ti, void *&ptr, const std::string &docstring="", const void *defval=0)
const std::type_info * getTypeInfo() const
Return the type_info for the described type.
Base class for elements of a container that can have aux data.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
std::string label(const std::string &format, int i)
Block filler tool for noisy FEB information.
static const auxid_t null_auxid
To signal no aux data item.
size_t auxid_t
Identifier for a particular aux data item.