@@ -2016,25 +2016,19 @@ concept persistent_with_common_getter = is_persistent_v<T> && requires(T t) {
20162016template <typename R, typename T, persistent_with_common_getter<R> C>
20172017ColumnGetterFunction<R, T> createGetterPtr (const std::string_view& columnLabel)
20182018{
2019- const size_t n = columnLabel.size ();
2020-
2021- if (n == 0 || n != strlen (C::columnLabel ())) {
2022- return nullptr ;
2023- }
2024-
2025- return (std::strcmp (columnLabel.data (), C::columnLabel ())) ? nullptr : &getColumnValue<R, T, C>;
2019+ return std::strncmp (columnLabel.data (), C::columnLabel (), columnLabel.size ()) ? nullptr : &getColumnValue<R, T, C>;
20262020}
20272021
20282022template <typename R, typename T, dynamic_with_common_getter<R> C>
20292023ColumnGetterFunction<R, T> createGetterPtr (const std::string_view& columnLabel)
20302024{
2031- const size_t n = columnLabel.size ();
2025+ // allows user to use consistent formatting (with prefix) of all column labels
2026+ // by default there isn't 'f' prefix for dynamic column labels, strncmp(x,y,0) is always 0
2027+ bool isPrefixMatch = columnLabel.size () > 1 && !std::strncmp (columnLabel.substr (1 ).data (), C::columnLabel (), columnLabel.size () - 1 );
2028+ // check also exact match if user is aware of prefix missing
2029+ bool isExactMatch = !std::strncmp (columnLabel.data (), C::columnLabel (), columnLabel.size ());
20322030
2033- if (n == 0 || (n != strlen (C::columnLabel ()) && n - 1 != strlen (C::columnLabel ()))) {
2034- return nullptr ;
2035- }
2036-
2037- return ((std::strcmp (&columnLabel[1 ], C::columnLabel ()) && std::strcmp (columnLabel.data (), C::columnLabel ()))) ? nullptr : &getColumnValue<R, T, C>;
2031+ return (isPrefixMatch || isExactMatch) ? &getColumnValue<R, T, C> : nullptr ;
20382032}
20392033
20402034template <typename R, typename T, typename ... Cs>
@@ -2045,7 +2039,7 @@ ColumnGetterFunction<R, T> getColumnGetterByLabel(o2::framework::pack<Cs...>, co
20452039 (void )((func = createGetterPtr<R, T, Cs>(columnLabel), func) || ...);
20462040
20472041 if (!func) {
2048- throw framework::runtime_error (" Getter for provided columnLabel not found! " );
2042+ throw framework::runtime_error_f (" Getter for \" %s \" not found" , columnLabel );
20492043 }
20502044
20512045 return func;
@@ -2059,6 +2053,10 @@ ColumnGetterFunction<R, typename T::iterator> getColumnGetterByLabel(const std::
20592053{
20602054 using TypesWithCommonGetter = o2::framework::selected_pack_multicondition<with_common_getter_t , framework::pack<R>, typename T::columns>;
20612055
2056+ if (columnLabel.size () == 0 ) {
2057+ throw framework::runtime_error (" columnLabel: must not be empty" );
2058+ }
2059+
20622060 return getColumnGetterByLabel<R, typename T::iterator>(TypesWithCommonGetter{}, columnLabel);
20632061}
20642062} // namespace row_helpers
0 commit comments