ATLAS Offline Software
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 //
12 // Core include(s):
16 
17 #include <iostream>
18 #include <utility>
19 
20 
21 // Local include(s):
23 
24 namespace 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  //-----------------------------------------------------------------------
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
xAOD::BPhysMetaDataHelper::valuesVS
std::map< std::string, std::vector< std::string > > valuesVS() const
xAOD::BPhysMetaDataHelper::m_fm
const xAOD::FileMetaData * m_fm
FileMetaData object pointer.
Definition: BPhysMetaDataHelper.h:144
header
Definition: hcg.cxx:526
xAOD::BPhysMetaDataHelper::m_prefix
std::string m_prefix
Prefix for variable names.
Definition: BPhysMetaDataHelper.h:147
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
xAOD::BPhysMetaDataHelper::BPhysMetaDataHelper
BPhysMetaDataHelper(const xAOD::FileMetaData *fm)
Main constructor.
Definition: BPhysMetaDataHelper.cxx:26
SG::normalizedTypeinfoName
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...
Definition: normalizedTypeinfoName.cxx:120
xAOD::BPhysMetaDataHelper::valuesS
std::map< std::string, std::string > valuesS() const
skel.it
it
Definition: skel.GENtoEVGEN.py:423
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::BPhysMetaDataHelper::varTypes
std::map< std::string, const std::type_info * > varTypes() const
Map of metadata names and types.
Definition: BPhysMetaDataHelper.cxx:43
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
xAOD::BPhysMetaDataHelper::valuesVB
std::map< std::string, std::vector< bool > > valuesVB() const
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
xAOD::BPhysMetaDataHelper::cacheVarTypes
void cacheVarTypes() const
Updating internal variable-to-variable-type cache.
Definition: BPhysMetaDataHelper.cxx:128
DQPostProcessTest.mf
mf
Definition: DQPostProcessTest.py:19
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
xAOD::BPhysMetaDataHelper::valuesVD
std::map< std::string, std::vector< double > > valuesVD() const
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
xAOD::BPhysMetaDataHelper::valuesF
std::map< std::string, float > valuesF() const
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
SG::AuxElement::getAuxIDs
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.
Definition: AuxElement.cxx:335
xAOD::str
std::string str(const TrigT2MbtsBits_v1 &trigT2MbtsBits)
Definition: TrigT2MbtsBits_v1.cxx:37
BPhysMetaDataHelper.h
B-physcis FileMetaData helpers.
xAOD::FileMetaData_v1
Class holding file-level metadata about an xAOD file.
Definition: FileMetaData_v1.h:34
normalizedTypeinfoName.h
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
xAOD::BPhysMetaDataHelper::valuesI
std::map< std::string, int > valuesI() const
xAOD::BPhysMetaDataHelper::m_tmap
std::map< std::string, const std::type_info * > m_tmap
map of metadata names and variable types
Definition: BPhysMetaDataHelper.h:153
xAOD::BPhysMetaDataHelper::valuesVF
std::map< std::string, std::vector< float > > valuesVF() const
xAOD::BPhysMetaDataHelper::varTypesToString
TString varTypesToString(TString header="") const
List of metadata names and types as string.
Definition: BPhysMetaDataHelper.cxx:139
xAOD::BPhysMetaDataHelper::m_tmapOk
bool m_tmapOk
flag indicating an up-to-date cache
Definition: BPhysMetaDataHelper.h:155
TRT_PAI_physicsConstants::mb
const double mb
1mb to cm2
Definition: TRT_PAI_physicsConstants.h:15
xAOD::BPhysMetaDataHelper::metaObj
const xAOD::FileMetaData * metaObj() const
Getter method for the cached xAOD::FileMetaData object.
Definition: BPhysMetaDataHelper.cxx:32
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
xAOD::BPhysMetaDataHelper::valuesVI
std::map< std::string, std::vector< int > > valuesVI() const
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
str
Definition: BTagTrackIpAccessor.cxx:11
xAOD::BPhysMetaDataHelper::metaDataToString
TString metaDataToString(TString header="") const
Complete metadata contents as TString.
Definition: BPhysMetaDataHelper.cxx:53
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
xAOD::BPhysMetaDataHelper::setPrefix
void setPrefix(std::string prefix)
Set prefix for variable names.
Definition: BPhysMetaDataHelper.cxx:37
xAOD::BPhysMetaDataHelper::valuesB
std::map< std::string, bool > valuesB() const
xAOD::BPhysMetaDataHelper::valuesD
std::map< std::string, double > valuesD() const
GET_VALUES_IMP
#define GET_VALUES_IMP(SYMBOL, TYPE)
Definition: BPhysMetaDataHelper.cxx:182
GET_VALUE_IMP
#define GET_VALUE_IMP(TYPE)
Definition: BPhysMetaDataHelper.cxx:154