ATLAS Offline Software
Control/AthContainers/Root/debug.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
13 #include "AthContainers/debug.h"
17 #include "CxxUtils/StrFormat.h"
18 #include <vector>
19 #include <sstream>
20 #include <iostream>
21 
22 
23 namespace SGdebug {
24 
25 
30 std::string aux_var_name (SG::auxid_t id)
31 {
33  return reg.getClassName(id) + "::" + reg.getName(id);
34 }
35 
36 
42 {
43  std::cout << aux_var_name(id) << "\n";
44 }
45 
46 
47 /******************************************************************************
48  * Print the list of aux variables given some object.
49  */
50 
51 
56 void print_aux_vars (const SG::auxid_set_t& auxids)
57 {
59  std::vector<SG::auxid_t> ids (auxids.begin(), auxids.end());
60  std::sort (ids.begin(), ids.end());
61 
62  for (SG::auxid_t id : ids) {
63  std::cout << id << " "
64  << reg.getClassName(id) << "::" << reg.getName(id) << " "
65  << "[" << reg.getTypeName(id);
66 
67  SG::AuxVarFlags flags = reg.getFlags(id);
69  std::cout << " (atomic)";
70  }
71 
72  std::cout << "]\n";
73  }
74 }
75 
76 
82 {
83  print_aux_vars (store.getAuxIDs());
84 }
85 
86 
92 {
94 }
95 
96 
102 {
103  print_aux_vars (vec.getAuxIDs());
104 }
105 
106 
112 {
113  print_aux_vars (*vec);
114 }
115 
116 
122 {
123  print_aux_vars (elt.getAuxIDs());
124 }
125 
126 
132 {
133  print_aux_vars (*elt);
134 }
135 
136 
137 /******************************************************************************
138  * Dump out aux variables.
139  */
140 
141 
142 namespace {
143 
144 
145 template <class T>
146 void convert (std::ostream& os, const T& x)
147 {
148  os << x;
149 }
150 
151 
152 void convert (std::ostream& os, const float x)
153 {
154  os << CxxUtils::strformat ("%.3f", x);
155 }
156 
157 
158 void convert (std::ostream& os, const double x)
159 {
160  os << CxxUtils::strformat ("%.3f", x);
161 }
162 
163 
164 template <class T>
165 void convert (std::ostream& os, const std::vector<T>& x)
166 {
167  os << "[";
168  bool first = true;
169  // using `decltype(auto)` in case T=bool
170  // cppcheck-suppress internalAstError
171  for (decltype(auto) elt : x) {
172  if (first)
173  first = false;
174  else
175  os << ", ";
176  convert (os, elt);
177  }
178  os << "]";
179 }
180 
181 
182 struct AuxVarSort
183 {
184  AuxVarSort (SG::auxid_t the_id)
185  : id(the_id),
186  name(aux_var_name(the_id))
187  {}
188 
189  SG::auxid_t id;
190  std::string name;
191 };
192 
193 
194 bool operator< (const AuxVarSort& a, const AuxVarSort& b )
195 {
196  return a.name < b.name;
197 }
198 
199 
200 } // anonymous namespace
201 
202 
208 std::string aux_var_as_string (SG::auxid_t auxid, const void* p)
209 {
210  std::ostringstream os;
211 
213  const std::type_info* ti = r.getType(auxid);
214 #define CONVERT(T) if (ti == &typeid(T)) convert (os, *reinterpret_cast<const T*>(p)); else
215 #define CONVERT1(T) CONVERT(T) CONVERT(std::vector<T>)
216  CONVERT1 (int)
217  CONVERT1 (unsigned int)
218  CONVERT1 (short)
219  CONVERT1 (unsigned short)
220  CONVERT1 (char)
221  CONVERT1 (unsigned char)
222  CONVERT1 (long)
223  CONVERT1 (unsigned long)
224  CONVERT1 (long long)
225  CONVERT1 (unsigned long long)
226  CONVERT1 (float)
227  CONVERT1 (double)
228  CONVERT1 (bool)
229  CONVERT1 (std::string)
230  //else
231  os << "<??? " << AthContainers_detail::typeinfoName(*ti) << ">";
232  return os.str();
233 }
234 
235 
242 {
243  if (i >= store.size()) return;
245  const SG::auxid_set_t& ids = store.getAuxIDs();
246  std::vector<AuxVarSort> vars (ids.begin(), ids.end());
247  std::sort (vars.begin(), vars.end());
248  for (const AuxVarSort& v : vars) {
249  const void* pbeg = store.getData (v.id);
250  size_t eltsz = reg.getEltSize (v.id);
251  const char* p = reinterpret_cast<const char*>(pbeg) + eltsz*i;
252  std::cout << v.name << " " << aux_var_as_string (v.id, p) << "\n";
253  }
254 }
255 
256 
263 {
264  dump_aux_vars (*store, i);
265 }
266 
267 
273 {
274  size_t sz = store.size();
275  for (size_t i = 0; i < sz; i++) {
276  std::cout << "=== Element " << i << "\n";
277  dump_aux_vars (store, i);
278  }
279 }
280 
281 
287 {
288  dump_aux_vars (*store);
289 }
290 
291 
297 void dump_aux_vars (const SG::AuxVectorData& vec, size_t i)
298 {
299  const SG::IConstAuxStore* store = vec.getConstStore();
300  if (store)
301  dump_aux_vars (*store, i);
302 }
303 
304 
310 void dump_aux_vars (const SG::AuxVectorData* vec, size_t i)
311 {
312  dump_aux_vars (*vec, i);
313 }
314 
315 
321 {
322  const SG::IConstAuxStore* store = vec.getConstStore();
323  if (store)
324  dump_aux_vars (*store);
325 }
326 
327 
333 {
334  dump_aux_vars (*vec);
335 }
336 
337 
342 void dump_aux_vars (const SG::AuxElement& elt)
343 {
344  const SG::AuxVectorData* cont = elt.container();
345  if (cont)
346  dump_aux_vars (*cont, elt.index());
347 }
348 
349 
354 void dump_aux_vars (const SG::AuxElement* elt)
355 {
356  dump_aux_vars (*elt);
357 }
358 
359 
360 } // namespace SG
operator<
bool operator<(const DataVector< T > &a, const DataVector< T > &b)
Vector ordering relation.
beamspotman.r
def r
Definition: beamspotman.py:676
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
beamspotPlotBcids.sz
sz
Definition: beamspotPlotBcids.py:521
SGdebug::aux_var_as_string
std::string aux_var_as_string(SG::auxid_t auxid, const void *p)
Convert an aux variable to a string.
Definition: Control/AthContainers/Root/debug.cxx:208
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:446
SGdebug
Definition: Control/AthContainers/AthContainers/debug.h:25
CxxUtils::ConcurrentBitset::end
const_iterator end() const
Return an end iterator.
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
x
#define x
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
SGdebug::print_aux_vars
void print_aux_vars(const SG::auxid_set_t &auxids)
Print the list of aux variables in a set.
Definition: Control/AthContainers/Root/debug.cxx:56
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:62
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
StrFormat.h
Provide helper functions to create formatted strings.
lumiFormat.i
int i
Definition: lumiFormat.py:92
error.h
Helper for emitting error messages.
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
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
SG::AuxVarFlags
AuxVarFlags
Additional flags to qualify an auxiliary variable.
Definition: AuxTypes.h:58
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
CxxUtils::ConcurrentBitset::begin
const_iterator begin() const
Return a begin iterator.
CxxUtils::strformat
std::string strformat(const char *fmt,...)
return a std::string according to a format fmt and varargs
Definition: StrFormat.cxx:49
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
TMVAToMVAUtils::convert
std::unique_ptr< MVAUtils::BDT > convert(TMVA::MethodBDT *bdt, bool isRegression=true, bool useYesNoLeaf=false)
Definition: TMVAToMVAUtils.h:114
SG::Atomic
@ Atomic
Mark that this variable should only be accessed atomically.
Definition: AuxTypes.h:70
python.PyAthena.v
v
Definition: PyAthena.py:157
a
TList * a
Definition: liststreamerinfos.cxx:10
CONVERT1
#define CONVERT1(T)
DeMoScan.first
bool first
Definition: DeMoScan.py:534
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
SGdebug::dump_aux_vars
void dump_aux_vars(const SG::IConstAuxStore &store, size_t i)
Dump aux variables from a store for a single element.
Definition: Control/AthContainers/Root/debug.cxx:241
SGdebug::print_aux_var_name
void print_aux_var_name(SG::auxid_t id)
Print the name corresponding to a given aux id.
Definition: Control/AthContainers/Root/debug.cxx:41
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:167
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
IConstAuxStore.h
Interface for const operations on an auxiliary store.
SG::IConstAuxStore
Interface for const operations on an auxiliary store.
Definition: IConstAuxStore.h:64
SGdebug::aux_var_name
std::string aux_var_name(SG::auxid_t id)
Return the name corresponding to a given aux id.
Definition: Control/AthContainers/Root/debug.cxx:30
debug.h
Helper functions intended to be called from the debugger.