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