/[PAMELA software]/DarthVader/ToFLevel2/src/TimeOfFlightLevel2.cpp
ViewVC logotype

Contents of /DarthVader/ToFLevel2/src/TimeOfFlightLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Sat Jun 17 12:14:56 2006 UTC (18 years, 5 months ago) by mocchiut
Branch: ToFLevel2
CVS Tags: v0r01, v0r02, v1r01beta, start, v1r00, v1r01
Changes since 1.1: +0 -0 lines
Imported sources

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

  ViewVC Help
Powered by ViewVC 1.1.23