00001 #include "ExceptionGenerator.h"
00002
00003 #include <iostream>
00004 #include <typeinfo>
00005 #include <map>
00006 #include <sstream>
00007
00008 #include "TRandom3.h"
00009
00010 #include "xgi/Method.h"
00011 #include "xgi/Utils.h"
00012
00013 #include "cgicc/Cgicc.h"
00014 #include "cgicc/FormEntry.h"
00015 #include "cgicc/HTMLClasses.h"
00016
00017 #include "FWCore/Utilities/interface/Exception.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019
00020 #include "boost/tokenizer.hpp"
00021
00022 #include <stdio.h>
00023 #include <sys/types.h>
00024 #include <signal.h>
00025
00026 using namespace std;
00027
00028 namespace evf{
00029
00030 const std::string ExceptionGenerator::menu[menu_items] =
00031 {"Sleep x ms", "SleepForever", "Cms Exception", "Exit with error", "Abort", "Unknown Exception", "Endless loop", "Generate Error Message", "Segfault",
00032 "Burn CPU","HLT timing distribution","HLT timing with memory access","Timed segfault","Invalid free()"};
00033
00034 ExceptionGenerator::ExceptionGenerator( const edm::ParameterSet& pset) :
00035 ModuleWeb("ExceptionGenerator"),
00036 actionId_(pset.getUntrackedParameter<int>("defaultAction",-1)),
00037 intqualifier_(pset.getUntrackedParameter<int>("defaultQualifier",0)),
00038 actionRequired_(actionId_!=-1)
00039 {
00040
00041 }
00042 void ExceptionGenerator::beginJob()
00043 {
00044
00045
00046
00047
00048
00049 timingHisto_ = new TH1D("timingHisto_","Total time for all modules per event",100,0,1000);
00050 timingHisto_->SetBinContent(1,5016);
00051 timingHisto_->SetBinContent(2,4563);
00052 timingHisto_->SetBinContent(3,3298);
00053 timingHisto_->SetBinContent(4,1995);
00054 timingHisto_->SetBinContent(5,1708);
00055 timingHisto_->SetBinContent(6,1167);
00056 timingHisto_->SetBinContent(7,928);
00057 timingHisto_->SetBinContent(8,785);
00058 timingHisto_->SetBinContent(9,643);
00059 timingHisto_->SetBinContent(10,486);
00060 timingHisto_->SetBinContent(11,427);
00061 timingHisto_->SetBinContent(12,335);
00062 timingHisto_->SetBinContent(13,332);
00063 timingHisto_->SetBinContent(14,327);
00064 timingHisto_->SetBinContent(15,258);
00065 timingHisto_->SetBinContent(16,257);
00066 timingHisto_->SetBinContent(17,222);
00067 timingHisto_->SetBinContent(18,253);
00068 timingHisto_->SetBinContent(19,223);
00069 timingHisto_->SetBinContent(20,177);
00070 timingHisto_->SetBinContent(21,148);
00071 timingHisto_->SetBinContent(22,148);
00072 timingHisto_->SetBinContent(23,113);
00073 timingHisto_->SetBinContent(24,83);
00074 timingHisto_->SetBinContent(25,84);
00075 timingHisto_->SetBinContent(26,75);
00076 timingHisto_->SetBinContent(27,61);
00077 timingHisto_->SetBinContent(28,66);
00078 timingHisto_->SetBinContent(29,51);
00079 timingHisto_->SetBinContent(30,43);
00080 timingHisto_->SetBinContent(31,38);
00081 timingHisto_->SetBinContent(32,27);
00082 timingHisto_->SetBinContent(33,34);
00083 timingHisto_->SetBinContent(34,28);
00084 timingHisto_->SetBinContent(35,18);
00085 timingHisto_->SetBinContent(36,26);
00086 timingHisto_->SetBinContent(37,18);
00087 timingHisto_->SetBinContent(38,11);
00088 timingHisto_->SetBinContent(39,11);
00089 timingHisto_->SetBinContent(40,12);
00090 timingHisto_->SetBinContent(41,14);
00091 timingHisto_->SetBinContent(42,11);
00092 timingHisto_->SetBinContent(43,8);
00093 timingHisto_->SetBinContent(44,4);
00094 timingHisto_->SetBinContent(45,2);
00095 timingHisto_->SetBinContent(46,5);
00096 timingHisto_->SetBinContent(47,3);
00097 timingHisto_->SetBinContent(48,4);
00098 timingHisto_->SetBinContent(49,6);
00099 timingHisto_->SetBinContent(50,6);
00100 timingHisto_->SetBinContent(51,3);
00101 timingHisto_->SetBinContent(52,5);
00102 timingHisto_->SetBinContent(53,6);
00103 timingHisto_->SetBinContent(54,6);
00104 timingHisto_->SetBinContent(55,6);
00105 timingHisto_->SetBinContent(56,4);
00106 timingHisto_->SetBinContent(57,5);
00107 timingHisto_->SetBinContent(58,9);
00108 timingHisto_->SetBinContent(59,3);
00109 timingHisto_->SetBinContent(60,3);
00110 timingHisto_->SetBinContent(61,8);
00111 timingHisto_->SetBinContent(62,7);
00112 timingHisto_->SetBinContent(63,5);
00113 timingHisto_->SetBinContent(64,7);
00114 timingHisto_->SetBinContent(65,5);
00115 timingHisto_->SetBinContent(66,5);
00116 timingHisto_->SetBinContent(67,4);
00117 timingHisto_->SetBinContent(68,2);
00118 timingHisto_->SetBinContent(69,2);
00119 timingHisto_->SetBinContent(70,4);
00120 timingHisto_->SetBinContent(71,5);
00121 timingHisto_->SetBinContent(72,4);
00122 timingHisto_->SetBinContent(73,5);
00123 timingHisto_->SetBinContent(74,3);
00124 timingHisto_->SetBinContent(75,5);
00125 timingHisto_->SetBinContent(76,3);
00126 timingHisto_->SetBinContent(77,9);
00127 timingHisto_->SetBinContent(78,2);
00128 timingHisto_->SetBinContent(79,2);
00129 timingHisto_->SetBinContent(80,5);
00130 timingHisto_->SetBinContent(81,5);
00131 timingHisto_->SetBinContent(82,5);
00132 timingHisto_->SetBinContent(83,5);
00133 timingHisto_->SetBinContent(84,4);
00134 timingHisto_->SetBinContent(85,4);
00135 timingHisto_->SetBinContent(86,9);
00136 timingHisto_->SetBinContent(87,5);
00137 timingHisto_->SetBinContent(88,4);
00138 timingHisto_->SetBinContent(89,4);
00139 timingHisto_->SetBinContent(90,5);
00140 timingHisto_->SetBinContent(91,3);
00141 timingHisto_->SetBinContent(92,3);
00142 timingHisto_->SetBinContent(93,3);
00143 timingHisto_->SetBinContent(94,7);
00144 timingHisto_->SetBinContent(95,5);
00145 timingHisto_->SetBinContent(96,6);
00146 timingHisto_->SetBinContent(97,2);
00147 timingHisto_->SetBinContent(98,3);
00148 timingHisto_->SetBinContent(99,5);
00149 timingHisto_->SetBinContent(101,147);
00150 timingHisto_->SetEntries(24934);
00151 }
00152 void ExceptionGenerator::beginRun(edm::Run& r, const edm::EventSetup& iSetup)
00153 {
00154 gettimeofday(&tv_start_,0);
00155 }
00156
00157 void ExceptionGenerator::analyze(const edm::Event & e, const edm::EventSetup& c)
00158 {
00159 float dummy = 0.;
00160 unsigned int iterations = 0;
00161 if(actionRequired_)
00162 {
00163 int *pi = 0;
00164 int ind = 0;
00165 int step = 1;
00166 switch(actionId_)
00167 {
00168 case 0:
00169 ::usleep(intqualifier_*1000);
00170 break;
00171 case 1:
00172 ::sleep(0xFFFFFFF);
00173 break;
00174 case 2:
00175 throw cms::Exception(qualifier_) << "This exception was generated by the ExceptionGenerator";
00176 break;
00177 case 3:
00178 exit(-1);
00179 break;
00180 case 4:
00181 abort();
00182 break;
00183 case 5:
00184 throw qualifier_;
00185 break;
00186 case 6:
00187 while(1){ind+=step; if(ind>1000000) step = -1; if(ind==0) step = 1;}
00188 break;
00189 case 7:
00190 edm::LogError("TestErrorMessage") << qualifier_;
00191 break;
00192 case 8:
00193 *pi=0;
00194 break;
00195 case 9:
00196 for(unsigned int j=0; j<intqualifier_*1000;j++){
00197 dummy += sqrt(log(float(j+1)))/float(j*j);
00198 }
00199 break;
00200 case 10:
00201 iterations = static_cast<unsigned int>(
00202 timingHisto_->GetRandom() * intqualifier_*17. + 0.5
00203 );
00204 for(unsigned int j=0; j<iterations;j++){
00205 dummy += sqrt(log(float(j+1)))/float(j*j);
00206 }
00207 break;
00208 case 11:
00209 {
00210 iterations = static_cast<unsigned int>(
00211 timingHisto_->GetRandom() * intqualifier_*12. + 0.5
00212 );
00213 TRandom3 random(iterations);
00214 const size_t dataSize = 32*500;
00215 std::vector<double> data(dataSize);
00216 random.RndmArray(dataSize, &data[0]);
00217
00218 for(unsigned int j=0; j<iterations;j++){
00219 const size_t index = static_cast<size_t>(random.Rndm() * dataSize + 0.5);
00220 const double value = data[index];
00221 dummy += sqrt(log(value+1))/(value*value);
00222 if ( random.Rndm() < 0.1 )
00223 data[index] = dummy;
00224 }
00225 }
00226 break;
00227 case 12:
00228 {
00229 timeval tv_now;
00230 gettimeofday(&tv_now,0);
00231 if (tv_now.tv_sec-tv_start_.tv_sec>intqualifier_)
00232 *pi=0;
00233 }
00234 break;
00235 case 13:
00236 void *vp = malloc(1024);
00237 memset((char *)vp - 32, 0, 1024);
00238 free(vp);
00239 break;
00240 }
00241 }
00242 }
00243
00244 void ExceptionGenerator::endLuminosityBlock(edm::LuminosityBlock const &lb, edm::EventSetup const &es)
00245 {
00246
00247 }
00248
00249 void ExceptionGenerator::defaultWebPage(xgi::Input *in, xgi::Output *out)
00250 {
00251 gettimeofday(&tv_start_,0);
00252 std::string path;
00253 std::string urn;
00254 std::string mname;
00255 std::string query;
00256 try
00257 {
00258 cgicc::Cgicc cgi(in);
00259 if ( xgi::Utils::hasFormElement(cgi,"exceptiontype") )
00260 {
00261 actionId_ = xgi::Utils::getFormElement(cgi, "exceptiontype")->getIntegerValue();
00262 try {
00263 qualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getValue();
00264 intqualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getIntegerValue();
00265 }
00266 catch (...) {
00267
00268 }
00269 actionRequired_ = true;
00270 }
00271 if ( xgi::Utils::hasFormElement(cgi,"module") )
00272 mname = xgi::Utils::getFormElement(cgi, "module")->getValue();
00273 cgicc::CgiEnvironment cgie(in);
00274 if(original_referrer_ == "")
00275 original_referrer_ = cgie.getReferrer();
00276 path = cgie.getPathInfo();
00277 query = cgie.getQueryString();
00278 if(actionId_>=0)
00279 std::cout << " requested action " << actionId_ << " "
00280 << menu[actionId_] << ". Number of cycles "
00281 << intqualifier_ << std::endl;
00282 }
00283 catch (const std::exception & e)
00284 {
00285
00286 }
00287
00288 using std::endl;
00289 *out << "<html>" << endl;
00290 *out << "<head>" << endl;
00291
00292
00293 *out << "<STYLE type=\"text/css\"> #T1 {border-width: 2px; border: solid blue; text-align: center} </STYLE> " << endl;
00294 *out << "<link type=\"text/css\" rel=\"stylesheet\"";
00295 *out << " href=\"/" << urn
00296 << "/styles.css\"/>" << endl;
00297
00298 *out << "<title>" << moduleName_
00299 << " MAIN</title>" << endl;
00300
00301 *out << "</head>" << endl;
00302 *out << "<body onload=\"loadXMLDoc()\">" << endl;
00303 *out << "<table border=\"0\" width=\"100%\">" << endl;
00304 *out << "<tr>" << endl;
00305 *out << " <td align=\"left\">" << endl;
00306 *out << " <img" << endl;
00307 *out << " align=\"middle\"" << endl;
00308 *out << " src=\"/evf/images/systemerror.jpg\"" << endl;
00309 *out << " alt=\"main\"" << endl;
00310 *out << " width=\"90\"" << endl;
00311 *out << " height=\"64\"" << endl;
00312 *out << " border=\"\"/>" << endl;
00313 *out << " <b>" << endl;
00314 *out << moduleName_ << endl;
00315 *out << " </b>" << endl;
00316 *out << " </td>" << endl;
00317 *out << " <td width=\"32\">" << endl;
00318 *out << " <a href=\"/urn:xdaq-application:lid=3\">" << endl;
00319 *out << " <img" << endl;
00320 *out << " align=\"middle\"" << endl;
00321 *out << " src=\"/hyperdaq/images/HyperDAQ.jpg\"" << endl;
00322 *out << " alt=\"HyperDAQ\"" << endl;
00323 *out << " width=\"32\"" << endl;
00324 *out << " height=\"32\"" << endl;
00325 *out << " border=\"\"/>" << endl;
00326 *out << " </a>" << endl;
00327 *out << " </td>" << endl;
00328 *out << " <td width=\"32\">" << endl;
00329 *out << " </td>" << endl;
00330 *out << " <td width=\"32\">" << endl;
00331 *out << " <a href=\"" << original_referrer_ << "\">" << endl;
00332 *out << " <img" << endl;
00333 *out << " align=\"middle\"" << endl;
00334 *out << " src=\"/evf/images/spoticon.jpg\"" << endl;
00335 *out << " alt=\"main\"" << endl;
00336 *out << " width=\"32\"" << endl;
00337 *out << " height=\"32\"" << endl;
00338 *out << " border=\"\"/>" << endl;
00339 *out << " </a>" << endl;
00340 *out << " </td>" << endl;
00341 *out << "</tr>" << endl;
00342 *out << "</table>" << endl;
00343
00344 *out << "<hr/>" << endl;
00345
00346 *out << cgicc::form().set("method","GET").set("action", path )
00347 << std::endl;
00348 boost::char_separator<char> sep("&");
00349 boost::tokenizer<boost::char_separator<char> > tokens(query, sep);
00350 for (boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = tokens.begin();
00351 tok_iter != tokens.end(); ++tok_iter){
00352 size_t pos = (*tok_iter).find_first_of("=");
00353 if(pos != std::string::npos){
00354 std::string first = (*tok_iter).substr(0 , pos);
00355 std::string second = (*tok_iter).substr(pos+1, (*tok_iter).length()-pos-1);
00356 *out << cgicc::input().set("type","hidden").set("name",first).set("value", second)
00357 << std::endl;
00358 }
00359 }
00360
00361 *out << "Select " << endl;
00362 *out << cgicc::select().set("name","exceptiontype") << std::endl;
00363 char istring[2];
00364
00365 for(int i = 0; i < menu_items; i++)
00366 {
00367 sprintf(istring,"%d",i);
00368 *out << cgicc::option().set("value",istring) << menu[i] << cgicc::option() << std::endl;
00369 }
00370 *out << cgicc::select() << std::endl;
00371 *out << "<br>" << endl;
00372 *out << "Qualifier" << endl;
00373 *out << cgicc::input().set("type","text").set("name","qualifier") << std::endl;
00374 *out << cgicc::input().set("type","submit").set("value","Do It !") << std::endl;
00375 *out << cgicc::form() << std::endl;
00376
00377 *out << "</body>" << endl;
00378 *out << "</html>" << endl;
00379 }
00380 void ExceptionGenerator::publish(xdata::InfoSpace *is)
00381 {
00382 }
00383 void ExceptionGenerator::publishForkInfo(moduleweb::ForkInfoObj *forkInfoObj)
00384 {
00385 }
00386 }