/[PAMELA software]/DarthVader/NDLevel2/src/ND_LEVEL2.cpp
ViewVC logotype

Contents of /DarthVader/NDLevel2/src/ND_LEVEL2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Fri May 19 13:15:26 2006 UTC (18 years, 6 months ago) by mocchiut
Branch: MAIN
Branch point for: DarthVader
Initial revision

1 //
2 // L2ND.ccp -- standalone program to call the l2NDcore subroutine.
3 //
4 //
5 // Version 3.00 17/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 #include <TString.h>
22 #include <TSQLServer.h>
23 //
24 // This package headers
25 //
26 #include <NDCore.h>
27 #include <NDVerl2.h>
28 //
29 using namespace std;
30 //
31 // Usage subroutine
32 //
33 void usage(){
34 printf("\nUsage:\n");
35 printf("\n NDLevel2 [-v] [-h] [--version] -idRun ID_RUN [-outDir outDir] [-processFile filename] [-processFolder folder]\n");
36 printf("\n [-host host] [-user username] [-psw password]\n");
37 printf("\n --version print informations about compilation and exit\n");
38 printf("\n -h | --help print this help and exit \n");
39 printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
40 printf("\n -idRun ID_RUN: ID number of the run to be processed \n");
41 printf("\n -outDir Path where to put the output [default ./] \n");
42 printf("\n -processFile output filename [default ID_RUN.Level2.root]\n");
43 printf("\n -processFolder folder for output data but the processFile [default \"NDFolder\"]\n");
44 printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n");
45 printf("\n -user username for the DB [default = anonymous] \n");
46 printf("\n -psw password for the DB [default = \"\"]\n");
47 printf("\n Notice that parameter order does not matter. \n");
48 printf("\nExample: \n\nNDLevel2 -idRun 1085 -processFile nomefile.root\n\n");
49 };
50 //
51 Bool_t debug = false;
52 //
53 // Here the main
54 //
55 int main(int numinp, char *inps[]){
56 //
57 // Variables booking
58 //
59 TFile *processFile =0;
60 int nul = 0;
61 int error = 0;
62 Bool_t beverbose = false;
63 ULong64_t run = 0;
64 TString filename="";
65 TString processFolder;
66 TString outDir = "./";
67 TSQLServer *dbc = 0;
68 Bool_t givenid = false;
69 processFolder = "NDFolder";
70 //
71 TString host = "mysql://localhost/pamelaprod";
72 TString user = "anonymous";
73 TString psw = "";
74 //
75 // Checking input parameters
76 //
77 if ( numinp > 1 ){
78 for ( int i = 0; i < numinp; i++ ){
79 if ( !strcmp(inps[i],"--version") ){
80 NDInfo(true);
81 exit(0);
82 };
83 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
84 usage();
85 exit(0);
86 };
87 if ( !strcmp(inps[i],"-idRun") ) {
88 if ( numinp-1 < i+1 ) {
89 usage();
90 exit(-3);
91 };
92 givenid = true;
93 char *pEnd;
94 run = strtoull(inps[i+1],&pEnd,0);
95 };
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 ND - 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 // Check that an input run number has been given
157 //
158 if ( !givenid ) {
159 printf("\n ND - ERROR: you must provide a run number (at least 0)\n\n");
160 exit(-1);
161 };
162 //
163 char *version = NDInfo(false);
164 //
165 // Start:
166 //
167 printf("\n Welcome to the ND LEVEL2 flight software, version %s \n",version);
168 //
169 // Connect to the DB
170 //
171 printf("\nConnecting to database... \n");
172 //
173 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
174 if( !dbc ) {
175 printf(" ND - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
176 exit(-2);
177 };
178 bool connect = dbc->IsConnected();
179 //
180 if( !connect ) {
181 printf(" ND - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
182 exit(-2);
183 };
184 printf("...connected! \n\n");
185 //
186 if ( filename.IsNull() ){
187 stringstream strun;
188 strun.str("");
189 strun << run;
190 filename += strun.str();
191 filename += ".Level2.root";
192 };
193 filename = outDir + "/" + filename;
194 processFile = new TFile(filename.Data(),"UPDATE");
195 //
196 // Run the core program, put any output error in the "error" variable
197 //
198 error = NDCore(run, processFile,dbc, numinp, inps);
199 //
200 // Close the DB connection
201 //
202 printf("\nClose the connection to the database... \n");
203 dbc->Close();
204 printf("...connection terminated!\n\n");
205 //
206 // Close redirection if the case.
207 //
208 if ( !beverbose ) close(nul);
209 //
210 // Return "error"
211 //
212 if ( error > 0 ) printf(" ND - WARNING: exiting with signal %i \n\n",error);
213 if ( error < 0 ) printf(" ND - ERROR: exiting with signal %i \n\n",error);
214 processFile->Close();
215 exit(error);
216 }

  ViewVC Help
Powered by ViewVC 1.1.23