CMS 3D CMS Logo

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