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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Sep 6 08:05:10 2006 UTC (18 years, 3 months ago) by mocchiut
Branch: MAIN
CVS Tags: v5r00, v4r00, v2r01, v9r00, v9r01, v3r04, v3r05, v3r06, v3r00, v3r03, v6r01, v6r00, v2r00BETA
Changes since 1.1: +3 -3 lines
small update, still not compiling

1 mocchiut 1.1 //
2     // C/C++ headers
3     //
4     #include <iostream>
5     #include <sstream>
6     #include <TSystem.h>
7     //
8     // ROOT headers
9     //
10 mocchiut 1.2 #include <TFile.h>
11 mocchiut 1.1 #include <TString.h>
12     #include <TSQLServer.h>
13     //
14     // This package headers
15     //
16     #include <ToFCore.h>
17     #include <ToFVerl2.h>
18     //
19     using namespace std;
20     //
21     // Usage subroutine
22     //
23     void usage(){
24     printf("\nUsage:\n");
25     printf("\n ToFLevel2 [-v] [-h] [--version] -idRun ID_RUN [-processFile filename] [-processFolder folder]\n");
26     printf("\n [-host host] [-user username] [-psw password]\n");
27     printf("\n --version print informations about compilation and exit\n");
28     printf("\n -h | --help print this help and exit \n");
29     printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
30     printf("\n -idRun ID_RUN: ID number of the run to be processed \n");
31     printf("\n -processFile filename : output filename [default ID_RUN.Level2.root]\n");
32     printf("\n -processFolder default \"ToFFolder\"\n");
33     printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n");
34     printf("\n -user username for the DB [default = anonymous] \n");
35     printf("\n -psw password for the DB [default = \"\"]\n");
36     printf("\n Notice that parameter order does not matter. \n");
37     printf("\nExample: \n\nToFLevel2 -idRun 1085 -processFile nomefile.root\n\n");
38     };
39     //
40     bool debug = false;
41     //
42     // Here the main
43     //
44     int main(int numinp, char *inps[]){
45     //
46     // Variables booking
47     //
48     TFile *processFile =0;
49     int nul = 0;
50     Int_t error = 0;
51     Bool_t beverbose = false;
52 mocchiut 1.2 UInt_t run = 0;
53 mocchiut 1.1 TString filename="";
54     TString processFolder;
55     TString outdir = "./";
56     TSQLServer *dbc = 0;
57     Bool_t givenid = false;
58     processFolder = "ToFFolder";
59     //
60     TString host = "mysql://localhost/pamelaprod";
61     TString user = "anonymous";
62     TString psw = "";
63     //
64     // Checking input parameters
65     //
66     if ( numinp > 1 ){
67     for ( int i = 0; i < numinp; i++ ){
68     if ( !strcmp(inps[i],"--version") ){
69     ToFInfo(true);
70     exit(0);
71     };
72     if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
73     usage();
74     exit(0);
75     };
76     if ( !strcmp(inps[i],"-idRun") ) {
77     if ( numinp-1 < i+1 ){
78     usage();
79     exit(-3);
80     };
81     givenid = true;
82 mocchiut 1.2 run = (UInt_t)atoll(inps[i+1]);
83 mocchiut 1.1 };
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