ATLAS Offline Software
Loading...
Searching...
No Matches
Control/AthContainers/Root/debug.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12
13#include "AthContainers/debug.h"
19#include "AthLinks/DataLinkBase.h"
20#ifndef XAOD_STANDALONE
21# include "SGTools/DataProxy.h"
22#endif
23#include "CxxUtils/StrFormat.h"
24#include <format>
25#include <vector>
26#include <sstream>
27#include <iostream>
28
29
30namespace SGdebug {
31
32
37std::string aux_var_name (SG::auxid_t id)
38{
40 return reg.getClassName(id) + "::" + reg.getName(id);
41}
42
43
49{
50 std::cout << aux_var_name(id) << "\n";
51}
52
53
54/******************************************************************************
55 * Print the list of aux variables given some object.
56 */
57
58
65void print_aux_vars (const SG::auxid_set_t& auxids,
66 const SG::auxid_set_t& decors,
67 std::ostream& os)
68{
70 std::vector<SG::auxid_t> ids (auxids.begin(), auxids.end());
71 std::sort (ids.begin(), ids.end());
72
73 for (SG::auxid_t id : ids) {
74 os << id << " "
75 << reg.getClassName(id) << "::" << reg.getName(id) << " "
76 << "[" << reg.getTypeName(id);
77
78 SG::AuxVarFlags flags = reg.getFlags(id);
79 if (flags & SG::AuxVarFlags::Atomic) {
80 os << " (atomic)";
81 }
82 if (flags & SG::AuxVarFlags::Linked) {
83 os << " (linked)";
84 }
85 if (decors.test (id)) {
86 os << " (decor)";
87 }
88
89 os << "]\n";
90 }
91}
92
93
98void print_aux_vars (const SG::auxid_set_t& auxids)
99{
100 print_aux_vars (auxids, SG::auxid_set_t(), std::cout);
101}
102
103
109void print_aux_vars (const SG::IConstAuxStore& store, std::ostream& os)
110{
111 print_aux_vars (store.getAuxIDs(), store.getDecorIDs(), os);
112}
113
114
120{
121 print_aux_vars (store, std::cout);
122}
123
124
130{
131 print_aux_vars (*store);
132}
133
134
140void print_aux_vars (const SG::AuxVectorData& vec, std::ostream& os)
141{
142 print_aux_vars (vec.getAuxIDs(), vec.getDecorIDs(), os);
143}
144
145
151{
152 print_aux_vars (vec, std::cout);
153}
154
155
161{
163}
164
165
171{
172 print_aux_vars (elt.getAuxIDs(), elt.getDecorIDs(), std::cout);
173}
174
175
181{
182 print_aux_vars (*elt);
183}
184
185
186/******************************************************************************
187 * Dump out aux variables.
188 */
189
190
191namespace {
192
193
194template <class T>
195void convert (std::ostream& os, const T& x)
196{
197 os << x;
198}
199
200
201void convert (std::ostream& os, const char x)
202{
203 os << static_cast<int > (x);
204}
205
206
207void convert (std::ostream& os, const unsigned char x)
208{
209 os << static_cast<unsigned > (x);
210}
211
212
213void convert (std::ostream& os, const float x)
214{
215 os << CxxUtils::strformat ("%.3f", x);
216}
217
218
219void convert (std::ostream& os, const double x)
220{
221 os << CxxUtils::strformat ("%.3f", x);
222}
223
224
225void convert (std::ostream& os, const SG::JaggedVecEltBase& x, size_t i)
226{
227 os << std::format ("[{},{}]", x.begin(i), x.end());
228}
229
230
231void convert (std::ostream& os, const DataLinkBase& x)
232{
233#ifdef XAOD_STANDALONE
234 os << std::format ("DataLink[{}]", x.persKey());
235#else
236 os << std::format ("DataLink[{}/{}]", x.proxy() ? x.proxy()->clID() : CLID_NULL, x.dataID());
237#endif
238}
239
240
241void convert (std::ostream& os, const SG::PackedLinkBase& x)
242{
243 os << std::format ("PackedLink[{}/{}]", x.collection(), x.index());
244}
245
246
247template <class T>
248void convert (std::ostream& os, const std::vector<T>& x)
249{
250 os << "[";
251 bool first = true;
252 // using `decltype(auto)` in case T=bool
253 // cppcheck-suppress internalAstError
254 for (decltype(auto) elt : x) {
255 if (first)
256 first = false;
257 else
258 os << ", ";
259 convert (os, elt);
260 }
261 os << "]";
262}
263
264
265struct AuxVarSort
266{
267 AuxVarSort (SG::auxid_t the_id)
268 : id(the_id),
269 name(aux_var_name(the_id))
270 {}
271
272 SG::auxid_t id;
273 std::string name;
274};
275
276
277bool operator< (const AuxVarSort& a, const AuxVarSort& b )
278{
279 return a.name < b.name;
280}
281
282
283} // anonymous namespace
284
285
292std::string aux_var_as_string (SG::auxid_t auxid, const void* p, size_t i)
293{
294 if (!p) {
295 return "(null)";
296 }
297
298 std::ostringstream os;
299
301 const std::type_info* ti = r.getType(auxid);
302#define CONVERT(T) if (ti == &typeid(T)) convert (os, *reinterpret_cast<const T*>(p)); else
303#define CONVERT1(T) CONVERT(T) CONVERT(std::vector<T>)
304 CONVERT1 (int)
305 CONVERT1 (unsigned int)
306 CONVERT1 (short)
307 CONVERT1 (unsigned short)
308 CONVERT1 (char)
309 CONVERT1 (unsigned char)
310 CONVERT1 (long)
311 CONVERT1 (unsigned long)
312 CONVERT1 (long long)
313 CONVERT1 (unsigned long long)
314 CONVERT1 (float)
315 CONVERT1 (double)
316 CONVERT1 (bool)
317 CONVERT1 (std::string)
318 //else
319 {
320 std::string tiname = AthContainers_detail::typeinfoName(*ti);
321 if (tiname.starts_with ("SG::JaggedVecElt<")) {
322 convert (os, *reinterpret_cast<const SG::JaggedVecEltBase*>(p), i);
323 }
324 else if (tiname.starts_with ("DataLink<")) {
325 convert (os, *reinterpret_cast<const DataLinkBase*>(p));
326 }
327 else if (tiname.starts_with ("SG::PackedLink<")) {
328 convert (os, *reinterpret_cast<const SG::PackedLinkBase*>(p));
329 }
330 else if (tiname.starts_with ("std::vector<SG::PackedLink<")) {
331 convert (os, *reinterpret_cast<const std::vector<SG::PackedLinkBase>*>(p));
332 }
333 else {
334 os << "<??? " << tiname << ">";
335 }
336 }
337 return os.str();
338}
339
340
347void dump_aux_vars (std::ostream& os, const SG::IConstAuxStore& store, size_t i)
348{
349 if (i >= store.size()) return;
351 const SG::auxid_set_t& ids = store.getAuxIDs();
352 std::vector<AuxVarSort> vars (ids.begin(), ids.end());
353 std::sort (vars.begin(), vars.end());
354 for (const AuxVarSort& v : vars) {
355 if (reg.isLinked (v.id)) continue;
356 const void* pbeg = store.getData (v.id);
357 size_t eltsz = reg.getEltSize (v.id);
358 const char* p = reinterpret_cast<const char*>(pbeg) + eltsz*i;
359 os << v.name << " " << aux_var_as_string (v.id, p, i) << "\n";
360 SG::auxid_t linked_id = reg.linkedVariable (v.id);
361 if (linked_id != SG::null_auxid) {
362 os << " linked: " << aux_var_name (linked_id) << " ";
363 const SG::IAuxTypeVector* lv = store.linkedVector (v.id);
364 if (!lv) {
365 os << "(missing linkedVector)\n";
366 continue;
367 }
368 size_t sz = lv->size();
369 const char* lbeg = reinterpret_cast<const char*>(lv->toPtr());
370 size_t leltsz = reg.getEltSize (linked_id);
371 os << "[";
372 bool first = true;
373 for (size_t j = 0; j < sz; j++) {
374 if (first)
375 first = false;
376 else
377 os << ", ";
378 const char* p = reinterpret_cast<const char*>(lbeg) + leltsz*j;
379 os << aux_var_as_string (linked_id, p, i);
380 }
381 os << "]\n";
382 }
383 }
384}
385
386
392void dump_aux_vars (const SG::IConstAuxStore& store, size_t i)
393{
394 dump_aux_vars (std::cout, store, i);
395}
396
397
403void dump_aux_vars (const SG::IConstAuxStore* store, size_t i)
404{
405 dump_aux_vars (*store, i);
406}
407
408
414{
415 size_t sz = store.size();
416 for (size_t i = 0; i < sz; i++) {
417 std::cout << "=== Element " << i << "\n";
418 dump_aux_vars (store, i);
419 }
420}
421
422
428{
429 dump_aux_vars (*store);
430}
431
432
438void dump_aux_vars (const SG::AuxVectorData& vec, size_t i)
439{
440 const SG::IConstAuxStore* store = vec.getConstStore();
441 if (store)
442 dump_aux_vars (*store, i);
443}
444
445
451void dump_aux_vars (const SG::AuxVectorData* vec, size_t i)
452{
453 dump_aux_vars (*vec, i);
454}
455
456
462{
463 const SG::IConstAuxStore* store = vec.getConstStore();
464 if (store)
465 dump_aux_vars (*store);
466}
467
468
474{
476}
477
478
484{
485 const SG::AuxVectorData* cont = elt.container();
486 if (cont)
487 dump_aux_vars (*cont, elt.index());
488}
489
490
496{
497 dump_aux_vars (*elt);
498}
499
500
501} // namespace SG
Handle mappings between names and auxid_t.
std::vector< size_t > vec
Helper functions intended to be called from the debugger.
#define CONVERT1(T)
bool operator<(const DataVector< T > &a, const DataVector< T > &b)
Vector ordering relation.
Interface for const operations on an auxiliary store.
Definition of JaggedVecElt.
static Double_t sz
static Double_t a
Definition of PackedLink type.
Provide helper functions to create formatted strings.
#define x
const_iterator end() const
Return an end iterator.
bool test(bit_t bit) const
Test to see if a bit is set.
const_iterator begin() const
Return a begin iterator.
Type-independent part of DataLink; holds the persistent state.
Base class for elements of a container that can have aux data.
Definition AuxElement.h:484
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.
const SG::auxid_set_t & getDecorIDs() const
Return a set of identifiers for decorations for this object.
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Manage lookup of vectors of auxiliary data.
Abstract interface for manipulating vectors of arbitrary types.
virtual void * toPtr()=0
Return a pointer to the start of the vector's data.
virtual size_t size() const =0
Return the size of the vector.
Interface for const operations on an auxiliary store.
Describe one element of a jagged vector (base class).
A set of aux data identifiers.
Definition AuxTypes.h:47
Helper for emitting error messages.
int r
Definition globals.cxx:22
std::string strformat(const char *fmt,...)
return a std::string according to a format fmt and varargs
Definition StrFormat.cxx:49
bool first
Definition DeMoScan.py:534
AuxVarFlags
Additional flags to qualify an auxiliary variable.
Definition AuxTypes.h:58
@ Atomic
Mark that this variable should only be accessed atomically.
Definition AuxTypes.h:70
@ Linked
Mark that this variable is linked to another one.
Definition AuxTypes.h:77
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
void dump_aux_vars(std::ostream &os, const SG::IConstAuxStore &store, size_t i)
Dump aux variables from a store for a single element.
void print_aux_vars(const SG::auxid_set_t &auxids, const SG::auxid_set_t &decors, std::ostream &os)
Print the list of aux variables in a set.
std::string aux_var_name(SG::auxid_t id)
Return the name corresponding to a given aux id.
std::string aux_var_as_string(SG::auxid_t auxid, const void *p, size_t i)
Convert an aux variable to a string.
void print_aux_var_name(SG::auxid_t id)
Print the name corresponding to a given aux id.
std::unique_ptr< MVAUtils::BDT > convert(TMVA::MethodBDT *bdt, bool isRegression=true, bool useYesNoLeaf=false)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
A packed version of ElementLink.