| The Gaudi Framework v32r1 (f65d50dc)

Print.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // STD & STL
5 // ============================================================================
6 #include <ctype.h>
7 #include <functional>
8 #include <string>
9 #include <vector>
10 // ============================================================================
11 // AIDA
12 // ============================================================================
13 #include "AIDA/IHistogram1D.h"
14 #include "AIDA/IHistogram2D.h"
15 #include "AIDA/IHistogram3D.h"
16 #include "AIDA/IProfile1D.h"
17 #include "AIDA/IProfile2D.h"
18 // ============================================================================
19 // GaudiKernel
20 // ============================================================================
21 #include "GaudiKernel/DataObject.h"
22 #include "GaudiKernel/INTuple.h"
23 #include "GaudiKernel/IRegistry.h"
24 #include "GaudiKernel/StatEntity.h"
25 // ============================================================================
26 // GaudiAlg
27 // ============================================================================
28 #include "GaudiAlg/HistoID.h"
29 #include "GaudiAlg/Print.h"
30 // ============================================================================
31 // Boost
32 // ============================================================================
33 #include "boost/format.hpp"
34 // ============================================================================
40 // ============================================================================
41 namespace {
46 static const std::string s_invalidLocation = "<UNKNOWN LOCATION>";
47 } // namespace
48 // ============================================================================
49 const std::string& GaudiAlg::Print::location( const AIDA::IHistogram* aida ) {
50 if ( !aida ) { return s_invalidLocation; }
51 const DataObject* object = dynamic_cast<const DataObject*>( aida );
52 if ( !object ) { return s_invalidLocation; }
53 IRegistry* registry = object->registry();
54 if ( !registry ) { return s_invalidLocation; }
55 return registry->identifier();
56 }
57 // ============================================================================
58 void GaudiAlg::Print1D::print( MsgStream& stream, const AIDA::IHistogram1D* aida, const GaudiAlg::HistoID& ID ) {
59 stream << toString( aida, ID ) << endmsg;
60 }
61 // ============================================================================
62 std::string GaudiAlg::Print1D::toString( const AIDA::IHistogram1D* aida, const GaudiAlg::HistoID& ID ) {
63 boost::format fmt( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|" );
64 fmt % ID.idAsString() % aida->title();
65 fmt % ( aida->allEntries() - aida->extraEntries() ) % aida->allEntries();
66 fmt % aida->mean() % aida->rms();
67 //
68 return fmt.str();
69 }
70 // ============================================================================
71 void GaudiAlg::Print2D::print( MsgStream& stream, const AIDA::IHistogram2D* aida, const GaudiAlg::HistoID& ID ) {
72 stream << toString( aida, ID ) << endmsg;
73 }
74 // ============================================================================
75 std::string GaudiAlg::Print2D::toString( const AIDA::IHistogram2D* aida, const GaudiAlg::HistoID& ID ) {
76 boost::format fmt( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|" );
77 fmt % ID.idAsString() % aida->title();
78 fmt % ( aida->allEntries() - aida->extraEntries() ) % aida->allEntries();
79 fmt % aida->meanX() % aida->rmsX();
80 fmt % aida->meanY() % aida->rmsY();
81 //
82 return fmt.str();
83 }
84 // ============================================================================
85 void GaudiAlg::Print3D::print( MsgStream& stream, const AIDA::IHistogram3D* aida, const GaudiAlg::HistoID& ID ) {
86 stream << toString( aida, ID ) << endmsg;
87 }
88 // ============================================================================
89 std::string GaudiAlg::Print3D::toString( const AIDA::IHistogram3D* aida, const GaudiAlg::HistoID& ID ) {
90 boost::format fmt( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| "
91 "Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|,<Z>/sZ=%|.5|/%|-.5|" );
92 fmt % ID.idAsString() % aida->title();
93 fmt % ( aida->allEntries() - aida->extraEntries() ) % aida->allEntries();
94 fmt % aida->meanX() % aida->rmsX();
95 fmt % aida->meanY() % aida->rmsY();
96 fmt % aida->meanZ() % aida->rmsZ();
97 //
98 return fmt.str();
99 }
100 // ============================================================================
101 void GaudiAlg::Print1DProf::print( MsgStream& stream, const AIDA::IProfile1D* aida, const GaudiAlg::HistoID& ID ) {
102 stream << toString( aida, ID ) << endmsg;
103 }
104 // ============================================================================
105 std::string GaudiAlg::Print1DProf::toString( const AIDA::IProfile1D* aida, const GaudiAlg::HistoID& ID ) {
106 boost::format fmt( " ID=%|-25|%|30t| \"%|.55s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|" );
107 fmt % ID.idAsString() % aida->title();
108 fmt % ( aida->allEntries() - aida->extraEntries() ) % aida->allEntries();
109 fmt % aida->mean() % aida->rms();
110 //
111 return fmt.str();
112 }
113 // ============================================================================
114 void GaudiAlg::Print2DProf::print( MsgStream& stream, const AIDA::IProfile2D* aida, const GaudiAlg::HistoID& ID ) {
115 stream << toString( aida, ID ) << endmsg;
116 }
117 // ============================================================================
118 std::string GaudiAlg::Print2DProf::toString( const AIDA::IProfile2D* aida, const GaudiAlg::HistoID& ID ) {
119 boost::format fmt( " ID=%|-25|%|30t| \"%|.55s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|" );
120 fmt % ID.idAsString() % aida->title();
121 fmt % ( aida->allEntries() - aida->extraEntries() ) % aida->allEntries();
122 fmt % aida->meanX() % aida->rmsX();
123 fmt % aida->meanY() % aida->rmsY();
124 //
125 return fmt.str();
126 }
127 // ============================================================================
128 std::string GaudiAlg::PrintStat::print( const StatEntity& stat, const std::string& tag ) {
129 std::ostringstream ost;
130 stat.print( ost, true, tag );
131 return ost.str();
132 }
133 // ============================================================================
134 std::string GaudiAlg::PrintTuple::print( const INTuple* tuple, const GaudiAlg::TupleID& ID ) {
135 boost::format fmt( " ID=%|-12|%|18t|%|-s|" );
136 fmt % ID.idAsString() % print( tuple );
137 return fmt.str();
138 }
139 // ============================================================================
140 namespace {
141 std::string _print( const INTuple::ItemContainer& items ) {
142 std::string str;
143 for ( const auto& item : items ) {
144 if ( !item ) { continue; }
145 if ( !str.empty() ) { str += ","; }
146 str += item->name();
147 if ( 0 != item->ndim() ) { str += '[' + std::to_string( item->ndim() ) + ']'; }
148 if ( item->hasIndex() ) { str += "/V"; }
149 }
150 return str;
151 }
152 } // namespace
153 // ============================================================================
154 std::string GaudiAlg::PrintTuple::print( const INTuple* tuple ) {
155 boost::format fmt( "Title=\"%|.39s|\" %|48t|#items=%|-3|%|50t|{%|.81s|}" );
156 fmt % tuple->title();
157 fmt % tuple->items().size();
158 fmt % _print( tuple->items() );
159 return fmt.str();
160 }
161 // ============================================================================
162
163 // ============================================================================
164 // The END
165 // ============================================================================
GaudiAlg::PrintTuple::print
static std::string print(const INTuple *tuple, const GaudiAlg::TupleID &ID)
Definition: Print.cpp:134
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
std::string::empty
T empty(T... args)
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
GaudiAlg::PrintStat::print
static std::string print(const StatEntity &stat, const std::string &tag)
Definition: Print.cpp:128
GaudiAlg::Print3D::print
static void print(MsgStream &stream, const AIDA::IHistogram3D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:85
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:334
std::to_string
T to_string(T... args)
GaudiAlg::Print1D::toString
static std::string toString(const AIDA::IHistogram1D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:62
INTuple::title
virtual const std::string & title() const =0
Object title.
GaudiAlg::Print1DProf::print
static void print(MsgStream &stream, const AIDA::IProfile1D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:101
std::string
STL class.
INTuple
NTuple interface class definition.
Definition: INTuple.h:81
GaudiAlg::ID::idAsString
GAUDI_API LiteralID idAsString() const
Return ID as string, for both numeric and literal IDs.
Definition: GaudiHistoID.cpp:20
HistoID.h
INTuple.h
GaudiAlg::Print::location
static const std::string & location(const AIDA::IHistogram *aida)
Definition: Print.cpp:49
std::ostringstream
STL class.
std::ostringstream::str
T str(T... args)
IRegistry.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
Print.h
collection of useful utilities to print certain objects (currently used for implementation in class G...
GaudiAlg::Print3D::toString
static std::string toString(const AIDA::IHistogram3D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:89
GaudiPluginService.cpluginsvc.registry
def registry()
Definition: cpluginsvc.py:71
GaudiAlg::Print1D::print
static void print(MsgStream &stream, const AIDA::IHistogram1D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:58
std::vector::size
T size(T... args)
std::vector
STL class.
GaudiAlg::Print2DProf::print
static void print(MsgStream &stream, const AIDA::IProfile2D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:114
StatEntity.h
GaudiAlg::Print2D::print
static void print(MsgStream &stream, const AIDA::IHistogram2D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:71
GaudiAlg::Print2D::toString
static std::string toString(const AIDA::IHistogram2D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:75
INTuple::items
virtual ItemContainer & items()=0
Access item container.
GaudiAlg::Print1DProf::toString
static std::string toString(const AIDA::IProfile1D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:105
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
GaudiAlg::Print2DProf::toString
static std::string toString(const AIDA::IProfile2D *aida, const GaudiAlg::HistoID &ID)
Definition: Print.cpp:118
GaudiAlg::ID
ID class for Histogram and Ntuples.
Definition: GaudiHistoID.h:43
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
DataObject.h