ATLAS Offline Software
Classes | Namespaces | Macros | Functions
PrintHelpers.cxx File Reference
#include <cstdint>
#include <iostream>
#include "AthContainers/AuxElement.h"
#include "AthContainers/AuxTypeRegistry.h"
#include "AthContainers/tools/AtomicConstAccessor.h"
#include "xAODCore/tools/PrintHelpers.h"
Include dependency graph for PrintHelpers.cxx:

Go to the source code of this file.

Classes

struct  PrintHelpers::VecPrintType< T >
 
struct  PrintHelpers::VecPrintType< char >
 
struct  PrintHelpers::VecPrintType< int8_t >
 
struct  PrintHelpers::VecPrintType< uint8_t >
 

Namespaces

 PrintHelpers
 
 xAOD
 ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
 

Macros

#define PRINTER(TYPE)
 

Functions

template<typename T , typename U >
std::ostream & operator<< (std::ostream &out, const std::pair< T, U > &p)
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const std::vector< T > &vec)
 Helper operator to pretty-print the values of vectors. More...
 
std::ostream & operator<< (std::ostream &out, const SG::AuxElement &obj)
 Operator printing the payload of an xAOD object. More...
 
void xAOD::dump (const SG::AuxElement &obj)
 Helper function for dumping xAOD objects on the screen in PyROOT. More...
 

Macro Definition Documentation

◆ PRINTER

#define PRINTER (   TYPE)
Value:
do { \
SG::ConstAccessor< TYPE > acc( auxid ); \
if( acc.isAvailable( obj ) ) { \
out << acc( obj ); \
} \
} while( 0 )

Function Documentation

◆ operator<<() [1/3]

std::ostream& operator<< ( std::ostream &  out,
const SG::AuxElement obj 
)

Operator printing the payload of an xAOD object.

This function can be used to quickly get an idea about the payload held by any type of xAOD object. It prints the type and name of each auxiliary variable associated with the object. And for some simple types (primitives and some vectors of primitives) it even prints the values of these variables.

Parameters
outThe stream to write the information to
objThe object to write the information about
Returns
The same stream object that was given to the function

Helper macro to make the code slightly shorter

Definition at line 66 of file PrintHelpers.cxx.

66  {
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  SG::ConstAccessor< TYPE > acc( auxid ); \
113  if( acc.isAvailable( obj ) ) { \
114  out << acc( obj ); \
115  } \
116  } while( 0 )
117 
118  // The type of the variable:
119  const std::type_info* ti = reg.getType( auxid );
120  if( reg.getFlags( auxid ) & SG::AuxVarFlags::Atomic ) {
121  if( *ti == typeid( unsigned int ) ) {
123  if ( acc.isAvailable( obj )) {
124  out << acc (obj);
125  }
126  }
127  else {
128  out << "(Unsupported atomic type)\n";
129  }
130  } else if( *ti == typeid( int8_t ) ) {
132  if( acc.isAvailable( obj ) ) {
133  out << static_cast< int >( acc( obj ) );
134  }
135  } else if( *ti == typeid( uint8_t ) ) {
137  if( acc.isAvailable( obj ) ) {
138  out << static_cast< int >( acc( obj ) );
139  }
140  } else if( *ti == typeid( int16_t ) ) {
141  PRINTER( int16_t );
142  } else if( *ti == typeid( uint16_t ) ) {
143  PRINTER( uint16_t );
144  } else if( *ti == typeid( int32_t ) ) {
145  PRINTER( int32_t );
146  } else if( *ti == typeid( uint32_t ) ) {
147  PRINTER( uint32_t );
148  } else if( *ti == typeid( int64_t ) ) {
149  PRINTER( int64_t );
150  } else if( *ti == typeid( uint64_t ) ) {
151  PRINTER( uint64_t );
152  } else if( *ti == typeid( long ) ) {
153  PRINTER( long );
154  } else if( *ti == typeid( unsigned long ) ) {
155  PRINTER( unsigned long );
156  } else if( *ti == typeid( unsigned long long ) ) {
157  PRINTER( unsigned long long );
158  } else if( *ti == typeid( float ) ) {
159  PRINTER( float );
160  } else if( *ti == typeid( double ) ) {
161  PRINTER( double );
162  } else if( *ti == typeid( std::vector< float > ) ) {
163  PRINTER( std::vector< float > );
164  } else if( *ti == typeid( std::vector< double > ) ) {
165  PRINTER( std::vector< double > );
166  } else if( *ti == typeid( std::vector< char > ) ) {
167  PRINTER( std::vector< char > );
168  } else if( *ti == typeid( std::vector< int8_t > ) ) {
169  PRINTER( std::vector< int8_t > );
170  } else if( *ti == typeid( std::vector< uint8_t > ) ) {
171  PRINTER( std::vector< uint8_t > );
172  } else if( *ti == typeid( std::vector< int16_t > ) ) {
173  PRINTER( std::vector< int16_t > );
174  } else if( *ti == typeid( std::vector< uint16_t > ) ) {
175  PRINTER( std::vector< uint16_t > );
176  } else if( *ti == typeid( std::vector< int32_t > ) ) {
177  PRINTER( std::vector< int32_t > );
178  } else if( *ti == typeid( std::vector< uint32_t > ) ) {
179  PRINTER( std::vector< uint32_t > );
180  } else if( *ti == typeid( std::vector< int64_t > ) ) {
181  PRINTER( std::vector< int64_t > );
182  } else if( *ti == typeid( std::vector< uint64_t > ) ) {
183  PRINTER( std::vector< uint64_t > );
184  } else if( *ti == typeid( std::vector< std::string > ) ) {
185  PRINTER( std::vector< std::string > );
186  } else if( *ti == typeid( std::vector< std::pair<std::string, std::string> > ) ) {
187  using Stringpair_t = std::pair<std::string, std::string>;
188  PRINTER( std::vector< Stringpair_t > );
189  } else {
190  out << "N/A";
191  }
192 
193 // Get rid of the temporary macro...
194 #undef PRINTER
195  }
196 
197  // Return the same stream:
198  return out;
199 }

◆ operator<<() [2/3]

template<typename T , typename U >
std::ostream& operator<< ( std::ostream &  out,
const std::pair< T, U > &  p 
)

Definition at line 40 of file PrintHelpers.cxx.

40  {
41  out << "(";
43  out << ", ";
45  out << ")";
46  return out;
47 }

◆ operator<<() [3/3]

template<typename T >
std::ostream& operator<< ( std::ostream &  out,
const std::vector< T > &  vec 
)

Helper operator to pretty-print the values of vectors.

Definition at line 51 of file PrintHelpers.cxx.

51  {
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 }
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:639
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::AuxTypeRegistry::getName
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
Definition: AuxTypeRegistry.cxx:881
CxxUtils::ConcurrentBitset::end
const_iterator end() const
Return an end iterator.
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
PRINTER
#define PRINTER(TYPE)
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
xAOD::int16_t
setScaleOne setStatusOne setSaturated int16_t
Definition: gFexGlobalRoI_v1.cxx:55
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::AuxTypeRegistry::getType
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
Definition: AuxTypeRegistry.cxx:908
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
SG::AuxTypeRegistry::getTypeName
std::string getTypeName(SG::auxid_t auxid) const
Return the type name of an aux data item.
Definition: AuxTypeRegistry.cxx:923
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::AuxTypeRegistry::getFlags
Flags getFlags(SG::auxid_t auxid) const
Return flags associated with an auxiliary variable.
Definition: AuxTypeRegistry.cxx:990
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
CxxUtils::ConcurrentBitset::begin
const_iterator begin() const
Return a begin iterator.
SG::Atomic
@ Atomic
Mark that this variable should only be accessed atomically.
Definition: AuxTypes.h:70
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
python.PyAthena.obj
obj
Definition: PyAthena.py:132