1 |
mocchiut |
1.1 |
// |
2 |
|
|
// L2OrbitalInfo.cc -- standalone program to call the OrbitalInfo subroutine. |
3 |
|
|
// |
4 |
|
|
// |
5 |
|
|
// Version 1.00 16/05/2006: working. |
6 |
|
|
// |
7 |
|
|
// Changelog: |
8 |
|
|
// |
9 |
|
|
// Input parameters must be now introduced by an identifier (-id run_id -file filename). Order does not matter. |
10 |
|
|
// Added verbose/not verbose option. |
11 |
|
|
// |
12 |
|
|
// |
13 |
|
|
// C/C++ headers |
14 |
|
|
// |
15 |
|
|
#include <iostream> |
16 |
|
|
#include <sstream> |
17 |
|
|
#include <TSystem.h> |
18 |
|
|
// |
19 |
|
|
// ROOT headers |
20 |
|
|
// |
21 |
mocchiut |
1.2 |
#include <TFile.h> |
22 |
mocchiut |
1.1 |
#include <TString.h> |
23 |
|
|
#include <TSQLServer.h> |
24 |
|
|
// |
25 |
|
|
// This package headers |
26 |
|
|
// |
27 |
|
|
#include <OrbitalInfoCore.h> |
28 |
|
|
#include <OrbitalInfoVerl2.h> |
29 |
|
|
// |
30 |
|
|
using namespace std; |
31 |
|
|
// |
32 |
|
|
// Usage subroutine |
33 |
|
|
// |
34 |
|
|
void usage(){ |
35 |
|
|
printf("\nUsage:\n"); |
36 |
|
|
printf("\n OrbitalInfo [-v] [-h] [--version] -idRun ID_RUN [-processFile filename] [-outDir outDir] [-processFolder folder]\n"); |
37 |
|
|
printf("\n [-host host] [-user username] [-psw password]\n"); |
38 |
|
|
printf("\n --version print informations about compilation and exit\n"); |
39 |
|
|
printf("\n -h | --help print this help and exit \n"); |
40 |
|
|
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
41 |
|
|
printf("\n -idRun ID_RUN: ID number of the run to be processed \n"); |
42 |
|
|
printf("\n -outDir Path where to put the output [default ./] \n"); |
43 |
|
|
printf("\n -processFile output filename [default ID_RUN.Level2.root]\n"); |
44 |
|
|
printf("\n -processFolder folder for output data but the processFile [default \"OrbitalInfoFolder\"]\n"); |
45 |
|
|
printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); |
46 |
|
|
printf("\n -user username for the DB [default = anonymous] \n"); |
47 |
|
|
printf("\n -psw password for the DB [default = \"\"]\n"); |
48 |
|
|
printf("\n Notice that parameter order does not matter. \n"); |
49 |
|
|
printf("\nExample: \n\nOrbitalInfo -idRun 1085 -processFile nomefile.root\n\n"); |
50 |
|
|
}; |
51 |
|
|
// |
52 |
|
|
Bool_t debug = false; |
53 |
|
|
// |
54 |
|
|
// Here the main |
55 |
|
|
// |
56 |
|
|
int main(int numinp, char *inps[]){ |
57 |
|
|
// |
58 |
|
|
// Variables booking |
59 |
|
|
// |
60 |
|
|
TFile *processFile =0; |
61 |
|
|
int nul = 0; |
62 |
|
|
int error = 0; |
63 |
|
|
Bool_t beverbose = false; |
64 |
mocchiut |
1.2 |
UInt_t run = 0; |
65 |
mocchiut |
1.1 |
TString filename=""; |
66 |
|
|
TString processFolder; |
67 |
|
|
TString outDir = "./"; |
68 |
|
|
TSQLServer *dbc = 0; |
69 |
|
|
Bool_t givenid = false; |
70 |
|
|
processFolder = "OrbitalInfoFolder"; |
71 |
|
|
// |
72 |
|
|
TString host = "mysql://localhost/pamelaprod"; |
73 |
|
|
TString user = "anonymous"; |
74 |
|
|
TString psw = ""; |
75 |
|
|
// |
76 |
|
|
// Checking input parameters |
77 |
|
|
// |
78 |
|
|
if ( numinp > 1 ){ |
79 |
|
|
for ( int i = 0; i < numinp; i++ ){ |
80 |
|
|
if ( !strcmp(inps[i],"--version") ){ |
81 |
|
|
OrbitalInfoInfo(true); |
82 |
|
|
exit(0); |
83 |
|
|
}; |
84 |
|
|
if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ |
85 |
|
|
usage(); |
86 |
|
|
exit(0); |
87 |
|
|
}; |
88 |
|
|
if ( !strcmp(inps[i],"-idRun") ) { |
89 |
|
|
if ( numinp-1 < i+1 ) { |
90 |
|
|
usage(); |
91 |
|
|
exit(-3); |
92 |
|
|
}; |
93 |
|
|
givenid = true; |
94 |
mocchiut |
1.2 |
run = (UInt_t)atoll(inps[i+1]); |
95 |
mocchiut |
1.1 |
}; |
96 |
|
|
if ( !strcmp(inps[i],"-outDir") ) { |
97 |
|
|
if ( numinp-1 < i+1 ){ |
98 |
|
|
usage(); |
99 |
|
|
exit(-3); |
100 |
|
|
}; |
101 |
|
|
outDir = (TString)inps[i+1]; |
102 |
|
|
}; |
103 |
|
|
if ( !strcmp(inps[i],"-processFile") ) { |
104 |
|
|
if ( numinp-1 < i+1 ){ |
105 |
|
|
usage(); |
106 |
|
|
exit(-3); |
107 |
|
|
}; |
108 |
|
|
filename = (TString)inps[i+1]; |
109 |
|
|
}; |
110 |
|
|
if ( !strcmp(inps[i],"-processFolder") ) { |
111 |
|
|
if ( numinp-1 < i+1 ){ |
112 |
|
|
usage(); |
113 |
|
|
exit(-3); |
114 |
|
|
}; |
115 |
|
|
processFolder = (TString)inps[i+1]; |
116 |
|
|
}; |
117 |
|
|
if ( !strcmp(inps[i],"-host") ) { |
118 |
|
|
if ( numinp-1 < i+1 ){ |
119 |
|
|
usage(); |
120 |
|
|
exit(-3); |
121 |
|
|
}; |
122 |
|
|
host = (TString)inps[i+1]; |
123 |
|
|
}; |
124 |
|
|
if ( !strcmp(inps[i],"-user") ) { |
125 |
|
|
if ( numinp-1 < i+1 ){ |
126 |
|
|
usage(); |
127 |
|
|
exit(-3); |
128 |
|
|
}; |
129 |
|
|
user = (TString)inps[i+1]; |
130 |
|
|
}; |
131 |
|
|
if ( !strcmp(inps[i],"-psw") ) { |
132 |
|
|
if ( numinp-1 < i+1 ){ |
133 |
|
|
usage(); |
134 |
|
|
exit(-3); |
135 |
|
|
}; |
136 |
|
|
psw = (TString)inps[i+1]; |
137 |
|
|
}; |
138 |
|
|
if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true; |
139 |
|
|
}; |
140 |
|
|
} else { |
141 |
|
|
// |
142 |
|
|
// no input parameters exit with error, we need at least the run id. |
143 |
|
|
// |
144 |
|
|
printf("\n OrbitalInfo - ERROR: you must provide a run number (at least 0)\n\n"); |
145 |
|
|
exit(-1); |
146 |
|
|
}; |
147 |
|
|
// |
148 |
|
|
// If not in verbose mode redirect to /dev/null the stdout and stderr |
149 |
|
|
// |
150 |
|
|
if ( !beverbose ){ |
151 |
|
|
nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE); |
152 |
|
|
dup2(nul,1); |
153 |
|
|
dup2(nul,2); |
154 |
|
|
}; |
155 |
|
|
|
156 |
|
|
// |
157 |
|
|
// Check that an input run number has been given |
158 |
|
|
// |
159 |
|
|
if ( !givenid ) { |
160 |
|
|
printf("\n OrbitalInfo - ERROR: you must provide a run number (at least 0)\n\n"); |
161 |
|
|
exit(-1); |
162 |
|
|
}; |
163 |
|
|
// |
164 |
|
|
char *version = OrbitalInfoInfo(false); |
165 |
|
|
// |
166 |
|
|
// Start: |
167 |
|
|
// |
168 |
|
|
printf("\n Welcome to the OrbitalInfo flight software, version %s \n",version); |
169 |
|
|
// |
170 |
|
|
// Connect to the DB |
171 |
|
|
// |
172 |
|
|
printf("\n Connecting to database... \n"); |
173 |
|
|
// |
174 |
|
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
175 |
|
|
if( !dbc ) { |
176 |
|
|
printf(" OrbitalInfo - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n"); |
177 |
|
|
exit(-2); |
178 |
|
|
}; |
179 |
|
|
bool connect = dbc->IsConnected(); |
180 |
|
|
// |
181 |
|
|
if( !connect ) { |
182 |
|
|
printf(" OrbitalInfo - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n"); |
183 |
|
|
exit(-2); |
184 |
|
|
}; |
185 |
|
|
printf("...connected! \n\n"); |
186 |
|
|
// |
187 |
|
|
if ( filename.IsNull() ){ |
188 |
|
|
stringstream strun; |
189 |
|
|
strun.str(""); |
190 |
|
|
strun << run; |
191 |
|
|
filename += strun.str(); |
192 |
|
|
filename += ".Level2.root"; |
193 |
|
|
}; |
194 |
|
|
filename = outDir + "/" + filename; |
195 |
|
|
processFile = new TFile(filename.Data(),"UPDATE"); |
196 |
|
|
// |
197 |
|
|
// Run the core program, put any output error in the "error" variable |
198 |
|
|
// |
199 |
|
|
error = OrbitalInfoCore(run, processFile ,dbc, numinp, inps); |
200 |
|
|
// |
201 |
|
|
// Close the DB connection |
202 |
|
|
// |
203 |
|
|
printf("\nClose the connection to the database... \n"); |
204 |
|
|
dbc->Close(); |
205 |
|
|
printf("...connection terminated!\n\n"); |
206 |
|
|
// |
207 |
|
|
// Close redirection if the case. |
208 |
|
|
// |
209 |
|
|
if ( !beverbose ) close(nul); |
210 |
|
|
processFile->Close(); |
211 |
|
|
// |
212 |
|
|
// Return "error" |
213 |
|
|
// |
214 |
|
|
if ( error > 0 ) printf(" OrbitalInfo - WARNING: exiting with signal %i \n\n",error); |
215 |
|
|
if ( error < 0 ) printf(" OrbitalInfo - ERROR: exiting with signal %i \n\n",error); |
216 |
|
|
exit(error); |
217 |
|
|
} |