Diana Software
diana.cc
Go to the documentation of this file.
1 /* Main program for Diana offline
2  MP created 15/11/05
3  $Id: main.cc 3 2006-04-20 17:37:43Z pallas $
4  */
5 
6 #include "QFrameWork.hh"
7 #include "QModuleFactory.hh"
8 #include "QOptions.hh"
9 #include "QMessage.hh"
10 #include "QProcessStatus.hh"
11 #include "QError.hh"
12 #include "QGSL.hh"
13 #include "QDianaDebug.hh"
14 #include "QDll.hh"
15 
16 #include "TSystem.h"
17 
18 #include <iostream>
19 #include <sstream>
20 #include <stdexcept>
21 #include <time.h>
22 #include <signal.h>
23 #include <sys/time.h>
24 #include <sys/resource.h>
25 
26 using Diana::QOptions;
27 using Diana::QModuleFactory;
28 using Diana::QFrameWork;
29 using Diana::QMessageHandler;
30 using Diana::QGSL;
31 using Diana::QDLLLoader;
32 
33 
34 int main(int argc, char *argv[]) {
35 
36  time_t start_time = ::time (0);
37 
38  bool good = true;
39  std::stringstream errstr;
40  std::stringstream trace;
41 
42  try {
44  QOptions::GetInstance().Init(argc, argv);
45  if(QOptions::GetInstance().GetString("General.GSLErrorHandler") == std::string("diana"))
47 
48  // by default handle no signal but SIGINT
49  // other possible configuration is specific for online and
50  // is performed by MEventBuilder
52  status.Associate(SIGINT, QExiting_s);
53  status.SetState(QRunning_s);
54 
55  QMessageHandler::Get()->Send(NoFilterMsg,"Diana Main Program","Start");
57  QFrameWork f;
58  f.Run();
59  }
60 
61  catch (QError& err)
62  {
63  errstr << "Error: "<<std::endl
64  << "Q> Exception: QError" << std::endl
65  << "Q> Code : " << (int)err.GetCode()
66  << " (" << err.ToString() << ")";
67  if("" != err.GetDescription()) {
68  errstr << std::endl<<"Q> Descr : " << err.GetDescription();
69  }
70  diana_stacktrace(trace);
71  good = false;
72  }
73  catch (std::exception& ex) {
74  errstr << "Error: "<<std::endl
75  <<"Q> Exception: " << ex.what();
76  diana_stacktrace(trace);
77  good = false;
78  }
79  catch (...) {
80  errstr << "Error: "<<std::endl
81  << "Q> Exception: Unknown type";
82  diana_stacktrace(trace);
83  good = false;
84  }
85  if(good) QMessageHandler::Get()->Send(NoFilterMsg,"Diana Main Program","Exit successfully");
86  else {
87  QMessageHandler::Get()->Send(NoFilterMsg,"Diana Main Program",errstr.str());
88  }
89  // end of run statistics
90  time_t end_time = ::time (0);
91  struct rusage usage_data;
92  if (!::getrusage (RUSAGE_SELF, &usage_data)) {
93  char s[1000];
94  snprintf (s, 1000,"Timing statistics: \n\n Real Time: %.0f s\n User Time: %ld s\n System Time: %ld\n",
95  ::difftime (end_time, start_time), usage_data.ru_utime.tv_sec, usage_data.ru_stime.tv_sec);
96  QMessageHandler::Get()->Send(NoFilterMsg,"Diana Main Program",s);
97  }
98  if(good) return 0;
99 
100  // Print the the message handler with prefix
101  QMessageHandler::Get()->Send(NoFilterMsg,"Backtrace",trace.str().c_str()) ;
102  // Print the the message handler without prefix
103  // QMessageHandler::Get()->Send(NoFilterMsg,"",trace.str().c_str()) ;
104  // Print the backtrace to stderr
105  // std::cerr << trace.str();
106  return 1;
107 }
108 
err
Definition: CheckOF.C:114
@ QExiting_s
@ QRunning_s
void diana_stacktrace(std::ostream &o, size_t MaxLines)
Definition: QDianaDebug.cc:74
@ NoFilterMsg
Definition: QMessageDefs.hh:11
static QDLLLoader & GetInstance()
Definition: QDll.cc:44
void SetAutoLoad(const bool autoload)
Definition: QDll.hh:56
error class with error type and description
Definition: QError.hh:115
Main class of the diana framework.
Definition: QFrameWork.hh:19
void Run()
main function, basically the real main program in diana. It runs a list of sequences provided by the ...
Definition: QFrameWork.cc:41
static QGSL & GetInstance()
Definition: QGSL.cc:18
void InitErrorHandler()
Definition: QGSL.cc:24
static QMessageHandler * Get()
Definition: QMessage.cc:24
void Send(MsgLevel l, const std::string &sender, const std::string &msg)
Definition: QMessage.cc:31
static QModuleFactory * Get()
void Init(int argc, char *const argv[])
Definition: QOptions.cc:166
static QOptions & GetInstance()
Definition: QOptions.cc:23
process status and signal handler
static QProcessStatus & GetInstance()
get singleton Instance
void Associate(int signalId, ProcessStatus_t pStatus)
associate a signal to a given process status
void SetState(ProcessStatus_t state)
change current process status bypassing status queue vector
int main(int argc, char *argv[])
Definition: diana.cc:34