LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LCWarning.cc
Go to the documentation of this file.
1 #include "UTIL/LCWarning.h"
2 
3 #include <iostream>
4 #include "Exceptions.h"
5 
6 using namespace std;
7 
8 namespace UTIL{
9 
10 
12 LCWarning::LCWarning( ostream& outstream ) : _outstream(outstream) {
13 
14 
15  // ----- Warnings for SimTrackerHit ---------------------------------------
17  "SIMTRACKERHIT_DEPRECATED_GETDEDX",
18  "used DEPRECATED method SimTrackerHitImpl::getdEdx()\n"
19  "please change your code to use SimTrackerHitImpl::getEDep() instead"
20  );
21 
23  "SIMTRACKERHIT_DEPRECATED_SETDEDX",
24  "used DEPRECATED method SimTrackerHitImpl::setdEdx()\n"
25  "please change your code to use SimTrackerHitImpl::setEDep() instead"
26  );
27 
29  "SIMTRACKERHIT_DEPRECATED_GETCELLID",
30  "used DEPRECATED method SimTrackerHitImpl::getCellID()\n"
31  "please change your code to use SimTrackerHitImpl::getCellID0() instead"
32  );
33 
35  "SIMTRACKERHIT_DEPRECATED_SETCELLID",
36  "used DEPRECATED method SimTrackerHitImpl::setCellID()\n"
37  "please change your code to use SimTrackerHitImpl::setCellID0() instead"
38  );
39 
40  // ------------------------------------------------------------------------
41 
42 
43 
44  // ----- Warnings for TrackerHit ------------------------------------------
46  "TRACKERHIT_DEPRECATED_GETDEDX",
47  "used DEPRECATED method TrackerHitImpl::getdEdx()\n"
48  "please change your code to use TrackerHitImpl::getEDep()"
49  );
50 
52  "TRACKERHIT_DEPRECATED_SETDEDX",
53  "used DEPRECATED method TrackerHitImpl::setdEdx()\n"
54  "please change your code to use TrackerHitImpl::setEDep() instead."
55  );
56  // ------------------------------------------------------------------------
57 
58 
59 
60  // ----- Warnings for SimCalorimeterHit ---------------------------------------
62  "SIMCALORIMETERHIT_DEPRECATED_GETNMCPARTICLES",
63  "used DEPRECATED method SimCalorimeterHitImpl::getNMCParticles()\n"
64  "please change your code to use SimCalorimeterHitImpl::getNMCContributions() instead"
65  );
66  // ------------------------------------------------------------------------
67 
68 
69 
70  // ----- Warnings for MCParticle ------------------------------------------
72  "MCPARTICLE_DEPRECATED_GETNUMBEROFPARENTS",
73  "used DEPRECATED method MCParticleImpl::getNumberOfParents()\n"
74  "please change your code to use MCParticleImpl::getParents().size() instead."
75  );
76 
78  "MCPARTICLE_DEPRECATED_GETPARENT",
79  "used DEPRECATED method MCParticleImpl::getParent(i)\n"
80  "please change your code to use MCParticleImpl::getParents()[i] instead."
81  );
82 
84  "MCPARTICLE_DEPRECATED_GETNUMBEROFDAUGHTERS",
85  "used DEPRECATED method MCParticleImpl::getNumberOfDaughters()\n"
86  "please change your code to use MCParticleImpl::getDaughters().size() instead."
87  );
88 
90  "MCPARTICLE_DEPRECATED_GETDAUGHTER",
91  "used DEPRECATED method MCParticleImpl::getDaughter(i)\n"
92  "please change your code to use MCParticleImpl::getDaughters()[i] instead."
93  );
94  // ------------------------------------------------------------------------
95 
96 
97 }
99 
100 
101 
102 void LCWarning::registerWarning( const string& id, const string& txt, int max ) {
103 
104  if( _warning_cfg.find( id ) != _warning_cfg.end() ){
105  throw EVENT::Exception( std::string( "Warning [ "+id+" ] was already registered") );
106  }
107 
108  _warning_cfg[ id ].txt = txt ;
109  _warning_cfg[ id ].max = max ;
110  _warning_cfg[ id ].counter = max ;
111 
112  // _outstream << "registered warning " << id << "with max limit: " << max << endl;
113 }
114 
115 
116 
117 void LCWarning::printWarning( const string& id ) {
118 
119  // if max limit has been reached for displaying the warning, just return and do nothing.
120  if( _warning_cfg[ id ].counter <= 0 ){ return ; }
121 
122  _outstream << endl << endl
123  << endl << "=========== WARNING ========================================================="
124  << endl << _warning_cfg[ id ].txt;
125 
126  if( _warning_cfg[ id ].counter > 1 ){
127  _outstream << endl << "*** this warning will be printed (at most) "
128  << _warning_cfg[ id ].max << " time(s). [ "
129  << _warning_cfg[ id ].counter-1 << " time(s) left ]" ;
130  }
131  // max warnings have been reached.
132  else{
133  _outstream << endl << "*** the maximum amount of times for printing this warning has been reached."
134  << endl << "*** this warning will be printed one last time before the application exits." ;
135 
136  }
137 
138  _outstream << endl << "============================================================================="
139  << endl << endl ;
140 
141  // decrease counter
142  _warning_cfg[ id ].counter-- ;
143 }
144 
145 
146 
147 // destructor shows warnings one very last time before program ends
149 
150  bool first_warning = true;
151 
153  if( (*_warning_cfg_it).second.max != (*_warning_cfg_it).second.counter ){
154  if( first_warning ){
155  _outstream << endl << endl
156  << endl << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
157  << endl << "+++ FOLLOWING WARNINGS WERE FOUND:"
158  << endl << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
159  ;
160  first_warning = false ;
161  }
162  _outstream << endl << endl << _warning_cfg[ (*_warning_cfg_it).first ].txt ;
163  }
164  }
165  _outstream << endl << endl;
166 }
167 
168 
169 
170 // singleton
172 {
173  static LCWarning instance;
174  return instance;
175 }
176 
177 
178 
179 } // namespace UTIL
180 
Base exception class for LCIO - all other exceptions extend this.
Definition: Exceptions.h:21
std::ostream & _outstream
Definition: LCWarning.h:53
static LCWarning & instance
Definition: LCWarning.h:42
T endl(T...args)
std::map< std::string, _warning_cfg_struct >::iterator _warning_cfg_it
Definition: LCWarning.h:52
std::map< std::string, _warning_cfg_struct > _warning_cfg
Definition: LCWarning.h:51
void printWarning(const std::string &id)
print the warning text associated to the given id
Definition: LCWarning.cc:117
STL class.
void registerWarning(const std::string &id, const std::string &txt, int max=10)
register a new warning
Definition: LCWarning.cc:102
static LCWarning & getInstance()
Definition: LCWarning.cc:171
Utility class to show warnings in LCIO.
Definition: LCWarning.h:20
STL class.