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