Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-05 22:48:05

0001 #include "TEnv.h"
0002 #include "TSystem.h"
0003 #include "TEveManager.h"
0004 #include "TRint.h"
0005 #include "TApplication.h"
0006 #include "TSysEvtHandler.h"
0007 #include "Getline.h"
0008 #include <iostream>
0009 #include <fstream>
0010 #include <cstring>
0011 #include <memory>
0012 #include <csignal>
0013 
0014 #include "Fireworks/Core/interface/CmsShowMain.h"
0015 #include "Fireworks/Core/interface/fwPaths.h"
0016 /* NOTE: This is a short term work around until FWLite can properly handle the MessageLogger
0017  */
0018 #include "FWCore/MessageLogger/interface/AbstractMLscribe.h"
0019 #include "FWCore/MessageLogger/interface/ErrorObj.h"
0020 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
0021 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0022 
0023 namespace {
0024   class SilentMLscribe : public edm::service::AbstractMLscribe {
0025   public:
0026     SilentMLscribe() {}
0027 
0028     // ---------- member functions ---------------------------
0029 
0030     void runCommand(edm::MessageLoggerQ::OpCode opcode, void* operand) override;
0031 
0032     SilentMLscribe(const SilentMLscribe&) = delete;  // stop default
0033 
0034     const SilentMLscribe& operator=(const SilentMLscribe&) = delete;  // stop default
0035 
0036     // ---------- member data --------------------------------
0037   };
0038 
0039   void SilentMLscribe::runCommand(edm::MessageLoggerQ::OpCode opcode, void* operand) {
0040     //even though we don't print, have to clean up memory
0041     switch (opcode) {
0042       case edm::MessageLoggerQ::LOG_A_MESSAGE: {
0043         edm::ErrorObj* errorobj_p = static_cast<edm::ErrorObj*>(operand);
0044         //std::cerr<<errorobj_p->xid().severity.getInputStr()<<" "<<errorobj_p->xid().id<<" -----------------------"<<std::endl;
0045         //std::cerr <<errorobj_p->fullText()<<std::endl;
0046         delete errorobj_p;
0047         break;
0048       }
0049       case edm::MessageLoggerQ::JOBMODE:
0050       case edm::MessageLoggerQ::GROUP_STATS: {
0051         std::string* string_p = static_cast<std::string*>(operand);
0052         delete string_p;
0053         break;
0054       }
0055       default:
0056         break;
0057     }
0058   }
0059 
0060 }  // namespace
0061 
0062 namespace {
0063   void signal_handler_wrapper(int sid, siginfo_t* sinfo, void* sctx) {
0064 #if defined(R__LINUX)
0065     std::cerr << "Program received signal ID = " << sid << std::endl;
0066     std::cerr << "Printing stack trace ... " << std::endl;
0067 
0068     TString gdbCommand("scripts/gdb-backtrace.sh");
0069     fireworks::setPath(gdbCommand);
0070     gdbCommand += " ";
0071 
0072     gdbCommand += gSystem->GetPid();
0073 
0074     gSystem->Exec(gdbCommand.Data());
0075     gSystem->Exit(sid);
0076     Getlinem(kCleanUp, nullptr);
0077 #endif
0078   }
0079 }  // namespace
0080 
0081 void run_app(TApplication& app, int argc, char** argv) {
0082   //Remove when FWLite handles the MessageLogger
0083   edm::MessageLoggerQ::setMLscribe_ptr(
0084       std::shared_ptr<edm::service::AbstractMLscribe>(std::make_shared<SilentMLscribe>()));
0085   edm::MessageDrop::instance()->messageLoggerScribeIsRunning = edm::MLSCRIBE_RUNNING_INDICATOR;
0086   //---------------------
0087   std::unique_ptr<CmsShowMain> pMain(new CmsShowMain(argc, argv));
0088 
0089   // Avoid haing root handling various associated to an error and install
0090   // back the default ones.
0091   gSystem->ResetSignal(kSigBus);
0092   gSystem->ResetSignal(kSigSegmentationViolation);
0093   gSystem->ResetSignal(kSigIllegalInstruction);
0094   gSystem->ResetSignal(kSigSystem);
0095   gSystem->ResetSignal(kSigPipe);
0096   gSystem->ResetSignal(kSigFloatingException);
0097 
0098   struct sigaction sac;
0099   sac.sa_sigaction = signal_handler_wrapper;
0100   sigemptyset(&sac.sa_mask);
0101   sac.sa_flags = SA_SIGINFO;
0102   sigaction(SIGILL, &sac, nullptr);
0103   sigaction(SIGSEGV, &sac, nullptr);
0104   sigaction(SIGBUS, &sac, nullptr);
0105   sigaction(SIGFPE, &sac, nullptr);
0106 
0107   app.Run();
0108   pMain.reset();
0109 
0110   TEveManager::Terminate();
0111   app.Terminate();
0112 
0113   //Remove when FWLite handled the MessageLogger
0114   edm::MessageLoggerQ::MLqEND();
0115 }
0116 
0117 int main(int argc, char** argv) {
0118   const char* dummyArgvArray[] = {"cmsShow"};
0119   char** dummyArgv = const_cast<char**>(dummyArgvArray);
0120   int dummyArgc = 1;
0121   gEnv->SetValue("Gui.BackgroundColor", "#9f9f9f");
0122 
0123   // print version
0124   TString infoText;
0125   if (gSystem->Getenv("CMSSW_VERSION")) {
0126     infoText = gSystem->Getenv("CMSSW_VERSION");
0127   } else {
0128     TString infoFileName("data/version.txt");
0129     fireworks::setPath(infoFileName);
0130     std::ifstream infoFile(infoFileName);
0131     infoText.ReadLine(infoFile);
0132     infoFile.close();
0133   }
0134   printf("Starting cmsShow, version %s.\n", infoText.Data());
0135   fflush(stdout);
0136 
0137   // check root interactive promp
0138   bool isri = false;
0139   for (Int_t i = 0; i < argc; i++) {
0140     if (strncmp(argv[i], "-r", 2) == 0 || strncmp(argv[i], "--root", 6) == 0) {
0141       isri = true;
0142     }
0143   }
0144 
0145   try {
0146     if (isri) {
0147       std::cerr << "" << std::endl;
0148       std::cerr << "WARNING:You are running cmsShow with ROOT prompt enabled." << std::endl;
0149       std::cerr << "If you encounter an issue you suspect to be a bug in     " << std::endl;
0150       std::cerr << "cmsShow, please re-run without this option and try to    " << std::endl;
0151       std::cerr << "reproduce it before submitting a bug-report.             " << std::endl;
0152       std::cerr << "" << std::endl;
0153 
0154       TRint app("cmsShow", &dummyArgc, dummyArgv);
0155       run_app(app, argc, argv);
0156     } else {
0157       TApplication app("cmsShow", &dummyArgc, dummyArgv);
0158       run_app(app, argc, argv);
0159     }
0160   } catch (std::exception& iException) {
0161     std::cerr << "CmsShow unhandled exception " << iException.what() << std::endl;
0162     return 1;
0163   }
0164 
0165   return 0;
0166 }