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 #include "boost/format.hpp"
00037 #include "boost/lexical_cast.hpp"
00038
00044
00045 namespace
00046 {
00051 static const std::string s_invalidLocation = "<UNKNOWN LOCATION>" ;
00052 }
00053
00054 const std::string& GaudiAlg::Print::location
00055 ( const AIDA::IHistogram* aida )
00056 {
00057 if ( 0 == aida ) { return s_invalidLocation ; }
00058 const DataObject* object = dynamic_cast<const DataObject*>( aida ) ;
00059 if ( 0 == object ) { return s_invalidLocation ; }
00060 IRegistry* registry = object->registry() ;
00061 if ( 0 == registry ) { return s_invalidLocation ; }
00062 return registry->identifier() ;
00063 }
00064
00065 void GaudiAlg::Print1D::print
00066 ( MsgStream & stream,
00067 const AIDA::IHistogram1D* aida ,
00068 const GaudiAlg::HistoID& ID )
00069 { stream << toString ( aida , ID ) << endmsg ; }
00070
00071 std::string GaudiAlg::Print1D::toString
00072 ( const AIDA::IHistogram1D* aida ,
00073 const GaudiAlg::HistoID& ID )
00074 {
00075 boost::format fmt
00076 ( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|" ) ;
00077 fmt % ID.idAsString() % aida->title();
00078 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00079 fmt % aida->mean() % aida->rms() ;
00080
00081 return fmt.str() ;
00082 }
00083
00084 void GaudiAlg::Print2D::print
00085 ( MsgStream & stream,
00086 const AIDA::IHistogram2D* aida ,
00087 const GaudiAlg::HistoID& ID )
00088 { stream << toString ( aida , ID ) << endmsg ; }
00089
00090 std::string GaudiAlg::Print2D::toString
00091 ( const AIDA::IHistogram2D* aida ,
00092 const GaudiAlg::HistoID& ID )
00093 {
00094 boost::format fmt
00095 ( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|" ) ;
00096 fmt % ID.idAsString() % aida->title();
00097 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00098 fmt % aida->meanX() % aida->rmsX() ;
00099 fmt % aida->meanY() % aida->rmsY() ;
00100
00101 return fmt.str() ;
00102 }
00103
00104 void GaudiAlg::Print3D::print
00105 ( MsgStream & stream,
00106 const AIDA::IHistogram3D* aida ,
00107 const GaudiAlg::HistoID& ID )
00108 { stream << toString ( aida , ID ) << endmsg ; }
00109
00110 std::string GaudiAlg::Print3D::toString
00111 ( const AIDA::IHistogram3D* aida ,
00112 const GaudiAlg::HistoID& ID )
00113 {
00114 boost::format fmt
00115 ( " ID=%|-25|%|30t| \"%|.45s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|,<Z>/sZ=%|.5|/%|-.5|" ) ;
00116 fmt % ID.idAsString() % aida->title();
00117 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00118 fmt % aida->meanX() % aida->rmsX() ;
00119 fmt % aida->meanY() % aida->rmsY() ;
00120 fmt % aida->meanZ() % aida->rmsZ() ;
00121
00122 return fmt.str() ;
00123 }
00124
00125 void GaudiAlg::Print1DProf::print
00126 ( MsgStream & stream,
00127 const AIDA::IProfile1D* aida ,
00128 const GaudiAlg::HistoID& ID )
00129 { stream << toString ( aida , ID ) << endmsg ; }
00130
00131 std::string GaudiAlg::Print1DProf::toString
00132 ( const AIDA::IProfile1D* aida ,
00133 const GaudiAlg::HistoID& ID )
00134 {
00135 boost::format fmt
00136 ( " ID=%|-25|%|30t| \"%|.55s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|" ) ;
00137 fmt % ID.idAsString() % aida->title();
00138 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00139 fmt % aida->mean() % aida->rms() ;
00140
00141 return fmt.str() ;
00142 }
00143
00144 void GaudiAlg::Print2DProf::print
00145 ( MsgStream & stream,
00146 const AIDA::IProfile2D* aida ,
00147 const GaudiAlg::HistoID& ID )
00148 { stream << toString ( aida , ID ) << endmsg ; }
00149
00150 std::string GaudiAlg::Print2DProf::toString
00151 ( const AIDA::IProfile2D* aida ,
00152 const GaudiAlg::HistoID& ID )
00153 {
00154 boost::format fmt
00155 ( " ID=%|-25|%|30t| \"%|.55s|\" %|79t| Ents/All=%|5|/%|-5|<X>/sX=%|.5|/%|-.5|,<Y>/sY=%|.5|/%|-.5|" );
00156 fmt % ID.idAsString() % aida->title();
00157 fmt % (aida->allEntries()-aida->extraEntries()) % aida->allEntries() ;
00158 fmt % aida->meanX() % aida->rmsX() ;
00159 fmt % aida->meanY() % aida->rmsY() ;
00160
00161 return fmt.str() ;
00162 }
00163
00164 std::string GaudiAlg::PrintStat::print
00165 ( const StatEntity& stat ,
00166 const std::string& tag )
00167 {
00168 return Gaudi::Utils::formatAsTableRow ( tag , stat ) ;
00169 }
00170
00171 std::string GaudiAlg::PrintTuple::print
00172 ( const INTuple* tuple ,
00173 const GaudiAlg::TupleID& ID )
00174 {
00175 boost::format fmt ( " ID=%|-12|%|18t|%|-s|") ;
00176 fmt % ID.idAsString() % print ( tuple ) ;
00177 return fmt.str() ;
00178 }
00179
00180 namespace
00181 {
00182 std::string _print ( const INTuple::ItemContainer& items )
00183 {
00184 std::string str ;
00185 for ( INTuple::ItemContainer::const_iterator iitem = items.begin() ;
00186 items.end() != iitem ; ++iitem )
00187 {
00188 if ( items.begin() != iitem ) { str +="," ; }
00189 const INTupleItem* item = *iitem ;
00190 if ( 0 == item ) { continue ; }
00191 str += item->name() ;
00192 if ( 0 != item->ndim() )
00193 { str += '[' + boost::lexical_cast<std::string>( item->ndim() ) + ']'; }
00194 if ( item->hasIndex() ) { str += "/V" ; }
00195 }
00196 return str ;
00197 }
00198 }
00199
00200 std::string GaudiAlg::PrintTuple::print
00201 ( const INTuple* tuple )
00202 {
00203 boost::format fmt
00204 ( "Title=\"%|.39s|\" %|48t|#items=%|-3|%|50t|{%|.81s|}" ) ;
00205 fmt % tuple->title() ;
00206 fmt % tuple->items().size() ;
00207 fmt % _print( tuple->items() ) ;
00208 return fmt.str() ;
00209 }
00210
00211
00212
00213
00214
00215
00216