CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/Utilities/plugins/ExceptionGenerator.cc

Go to the documentation of this file.
00001 #include "ExceptionGenerator.h"
00002 
00003 #include <iostream>
00004 #include <typeinfo>
00005 #include <map>
00006 #include <sstream>
00007 
00008 #include "xgi/Method.h"
00009 #include "xgi/Utils.h"
00010 
00011 #include "cgicc/Cgicc.h"
00012 #include "cgicc/FormEntry.h"
00013 #include "cgicc/HTMLClasses.h"
00014 
00015 #include "FWCore/Utilities/interface/Exception.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 #include "boost/tokenizer.hpp"
00019 
00020 #include <stdio.h>
00021 
00022 using namespace std;
00023 
00024 namespace evf{
00025 
00026     const std::string ExceptionGenerator::menu[menu_items] =  
00027       {"Sleep x ms", "SleepForever", "Cms Exception", "Exit with error", "Abort", "Unknown Exception", "Endless loop", "Generate Error Message", "Segfault", 
00028       "Burn CPU"};
00029 
00030     ExceptionGenerator::ExceptionGenerator( const edm::ParameterSet& pset) : 
00031       ModuleWeb("ExceptionGenerator"), 
00032       actionId_(pset.getUntrackedParameter<int>("defaultAction",-1)),
00033       intqualifier_(pset.getUntrackedParameter<int>("defaultQualifier",0)), 
00034       actionRequired_(actionId_!=-1)
00035     {
00036       
00037     }
00038   void ExceptionGenerator::beginJob()
00039   {
00040   }
00041   void ExceptionGenerator::beginRun(edm::Run& r)
00042   {
00043   }
00044   void ExceptionGenerator::analyze(const edm::Event & e, const edm::EventSetup& c)
00045     {
00046       float dummy = 0.;
00047       if(actionRequired_) 
00048         {
00049           int *pi = 0;
00050           int ind = 0; 
00051           int step = 1; 
00052           switch(actionId_)
00053             {
00054             case 0:
00055               ::usleep(intqualifier_*1000);
00056               break;
00057             case 1:
00058 	      ::sleep(0xFFFFFFF);
00059               break;
00060             case 2:
00061               throw cms::Exception(qualifier_) << "This exception was generated by the ExceptionGenerator";
00062               break;
00063             case 3:
00064               exit(-1);
00065               break;
00066             case 4:
00067               abort();
00068               break;
00069             case 5:
00070               throw qualifier_;
00071               break;
00072             case 6:
00073               while(1){ind+=step; if(ind>1000000) step = -1; if(ind==0) step = 1;}
00074               break;
00075             case 7:
00076               edm::LogError("TestErrorMessage") << qualifier_;
00077               break;
00078             case 8:
00079               *pi=0;
00080               break;
00081             case 9:
00082               for(unsigned int j=0; j<intqualifier_*1000;j++){
00083                 dummy += sqrt(log(float(j+1)))/float(j*j);
00084               }
00085               break;
00086 
00087             }
00088         }
00089     }
00090     
00091     void ExceptionGenerator::endLuminosityBlock(edm::LuminosityBlock const &lb, edm::EventSetup const &es)
00092     {
00093 
00094     }
00095     
00096     void ExceptionGenerator::defaultWebPage(xgi::Input *in, xgi::Output *out)
00097     {
00098       std::string path;
00099       std::string urn;
00100       std::string mname;
00101       std::string query;
00102       try 
00103         {
00104           cgicc::Cgicc cgi(in);
00105           if ( xgi::Utils::hasFormElement(cgi,"exceptiontype") )
00106             {
00107               actionId_ = xgi::Utils::getFormElement(cgi, "exceptiontype")->getIntegerValue();
00108               qualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getValue();
00109               intqualifier_ =  xgi::Utils::getFormElement(cgi, "qualifier")->getIntegerValue();
00110               actionRequired_ = true;
00111             }
00112           if ( xgi::Utils::hasFormElement(cgi,"module") )
00113             mname = xgi::Utils::getFormElement(cgi, "module")->getValue();
00114           cgicc::CgiEnvironment cgie(in);
00115           if(original_referrer_ == "")
00116             original_referrer_ = cgie.getReferrer();
00117           path = cgie.getPathInfo();
00118           query = cgie.getQueryString();
00119           if(actionId_>=0)
00120             std::cout << " requested action " << actionId_ << " " 
00121                       << menu[actionId_] << ". Number of cycles " 
00122                       << intqualifier_ << std::endl;
00123         }
00124       catch (const std::exception & e) 
00125         {
00126           // don't care if it did not work
00127         }
00128 
00129       using std::endl;
00130       *out << "<html>"                                                   << endl;
00131       *out << "<head>"                                                   << endl;
00132 
00133 
00134       *out << "<STYLE type=\"text/css\"> #T1 {border-width: 2px; border: solid blue; text-align: center} </STYLE> "                                      << endl; 
00135       *out << "<link type=\"text/css\" rel=\"stylesheet\"";
00136       *out << " href=\"/" <<  urn
00137            << "/styles.css\"/>"                   << endl;
00138 
00139       *out << "<title>" << moduleName_
00140            << " MAIN</title>"                                            << endl;
00141 
00142       *out << "</head>"                                                  << endl;
00143       *out << "<body onload=\"loadXMLDoc()\">"                           << endl;
00144       *out << "<table border=\"0\" width=\"100%\">"                      << endl;
00145       *out << "<tr>"                                                     << endl;
00146       *out << "  <td align=\"left\">"                                    << endl;
00147       *out << "    <img"                                                 << endl;
00148       *out << "     align=\"middle\""                                    << endl;
00149       *out << "     src=\"/evf/images/systemerror.jpg\""                 << endl;
00150       *out << "     alt=\"main\""                                        << endl;
00151       *out << "     width=\"90\""                                        << endl;
00152       *out << "     height=\"64\""                                       << endl;
00153       *out << "     border=\"\"/>"                                       << endl;
00154       *out << "    <b>"                                                  << endl;
00155       *out <<             moduleName_                                    << endl;
00156       *out << "    </b>"                                                 << endl;
00157       *out << "  </td>"                                                  << endl;
00158       *out << "  <td width=\"32\">"                                      << endl;
00159       *out << "    <a href=\"/urn:xdaq-application:lid=3\">"             << endl;
00160       *out << "      <img"                                               << endl;
00161       *out << "       align=\"middle\""                                  << endl;
00162       *out << "       src=\"/hyperdaq/images/HyperDAQ.jpg\""             << endl;
00163       *out << "       alt=\"HyperDAQ\""                                  << endl;
00164       *out << "       width=\"32\""                                      << endl;
00165       *out << "       height=\"32\""                                     << endl;
00166       *out << "       border=\"\"/>"                                     << endl;
00167       *out << "    </a>"                                                 << endl;
00168       *out << "  </td>"                                                  << endl;
00169       *out << "  <td width=\"32\">"                                      << endl;
00170       *out << "  </td>"                                                  << endl;
00171       *out << "  <td width=\"32\">"                                      << endl;
00172       *out << "    <a href=\"" << original_referrer_  << "\">"           << endl;
00173       *out << "      <img"                                               << endl;
00174       *out << "       align=\"middle\""                                  << endl;
00175       *out << "       src=\"/evf/images/spoticon.jpg\""                  << endl;
00176       *out << "       alt=\"main\""                                      << endl;
00177       *out << "       width=\"32\""                                      << endl;
00178       *out << "       height=\"32\""                                     << endl;
00179       *out << "       border=\"\"/>"                                     << endl;
00180       *out << "    </a>"                                                 << endl;
00181       *out << "  </td>"                                                  << endl;
00182       *out << "</tr>"                                                    << endl;
00183       *out << "</table>"                                                 << endl;
00184 
00185       *out << "<hr/>"                                                    << endl;
00186   
00187       *out << cgicc::form().set("method","GET").set("action", path ) 
00188            << std::endl;
00189       boost::char_separator<char> sep("&");
00190       boost::tokenizer<boost::char_separator<char> > tokens(query, sep);
00191       for (boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = tokens.begin();
00192            tok_iter != tokens.end(); ++tok_iter){
00193         size_t pos = (*tok_iter).find_first_of("=");
00194         if(pos != std::string::npos){
00195           std::string first  = (*tok_iter).substr(0    ,                        pos);
00196           std::string second = (*tok_iter).substr(pos+1, (*tok_iter).length()-pos-1);
00197           *out << cgicc::input().set("type","hidden").set("name",first).set("value", second) 
00198                << std::endl;
00199         }
00200       }
00201 
00202       *out << "Select   "                                                << endl;
00203       *out << cgicc::select().set("name","exceptiontype")     << std::endl;
00204       char istring[2];
00205 
00206       for(int i = 0; i < menu_items; i++)
00207         {
00208           sprintf(istring,"%d",i);
00209           *out << cgicc::option().set("value",istring) << menu[i] << cgicc::option()       << std::endl;
00210         }
00211       *out << cgicc::select()        << std::endl;
00212       *out << "<br>"                                                     << endl;
00213       *out << "Qualifier"                                                << endl;
00214       *out << cgicc::input().set("type","text").set("name","qualifier")              << std::endl;
00215       *out << cgicc::input().set("type","submit").set("value","Do It !")             << std::endl;
00216       *out << cgicc::form()                                                << std::endl;  
00217 
00218       *out << "</body>"                                                  << endl;
00219       *out << "</html>"                                                  << endl;
00220     }
00221   void ExceptionGenerator::publish(xdata::InfoSpace *is)
00222   {
00223   }
00224 } // end namespace evf