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