Go to the documentation of this file.00001 #include "TEnv.h"
00002 #include "TSystem.h"
00003 #include "TEveManager.h"
00004 #include "TRint.h"
00005 #include "TApplication.h"
00006 #include "TSysEvtHandler.h"
00007 #include "Getline.h"
00008 #include <iostream>
00009 #include <fstream>
00010 #include <string.h>
00011 #include <memory>
00012 #include <signal.h>
00013
00014 #include "Fireworks/Core/src/CmsShowMain.h"
00015 #include "Fireworks/Core/interface/fwPaths.h"
00016
00017
00018 #include "FWCore/MessageLogger/interface/AbstractMLscribe.h"
00019 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00020 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
00021 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00022
00023 namespace {
00024 class SilentMLscribe : public edm::service::AbstractMLscribe {
00025
00026 public:
00027 SilentMLscribe() {}
00028
00029
00030 virtual
00031 void runCommand(edm::MessageLoggerQ::OpCode opcode, void * operand);
00032
00033 private:
00034 SilentMLscribe(const SilentMLscribe&);
00035
00036 const SilentMLscribe& operator=(const SilentMLscribe&);
00037
00038
00039
00040 };
00041
00042 void
00043 SilentMLscribe::runCommand(edm::MessageLoggerQ::OpCode opcode, void * operand) {
00044
00045 switch (opcode) {
00046 case edm::MessageLoggerQ::LOG_A_MESSAGE: {
00047 edm::ErrorObj * errorobj_p = static_cast<edm::ErrorObj *>(operand);
00048
00049
00050 delete errorobj_p;
00051 break;
00052 }
00053 case edm::MessageLoggerQ::JOBREPORT:
00054 case edm::MessageLoggerQ::JOBMODE:
00055 case edm::MessageLoggerQ::GROUP_STATS:
00056 {
00057 std::string* string_p = static_cast<std::string*> (operand);
00058 delete string_p;
00059 break;
00060 }
00061 default:
00062 break;
00063 }
00064 }
00065
00066 }
00067
00068 namespace
00069 {
00070 void signal_handler_wrapper(int sid, siginfo_t* sinfo, void* sctx)
00071 {
00072 std::cerr << "Program received signal ID = " << sid << std::endl;
00073 std::cerr << "Printing stack trace ... " << std::endl;
00074
00075 TString gdbCommand("scripts/gdb-backtrace.sh");
00076 fireworks::setPath(gdbCommand);
00077 gdbCommand += " ";
00078
00079 #if defined(R__MACOSX)
00080 gdbCommand += TString::Format("%s/cmsShow.exe %d", gSystem->Getenv("SHELLDIR"), gSystem->GetPid());
00081
00082 #elif defined(R__LINUX)
00083 gdbCommand += gSystem->GetPid();
00084
00085 #endif
00086 gSystem->Exec(gdbCommand.Data());
00087 gSystem->Exit(sid);
00088 Getlinem(kCleanUp, 0);
00089 }
00090 }
00091
00092 void run_app(TApplication &app, int argc, char **argv)
00093 {
00094
00095 edm::MessageLoggerQ::setMLscribe_ptr(boost::shared_ptr<edm::service::AbstractMLscribe>(new SilentMLscribe));
00096 edm::MessageDrop::instance()->messageLoggerScribeIsRunning = edm::MLSCRIBE_RUNNING_INDICATOR;
00097
00098 std::auto_ptr<CmsShowMain> pMain( new CmsShowMain(argc,argv) );
00099
00100
00101
00102 gSystem->ResetSignal(kSigBus);
00103 gSystem->ResetSignal(kSigSegmentationViolation);
00104 gSystem->ResetSignal(kSigIllegalInstruction);
00105 gSystem->ResetSignal(kSigSystem);
00106 gSystem->ResetSignal(kSigPipe);
00107 gSystem->ResetSignal(kSigFloatingException);
00108
00109 struct sigaction sac;
00110 sac.sa_sigaction = signal_handler_wrapper;
00111 sigemptyset(&sac.sa_mask);
00112 sac.sa_flags = SA_SIGINFO;
00113 sigaction(SIGILL, &sac, 0);
00114 sigaction(SIGSEGV, &sac, 0);
00115 sigaction(SIGBUS, &sac, 0);
00116 sigaction(SIGFPE, &sac, 0);
00117
00118 app.Run();
00119 pMain.reset();
00120
00121 TEveManager::Terminate();
00122 app.Terminate();
00123
00124
00125 edm::MessageLoggerQ::MLqEND();
00126 }
00127
00128 int main (int argc, char **argv)
00129 {
00130 const char* dummyArgvArray[] = {"cmsShow"};
00131 char** dummyArgv = const_cast<char**>(dummyArgvArray);
00132 int dummyArgc = 1;
00133 gEnv->SetValue("Gui.BackgroundColor", "#9f9f9f");
00134
00135
00136 TString infoText;
00137 if (gSystem->Getenv("CMSSW_VERSION"))
00138 {
00139 infoText = gSystem->Getenv("CMSSW_VERSION");
00140 }
00141 else
00142 {
00143 TString infoFileName("data/version.txt");
00144 fireworks::setPath(infoFileName);
00145 ifstream infoFile(infoFileName);
00146 infoText.ReadLine(infoFile);
00147 infoFile.close();
00148 }
00149 printf("Starting cmsShow, version %s.\n", infoText.Data());
00150 fflush(stdout);
00151
00152
00153 bool isri = false;
00154 for (Int_t i =0; i<argc; i++)
00155 {
00156 if (strncmp(argv[i], "-r", 2) == 0 ||
00157 strncmp(argv[i], "--root", 6) == 0)
00158 {
00159 isri=true;
00160 }
00161 }
00162
00163 try {
00164 if (isri) {
00165 std::cerr<<""<<std::endl;
00166 std::cerr<<"WARNING:You are running cmsShow with ROOT prompt enabled."<<std::endl;
00167 std::cerr<<"If you encounter an issue you suspect to be a bug in "<<std::endl;
00168 std::cerr<<"cmsShow, please re-run without this option and try to "<<std::endl;
00169 std::cerr<<"reproduce it before submitting a bug-report. "<<std::endl;
00170 std::cerr<<""<<std::endl;
00171
00172 TRint app("cmsShow", &dummyArgc, dummyArgv);
00173 run_app(app,argc, argv);
00174 } else {
00175 TApplication app("cmsShow", &dummyArgc, dummyArgv);
00176 run_app(app,argc, argv);
00177 }
00178 }
00179 catch(std::exception& iException)
00180 {
00181 std::cerr <<"CmsShow unhandled exception "<<iException.what()<<std::endl;
00182 return 1;
00183 }
00184
00185 return 0;
00186 }