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