CMS 3D CMS Logo

cmsShow.cc
Go to the documentation of this file.
1 #include "TEnv.h"
2 #include "TSystem.h"
3 #include "TEveManager.h"
4 #include "TRint.h"
5 #include "TApplication.h"
6 #include "TSysEvtHandler.h"
7 #include "Getline.h"
8 #include <iostream>
9 #include <fstream>
10 #include <cstring>
11 #include <memory>
12 #include <csignal>
13 
16 /* NOTE: This is a short term work around until FWLite can properly handle the MessageLogger
17  */
22 
23 namespace {
24  class SilentMLscribe : public edm::service::AbstractMLscribe {
25  public:
26  SilentMLscribe() {}
27 
28  // ---------- member functions ---------------------------
29 
30  void runCommand(edm::MessageLoggerQ::OpCode opcode, void* operand) override;
31 
32  SilentMLscribe(const SilentMLscribe&) = delete; // stop default
33 
34  const SilentMLscribe& operator=(const SilentMLscribe&) = delete; // stop default
35 
36  // ---------- member data --------------------------------
37  };
38 
39  void SilentMLscribe::runCommand(edm::MessageLoggerQ::OpCode opcode, void* operand) {
40  //even though we don't print, have to clean up memory
41  switch (opcode) {
43  edm::ErrorObj* errorobj_p = static_cast<edm::ErrorObj*>(operand);
44  //std::cerr<<errorobj_p->xid().severity.getInputStr()<<" "<<errorobj_p->xid().id<<" -----------------------"<<std::endl;
45  //std::cerr <<errorobj_p->fullText()<<std::endl;
46  delete errorobj_p;
47  break;
48  }
51  std::string* string_p = static_cast<std::string*>(operand);
52  delete string_p;
53  break;
54  }
55  default:
56  break;
57  }
58  }
59 
60 } // namespace
61 
62 namespace {
63  void signal_handler_wrapper(int sid, siginfo_t* sinfo, void* sctx) {
64 #if defined(R__LINUX)
65  std::cerr << "Program received signal ID = " << sid << std::endl;
66  std::cerr << "Printing stack trace ... " << std::endl;
67 
68  TString gdbCommand("scripts/gdb-backtrace.sh");
69  fireworks::setPath(gdbCommand);
70  gdbCommand += " ";
71 
72  gdbCommand += gSystem->GetPid();
73 
74  gSystem->Exec(gdbCommand.Data());
75  gSystem->Exit(sid);
76  Getlinem(kCleanUp, nullptr);
77 #endif
78  }
79 } // namespace
80 
81 void run_app(TApplication& app, int argc, char** argv) {
82  //Remove when FWLite handles the MessageLogger
84  std::shared_ptr<edm::service::AbstractMLscribe>(std::make_shared<SilentMLscribe>()));
86  //---------------------
87  std::unique_ptr<CmsShowMain> pMain(new CmsShowMain(argc, argv));
88 
89  // Avoid haing root handling various associated to an error and install
90  // back the default ones.
91  gSystem->ResetSignal(kSigBus);
92  gSystem->ResetSignal(kSigSegmentationViolation);
93  gSystem->ResetSignal(kSigIllegalInstruction);
94  gSystem->ResetSignal(kSigSystem);
95  gSystem->ResetSignal(kSigPipe);
96  gSystem->ResetSignal(kSigFloatingException);
97 
98  struct sigaction sac;
99  sac.sa_sigaction = signal_handler_wrapper;
100  sigemptyset(&sac.sa_mask);
101  sac.sa_flags = SA_SIGINFO;
102  sigaction(SIGILL, &sac, nullptr);
103  sigaction(SIGSEGV, &sac, nullptr);
104  sigaction(SIGBUS, &sac, nullptr);
105  sigaction(SIGFPE, &sac, nullptr);
106 
107  app.Run();
108  pMain.reset();
109 
110  TEveManager::Terminate();
111  app.Terminate();
112 
113  //Remove when FWLite handled the MessageLogger
115 }
116 
117 int main(int argc, char** argv) {
118  const char* dummyArgvArray[] = {"cmsShow"};
119  char** dummyArgv = const_cast<char**>(dummyArgvArray);
120  int dummyArgc = 1;
121  gEnv->SetValue("Gui.BackgroundColor", "#9f9f9f");
122 
123  // print version
124  TString infoText;
125  if (gSystem->Getenv("CMSSW_VERSION")) {
126  infoText = gSystem->Getenv("CMSSW_VERSION");
127  } else {
128  TString infoFileName("data/version.txt");
129  fireworks::setPath(infoFileName);
130  std::ifstream infoFile(infoFileName);
131  infoText.ReadLine(infoFile);
132  infoFile.close();
133  }
134  printf("Starting cmsShow, version %s.\n", infoText.Data());
135  fflush(stdout);
136 
137  // check root interactive promp
138  bool isri = false;
139  for (Int_t i = 0; i < argc; i++) {
140  if (strncmp(argv[i], "-r", 2) == 0 || strncmp(argv[i], "--root", 6) == 0) {
141  isri = true;
142  }
143  }
144 
145  try {
146  if (isri) {
147  std::cerr << "" << std::endl;
148  std::cerr << "WARNING:You are running cmsShow with ROOT prompt enabled." << std::endl;
149  std::cerr << "If you encounter an issue you suspect to be a bug in " << std::endl;
150  std::cerr << "cmsShow, please re-run without this option and try to " << std::endl;
151  std::cerr << "reproduce it before submitting a bug-report. " << std::endl;
152  std::cerr << "" << std::endl;
153 
154  TRint app("cmsShow", &dummyArgc, dummyArgv);
155  run_app(app, argc, argv);
156  } else {
157  TApplication app("cmsShow", &dummyArgc, dummyArgv);
158  run_app(app, argc, argv);
159  }
160  } catch (std::exception& iException) {
161  std::cerr << "CmsShow unhandled exception " << iException.what() << std::endl;
162  return 1;
163  }
164 
165  return 0;
166 }
static unsigned char messageLoggerScribeIsRunning
Definition: MessageDrop.h:70
void run_app(TApplication &app, int argc, char **argv)
Definition: cmsShow.cc:81
static MessageDrop * instance()
Definition: MessageDrop.cc:33
static const unsigned char MLSCRIBE_RUNNING_INDICATOR
Definition: MessageDrop.h:83
int main(int argc, char **argv)
Definition: cmsShow.cc:117
static void MLqEND()
static void setMLscribe_ptr(std::shared_ptr< edm::service::AbstractMLscribe > m)
void operator=(AbstractMLscribe const &)=delete
virtual void runCommand(MessageLoggerQ::OpCode opcode, void *operand)
void setPath(TString &v)
Definition: fwPaths.cc:15