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

Contents of /DarthVader/TriggerLevel2/src/TriggerLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Tue Nov 29 15:23:44 2011 UTC (13 years ago) by pam-fi
Branch: MAIN
CVS Tags: v10RED, v10REDr01, HEAD
Changes since 1.2: +2 -0 lines
Some fixes to prevent memory leaks or double delete.

1 //
2 // C/C++ headers
3 //
4 #include <iostream>
5 #include <sstream>
6 #include <TSystem.h>
7 //
8 // ROOT headers
9 //
10 #include <TFile.h>
11 #include <TString.h>
12 #include <TSQLServer.h>
13 //
14 // This package headers
15 //
16 #include <TrigCore.h>
17 #include <TrigVerl2.h>
18 //
19 using namespace std;
20 //
21 // Usage subroutine
22 //
23 void usage(){
24 printf("\nUsage:\n");
25 printf("\n TriggerLevel2 [-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 \"triggerFolder\"\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\nTriggerLevel2 -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 UInt_t run = 0;
53 TString filename="";
54 TString processFolder;
55 TString outdir = "./";
56 TSQLServer *dbc = 0;
57 Bool_t givenid = false;
58 processFolder = "triggerFolder";
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 TrigInfo(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 run = (UInt_t)atoll(inps[i+1]);
83 };
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 if ( !strcmp(inps[i],"-processFile") ) {
92 if ( numinp-1 < i+1 ){
93 usage();
94 exit(-3);
95 };
96 filename = (TString)inps[i+1];
97 };
98 if ( !strcmp(inps[i],"-processFolder") ) {
99 if ( numinp-1 < i+1 ){
100 usage();
101 exit(-3);
102 };
103 processFolder = (TString)inps[i+1];
104 };
105 if ( !strcmp(inps[i],"-host") ) {
106 if ( numinp-1 < i+1 ){
107 usage();
108 exit(-3);
109 };
110 host = (TString)inps[i+1];
111 };
112 if ( !strcmp(inps[i],"-user") ) {
113 if ( numinp-1 < i+1 ){
114 usage();
115 exit(-3);
116 };
117 user = (TString)inps[i+1];
118 };
119 if ( !strcmp(inps[i],"-psw") ) {
120 if ( numinp-1 < i+1 ){
121 usage();
122 exit(-3);
123 };
124 psw = (TString)inps[i+1];
125 };
126 if ( !strcmp(inps[i],"-v") || !strcmp(inps[i],"--verbose") ) beverbose = true;
127 };
128 } else {
129 //
130 // no input parameters exit with error, we need at least the run id.
131 //
132 printf(" TRIGGER - ERROR: you must provide a run number (at least -1)\n");
133 exit(-1);
134 };
135 //
136 // If not in verbose mode redirect to /dev/null the stdout and stderr
137 //
138 if ( !beverbose ){
139 nul = open("/dev/null", O_CREAT | O_RDWR,S_IREAD | S_IWRITE);
140 dup2(nul,1);
141 dup2(nul,2);
142 };
143 //
144 // Check that an input run number has been given
145 //
146 if ( !givenid ) {
147 printf(" TRIGGER - ERROR: you must provide a run number (at least -1)\n");
148 exit(-1);
149 };
150 //
151 char *version = TrigInfo(false);
152 //
153 // Start:
154 //
155 printf("\n Welcome to the Trigger LEVEL2 flight software, version %s \n",version);
156 //
157 // Connect to the DB
158 //
159 printf("\nConnecting to database... \n");
160 //
161 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
162 if( !dbc ) {
163 printf(" TRIGGER - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
164 exit(-2);
165 };
166 bool connect = dbc->IsConnected();
167 //
168 if( !connect ) {
169 printf(" TRIGGER - ERROR: problems connecting to the DB (check username and passwd), exiting...\n\n");
170 exit(-2);
171 };
172 printf("...connected! \n\n");
173 //
174 if ( filename.IsNull() ){
175 stringstream strun;
176 strun.str("");
177 strun << run;
178 filename += strun.str();
179 filename += ".Level2.root";
180 };
181 filename = outdir + "/" + filename;
182 processFile = new TFile(filename.Data(),"UPDATE");
183 //
184 // Run the core program, put any output error in the "error" variable
185 //
186 error = TrigCore(run, processFile ,dbc, numinp, inps);
187 if( processFile ) processFile->Close();
188 //
189 // Close the DB connection
190 //
191 printf("\nClose the connection to the database... \n");
192 dbc->Close();
193 delete dbc;
194 dbc = 0;
195 printf("...connection terminated!\n\n");
196 //
197 // Close redirection if the case.
198 //
199 if ( !beverbose ) close(nul);
200 //
201 // Return "error"
202 //
203 if ( error > 0 ) printf(" TRIGGER - WARNING: exiting with signal %i \n\n",error);
204 if ( error < 0 ) printf(" TRIGGER - ERROR: exiting with signal %i \n\n",error);
205 exit(error);
206 }

  ViewVC Help
Powered by ViewVC 1.1.23