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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Tue Apr 18 13:12:40 2006 UTC (18 years, 7 months ago) by mocchiut
Branch: MAIN
Branch point for: v0r00
Initial revision

1 mocchiut 1.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 --version print informations about compilation and exit\n");
24     printf("\n -h | --help print this help and exit \n");
25     printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
26     printf("\n -idRun ID_RUN: ID number of the run to be processed \n");
27     printf("\n -processFile filename : output filename [default ID_RUN.Level2.root]\n");
28     printf("\n -processFolder not used [default \"\"]\n");
29     printf("\n Notice that parameter order does not matter. \n");
30     printf("\nExample: \n\nMyDetector2Level2 -idRun 1085 -processFile nomefile.root\n\n");
31     };
32     //
33     // Here the main
34     //
35     int main(int numinp, char *inps[]){
36     //
37     // Variables booking
38     //
39     int nul = 0;
40     Int_t error = 0;
41     Bool_t beverbose = false;
42     ULong64_t run = 0;
43     TString filename;
44     TSQLServer *dbc = 0;
45     Bool_t givenid = false;
46     //
47     // Checking input parameters
48     //
49     if ( numinp > 1 ){
50     for ( int i = 0; i < numinp; i++ ){
51     if ( !strcmp(inps[i],"--version") ){
52     MyDect2Info(true);
53     exit(0);
54     };
55     if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
56     usage();
57     exit(0);
58     };
59     if ( !strcmp(inps[i],"-idRun") ) {
60     if ( numinp-1 < i+1 ) exit(-3);
61     givenid = true;
62     char *pEnd;
63     run = strtoull(inps[i+1],&pEnd,0);
64     };
65     if ( !strcmp(inps[i],"-processFile") ) {
66     if ( numinp-1 < i+1 ) exit(-3);
67     filename = (TString)inps[i+1];
68     };
69     if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true;
70     };
71     } else {
72     //
73     // no input parameters exit with error, we need at least the run id.
74     //
75     printf(" MYDETECTOR2 - ERROR: you must provide a run number (at least -1)\n");
76     exit(-1);
77     };
78     //
79     // If not in verbose mode redirect to /dev/null the stdout and stderr
80     //
81     if ( !beverbose ){
82     nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE);
83     dup2(nul,1);
84     dup2(nul,2);
85     };
86     //
87     // Check that an input run number has been given
88     //
89     if ( !givenid ) {
90     printf(" MYDETECTOR2 - ERROR: you must provide a run number (at least -1)\n");
91     exit(-1);
92     };
93     //
94     char *version = MyDect2Info(false);
95     //
96     // Start:
97     //
98     printf("\n Welcome to the MyDetector2 LEVEL2 flight software, version %s \n",version);
99     //
100     // Connect to the DB
101     //
102     printf("\nConnecting to database... \n");
103     //
104     dbc = TSQLServer::Connect("mysql://localhost/pamelaprod","anonymous","");
105     if( !dbc ) {
106     printf(" MYDETECTOR2 - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
107     exit(-2);
108     };
109     bool connect = dbc->IsConnected();
110     //
111     if( !connect ) {
112     printf(" MYDETECTOR2 - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
113     exit(-2);
114     };
115     printf("...connected! \n\n");
116     //
117     // Run the core program, put any output error in the "error" variable
118     //
119     error = MyDect2Core(run,filename,dbc);
120     //
121     // Close the DB connection
122     //
123     printf("\nClose the connection to the database... \n");
124     dbc->Close();
125     printf("...connection terminated!\n\n");
126     //
127     // Close redirection if the case.
128     //
129     if ( !beverbose ) close(nul);
130     //
131     // Return "error"
132     //
133     if ( error > 0 ) printf(" MYDETECTOR2 - WARNING: exiting with signal %i \n\n",error);
134     if ( error < 0 ) printf(" MYDETECTOR2 - ERROR: exiting with signal %i \n\n",error);
135     exit(error);
136     }

  ViewVC Help
Powered by ViewVC 1.1.23