Print.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <ctype.h>
00010 #include <string>
00011 #include <vector>
00012 #include <functional>
00013
00014
00015
00016 #include "AIDA/IHistogram1D.h"
00017 #include "AIDA/IHistogram2D.h"
00018 #include "AIDA/IHistogram3D.h"
00019 #include "AIDA/IProfile1D.h"
00020 #include "AIDA/IProfile2D.h"
00021
00022
00023
00024 #include "GaudiKernel/DataObject.h"
00025 #include "GaudiKernel/IRegistry.h"
00026 #include "GaudiKernel/StatEntity.h"
00027 #include "GaudiKernel/INTuple.h"
00028
00029
00030
00031 #include "GaudiAlg/HistoID.h"
00032 #include "GaudiAlg/Print.h"
00033
00034
00035
00036 #ifdef __ICC
00037
00038
00039 #pragma warning(disable:2259)
00040 #endif
00041 #include "boost/format.hpp"
00042 #include "boost/lexical_cast.hpp"
00043
00049
00050 namespace
00051 {
00056 static const std::string s_invalidLocation = "<UNKNOWN LOCATION>" ;
00057 }
00058
00059 const std::string& GaudiAlg::Print::location
00060 ( const AIDA::IHistogram* aida )
00061 {
00062 if ( 0 == aida ) { return s_invalidLocation ; }
00063 const DataObject* object = dynamic_cast<const DataObject*>( aida ) ;
00064 if ( 0 == object ) { return s_invalidLocation ; }
00065 IRegistry* registry = object->registry() ;
00066 if ( 0 == registry ) { return s_invalidLocation ; }
00067 return registry->identifier() ;
00068 }
00069
00070 void GaudiAlg::Print1D::print
00071 ( MsgStream & stream,
00072 const AIDA::IHistogram1D* aida ,
00073 const GaudiAlg::HistoID& ID )
00074 { stream << toString ( aida , ID ) << endmsg ; }
00075
00076 std::string GaudiAlg::Print1D::toString
00077 ( const AIDA::IHistogram1D* aida ,
00078 const GaudiAlg::HistoID& ID )
00079 {
00080 boost::format fmt
00081 ( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|" ) ;
00082 fmt % ID.idAsString() % aida->title();
00083 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00084 fmt % aida->mean() % aida->rms() ;
00085
00086 return fmt.str() ;
00087 }
00088
00089 void GaudiAlg::Print2D::print
00090 ( MsgStream & stream,
00091 const AIDA::IHistogram2D* aida ,
00092 const GaudiAlg::HistoID& ID )
00093 { stream << toString ( aida , ID ) << endmsg ; }
00094
00095 std::string GaudiAlg::Print2D::toString
00096 ( const AIDA::IHistogram2D* aida ,
00097 const GaudiAlg::HistoID& ID )
00098 {
00099 boost::format fmt
00100 ( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|" ) ;
00101 fmt % ID.idAsString() % aida->title();
00102 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00103 fmt % aida->meanX() % aida->rmsX() ;
00104 fmt % aida->meanY() % aida->rmsY() ;
00105
00106 return fmt.str() ;
00107 }
00108
00109 void GaudiAlg::Print3D::print
00110 ( MsgStream & stream,
00111 const AIDA::IHistogram3D* aida ,
00112 const GaudiAlg::HistoID& ID )
00113 { stream << toString ( aida , ID ) << endmsg ; }
00114
00115 std::string GaudiAlg::Print3D::toString
00116 ( const AIDA::IHistogram3D* aida ,
00117 const GaudiAlg::HistoID& ID )
00118 {
00119 boost::format fmt
00120 ( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|,<Z>/sZ=%|.5|/%|-.5|" ) ;
00121 fmt % ID.idAsString() % aida->title();
00122 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00123 fmt % aida->meanX() % aida->rmsX() ;
00124 fmt % aida->meanY() % aida->rmsY() ;
00125 fmt % aida->meanZ() % aida->rmsZ() ;
00126
00127 return fmt.str() ;
00128 }
00129
00130 void GaudiAlg::Print1DProf::print
00131 ( MsgStream & stream,
00132 const AIDA::IProfile1D* aida ,
00133 const GaudiAlg::HistoID& ID )
00134 { stream << toString ( aida , ID ) << endmsg ; }
00135
00136 std::string GaudiAlg::Print1DProf::toString
00137 ( const AIDA::IProfile1D* aida ,
00138 const GaudiAlg::HistoID& ID )
00139 {
00140 boost::format fmt
00141 ( " ID=%|-25|%|30t| \"%|.55s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|" ) ;
00142 fmt % ID.idAsString() % aida->title();
00143 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00144 fmt % aida->mean() % aida->rms() ;
00145
00146 return fmt.str() ;
00147 }
00148
00149 void GaudiAlg::Print2DProf::print
00150 ( MsgStream & stream,
00151 const AIDA::IProfile2D* aida ,
00152 const GaudiAlg::HistoID& ID )
00153 { stream << toString ( aida , ID ) << endmsg ; }
00154
00155 std::string GaudiAlg::Print2DProf::toString
00156 ( const AIDA::IProfile2D* aida ,
00157 const GaudiAlg::HistoID& ID )
00158 {
00159 boost::format fmt
00160 ( " ID=%|-25|%|30t| \"%|.55s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|" );
00161 fmt % ID.idAsString() % aida->title();
00162 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00163 fmt % aida->meanX() % aida->rmsX() ;
00164 fmt % aida->meanY() % aida->rmsY() ;
00165
00166 return fmt.str() ;
00167 }
00168
00169 std::string GaudiAlg::PrintStat::print
00170 ( const StatEntity& stat ,
00171 const std::string& tag )
00172 {
00173 return Gaudi::Utils::formatAsTableRow ( tag , stat ) ;
00174 }
00175
00176 std::string GaudiAlg::PrintTuple::print
00177 ( const INTuple* tuple ,
00178 const GaudiAlg::TupleID& ID )
00179 {
00180 boost::format fmt ( " ID=%|-12|%|18t|%|-s|") ;
00181 fmt % ID.idAsString() % print ( tuple ) ;
00182 return fmt.str() ;
00183 }
00184
00185 namespace
00186 {
00187 std::string _print ( const INTuple::ItemContainer& items )
00188 {
00189 std::string str ;
00190 for ( INTuple::ItemContainer::const_iterator iitem = items.begin() ;
00191 items.end() != iitem ; ++iitem )
00192 {
00193 if ( items.begin() != iitem ) { str +="," ; }
00194 const INTupleItem* item = *iitem ;
00195 if ( 0 == item ) { continue ; }
00196 str += item->name() ;
00197 if ( 0 != item->ndim() )
00198 { str += '[' + boost::lexical_cast<std::string>( item->ndim() ) + ']'; }
00199 if ( item->hasIndex() ) { str += "/V" ; }
00200 }
00201 return str ;
00202 }
00203 }
00204
00205 std::string GaudiAlg::PrintTuple::print
00206 ( const INTuple* tuple )
00207 {
00208 boost::format fmt
00209 ( "Title=\"%|.39s|\" %|48t|#items=%|-3|%|50t|{%|.81s|}" ) ;
00210 fmt % tuple->title() ;
00211 fmt % tuple->items().size() ;
00212 fmt % _print( tuple->items() ) ;
00213 return fmt.str() ;
00214 }
00215
00216
00217
00218
00219
00220
00221