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#include "AthLinks/ElementLinkBase.h"
21#ifndef XAOD_STANDALONE
22# include "SGTools/DataProxy.h"
23#endif
24#include <print>
25#include <vector>
26#include <sstream>
27#include <iostream>
28#include <cstring>
29
30
31namespace SGdebug {
32
33
38std::string aux_var_name (SG::auxid_t id)
39{
41 return reg.getClassName(id) + "::" + reg.getName(id);
42}
43
44
50{
51 std::println ("{}", aux_var_name(id));
52}
53
54
55/******************************************************************************
56 * Print the list of aux variables given some object.
57 */
58
59
66void print_aux_vars (const SG::auxid_set_t& auxids,
67 const SG::auxid_set_t& decors,
68 std::ostream& os)
69{
71 std::vector<SG::auxid_t> ids (auxids.begin(), auxids.end());
72 std::sort (ids.begin(), ids.end());
73
74 for (SG::auxid_t id : ids) {
75 std::print (os , "{} {}::{} [{}",
76 id, reg.getClassName(id), reg.getName(id), reg.getTypeName(id));
77
78 SG::AuxVarFlags flags = reg.getFlags(id);
79 if (flags & SG::AuxVarFlags::Atomic) {
80 std::print (os, " (atomic)");
81 }
82 if (flags & SG::AuxVarFlags::Linked) {
83 std::print (os, " (linked)");
84 }
85 if (decors.test (id)) {
86 std::print (os, " (decor)");
87 }
88
89 std::println (os, "]");
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
119void print_aux_vars (const SG::IConstAuxStore& store)
120{
121 print_aux_vars (store, std::cout);
122}
123
124
129void print_aux_vars (const SG::IConstAuxStore* store)
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 std::print (os, "{}", x);
198}
199
200
201void convert (std::ostream& os, const char x)
202{
203 std::print (os, "{}", static_cast<int>(x));
204}
205
206
207void convert (std::ostream& os, const unsigned char x)
208{
209 std::print (os, "{}", static_cast<unsigned>(x));
210}
211
212
213void convert (std::ostream& os, const float x)
214{
215 std::print (os, "{:.3f}", x);
216}
217
218
219void convert (std::ostream& os, const double x)
220{
221 std::print (os, "{:.3f}", x);
222}
223
224
225void convert (std::ostream& os, const SG::JaggedVecEltBase& x, size_t i)
226{
227 std::print (os, "[{},{}]", x.begin(i), x.end());
228}
229
230
231void convert (std::ostream& os, const DataLinkBase& x)
232{
233#ifdef XAOD_STANDALONE
234 std::print (os, "DataLink[{}]", x.persKey());
235#else
236 std::print (os, "DataLink[{}/{}]", x.proxy() ? x.proxy()->clID() : CLID_NULL, x.dataID());
237#endif
238}
239
240
241void convert (std::ostream& os, const ElementLinkBase& x)
242{
243#ifdef XAOD_STANDALONE
244 std::print (os, "ElementLink[{}:{}]", x.persKey(), x.persIndex());
245#else
246 std::print (os, "ElementLink[{}/{}:{}]", x.proxy() ? x.proxy()->clID() : CLID_NULL, x.dataID(), x.index());
247#endif
248}
249
250
251void convert (std::ostream& os, const SG::PackedLinkBase& x)
252{
253 std::print (os, "PackedLink[{}/{}]", x.collection(), x.index());
254}
255
256
257template <class T>
258void convert (std::ostream& os, const std::vector<T>& x)
259{
260 std::print (os, "[");
261 bool first = true;
262 // using `decltype(auto)` in case T=bool
263 // cppcheck-suppress internalAstError
264 for (decltype(auto) elt : x) {
265 if (first)
266 first = false;
267 else
268 std::print (os, ", ");
269 convert (os, elt);
270 }
271 std::print (os, "]");
272}
273
274
275struct AuxVarSort
276{
277 AuxVarSort (SG::auxid_t the_id)
278 : id(the_id),
279 name(aux_var_name(the_id))
280 {}
281
282 SG::auxid_t id;
283 std::string name;
284};
285
286
287bool operator< (const AuxVarSort& a, const AuxVarSort& b )
288{
289 return a.name < b.name;
290}
291
292
293} // anonymous namespace
294
295
302std::string aux_var_as_string (SG::auxid_t auxid, const void* p, size_t i)
303{
304 if (!p) {
305 return "(null)";
306 }
307
308 std::ostringstream os;
309
311 const std::type_info* ti = r.getType(auxid);
312#define CONVERT(T) if (ti == &typeid(T) || strcmp(ti->name(), typeid(T).name())==0) convert (os, *reinterpret_cast<const T*>(p)); else
313#define CONVERT1(T) CONVERT(T) CONVERT(std::vector<T>)
314 CONVERT1 (int)
315 CONVERT1 (unsigned int)
316 CONVERT1 (short)
317 CONVERT1 (unsigned short)
318 CONVERT1 (char)
319 CONVERT1 (unsigned char)
320 CONVERT1 (long)
321 CONVERT1 (unsigned long)
322 CONVERT1 (long long)
323 CONVERT1 (unsigned long long)
324 CONVERT1 (float)
325 CONVERT1 (double)
326 CONVERT1 (bool)
327 CONVERT1 (std::string)
328 //else
329 {
330 std::string tiname = AthContainers_detail::typeinfoName(*ti);
331 if (tiname.starts_with ("SG::JaggedVecElt<")) {
332 convert (os, *reinterpret_cast<const SG::JaggedVecEltBase*>(p), i);
333 }
334 else if (tiname.starts_with ("DataLink<")) {
335 convert (os, *reinterpret_cast<const DataLinkBase*>(p));
336 }
337 else if (tiname.starts_with ("ElementLink<")) {
338 convert (os, *reinterpret_cast<const ElementLinkBase*>(p));
339 }
340 else if (tiname.starts_with ("SG::PackedLink<")) {
341 convert (os, *reinterpret_cast<const SG::PackedLinkBase*>(p));
342 }
343 else if (tiname.starts_with ("std::vector<SG::PackedLink<")) {
344 convert (os, *reinterpret_cast<const std::vector<SG::PackedLinkBase>*>(p));
345 }
346 else {
347 std::print (os, "<??? {}>", tiname);
348 }
349 }
350 return os.str();
351}
352
353
360void dump_aux_vars (std::ostream& os, const SG::IConstAuxStore& store, size_t i)
361{
362 if (i >= store.size()) return;
364 const SG::auxid_set_t& ids = store.getAuxIDs();
365 std::vector<AuxVarSort> vars (ids.begin(), ids.end());
366 std::sort (vars.begin(), vars.end());
367 for (const AuxVarSort& v : vars) {
368 if (reg.isLinked (v.id)) continue;
369 const void* pbeg = store.getData (v.id);
370 size_t eltsz = reg.getEltSize (v.id);
371 const char* p = reinterpret_cast<const char*>(pbeg) + eltsz*i;
372 std::println (os, "{} {}",
373 v.name, aux_var_as_string (v.id, p, i));
374 SG::auxid_t linked_id = reg.linkedVariable (v.id);
375 if (linked_id != SG::null_auxid) {
376 std::print (os, " linked: {} ", aux_var_name (linked_id));
377 const SG::IAuxTypeVector* lv = store.linkedVector (v.id);
378 if (!lv) {
379 std::println (os, "(missing linkedVector)");
380 continue;
381 }
382 size_t sz = lv->size();
383 const char* lbeg = reinterpret_cast<const char*>(lv->toPtr());
384 size_t leltsz = reg.getEltSize (linked_id);
385 std::print (os, "[");
386 bool first = true;
387 for (size_t j = 0; j < sz; j++) {
388 if (first)
389 first = false;
390 else
391 std::print (os, ", ");
392 const char* p = reinterpret_cast<const char*>(lbeg) + leltsz*j;
393 std::print (os, "{}", aux_var_as_string (linked_id, p, i));
394 }
395 std::println (os, "]");
396 }
397 }
398}
399
400
406void dump_aux_vars (const SG::IConstAuxStore& store, size_t i)
407{
408 dump_aux_vars (std::cout, store, i);
409}
410
411
417void dump_aux_vars (const SG::IConstAuxStore* store, size_t i)
418{
419 dump_aux_vars (*store, i);
420}
421
422
427void dump_aux_vars (const SG::IConstAuxStore& store)
428{
429 size_t sz = store.size();
430 for (size_t i = 0; i < sz; i++) {
431 std::println ("=== Element {}", i);
432 dump_aux_vars (store, i);
433 }
434}
435
436
441void dump_aux_vars (const SG::IConstAuxStore* store)
442{
443 dump_aux_vars (*store);
444}
445
446
452void dump_aux_vars (const SG::AuxVectorData& vec, size_t i)
453{
454 const SG::IConstAuxStore* store = vec.getConstStore();
455 if (store)
456 dump_aux_vars (*store, i);
457}
458
459
465void dump_aux_vars (const SG::AuxVectorData* vec, size_t i)
466{
467 dump_aux_vars (*vec, i);
468}
469
470
476{
477 const SG::IConstAuxStore* store = vec.getConstStore();
478 if (store)
479 dump_aux_vars (*store);
480}
481
482
488{
490}
491
492
498{
499 const SG::AuxVectorData* cont = elt.container();
500 if (cont)
501 dump_aux_vars (*cont, elt.index());
502}
503
504
510{
511 dump_aux_vars (*elt);
512}
513
514
515} // 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.
#define x
Type-independent part of DataLink; holds the persistent state.
Base class for ElementLinks to vectors of pointers.
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.
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
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
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
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.