ATLAS Offline Software
Loading...
Searching...
No Matches
BPhysMetaDataHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6//
11
12// Core include(s):
16
17#include <iostream>
18#include <utility>
19
20
21// Local include(s):
23
24namespace xAOD {
25 //-----------------------------------------------------------------------
27 : m_fm(fm), m_tmapOk(false) {
28
29 assert(m_fm != 0); // sanity check: m_fm must not be null
30 }
31 //-----------------------------------------------------------------------
33
34 return m_fm;
35 }
36 //-----------------------------------------------------------------------
37 void BPhysMetaDataHelper::setPrefix(std::string prefix) {
38
39 m_prefix = std::move(prefix);
40 }
41 //-----------------------------------------------------------------------
42 std::map<std::string, const std::type_info*>
44
45 if ( ! m_tmapOk ) cacheVarTypes();
46
47 return m_tmap;
48 }
49 //-----------------------------------------------------------------------
50 //
51 // Return complete metadata contents as TString
52 //
54
55 TString str = std::move(header);
56 std::map<std::string, std::string> ms = valuesS();
57 for ( auto it = ms.begin(); it != ms.end(); ++it ) {
58 str += Form("%-30s :S : %s\n", it->first.c_str(), it->second.c_str());
59 }
60 std::map<std::string, int> mi = valuesI();
61 for ( auto it = mi.begin(); it != mi.end(); ++it ) {
62 str += Form("%-30s :I : %d\n", it->first.c_str(), it->second);
63 }
64 std::map<std::string, float> mf = valuesF();
65 for ( auto it = mf.begin(); it != mf.end(); ++it ) {
66 str += Form("%-30s :F : %f\n", it->first.c_str(), it->second);
67 }
68 std::map<std::string, double> md = valuesD();
69 for ( auto it = md.begin(); it != md.end(); ++it ) {
70 str += Form("%-30s :D : %f\n", it->first.c_str(), it->second);
71 }
72 std::map<std::string, bool> mb = valuesB();
73 for ( auto it = mb.begin(); it != mb.end(); ++it ) {
74 str += Form("%-30s :B : %s\n", it->first.c_str(),
75 (it->second ? "True" : "False") );
76 }
77 std::map<std::string, std::vector<int> > mvi = valuesVI();
78 for ( auto it = mvi.begin(); it != mvi.end(); ++it ) {
79 TString strv;
80 for (auto &ent : it->second) {
81 strv += Form("%d,", ent);
82 }
83 strv.Remove(TString::kTrailing, ',');
84 str += Form("%-30s :VI: [%s]\n", it->first.c_str(), strv.Data());
85 }
86 std::map<std::string, std::vector<float> > mvf = valuesVF();
87 for ( auto it = mvf.begin(); it != mvf.end(); ++it ) {
88 TString strv;
89 for (auto &ent : it->second) {
90 strv += Form("%f,", ent);
91 }
92 strv.Remove(TString::kTrailing, ',');
93 str += Form("%-30s :VF: [%s]\n", it->first.c_str(), strv.Data());
94 }
95 std::map<std::string, std::vector<double> > mvd = valuesVD();
96 for ( auto it = mvd.begin(); it != mvd.end(); ++it ) {
97 TString strv;
98 for (auto &ent : it->second) {
99 strv += Form("%f,", ent);
100 }
101 strv.Remove(TString::kTrailing, ',');
102 str += Form("%-30s :VD: [%s]\n", it->first.c_str(), strv.Data());
103 }
104 std::map<std::string, std::vector<bool> > mvb = valuesVB();
105 for ( auto it = mvb.begin(); it != mvb.end(); ++it ) {
106 TString strv;
107 // vector<bool> needs special treatment
108 for (auto &&ent : it->second) {
109 strv += Form("%s,", ent ? "True" : "False");
110 }
111 strv.Remove(TString::kTrailing, ',');
112 str += Form("%-30s :VB: [%s]\n", it->first.c_str(), strv.Data());
113 }
114 std::map<std::string, std::vector<std::string> > mvs = valuesVS();
115 for ( auto it = mvs.begin(); it != mvs.end(); ++it ) {
116 TString strv;
117 for (auto &ent : it->second) {
118 strv += Form("%s,", ent.c_str());;
119 }
120 strv.Remove(TString::kTrailing, ',');
121 str += Form("%-30s :VS: [%s]\n", it->first.c_str(), strv.Data());
122 }
123 str.Remove(TString::kTrailing, '\n');
124
125 return str;
126 }
127 //-----------------------------------------------------------------------
129
130 // Get the variable types
131 const SG::auxid_set_t& auxids = m_fm->getAuxIDs();
132 for ( SG::auxid_t auxid : auxids ) {
134 m_tmap[reg.getName(auxid)] = reg.getType(auxid);
135 }
136 m_tmapOk = true;
137 }
138 //-----------------------------------------------------------------------
140
141 TString str = std::move(header);
142 if ( !m_tmapOk ) cacheVarTypes();
143 for (auto &ent : m_tmap) {
144 str += Form("%-30s : %s\n", ent.first.c_str(),
145 SG::normalizedTypeinfoName( *ent.second ).c_str());
146 }
147 str.Remove(TString::kTrailing, '\n');
148 return str;
149 }
150 //-----------------------------------------------------------------------
151 //
152 // Getter methods for different metadata types
153 //
154#define GET_VALUE_IMP( TYPE ) \
155 bool BPhysMetaDataHelper::value(const std::string& name, TYPE & val) \
156 const { \
157 xAOD::FileMetaData::Accessor< TYPE > acc( m_prefix + name ); \
158 if ( ! acc.isAvailable( *m_fm ) ) { \
159 return false; \
160 } else { \
161 val = acc( *m_fm ); \
162 return true; \
163 } \
164 }
165
166 GET_VALUE_IMP( int )
167 GET_VALUE_IMP( float )
168 GET_VALUE_IMP( double )
169 GET_VALUE_IMP( bool )
170 GET_VALUE_IMP( std::string )
171 GET_VALUE_IMP( std::vector<int> )
172 GET_VALUE_IMP( std::vector<float> )
173 GET_VALUE_IMP( std::vector<double> )
174 GET_VALUE_IMP( std::vector<bool> )
175 GET_VALUE_IMP( std::vector<std::string> )
176
177#undef GET_VALUE_IMP
178 //-----------------------------------------------------------------------
179 //
180 // Getter methods for maps of different metadata types
181 //
182#define GET_VALUES_IMP( SYMBOL, TYPE ) \
183 std::map<std::string, TYPE> BPhysMetaDataHelper::values ## SYMBOL() const { \
184 std::map<std::string, TYPE > metaMap; \
185 const SG::auxid_set_t& auxids = m_fm->getAuxIDs(); \
186 for ( SG::auxid_t auxid : auxids ) { \
187 SG::AuxTypeRegistry& reg = SG::AuxTypeRegistry::instance(); \
188 const std::type_info* ti = reg.getType( auxid ); \
189 if ( ti != NULL && *ti == typeid( TYPE ) ) { \
190 SG::ConstAccessor< TYPE > acc( auxid ); \
191 const std::string name = reg.getName( auxid ); \
192 metaMap[name] = acc( *m_fm ); \
193 } \
194 } \
195 return metaMap; \
196 }
197
198 GET_VALUES_IMP( I , int )
199 GET_VALUES_IMP( F , float )
200 GET_VALUES_IMP( D , double )
201 GET_VALUES_IMP( B , bool )
202 GET_VALUES_IMP( S , std::string )
203 GET_VALUES_IMP( VI, std::vector<int> )
204 GET_VALUES_IMP( VF, std::vector<float> )
205 GET_VALUES_IMP( VD, std::vector<double> )
206 GET_VALUES_IMP( VB, std::vector<bool> )
207 GET_VALUES_IMP( VS, std::vector<std::string> )
208
209#undef GET_VALUES_IMP
210 //-----------------------------------------------------------------------
211
212} // namespace xAOD
Handle mappings between names and auxid_t.
#define GET_VALUES_IMP(SYMBOL, TYPE)
#define GET_VALUE_IMP(TYPE)
B-physcis FileMetaData helpers.
Helper class to provide constant type-safe access to aux data.
#define F(x, y, z)
Definition MD5.cxx:112
#define I(x, y, z)
Definition MD5.cxx:116
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
A set of aux data identifiers.
Definition AuxTypes.h:47
std::map< std::string, std::string > valuesS() const
std::map< std::string, double > valuesD() const
std::map< std::string, const std::type_info * > m_tmap
map of metadata names and variable types
void setPrefix(std::string prefix)
Set prefix for variable names.
TString metaDataToString(TString header="") const
Complete metadata contents as TString.
TString varTypesToString(TString header="") const
List of metadata names and types as string.
std::map< std::string, std::vector< bool > > valuesVB() const
std::map< std::string, const std::type_info * > varTypes() const
Map of metadata names and types.
std::map< std::string, bool > valuesB() const
void cacheVarTypes() const
Updating internal variable-to-variable-type cache.
BPhysMetaDataHelper(const xAOD::FileMetaData *fm)
Main constructor.
std::map< std::string, std::vector< std::string > > valuesVS() const
std::map< std::string, float > valuesF() const
std::map< std::string, int > valuesI() const
std::map< std::string, std::vector< int > > valuesVI() const
const xAOD::FileMetaData * m_fm
FileMetaData object pointer.
std::map< std::string, std::vector< float > > valuesVF() const
std::string m_prefix
Prefix for variable names.
bool m_tmapOk
flag indicating an up-to-date cache
const xAOD::FileMetaData * metaObj() const
Getter method for the cached xAOD::FileMetaData object.
std::map< std::string, std::vector< double > > valuesVD() const
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
FileMetaData_v1 FileMetaData
Declare the latest version of the class.
Convert a type_info to a normalized string representation (matching the names used in the root dictio...