XrdMonException.cc

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                             XrdMonException.cc                            */
00004 /*                                                                           */
00005 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
00006 /*                            All Rights Reserved                            */
00007 /*       Produced by Jacek Becla for Stanford University under contract      */
00008 /*              DE-AC02-76SF00515 with the Department of Energy              */
00009 /*****************************************************************************/
00010 
00011 // $Id: XrdMonException.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 #include "XrdMon/XrdMonException.hh"
00014 #include "XrdSys/XrdSysHeaders.hh"
00015 using std::cerr;
00016 using std::cout;
00017 using std::endl;
00018 
00019 map<err_t, XrdMonException::ErrInfo> XrdMonException::_oneTime;
00020 
00021 XrdMonException::XrdMonException(err_t err)
00022     : _err(err)
00023 {}
00024 
00025 XrdMonException::XrdMonException(err_t err,
00026                                      const string& s)
00027     : _err(err),
00028       _msg(s)
00029 {}
00030 
00031 XrdMonException::XrdMonException(err_t err,
00032                                      const char* s)
00033     : _err(err),
00034       _msg(s)
00035 {}
00036 
00037 void
00038 XrdMonException::printIt() const
00039 {
00040     cerr << "Caught exception " << err() 
00041          << " \"" << msg() << "\"" << endl;
00042 }
00043 
00044 void
00045 XrdMonException::printItOnce() const
00046 {
00047     map<err_t, ErrInfo >::iterator itr = _oneTime.find(err());
00048     if ( itr != _oneTime.end() ) {
00049         vector<string> v = itr->second.msgs;
00050         int i, size = v.size();
00051         for (i=0 ; i<size ; ++i ) {
00052             if ( v[i] == msg() ) {
00053                 ++itr->second.count;
00054                 cout << "this exception (" << err() << ") already "
00055                      << "printed " << itr->second.count << " times" << endl;
00056                 return; // this exception was already thrown
00057             }
00058         }
00059         v.push_back(msg());
00060         itr->second.count = 1;
00061     } else {
00062         ErrInfo ei;
00063         ei.msgs.push_back(msg());
00064         ei.count = 1;
00065         _oneTime[err()] = ei;
00066     }
00067     
00068     printIt();
00069 }
00070 

Generated on Tue Jul 5 14:46:43 2011 for ROOT_528-00b_version by  doxygen 1.5.1