/[PAMELA software]/calo/flight/MyDetector2Level2/src/MyDetector2Level2.cpp
ViewVC logotype

Contents of /calo/flight/MyDetector2Level2/src/MyDetector2Level2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Wed May 3 10:03:40 2006 UTC (18 years, 7 months ago) by mocchiut
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +32 -1 lines
Major update, requires GLTables and RunInfo

1 //
2 // C/C++ headers
3 //
4 #include <iostream>
5 //
6 // ROOT headers
7 //
8 #include <TString.h>
9 #include <TSQLServer.h>
10 //
11 // This package headers
12 //
13 #include <MyDect2Core.h>
14 #include <MyDect2Verl2.h>
15 //
16 using namespace std;
17 //
18 // Usage subroutine
19 //
20 void usage(){
21 printf("\nUsage:\n");
22 printf("\n MyDetector2Level2 [-v] [-h] [--version] -idRun ID_RUN [-processFile filename] [-processFolder folder]\n");
23 printf("\n [-host host] [-user username] [-psw password]\n");
24 printf("\n --version print informations about compilation and exit\n");
25 printf("\n -h | --help print this help and exit \n");
26 printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
27 printf("\n -idRun ID_RUN: ID number of the run to be processed \n");
28 printf("\n -processFile filename : output filename [default ID_RUN.Level2.root]\n");
29 printf("\n -processFolder default \"mydetector2Folder\"\n");
30 printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n");
31 printf("\n -user username for the DB [default = anonymous] \n");
32 printf("\n -psw password for the DB [default = \"\"]\n");
33 printf("\n Notice that parameter order does not matter. \n");
34 printf("\nExample: \n\nMyDetector2Level2 -idRun 1085 -processFile nomefile.root\n\n");
35 };
36 //
37 bool debug = false;
38 //
39 // Here the main
40 //
41 int main(int numinp, char *inps[]){
42 //
43 // Variables booking
44 //
45 int nul = 0;
46 Int_t error = 0;
47 Bool_t beverbose = false;
48 ULong64_t run = 0;
49 TString filename;
50 TSQLServer *dbc = 0;
51 Bool_t givenid = false;
52 TString processFolder = "mydetector2Folder";
53 //
54 TString host = "mysql://localhost/pamelaprod";
55 TString user = "anonymous";
56 TString psw = "";
57 //
58 // Checking input parameters
59 //
60 if ( numinp > 1 ){
61 for ( int i = 0; i < numinp; i++ ){
62 if ( !strcmp(inps[i],"--version") ){
63 MyDect2Info(true);
64 exit(0);
65 };
66 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
67 usage();
68 exit(0);
69 };
70 if ( !strcmp(inps[i],"-idRun") ) {
71 if ( numinp-1 < i+1 ){
72 usage();
73 exit(-3);
74 };
75 givenid = true;
76 char *pEnd;
77 run = strtoull(inps[i+1],&pEnd,0);
78 };
79 if ( !strcmp(inps[i],"-processFile") ) {
80 if ( numinp-1 < i+1 ){
81 usage();
82 exit(-3);
83 };
84 filename = (TString)inps[i+1];
85 };
86 if ( !strcmp(inps[i],"-processFolder") ) {
87 if ( numinp-1 < i+1 ){
88 usage();
89 exit(-3);
90 };
91 processFolder = (TString)inps[i+1];
92 };
93 if ( !strcmp(inps[i],"-host") ) {
94 if ( numinp-1 < i+1 ){
95 usage();
96 exit(-3);
97 };
98 host = (TString)inps[i+1];
99 };
100 if ( !strcmp(inps[i],"-user") ) {
101 if ( numinp-1 < i+1 ){
102 usage();
103 exit(-3);
104 };
105 user = (TString)inps[i+1];
106 };
107 if ( !strcmp(inps[i],"-psw") ) {
108 if ( numinp-1 < i+1 ){
109 usage();
110 exit(-3);
111 };
112 psw = (TString)inps[i+1];
113 };
114 if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true;
115 };
116 } else {
117 //
118 // no input parameters exit with error, we need at least the run id.
119 //
120 printf(" MYDETECTOR2 - ERROR: you must provide a run number (at least -1)\n");
121 exit(-1);
122 };
123 //
124 // If not in verbose mode redirect to /dev/null the stdout and stderr
125 //
126 if ( !beverbose ){
127 nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE);
128 dup2(nul,1);
129 dup2(nul,2);
130 };
131 //
132 // Check that an input run number has been given
133 //
134 if ( !givenid ) {
135 printf(" MYDETECTOR2 - ERROR: you must provide a run number (at least -1)\n");
136 exit(-1);
137 };
138 //
139 char *version = MyDect2Info(false);
140 //
141 // Start:
142 //
143 printf("\n Welcome to the MyDetector2 LEVEL2 flight software, version %s \n",version);
144 //
145 // Connect to the DB
146 //
147 printf("\nConnecting to database... \n");
148 //
149 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
150 if( !dbc ) {
151 printf(" MYDETECTOR2 - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
152 exit(-2);
153 };
154 bool connect = dbc->IsConnected();
155 //
156 if( !connect ) {
157 printf(" MYDETECTOR2 - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
158 exit(-2);
159 };
160 printf("...connected! \n\n");
161 //
162 // Run the core program, put any output error in the "error" variable
163 //
164 error = MyDect2Core(run,filename,processFolder,dbc);
165 //
166 // Close the DB connection
167 //
168 printf("\nClose the connection to the database... \n");
169 dbc->Close();
170 printf("...connection terminated!\n\n");
171 //
172 // Close redirection if the case.
173 //
174 if ( !beverbose ) close(nul);
175 //
176 // Return "error"
177 //
178 if ( error > 0 ) printf(" MYDETECTOR2 - WARNING: exiting with signal %i \n\n",error);
179 if ( error < 0 ) printf(" MYDETECTOR2 - ERROR: exiting with signal %i \n\n",error);
180 exit(error);
181 }

  ViewVC Help
Powered by ViewVC 1.1.23