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