CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/Core/bin/cmsShow.cc

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