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 <stdio.h>
00019
00020 using namespace std;
00021
00022 namespace evf{
00023
00024 const std::string ExceptionGenerator::menu[menu_items] =
00025 {"Sleep x ms", "SleepForever", "Cms Exception", "Exit with error", "Abort", "Unknown Exception", "Endless loop", "Generate Error Message" };
00026
00027 ExceptionGenerator::ExceptionGenerator( const edm::ParameterSet& pset) :
00028 ModuleWeb("ExceptionGenerator"), actionRequired_(false), actionId_(-1)
00029 {
00030
00031
00032 }
00033 void ExceptionGenerator::analyze(const edm::Event & e, const edm::EventSetup& c)
00034 {
00035 if(actionRequired_)
00036 {
00037 int ind = 0;
00038 int step = 1;
00039 switch(actionId_)
00040 {
00041 case 0:
00042 ::usleep(intqualifier_*1000);
00043 break;
00044 case 1:
00045 ::sleep(0xFFFFFFF);
00046 break;
00047 case 2:
00048 throw cms::Exception(qualifier_) << "This exception was generated by the ExceptionGenerator";
00049 break;
00050 case 3:
00051 exit(-1);
00052 break;
00053 case 4:
00054 abort();
00055 break;
00056 case 5:
00057 throw qualifier_;
00058 break;
00059 case 6:
00060 while(1){ind+=step; if(ind>1000000) step = -1; if(ind==0) step = 1;}
00061 break;
00062 case 7:
00063 edm::LogError("TestErrorMessage") << qualifier_;
00064 }
00065 }
00066 }
00067
00068 void ExceptionGenerator::endLuminosityBlock(edm::LuminosityBlock const &lb, edm::EventSetup const &es)
00069 {
00070
00071 }
00072
00073 void ExceptionGenerator::defaultWebPage(xgi::Input *in, xgi::Output *out)
00074 {
00075
00076 std::string path;
00077 std::string urn;
00078 std::string mname;
00079 try
00080 {
00081 cgicc::Cgicc cgi(in);
00082 if ( xgi::Utils::hasFormElement(cgi,"exceptiontype") )
00083 {
00084 actionId_ = xgi::Utils::getFormElement(cgi, "exceptiontype")->getIntegerValue();
00085 if(actionId_>0)
00086 qualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getValue();
00087 else
00088 intqualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getIntegerValue();
00089 actionRequired_ = true;
00090 }
00091 if ( xgi::Utils::hasFormElement(cgi,"module") )
00092 mname = xgi::Utils::getFormElement(cgi, "module")->getValue();
00093 cgicc::CgiEnvironment cgie(in);
00094 if(original_referrer_ == "")
00095 original_referrer_ = cgie.getReferrer();
00096 path = cgie.getPathInfo() + "?" + cgie.getQueryString();
00097
00098 }
00099 catch (const std::exception & e)
00100 {
00101
00102 }
00103
00104
00105 using std::endl;
00106 *out << "<html>" << endl;
00107 *out << "<head>" << endl;
00108
00109
00110 *out << "<STYLE type=\"text/css\"> #T1 {border-width: 2px; border: solid blue; text-align: center} </STYLE> " << endl;
00111 *out << "<link type=\"text/css\" rel=\"stylesheet\"";
00112 *out << " href=\"/" << urn
00113 << "/styles.css\"/>" << endl;
00114
00115 *out << "<title>" << moduleName_
00116 << " MAIN</title>" << endl;
00117
00118 *out << "</head>" << endl;
00119 *out << "<body onload=\"loadXMLDoc()\">" << endl;
00120 *out << "<table border=\"0\" width=\"100%\">" << endl;
00121 *out << "<tr>" << endl;
00122 *out << " <td align=\"left\">" << endl;
00123 *out << " <img" << endl;
00124 *out << " align=\"middle\"" << endl;
00125 *out << " src=\"/evf/images/systemerror.jpg\"" << endl;
00126 *out << " alt=\"main\"" << endl;
00127 *out << " width=\"90\"" << endl;
00128 *out << " height=\"64\"" << endl;
00129 *out << " border=\"\"/>" << endl;
00130 *out << " <b>" << endl;
00131 *out << moduleName_ << endl;
00132 *out << " </b>" << endl;
00133 *out << " </td>" << endl;
00134 *out << " <td width=\"32\">" << endl;
00135 *out << " <a href=\"/urn:xdaq-application:lid=3\">" << endl;
00136 *out << " <img" << endl;
00137 *out << " align=\"middle\"" << endl;
00138 *out << " src=\"/hyperdaq/images/HyperDAQ.jpg\"" << endl;
00139 *out << " alt=\"HyperDAQ\"" << endl;
00140 *out << " width=\"32\"" << endl;
00141 *out << " height=\"32\"" << endl;
00142 *out << " border=\"\"/>" << endl;
00143 *out << " </a>" << endl;
00144 *out << " </td>" << endl;
00145 *out << " <td width=\"32\">" << endl;
00146 *out << " </td>" << endl;
00147 *out << " <td width=\"32\">" << endl;
00148 *out << " <a href=\"" << original_referrer_ << "\">" << endl;
00149 *out << " <img" << endl;
00150 *out << " align=\"middle\"" << endl;
00151 *out << " src=\"/evf/images/spoticon.jpg\"" << endl;
00152 *out << " alt=\"main\"" << endl;
00153 *out << " width=\"32\"" << endl;
00154 *out << " height=\"32\"" << endl;
00155 *out << " border=\"\"/>" << endl;
00156 *out << " </a>" << endl;
00157 *out << " </td>" << endl;
00158 *out << "</tr>" << endl;
00159 *out << "</table>" << endl;
00160
00161 *out << "<hr/>" << endl;
00162
00163
00164 *out << cgicc::form().set("method","GET").set("action", path )
00165 << std::endl;
00166 *out << cgicc::input().set("type","hidden").set("name","module").set("value", mname)
00167 << std::endl;
00168 *out << "Select " << endl;
00169 *out << cgicc::select().set("name","exceptiontype") << std::endl;
00170 char istring[2];
00171
00172 for(int i = 0; i < menu_items; i++)
00173 {
00174 sprintf(istring,"%d",i);
00175 *out << cgicc::option().set("value",istring) << menu[i] << cgicc::option() << std::endl;
00176 }
00177 *out << cgicc::select() << std::endl;
00178 *out << "<br>" << endl;
00179 *out << "Qualifier" << endl;
00180 *out << cgicc::input().set("type","text").set("name","qualifier") << std::endl;
00181 *out << cgicc::input().set("type","submit").set("value","Do It !") << std::endl;
00182 *out << cgicc::form() << std::endl;
00183
00184 *out << "</body>" << endl;
00185 *out << "</html>" << endl;
00186 }
00187
00188 }