CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ExceptionGenerator.cc
Go to the documentation of this file.
1 #include "ExceptionGenerator.h"
2 
3 #include <iostream>
4 #include <typeinfo>
5 #include <map>
6 #include <sstream>
7 
8 #include "xgi/Method.h"
9 #include "xgi/Utils.h"
10 
11 #include "cgicc/Cgicc.h"
12 #include "cgicc/FormEntry.h"
13 #include "cgicc/HTMLClasses.h"
14 
17 
18 #include "boost/tokenizer.hpp"
19 
20 #include <stdio.h>
21 
22 using namespace std;
23 
24 namespace evf{
25 
26  const std::string ExceptionGenerator::menu[menu_items] =
27  {"Sleep x ms", "SleepForever", "Cms Exception", "Exit with error", "Abort", "Unknown Exception", "Endless loop", "Generate Error Message", "Segfault",
28  "Burn CPU"};
29 
31  ModuleWeb("ExceptionGenerator"),
32  actionId_(pset.getUntrackedParameter<int>("defaultAction",-1)),
33  intqualifier_(pset.getUntrackedParameter<int>("defaultQualifier",0)),
34  actionRequired_(actionId_!=-1)
35  {
36 
37  }
39  {
40  }
42  {
43  }
45  {
46  float dummy = 0.;
47  if(actionRequired_)
48  {
49  int *pi = 0;
50  int ind = 0;
51  int step = 1;
52  switch(actionId_)
53  {
54  case 0:
55  ::usleep(intqualifier_*1000);
56  break;
57  case 1:
58  ::sleep(0xFFFFFFF);
59  break;
60  case 2:
61  throw cms::Exception(qualifier_) << "This exception was generated by the ExceptionGenerator";
62  break;
63  case 3:
64  exit(-1);
65  break;
66  case 4:
67  abort();
68  break;
69  case 5:
70  throw qualifier_;
71  break;
72  case 6:
73  while(1){ind+=step; if(ind>1000000) step = -1; if(ind==0) step = 1;}
74  break;
75  case 7:
76  edm::LogError("TestErrorMessage") << qualifier_;
77  break;
78  case 8:
79  *pi=0;
80  break;
81  case 9:
82  for(unsigned int j=0; j<intqualifier_*1000;j++){
83  dummy += sqrt(log(float(j+1)))/float(j*j);
84  }
85  break;
86 
87  }
88  }
89  }
90 
92  {
93 
94  }
95 
97  {
98  std::string path;
99  std::string urn;
100  std::string mname;
101  std::string query;
102  try
103  {
104  cgicc::Cgicc cgi(in);
105  if ( xgi::Utils::hasFormElement(cgi,"exceptiontype") )
106  {
107  actionId_ = xgi::Utils::getFormElement(cgi, "exceptiontype")->getIntegerValue();
108  qualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getValue();
109  intqualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getIntegerValue();
110  actionRequired_ = true;
111  }
112  if ( xgi::Utils::hasFormElement(cgi,"module") )
113  mname = xgi::Utils::getFormElement(cgi, "module")->getValue();
114  cgicc::CgiEnvironment cgie(in);
115  if(original_referrer_ == "")
116  original_referrer_ = cgie.getReferrer();
117  path = cgie.getPathInfo();
118  query = cgie.getQueryString();
119  if(actionId_>=0)
120  std::cout << " requested action " << actionId_ << " "
121  << menu[actionId_] << ". Number of cycles "
122  << intqualifier_ << std::endl;
123  }
124  catch (const std::exception & e)
125  {
126  // don't care if it did not work
127  }
128 
129  using std::endl;
130  *out << "<html>" << endl;
131  *out << "<head>" << endl;
132 
133 
134  *out << "<STYLE type=\"text/css\"> #T1 {border-width: 2px; border: solid blue; text-align: center} </STYLE> " << endl;
135  *out << "<link type=\"text/css\" rel=\"stylesheet\"";
136  *out << " href=\"/" << urn
137  << "/styles.css\"/>" << endl;
138 
139  *out << "<title>" << moduleName_
140  << " MAIN</title>" << endl;
141 
142  *out << "</head>" << endl;
143  *out << "<body onload=\"loadXMLDoc()\">" << endl;
144  *out << "<table border=\"0\" width=\"100%\">" << endl;
145  *out << "<tr>" << endl;
146  *out << " <td align=\"left\">" << endl;
147  *out << " <img" << endl;
148  *out << " align=\"middle\"" << endl;
149  *out << " src=\"/evf/images/systemerror.jpg\"" << endl;
150  *out << " alt=\"main\"" << endl;
151  *out << " width=\"90\"" << endl;
152  *out << " height=\"64\"" << endl;
153  *out << " border=\"\"/>" << endl;
154  *out << " <b>" << endl;
155  *out << moduleName_ << endl;
156  *out << " </b>" << endl;
157  *out << " </td>" << endl;
158  *out << " <td width=\"32\">" << endl;
159  *out << " <a href=\"/urn:xdaq-application:lid=3\">" << endl;
160  *out << " <img" << endl;
161  *out << " align=\"middle\"" << endl;
162  *out << " src=\"/hyperdaq/images/HyperDAQ.jpg\"" << endl;
163  *out << " alt=\"HyperDAQ\"" << endl;
164  *out << " width=\"32\"" << endl;
165  *out << " height=\"32\"" << endl;
166  *out << " border=\"\"/>" << endl;
167  *out << " </a>" << endl;
168  *out << " </td>" << endl;
169  *out << " <td width=\"32\">" << endl;
170  *out << " </td>" << endl;
171  *out << " <td width=\"32\">" << endl;
172  *out << " <a href=\"" << original_referrer_ << "\">" << endl;
173  *out << " <img" << endl;
174  *out << " align=\"middle\"" << endl;
175  *out << " src=\"/evf/images/spoticon.jpg\"" << endl;
176  *out << " alt=\"main\"" << endl;
177  *out << " width=\"32\"" << endl;
178  *out << " height=\"32\"" << endl;
179  *out << " border=\"\"/>" << endl;
180  *out << " </a>" << endl;
181  *out << " </td>" << endl;
182  *out << "</tr>" << endl;
183  *out << "</table>" << endl;
184 
185  *out << "<hr/>" << endl;
186 
187  *out << cgicc::form().set("method","GET").set("action", path )
188  << std::endl;
189  boost::char_separator<char> sep("&");
190  boost::tokenizer<boost::char_separator<char> > tokens(query, sep);
191  for (boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = tokens.begin();
192  tok_iter != tokens.end(); ++tok_iter){
193  size_t pos = (*tok_iter).find_first_of("=");
194  if(pos != std::string::npos){
195  std::string first = (*tok_iter).substr(0 , pos);
196  std::string second = (*tok_iter).substr(pos+1, (*tok_iter).length()-pos-1);
197  *out << cgicc::input().set("type","hidden").set("name",first).set("value", second)
198  << std::endl;
199  }
200  }
201 
202  *out << "Select " << endl;
203  *out << cgicc::select().set("name","exceptiontype") << std::endl;
204  char istring[2];
205 
206  for(int i = 0; i < menu_items; i++)
207  {
208  sprintf(istring,"%d",i);
209  *out << cgicc::option().set("value",istring) << menu[i] << cgicc::option() << std::endl;
210  }
211  *out << cgicc::select() << std::endl;
212  *out << "<br>" << endl;
213  *out << "Qualifier" << endl;
214  *out << cgicc::input().set("type","text").set("name","qualifier") << std::endl;
215  *out << cgicc::input().set("type","submit").set("value","Do It !") << std::endl;
216  *out << cgicc::form() << std::endl;
217 
218  *out << "</body>" << endl;
219  *out << "</html>" << endl;
220  }
221  void ExceptionGenerator::publish(xdata::InfoSpace *is)
222  {
223  }
224 } // end namespace evf
int i
Definition: DBlmapReader.cc:9
#define Input(cl)
Definition: vmac.h:189
list step
Definition: launcher.py:15
boost::tokenizer< boost::char_separator< char > > tokenizer
void defaultWebPage(xgi::Input *in, xgi::Output *out)
void publish(xdata::InfoSpace *)
void sleep(Duration_t)
Definition: Utils.h:163
int path() const
Definition: HLTadd.h:3
U second(std::pair< T, U > const &p)
void beginRun(edm::Run &r)
void analyze(const edm::Event &e, const edm::EventSetup &c)
T sqrt(T t)
Definition: SSEVec.h:28
int j
Definition: DBlmapReader.cc:9
bool first
Definition: L1TdeRCT.cc:79
std::string moduleName_
Definition: ModuleWeb.h:23
static const int menu_items
tuple input
Definition: collect_tpl.py:10
tuple out
Definition: dbtoconf.py:99
Log< T >::type log(const T &t)
Definition: Log.h:22
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
static const std::string menu[menu_items]
#define Output(cl)
Definition: vmac.h:193
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:41
double pi
Definition: Run.h:32