ATLAS Offline Software
RootAuxDynDefs.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef ROOTAUXDYN_DEFS_H
5 #define ROOTAUXDYN_DEFS_H
6 
7 #include <format>
8 
9 namespace RootAuxDynIO
10 {
12  constexpr char AUX_POSTFIX[] = "Aux.";
13  constexpr size_t AUX_POSTFIX_LEN = sizeof(AUX_POSTFIX)-1;
14  constexpr char AUXDYN_POSTFIX[] = "Dyn.";
15  constexpr size_t AUXDYN_POSTFIX_LEN = sizeof(AUXDYN_POSTFIX)-1;
16 
21  inline bool endsWithAuxPostfix(std::string_view str) {
22  return str.ends_with(AUX_POSTFIX);
23  }
24 
29  bool removeAuxPostfix(std::string& str);
30 
36  std::string auxBranchName(const std::string& attr_name, const std::string& baseBranchName);
37 
43  std::string auxFieldName(const std::string& attr_name, const std::string& baseName);
44 
45 } // namespace
46 
47 
48 inline bool
50 {
51  if( endsWithAuxPostfix(str) ) {
52  str.resize( str.size() - AUX_POSTFIX_LEN );
53  return true;
54  }
55  return false;
56 }
57 
58 
59 inline std::string
60 RootAuxDynIO::auxBranchName(const std::string& attr_name, const std::string& baseBranchName)
61 {
62  std::string branch_name = baseBranchName;
63  if( !branch_name.empty() and branch_name.back() == '.' ) branch_name.pop_back();
64  branch_name += RootAuxDynIO::AUXDYN_POSTFIX + attr_name;
65  return branch_name;
66 }
67 
68 inline std::string
69 RootAuxDynIO::auxFieldName(const std::string& attr_name, const std::string& baseName)
70 {
71  // RNTuple field names cannot contain dot characters '.'
72  // Therefore, for now, we're using a colon instead ':'
73  // This can be changed in the future
74  std::string field_name = baseName;
75  if (field_name.ends_with(':')) {
76  field_name.pop_back();
77  }
78  field_name = std::format("{}Dyn:{}", field_name, attr_name);
79  return field_name;
80 }
81 
82 #endif
RootAuxDynIO::AUX_POSTFIX
constexpr char AUX_POSTFIX[]
Common post-fix for the names of auxiliary containers in StoreGate.
Definition: RootAuxDynDefs.h:12
vtune_athena.format
format
Definition: vtune_athena.py:14
RootAuxDynIO::AUXDYN_POSTFIX
constexpr char AUXDYN_POSTFIX[]
Definition: RootAuxDynDefs.h:14
RootAuxDynIO::removeAuxPostfix
bool removeAuxPostfix(std::string &str)
if a string ends with AUX_POSTFIX then remove it
Definition: RootAuxDynDefs.h:49
RootAuxDynIO::auxBranchName
std::string auxBranchName(const std::string &attr_name, const std::string &baseBranchName)
Construct branch name for a given dynamic attribute.
Definition: RootAuxDynDefs.h:60
collListGuids.attr_name
attr_name
Definition: collListGuids.py:72
RootAuxDynIO::auxFieldName
std::string auxFieldName(const std::string &attr_name, const std::string &baseName)
Construct field name for a given dynamic attribute.
Definition: RootAuxDynDefs.h:69
RootAuxDynIO::endsWithAuxPostfix
bool endsWithAuxPostfix(std::string_view str)
Check if a string ends with AUX_POSTFIX.
Definition: RootAuxDynDefs.h:21
RootAuxDynIO
Specialization of RootAuxDynStore for reading Aux Dynamic attributes from RNTuple.
Definition: RNTupleContainer.h:25
RootAuxDynIO::AUXDYN_POSTFIX_LEN
constexpr size_t AUXDYN_POSTFIX_LEN
Definition: RootAuxDynDefs.h:15
str
Definition: BTagTrackIpAccessor.cxx:11
RootAuxDynIO::AUX_POSTFIX_LEN
constexpr size_t AUX_POSTFIX_LEN
Definition: RootAuxDynDefs.h:13