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

Contents of /DarthVader/AnticounterLevel2/src/AnticounterLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Tue Sep 5 14:49:40 2006 UTC (18 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: v5r00, v4r00, v2r01, v9r00, v9r01, v3r04, v3r05, v3r06, v3r00, v3r01, v3r03, v6r01, v6r00, v2r00BETA
Changes since 1.1: +3 -3 lines
_NOT_ COMPILING yet, fixed AC, ND, S4, RunInfo, OrbitalInfo and Trigger

1 //
2 // C/C++ headers
3 //
4 #include <iostream>
5 #include <sstream>
6 //
7 // ROOT headers
8 //
9 #include <TFile.h>
10 #include <TString.h>
11 #include <TSQLServer.h>
12 //
13 // This package headers
14 //
15 #include <AcCore.h>
16 #include <AcVerl2.h>
17 //
18 using namespace std;
19 //
20 // Usage subroutine
21 //
22 void usage(){
23 printf("\nUsage:\n");
24 printf("\n AnticounterLevel2 [-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 \"anticounterFolder\"\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\nAnticounterLevel2 -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 UInt_t run = 0;
52 TString filename;
53 TString outDir = "./";
54 TSQLServer *dbc = 0;
55 Bool_t givenid = false;
56 TString processFolder = "anticounterFolder";
57 //
58 TString host = "mysql://localhost/pamelaprod";
59 TString user = "anonymous";
60 TString psw = "";
61 //
62 // Checking input parameters
63 //
64 if ( numinp > 1 ){
65 for ( int i = 0; i < numinp; i++ ){
66 if ( !strcmp(inps[i],"--version") ){
67 AcInfo(true);
68 exit(0);
69 };
70 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
71 usage();
72 exit(0);
73 };
74 if ( !strcmp(inps[i],"-idRun") ) {
75 if ( numinp-1 < i+1 ){
76 usage();
77 exit(-3);
78 };
79 givenid = true;
80 run = (UInt_t)atoll(inps[i+1]);
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