/[PAMELA software]/DarthVader/AnticounterLevel2/src/AnticounterLevel2.cpp
ViewVC logotype

Annotation of /DarthVader/AnticounterLevel2/src/AnticounterLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

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

  ViewVC Help
Powered by ViewVC 1.1.23