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 "CxxUtils/StrFormat.h"
25#include <print>
26#include <vector>
27#include <sstream>
28#include <iostream>
29#include <cstring>
30
31
32namespace SGdebug {
33
34
39std::string aux_var_name (SG::auxid_t id)
40{
42 return reg.getClassName(id) + "::" + reg.getName(id);
43}
44
45
51{
52 std::println ("{}", aux_var_name(id));
53}
54
55
56/******************************************************************************
57 * Print the list of aux variables given some object.
58 */
59
60
67void print_aux_vars (const SG::auxid_set_t& auxids,
68 const SG::auxid_set_t& decors,
69 std::ostream& os)
70{
72 std::vector<SG::auxid_t> ids (auxids.begin(), auxids.end());
73 std::sort (ids.begin(), ids.end());
74
75 for (SG::auxid_t id : ids) {
76 std::print (os , "{} {}::{} [{}",
77 id, reg.getClassName(id), reg.getName(id), reg.getTypeName(id));
78
79 SG::AuxVarFlags flags = reg.getFlags(id);
80 if (flags & SG::AuxVarFlags::Atomic) {
81 std::print (os, " (atomic)");
82 }
83 if (flags & SG::AuxVarFlags::Linked) {
84 std::print (os, " (linked)");
85 }
86 if (decors.test (id)) {
87 std::print (os, " (decor)");
88 }
89
90 std::println (os, "]");
91 }
92}
93
94
99void print_aux_vars (const SG::auxid_set_t& auxids)
100{
101 print_aux_vars (auxids, SG::auxid_set_t(), std::cout);
102}
103
104
110void print_aux_vars (const SG::IConstAuxStore& store, std::ostream& os)
111{
112 print_aux_vars (store.getAuxIDs(), store.getDecorIDs(), os);
113}
114
115
120void print_aux_vars (const SG::IConstAuxStore& store)
121{
122 print_aux_vars (store, std::cout);
123}
124
125
130void print_aux_vars (const SG::IConstAuxStore* store)
131{
132 print_aux_vars (*store);
133}
134
135
141void print_aux_vars (const SG::AuxVectorData& vec, std::ostream& os)
142{
143 print_aux_vars (vec.getAuxIDs(), vec.getDecorIDs(), os);
144}
145
146
152{
153 print_aux_vars (vec, std::cout);
154}
155
156
162{
164}
165
166
172{
173 print_aux_vars (elt.getAuxIDs(), elt.getDecorIDs(), std::cout);
174}
175
176
182{
183 print_aux_vars (*elt);
184}
185
186
187/******************************************************************************
188 * Dump out aux variables.
189 */
190
191
192namespace {
193
194
195template <class T>
196void convert (std::ostream& os, const T& x)
197{
198 std::print (os, "{}", x);
199}
200
201
202void convert (std::ostream& os, const char x)
203{
204 std::print (os, "{}", static_cast<int>(x));
205}
206
207
208void convert (std::ostream& os, const unsigned char x)
209{
210 std::print (os, "{}", static_cast<unsigned>(x));
211}
212
213
214void convert (std::ostream& os, const float x)
215{
216 std::print (os, "{:.3f}", x);
217}
218
219
220void convert (std::ostream& os, const double x)
221{
222 std::print (os, "{:.3f}", x);
223}
224
225
226void convert (std::ostream& os, const SG::JaggedVecEltBase& x, size_t i)
227{
228 std::print (os, "[{},{}]", x.begin(i), x.end());
229}
230
231
232void convert (std::ostream& os, const DataLinkBase& x)
233{
234#ifdef XAOD_STANDALONE
235 std::print (os, "DataLink[{}]", x.persKey());
236#else
237 std::print (os, "DataLink[{}/{}]", x.proxy() ? x.proxy()->clID() : CLID_NULL, x.dataID());
238#endif
239}
240
241
242void convert (std::ostream& os, const ElementLinkBase& x)
243{
244#ifdef XAOD_STANDALONE
245 std::print (os, "ElementLink[{}:{}]", x.persKey(), x.persIndex());
246#else
247 std::print (os, "ElementLink[{}/{}:{}]", x.proxy() ? x.proxy()->clID() : CLID_NULL, x.dataID(), x.index());
248#endif
249}
250
251
252void convert (std::ostream& os, const SG::PackedLinkBase& x)
253{
254 std::print (os, "PackedLink[{}/{}]", x.collection(), x.index());
255}
256
257
258template <class T>
259void convert (std::ostream& os, const std::vector<T>& x)
260{
261 std::print (os, "[");
262 bool first = true;
263 // using `decltype(auto)` in case T=bool
264 // cppcheck-suppress internalAstError
265 for (decltype(auto) elt : x) {
266 if (first)
267 first = false;
268 else
269 std::print (os, ", ");
270 convert (os, elt);
271 }
272 std::print (os, "]");
273}
274
275
276struct AuxVarSort
277{
278 AuxVarSort (SG::auxid_t the_id)
279 : id(the_id),
280 name(aux_var_name(the_id))
281 {}
282
283 SG::auxid_t id;
284 std::string name;
285};
286
287
288bool operator< (const AuxVarSort& a, const AuxVarSort& b )
289{
290 return a.name < b.name;
291}
292
293
294} // anonymous namespace
295
296
303std::string aux_var_as_string (SG::auxid_t auxid, const void* p, size_t i)
304{
305 if (!p) {
306 return "(null)";
307 }
308
309 std::ostringstream os;
310
312 const std::type_info* ti = r.getType(auxid);
313#define CONVERT(T) if (ti == &typeid(T) || strcmp(ti->name(), typeid(T).name())==0) convert (os, *reinterpret_cast<const T*>(p)); else
314#define CONVERT1(T) CONVERT(T) CONVERT(std::vector<T>)
315 CONVERT1 (int)
316 CONVERT1 (unsigned int)
317 CONVERT1 (short)
318 CONVERT1 (unsigned short)
319 CONVERT1 (char)
320 CONVERT1 (unsigned char)
321 CONVERT1 (long)
322 CONVERT1 (unsigned long)
323 CONVERT1 (long long)
324 CONVERT1 (unsigned long long)
325 CONVERT1 (float)
326 CONVERT1 (double)
327 CONVERT1 (bool)
328 CONVERT1 (std::string)
329 //else
330 {
331 std::string tiname = AthContainers_detail::typeinfoName(*ti);
332 if (tiname.starts_with ("SG::JaggedVecElt<")) {
333 convert (os, *reinterpret_cast<const SG::JaggedVecEltBase*>(p), i);
334 }
335 else if (tiname.starts_with ("DataLink<")) {
336 convert (os, *reinterpret_cast<const DataLinkBase*>(p));
337 }
338 else if (tiname.starts_with ("ElementLink<")) {
339 convert (os, *reinterpret_cast<const ElementLinkBase*>(p));
340 }
341 else if (tiname.starts_with ("SG::PackedLink<")) {
342 convert (os, *reinterpret_cast<const SG::PackedLinkBase*>(p));
343 }
344 else if (tiname.starts_with ("std::vector<SG::PackedLink<")) {
345 convert (os, *reinterpret_cast<const std::vector<SG::PackedLinkBase>*>(p));
346 }
347 else {
348 std::print (os, "<??? {}>", tiname);
349 }
350 }
351 return os.str();
352}
353
354
361void dump_aux_vars (std::ostream& os, const SG::IConstAuxStore& store, size_t i)
362{
363 if (i >= store.size()) return;
365 const SG::auxid_set_t& ids = store.getAuxIDs();
366 std::vector<AuxVarSort> vars (ids.begin(), ids.end());
367 std::sort (vars.begin(), vars.end());
368 for (const AuxVarSort& v : vars) {
369 if (reg.isLinked (v.id)) continue;
370 const void* pbeg = store.getData (v.id);
371 size_t eltsz = reg.getEltSize (v.id);
372 const char* p = reinterpret_cast<const char*>(pbeg) + eltsz*i;
373 std::println (os, "{} {}",
374 v.name, aux_var_as_string (v.id, p, i));
375 SG::auxid_t linked_id = reg.linkedVariable (v.id);
376 if (linked_id != SG::null_auxid) {
377 std::print (os, " linked: {} ", aux_var_name (linked_id));
378 const SG::IAuxTypeVector* lv = store.linkedVector (v.id);
379 if (!lv) {
380 std::println (os, "(missing linkedVector)");
381 continue;
382 }
383 size_t sz = lv->size();
384 const char* lbeg = reinterpret_cast<const char*>(lv->toPtr());
385 size_t leltsz = reg.getEltSize (linked_id);
386 std::print (os, "[");
387 bool first = true;
388 for (size_t j = 0; j < sz; j++) {
389 if (first)
390 first = false;
391 else
392 std::print (os, ", ");
393 const char* p = reinterpret_cast<const char*>(lbeg) + leltsz*j;
394 std::print (os, "{}", aux_var_as_string (linked_id, p, i));
395 }
396 std::println (os, "]");
397 }
398 }
399}
400
401
407void dump_aux_vars (const SG::IConstAuxStore& store, size_t i)
408{
409 dump_aux_vars (std::cout, store, i);
410}
411
412
418void dump_aux_vars (const SG::IConstAuxStore* store, size_t i)
419{
420 dump_aux_vars (*store, i);
421}
422
423
428void dump_aux_vars (const SG::IConstAuxStore& store)
429{
430 size_t sz = store.size();
431 for (size_t i = 0; i < sz; i++) {
432 std::println ("=== Element {}", i);
433 dump_aux_vars (store, i);
434 }
435}
436
437
442void dump_aux_vars (const SG::IConstAuxStore* store)
443{
444 dump_aux_vars (*store);
445}
446
447
453void dump_aux_vars (const SG::AuxVectorData& vec, size_t i)
454{
455 const SG::IConstAuxStore* store = vec.getConstStore();
456 if (store)
457 dump_aux_vars (*store, i);
458}
459
460
466void dump_aux_vars (const SG::AuxVectorData* vec, size_t i)
467{
468 dump_aux_vars (*vec, i);
469}
470
471
477{
478 const SG::IConstAuxStore* store = vec.getConstStore();
479 if (store)
480 dump_aux_vars (*store);
481}
482
483
489{
491}
492
493
499{
500 const SG::AuxVectorData* cont = elt.container();
501 if (cont)
502 dump_aux_vars (*cont, elt.index());
503}
504
505
511{
512 dump_aux_vars (*elt);
513}
514
515
516} // 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
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.