ATLAS Offline Software
PrintHelpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 // System include(s):
7 #include <cstdint>
8 #include <iostream>
9 
10 // EDM include(s):
14 
15 // Local include(s):
17 
18 namespace PrintHelpers {
19 
20 template <class T> struct VecPrintType {
21  typedef T type;
22 };
23 
24 template <> struct VecPrintType<char> {
25  using type = int;
26 };
27 
28 template <> struct VecPrintType<int8_t> {
29  using type = int;
30 };
31 
32 template <> struct VecPrintType<uint8_t> {
33  using type = unsigned int;
34 };
35 
36 } // namespace PrintHelpers
37 
38 
39 template< typename T, typename U >
40 std::ostream& operator<< ( std::ostream& out, const std::pair< T, U >& p ) {
41  out << "(";
43  out << ", ";
45  out << ")";
46  return out;
47 }
48 
50 template< typename T >
51 std::ostream& operator<< ( std::ostream& out, const std::vector< T >& vec ) {
52 
53  out << "[";
54  for( size_t i = 0; i < vec.size(); ++i ) {
56  if( i < vec.size() - 1 ) {
57  out << ", ";
58  }
59  }
60  out << "]";
61 
62  // Return the same stream:
63  return out;
64 }
65 
66 std::ostream& operator<< ( std::ostream& out, const SG::AuxElement& obj ) {
67 
68  // Start off with some basic information:
69  out << "SG::AuxElement\n";
70  out << " ";
71  if( obj.usingStandaloneStore() ) {
72  out << "using standalone store\n";
73  } else if( obj.usingPrivateStore() ) {
74  out << "using private store\n";
75  } else if( obj.container() ) {
76  out << "in container\n";
77  } else {
78  // If there's no auxiliary store, bail now:
79  out << "standalone object, without auxiliary store";
80  return out;
81  }
82 
83  // If the container doesn't have an auxiliary store, bail now:
84  if( ! obj.container()->getConstStore() ) {
85  return out;
86  }
87 
88  out << " Variables:";
89 
90  // Get a convenience pointer to the aux type registry:
92 
93  // Get the auxiliary IDs of the object:
94  const SG::auxid_set_t& auxids =
95  ( obj.container()->getConstStore() ?
96  obj.container()->getConstStore()->getAuxIDs() :
97  obj.getConstStore()->getAuxIDs() );
98 
99  // Sort auxids to get predictable ordering.
100  std::vector<SG::auxid_t> auxids_v (auxids.begin(), auxids.end());
101  std::sort (auxids_v.begin(), auxids_v.end());
102 
103  for( SG::auxid_t auxid : auxids_v ) {
104 
105  out << "\n - type: " << reg.getTypeName( auxid )
106  << ", \tname: \"" << reg.getName( auxid );
107  out << "\", \tvalue: ";
108 
110 #define PRINTER( TYPE ) \
111  do { \
112  if( obj.isAvailable< TYPE >( reg.getName( auxid ) ) ) { \
113  out << obj.auxdata< TYPE >( reg.getName( auxid ) ); \
114  } \
115  } while( 0 )
116 
117  // The type of the variable:
118  const std::type_info* ti = reg.getType( auxid );
119  if( reg.getFlags( auxid ) & SG::AuxVarFlags::Atomic ) {
120  if( *ti == typeid( unsigned int ) ) {
121  SG::AtomicConstAccessor<unsigned int> acc( reg.getName( auxid ) );
122  if ( acc.isAvailable( obj )) {
123  out << acc (obj);
124  }
125  }
126  else {
127  out << "(Unsupported atomic type)\n";
128  }
129  } else if( *ti == typeid( int8_t ) ) {
130  if( obj.isAvailable< int8_t >( reg.getName( auxid ) ) ) {
131  out << static_cast< int >( obj.auxdata< int8_t >( reg.getName( auxid ) ) );
132  }
133  } else if( *ti == typeid( uint8_t ) ) {
134  if( obj.isAvailable< uint8_t >( reg.getName( auxid ) ) ) {
135  out << static_cast< int >( obj.auxdata< uint8_t >( reg.getName( auxid ) ) );
136  }
137  } else if( *ti == typeid( int16_t ) ) {
138  PRINTER( int16_t );
139  } else if( *ti == typeid( uint16_t ) ) {
140  PRINTER( uint16_t );
141  } else if( *ti == typeid( int32_t ) ) {
142  PRINTER( int32_t );
143  } else if( *ti == typeid( uint32_t ) ) {
144  PRINTER( uint32_t );
145  } else if( *ti == typeid( int64_t ) ) {
146  PRINTER( int64_t );
147  } else if( *ti == typeid( uint64_t ) ) {
148  PRINTER( uint64_t );
149  } else if( *ti == typeid( long ) ) {
150  PRINTER( long );
151  } else if( *ti == typeid( unsigned long ) ) {
152  PRINTER( unsigned long );
153  } else if( *ti == typeid( unsigned long long ) ) {
154  PRINTER( unsigned long long );
155  } else if( *ti == typeid( float ) ) {
156  PRINTER( float );
157  } else if( *ti == typeid( double ) ) {
158  PRINTER( double );
159  } else if( *ti == typeid( std::vector< float > ) ) {
160  PRINTER( std::vector< float > );
161  } else if( *ti == typeid( std::vector< double > ) ) {
162  PRINTER( std::vector< double > );
163  } else if( *ti == typeid( std::vector< char > ) ) {
164  PRINTER( std::vector< char > );
165  } else if( *ti == typeid( std::vector< int8_t > ) ) {
166  PRINTER( std::vector< int8_t > );
167  } else if( *ti == typeid( std::vector< uint8_t > ) ) {
168  PRINTER( std::vector< uint8_t > );
169  } else if( *ti == typeid( std::vector< int16_t > ) ) {
170  PRINTER( std::vector< int16_t > );
171  } else if( *ti == typeid( std::vector< uint16_t > ) ) {
172  PRINTER( std::vector< uint16_t > );
173  } else if( *ti == typeid( std::vector< int32_t > ) ) {
174  PRINTER( std::vector< int32_t > );
175  } else if( *ti == typeid( std::vector< uint32_t > ) ) {
176  PRINTER( std::vector< uint32_t > );
177  } else if( *ti == typeid( std::vector< int64_t > ) ) {
178  PRINTER( std::vector< int64_t > );
179  } else if( *ti == typeid( std::vector< uint64_t > ) ) {
180  PRINTER( std::vector< uint64_t > );
181  } else if( *ti == typeid( std::vector< std::string > ) ) {
182  PRINTER( std::vector< std::string > );
183  } else if( *ti == typeid( std::vector< std::pair<std::string, std::string> > ) ) {
184  using Stringpair_t = std::pair<std::string, std::string>;
185  PRINTER( std::vector< Stringpair_t > );
186  } else {
187  out << "N/A";
188  }
189 
190 // Get rid of the temporary macro...
191 #undef PRINTER
192  }
193 
194  // Return the same stream:
195  return out;
196 }
197 
198 namespace xAOD {
199 
200  void dump( const SG::AuxElement& obj ) {
201 
202  // Do the printout simply using the operator:
203  std::cout << obj << std::endl;
204  return;
205  }
206 
207 } // namespace xAOD
AtomicConstAccessor.h
Access an auxiliary variable atomically.
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:446
PrintHelpers::VecPrintType< uint8_t >::type
unsigned int type
Definition: PrintHelpers.cxx:33
CxxUtils::ConcurrentBitset::end
const_iterator end() const
Return an end iterator.
xAOD::char
char
Definition: TrigDecision_v1.cxx:38
PRINTER
#define PRINTER(TYPE)
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
xAOD::int16_t
setScaleOne setStatusOne setSaturated int16_t
Definition: gFexGlobalRoI_v1.cxx:55
PrintHelpers::VecPrintType< char >::type
int type
Definition: PrintHelpers.cxx:25
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
PrintHelpers
Definition: PrintHelpers.cxx:18
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
lumiFormat.i
int i
Definition: lumiFormat.py:92
SG::AtomicConstAccessor
Access an auxiliary variable atomically.
Definition: AtomicConstAccessor.h:45
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
PrintHelpers::VecPrintType
Definition: PrintHelpers.cxx:20
CxxUtils::ConcurrentBitset::begin
const_iterator begin() const
Return a begin iterator.
PrintHelpers::VecPrintType::type
T type
Definition: PrintHelpers.cxx:21
operator<<
std::ostream & operator<<(std::ostream &out, const std::pair< T, U > &p)
Definition: PrintHelpers.cxx:40
test_pythinning.out
out
Definition: test_pythinning.py:94
PrintHelpers::VecPrintType< int8_t >::type
int type
Definition: PrintHelpers.cxx:29
SG::Atomic
@ Atomic
Mark that this variable should only be accessed atomically.
Definition: AuxTypes.h:70
readCCLHist.int
int
Definition: readCCLHist.py:84
PrintHelpers.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
xAOD::dump
void dump(const SG::AuxElement &obj)
Helper function for dumping xAOD objects on the screen in PyROOT.
Definition: PrintHelpers.cxx:200
python.PyAthena.obj
obj
Definition: PyAthena.py:135
AuxElement.h
Base class for elements of a container that can have aux data.