Skip to content

Commit 19e9530

Browse files
authored
Add new 'append' and 'extend' strategies (#530)
1 parent 37f164e commit 19e9530

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

source/framework/core/src/TRestDataSet.cxx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@
228228
/// not exactly the same, then a warning output message will be prompted.
229229
/// - **last**: It will simply register the value of the metadata member
230230
/// from the last file in the list of selected files.
231+
/// - **append**: It will append the metadata member value to the previous
232+
/// value. The user can specify the appender string after the `append`
233+
/// keyword. If no appender is given, then an empty string will be used.
234+
/// It will check if the value is already in the string and not append it
235+
/// if it is. Use _extend_ if you want to force the append.
236+
/// - **extend**: same as _append_ but it will not check if the value is
237+
/// already in the string.
231238
///
232239
/// ### Adding a new column based on relevant quantities
233240
///
@@ -513,6 +520,26 @@ std::vector<std::string> TRestDataSet::FileSelection() {
513520
}
514521

515522
if (properties.strategy == "last") properties.value = value;
523+
524+
if (properties.strategy.find("append") != std::string::npos) {
525+
// Get appender from "append" til the end of string. E.g. "append," -> "," or "append" -> ""
526+
std::string appender = properties.strategy.substr(properties.strategy.find("append") + 6);
527+
if (properties.value.empty())
528+
properties.value = value;
529+
else
530+
// do not append if value already contains the value to append
531+
if (properties.value.find(value) == std::string::npos)
532+
properties.value += appender + value;
533+
}
534+
535+
if (properties.strategy.find("extend") != std::string::npos) {
536+
// Get appender from "extend" til the end of string. E.g. "extend," -> "," or "extend" -> ""
537+
std::string appender = properties.strategy.substr(properties.strategy.find("extend") + 6);
538+
if (properties.value.empty())
539+
properties.value = value;
540+
else
541+
properties.value += appender + value;
542+
}
516543
}
517544

518545
if (run.GetStartTimestamp() < fStartTime) fStartTime = run.GetStartTimestamp();

0 commit comments

Comments
 (0)