ATLAS Offline Software
Loading...
Searching...
No Matches
PrintHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6// System include(s):
7#include <cstdint>
8#include <print>
9#include <sstream>
10
11// EDM include(s):
15
16// Local include(s):
18
19namespace PrintHelpers {
20
21template <class T> struct VecPrintType {
22 typedef T type;
23};
24
25template <> struct VecPrintType<char> {
26 using type = int;
27};
28
29template <> struct VecPrintType<int8_t> {
30 using type = int;
31};
32
33template <> struct VecPrintType<uint8_t> {
34 using type = unsigned int;
35};
36
37} // namespace PrintHelpers
38
39
40std::ostream& operator<< ( std::ostream& out, const SG::AuxElement& obj ) {
41 std::print( out, "{}", xAOD::toString( obj ) );
42 return out;
43}
44
45std::string xAOD::toString( const SG::AuxElement& obj ) {
46 std::ostringstream out;
47
48 // Start off with some basic information:
49 std::println( out, "SG::AuxElement" );
50 std::print( out, " " );
51 if( obj.usingStandaloneStore() ) {
52 std::println( out, "using standalone store" );
53 } else if( obj.usingPrivateStore() ) {
54 std::println( out, "using private store" );
55 } else if( obj.container() ) {
56 std::println( out, "in container" );
57 } else {
58 // If there's no auxiliary store, bail now:
59 std::print( out, "standalone object, without auxiliary store" );
60 return out.str();
61 }
62
63 // If the container doesn't have an auxiliary store, bail now:
64 if( ! obj.container()->getConstStore() ) {
65 return out.str();
66 }
67
68 std::print( out, " Variables:" );
69
70 // Get a convenience pointer to the aux type registry:
72
73 // Get the auxiliary IDs of the object:
74 const SG::auxid_set_t& auxids =
75 ( obj.container()->getConstStore() ?
76 obj.container()->getConstStore()->getAuxIDs() :
77 obj.getConstStore()->getAuxIDs() );
78
79 // Sort auxids to get predictable ordering.
80 std::vector<SG::auxid_t> auxids_v (auxids.begin(), auxids.end());
81 std::sort (auxids_v.begin(), auxids_v.end());
82
83 for( SG::auxid_t auxid : auxids_v ) {
84
85 std::print( out, "\n - type: {}, \tname: \"{}\", \tvalue: ",
86 reg.getTypeName( auxid ), reg.getName( auxid ) );
87
89#define PRINTER( TYPE ) \
90 do { \
91 SG::ConstAccessor< TYPE > acc( auxid ); \
92 if( acc.isAvailable( obj ) ) { \
93 std::print( out, "{}", acc( obj ) ); \
94 } \
95 } while( 0 )
96
97 // The type of the variable:
98 const std::type_info* ti = reg.getType( auxid );
99 if( reg.getFlags( auxid ) & SG::AuxVarFlags::Atomic ) {
100 if( *ti == typeid( unsigned int ) ) {
101 SG::AtomicConstAccessor<unsigned int> acc( reg.getName( auxid ) );
102 if ( acc.isAvailable( obj )) {
103 std::print( out, "{}", acc (obj) );
104 }
105 }
106 else {
107 std::println( out, "(Unsupported atomic type)\n" );
108 }
109 } else if( *ti == typeid( int8_t ) ) {
111 if( acc.isAvailable( obj ) ) {
112 std::print( out, "{}", static_cast< int >( acc( obj ) ) );
113 }
114 } else if( *ti == typeid( uint8_t ) ) {
116 if( acc.isAvailable( obj ) ) {
117 std::print( out, "{}", static_cast< int >( acc( obj ) ) );
118 }
119 } else if( *ti == typeid( int16_t ) ) {
120 PRINTER( int16_t );
121 } else if( *ti == typeid( uint16_t ) ) {
122 PRINTER( uint16_t );
123 } else if( *ti == typeid( int32_t ) ) {
124 PRINTER( int32_t );
125 } else if( *ti == typeid( uint32_t ) ) {
126 PRINTER( uint32_t );
127 } else if( *ti == typeid( int64_t ) ) {
128 PRINTER( int64_t );
129 } else if( *ti == typeid( uint64_t ) ) {
130 PRINTER( uint64_t );
131 } else if( *ti == typeid( long ) ) {
132 PRINTER( long );
133 } else if( *ti == typeid( unsigned long ) ) {
134 PRINTER( unsigned long );
135 } else if( *ti == typeid( unsigned long long ) ) {
136 PRINTER( unsigned long long );
137 } else if( *ti == typeid( float ) ) {
138 PRINTER( float );
139 } else if( *ti == typeid( double ) ) {
140 PRINTER( double );
141 } else if( *ti == typeid( std::vector< float > ) ) {
142 PRINTER( std::vector< float > );
143 } else if( *ti == typeid( std::vector< double > ) ) {
144 PRINTER( std::vector< double > );
145 } else if( *ti == typeid( std::vector< char > ) ) {
146 PRINTER( std::vector< char > );
147 } else if( *ti == typeid( std::vector< int8_t > ) ) {
148 PRINTER( std::vector< int8_t > );
149 } else if( *ti == typeid( std::vector< uint8_t > ) ) {
150 PRINTER( std::vector< uint8_t > );
151 } else if( *ti == typeid( std::vector< int16_t > ) ) {
152 PRINTER( std::vector< int16_t > );
153 } else if( *ti == typeid( std::vector< uint16_t > ) ) {
154 PRINTER( std::vector< uint16_t > );
155 } else if( *ti == typeid( std::vector< int32_t > ) ) {
156 PRINTER( std::vector< int32_t > );
157 } else if( *ti == typeid( std::vector< uint32_t > ) ) {
158 PRINTER( std::vector< uint32_t > );
159 } else if( *ti == typeid( std::vector< int64_t > ) ) {
160 PRINTER( std::vector< int64_t > );
161 } else if( *ti == typeid( std::vector< uint64_t > ) ) {
162 PRINTER( std::vector< uint64_t > );
163 } else if( *ti == typeid( std::vector< std::string > ) ) {
164 PRINTER( std::vector< std::string > );
165 } else if( *ti == typeid( std::vector< std::pair<std::string, std::string> > ) ) {
166 using Stringpair_t = std::pair<std::string, std::string>;
167 PRINTER( std::vector< Stringpair_t > );
168 } else {
169 std::print( out, "N/A" );
170 }
171
172// Get rid of the temporary macro...
173#undef PRINTER
174 }
175
176 // Return the same stream:
177 return out.str();
178}
179
180namespace xAOD {
181
182 void dump( const SG::AuxElement& obj ) {
183
184 // Do the printout simply using the operator:
185 std::println( "{}", obj );
186 return;
187 }
188
189} // namespace xAOD
Access an auxiliary variable atomically.
Base class for elements of a container that can have aux data.
Handle mappings between names and auxid_t.
std::ostream & operator<<(std::ostream &out, const SG::AuxElement &obj)
Operator printing the payload of an xAOD object.
#define PRINTER(TYPE)
Access an auxiliary variable atomically.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Helper class to provide constant type-safe access to aux data.
A set of aux data identifiers.
Definition AuxTypes.h:47
@ Atomic
Mark that this variable should only be accessed atomically.
Definition AuxTypes.h:70
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
-event-from-file
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
setScaleOne setStatusOne setSaturated int16_t
setWord1 uint16_t
std::string toString(const SG::AuxElement &obj)
setEventNumber uint32_t
static const SG::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.