/data3/calcul/jacquem/working_dir/Micromegas/micromegasFrameWork/lcio/src/cpp/src/UTIL/LCWarning.cc

Go to the documentation of this file.
00001 #include "UTIL/LCWarning.h"
00002 
00003 #include <iostream>
00004 #include "Exceptions.h"
00005 
00006 using namespace std;
00007 
00008 namespace UTIL{
00009 
00010 
00011 ///// add new warnings here ===================================================
00012 LCWarning::LCWarning( ostream& outstream ) : _outstream(outstream) {
00013 
00014 
00015     // ----- Warnings for SimTrackerHit ---------------------------------------
00016     registerWarning(
00017         "SIMTRACKERHIT_DEPRECATED_GETDEDX",
00018         "used DEPRECATED method SimTrackerHitImpl::getdEdx()\n"
00019         "please change your code to use SimTrackerHitImpl::getEDep() instead"
00020     );
00021 
00022     registerWarning(
00023         "SIMTRACKERHIT_DEPRECATED_SETDEDX",
00024         "used DEPRECATED method SimTrackerHitImpl::setdEdx()\n"
00025         "please change your code to use SimTrackerHitImpl::setEDep() instead"
00026     );
00027     // ------------------------------------------------------------------------
00028 
00029 
00030 
00031     // ----- Warnings for TrackerHit ------------------------------------------
00032     registerWarning(
00033         "TRACKERHIT_DEPRECATED_GETDEDX",
00034         "used DEPRECATED method TrackerHitImpl::getdEdx()\n"
00035         "please change your code to use TrackerHitImpl::getEDep()"
00036     );
00037 
00038     registerWarning(
00039         "TRACKERHIT_DEPRECATED_SETDEDX",
00040         "used DEPRECATED method TrackerHitImpl::setdEdx()\n"
00041         "please change your code to use TrackerHitImpl::setEDep() instead."
00042     );
00043     // ------------------------------------------------------------------------
00044 
00045 
00046 
00047     // ----- Warnings for SimCalorimeterHit ---------------------------------------
00048     registerWarning(
00049         "SIMCALORIMETERHIT_DEPRECATED_GETNMCPARTICLES",
00050         "used DEPRECATED method SimCalorimeterHitImpl::getNMCParticles()\n"
00051         "please change your code to use SimCalorimeterHitImpl::getNMCContributions() instead"
00052     );
00053     // ------------------------------------------------------------------------
00054 
00055 
00056 
00057     // ----- Warnings for MCParticle ------------------------------------------
00058     registerWarning(
00059         "MCPARTICLE_DEPRECATED_GETNUMBEROFPARENTS",
00060         "used DEPRECATED method MCParticleImpl::getNumberOfParents()\n"
00061         "please change your code to use MCParticleImpl::getParents().size() instead."
00062     );
00063 
00064     registerWarning(
00065         "MCPARTICLE_DEPRECATED_GETPARENT",
00066         "used DEPRECATED method MCParticleImpl::getParent(i)\n"
00067         "please change your code to use MCParticleImpl::getParents()[i] instead."
00068     );
00069 
00070     registerWarning(
00071         "MCPARTICLE_DEPRECATED_GETNUMBEROFDAUGHTERS",
00072         "used DEPRECATED method MCParticleImpl::getNumberOfDaughters()\n"
00073         "please change your code to use MCParticleImpl::getDaughters().size() instead."
00074     );
00075 
00076     registerWarning(
00077         "MCPARTICLE_DEPRECATED_GETDAUGHTER",
00078         "used DEPRECATED method MCParticleImpl::getDaughter(i)\n"
00079         "please change your code to use MCParticleImpl::getDaughters()[i] instead."
00080     );
00081     // ------------------------------------------------------------------------
00082 
00083 
00084 }
00085 ///// =========================================================================
00086 
00087 
00088 
00089 void LCWarning::registerWarning( const string id, const string txt, int max ) {
00090 
00091     if( _warning_cfg.find( id ) != _warning_cfg.end() ){
00092         throw EVENT::Exception( std::string( "Warning [ "+id+" ] was already registered") ); 
00093     }
00094 
00095     _warning_cfg[ id ].txt = txt ;
00096     _warning_cfg[ id ].max = max ;
00097     _warning_cfg[ id ].counter = max ;
00098 
00099     // _outstream << "registered warning " << id << "with max limit: " << max << endl;
00100 }
00101 
00102 
00103 
00104 void LCWarning::printWarning( const string id ) {
00105 
00106     // if max limit has been reached for displaying the warning, just return and do nothing.
00107     if( _warning_cfg[ id ].counter <= 0 ){ return ; }
00108 
00109     _outstream << endl << endl
00110          << endl << "=========== WARNING ========================================================="
00111          << endl << _warning_cfg[ id ].txt;
00112 
00113     if(  _warning_cfg[ id ].counter > 1 ){
00114         _outstream << endl << "*** this warning will be printed (at most) "
00115             << _warning_cfg[ id ].max << " time(s). [ "
00116             << _warning_cfg[ id ].counter-1 << " time(s) left ]" ;
00117     }
00118     // max warnings have been reached.
00119     else{
00120         _outstream << endl << "*** the maximum amount of times for printing this warning has been reached."
00121             << endl << "*** this warning will be printed one last time before the application exits." ;
00122 
00123     }
00124 
00125     _outstream << endl << "============================================================================="
00126          << endl << endl ;
00127 
00128     // decrease counter
00129     _warning_cfg[ id ].counter-- ;
00130 }
00131 
00132 
00133 
00134 // destructor shows warnings one very last time before program ends
00135 LCWarning::~LCWarning(){
00136 
00137     bool first_warning = true;
00138 
00139     for( _warning_cfg_it = _warning_cfg.begin(); _warning_cfg_it != _warning_cfg.end(); _warning_cfg_it++ ){
00140         if( (*_warning_cfg_it).second.max != (*_warning_cfg_it).second.counter ){
00141             if( first_warning ){
00142                 _outstream << endl << endl
00143                     << endl << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
00144                     << endl << "+++ FOLLOWING WARNINGS WERE FOUND:"
00145                     << endl << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
00146                 ;
00147                 first_warning = false ;
00148             }
00149             _outstream << endl << endl << _warning_cfg[ (*_warning_cfg_it).first ].txt ;
00150         }
00151     }
00152     _outstream << endl << endl;
00153 }
00154 
00155 
00156 
00157 // singleton
00158 LCWarning& LCWarning::getInstance()
00159 {
00160   static LCWarning instance;
00161   return instance;
00162 }
00163 
00164 
00165 
00166 } // namespace UTIL
00167 

Generated on Mon Jan 7 13:15:21 2013 for MicromegasFramework by  doxygen 1.4.7