/[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.2 - (hide annotations) (download)
Fri Apr 21 12:39:36 2006 UTC (18 years, 7 months ago) by mocchiut
Branch: MAIN
Changes since 1.1: +18 -4 lines
Some bugs fixed expecially in the reprocessing of data

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 mocchiut 1.2 printf("\n -processFolder default \"mydetector2Folder\"\n");
29 mocchiut 1.1 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 mocchiut 1.2 TString processFolder = "mydetector2Folder";
47 mocchiut 1.1 //
48     // Checking input parameters
49     //
50     if ( numinp > 1 ){
51     for ( int i = 0; i < numinp; i++ ){
52     if ( !strcmp(inps[i],"--version") ){
53     MyDect2Info(true);
54     exit(0);
55     };
56     if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
57     usage();
58     exit(0);
59     };
60     if ( !strcmp(inps[i],"-idRun") ) {
61 mocchiut 1.2 if ( numinp-1 < i+1 ){
62     usage();
63     exit(-3);
64     };
65 mocchiut 1.1 givenid = true;
66     char *pEnd;
67     run = strtoull(inps[i+1],&pEnd,0);
68     };
69     if ( !strcmp(inps[i],"-processFile") ) {
70 mocchiut 1.2 if ( numinp-1 < i+1 ){
71     usage();
72     exit(-3);
73     };
74 mocchiut 1.1 filename = (TString)inps[i+1];
75     };
76 mocchiut 1.2 if ( !strcmp(inps[i],"-processFolder") ) {
77     if ( numinp-1 < i+1 ){
78     usage();
79     exit(-3);
80     };
81     processFolder = (TString)inps[i+1];
82     };
83 mocchiut 1.1 if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true;
84     };
85     } else {
86     //
87     // no input parameters exit with error, we need at least the run id.
88     //
89     printf(" MYDETECTOR2 - ERROR: you must provide a run number (at least -1)\n");
90     exit(-1);
91     };
92     //
93     // If not in verbose mode redirect to /dev/null the stdout and stderr
94     //
95     if ( !beverbose ){
96     nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE);
97     dup2(nul,1);
98     dup2(nul,2);
99     };
100     //
101     // Check that an input run number has been given
102     //
103     if ( !givenid ) {
104     printf(" MYDETECTOR2 - ERROR: you must provide a run number (at least -1)\n");
105     exit(-1);
106     };
107     //
108     char *version = MyDect2Info(false);
109     //
110     // Start:
111     //
112     printf("\n Welcome to the MyDetector2 LEVEL2 flight software, version %s \n",version);
113     //
114     // Connect to the DB
115     //
116     printf("\nConnecting to database... \n");
117     //
118     dbc = TSQLServer::Connect("mysql://localhost/pamelaprod","anonymous","");
119     if( !dbc ) {
120     printf(" MYDETECTOR2 - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
121     exit(-2);
122     };
123     bool connect = dbc->IsConnected();
124     //
125     if( !connect ) {
126     printf(" MYDETECTOR2 - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
127     exit(-2);
128     };
129     printf("...connected! \n\n");
130     //
131     // Run the core program, put any output error in the "error" variable
132     //
133 mocchiut 1.2 error = MyDect2Core(run,filename,processFolder,dbc);
134 mocchiut 1.1 //
135     // Close the DB connection
136     //
137     printf("\nClose the connection to the database... \n");
138     dbc->Close();
139     printf("...connection terminated!\n\n");
140     //
141     // Close redirection if the case.
142     //
143     if ( !beverbose ) close(nul);
144     //
145     // Return "error"
146     //
147     if ( error > 0 ) printf(" MYDETECTOR2 - WARNING: exiting with signal %i \n\n",error);
148     if ( error < 0 ) printf(" MYDETECTOR2 - ERROR: exiting with signal %i \n\n",error);
149     exit(error);
150     }

  ViewVC Help
Powered by ViewVC 1.1.23