/[PAMELA software]/PadmeAmidala/src/PadmeAmidala.cpp
ViewVC logotype

Contents of /PadmeAmidala/src/PadmeAmidala.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Tue Jan 27 10:15:40 2009 UTC (15 years, 10 months ago) by mocchiut
Branch: MAIN
Changes since 1.7: +5 -1 lines
Exit code 255 implemented

1 //
2 // C/C++ headers
3 //
4 #include <iostream>
5 #include <iomanip>
6 #include <fstream>
7 #include <sstream>
8 #include <string.h>
9 //
10 // ROOT headers
11 //
12 #include <TSQLServer.h>
13 #include <TString.h>
14 #include <TTimeStamp.h>
15 #include <TFile.h>
16 #include <TSystem.h>
17 #include <TChain.h>
18 #include <TH1.h>
19 #include <TTree.h>
20 #include <TKey.h>
21 #include <Riostream.h>
22 #include <TObjString.h>
23 #include <TClass.h>
24 //
25 // Detector's package headers
26 //
27 #include <RunGlue.h>
28 //
29 using namespace std;
30 //
31 //
32 //
33 #include <PadmeAmidalaVerl2.h>
34 //
35 //
36 // Usage subroutine
37 //
38 void amidalausage(){
39 printf("\nUsage:\n");
40 printf("\n Amidala [ options ]\n");
41 printf("\n Options are:\n\n");
42 printf(" --version print informations about compilation and exit\n");
43 printf(" -h | --help print this help and exit \n");
44 printf(" -g | --debug set debug flag\n");
45 printf(" -idRun run merge all runs in the directory which have the same date of run \"run\"\n");
46 printf(" -outdir dir output directory \"dir\"\n");
47 printf(" -dir dir merge all runs in the directory \"dir\"\n");
48 printf(" -d | -delete delete original DarthVader runs once merged\n");
49 printf(" -no-DBupdate do not update the DB\n");
50 printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");
51 printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n");
52 printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n");
53 printf("\nExamples: \n");
54 printf(" Amidala -idRun 1085 \n");
55 printf(" Amidala -dir /home/pamela/level2/ \n\n");
56 };
57 //
58 // Here the main
59 //
60 int main(int numinp, char *inps[]){
61 //
62 // Variables booking
63 //
64 TString message;
65 //
66 UInt_t run = 0;
67 //
68 TString dir = "";
69 TString outdir = "";
70 TString dectlist = "";
71 //
72 TSQLServer *dbc = 0;
73 TString host = "mysql://localhost/pamelaprod";
74 TString user = "anonymous";
75 TString psw = "";
76 Bool_t debug = false;
77 Bool_t delop = false;
78 Bool_t dbup = true;
79 //
80 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
81 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
82 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
83 if ( !pamdbhost ) pamdbhost = "";
84 if ( !pamdbuser ) pamdbuser = "";
85 if ( !pamdbpsw ) pamdbpsw = "";
86 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
87 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
88 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
89 //
90 stringstream myquery;
91 //
92 // Checking input parameters
93 //
94 Int_t i = 0;
95 if ( numinp > 1 ){
96 while ( i < numinp ){
97 if ( !strcmp(inps[i],"--version") ){
98 AmidalaInfo(true);
99 exit(0);
100 };
101 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
102 amidalausage();
103 exit(0);
104 };
105 if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ){
106 debug = true;
107 };
108 if ( !strcmp(inps[i],"-d") || !strcmp(inps[i],"-delete") ){
109 delop = true;
110 };
111 if ( !strcmp(inps[i],"-no-DBupdate") ){
112 dbup = false;
113 };
114 if ( !strcmp(inps[i],"-idRun") ) {
115 if ( numinp-1 < i+1 ) {
116 amidalausage();
117 exit(-3);
118 };
119 run = (UInt_t)atoll(inps[i+1]);
120 };
121 if ( !strcmp(inps[i],"-dir") ) {
122 if ( numinp-1 < i+1 ){
123 amidalausage();
124 exit(-3);
125 };
126 dir = (TString)inps[i+1];
127 };
128 if ( !strcmp(inps[i],"-outdir") ) {
129 if ( numinp-1 < i+1 ){
130 amidalausage();
131 exit(-3);
132 };
133 outdir = (TString)inps[i+1];
134 };
135 if ( !strcmp(inps[i],"-host") ) {
136 if ( numinp-1 < i+1 ){
137 amidalausage();
138 exit(-3);
139 };
140 host = (TString)inps[i+1];
141 };
142 if ( !strcmp(inps[i],"-user") ) {
143 if ( numinp-1 < i+1 ){
144 amidalausage();
145 exit(-3);
146 };
147 user = (TString)inps[i+1];
148 };
149 if ( !strcmp(inps[i],"-psw") ) {
150 if ( numinp-1 < i+1 ){
151 amidalausage();
152 exit(-3);
153 };
154 psw = (TString)inps[i+1];
155 };
156 //
157 if ( !strcmp(inps[i],"-CAL") ) {
158 dectlist +=" -CAL";
159 };
160 if ( !strcmp(inps[i],"-CAL1") ) {
161 dectlist +=" -CAL1";
162 };
163 if ( !strcmp(inps[i],"-TRK") ) {
164 dectlist +=" -TRK";
165 };
166 if ( !strcmp(inps[i],"-TRK1") ) {
167 dectlist +=" -TRK1";
168 };
169 if ( !strcmp(inps[i],"-TRKh") ) {
170 dectlist +=" -TRKh";
171 };
172 if ( !strcmp(inps[i],"-TOF") ) {
173 dectlist +=" -TOF";
174 };
175 if ( !strcmp(inps[i],"-TRG") ) {
176 dectlist +=" -TRG";
177 };
178 if ( !strcmp(inps[i],"-S4") ) {
179 dectlist +=" -S4";
180 };
181 if ( !strcmp(inps[i],"-ND") ) {
182 dectlist +=" -ND";
183 };
184 if ( !strcmp(inps[i],"-AC") ) {
185 dectlist +=" -AC";
186 };
187 if ( !strcmp(inps[i],"-RUN") ) {
188 dectlist +=" -RUN";
189 };
190 if ( !strcmp(inps[i],"-ORB") ) {
191 dectlist +=" -ORB";
192 };
193 //
194 if ( !strcmp(inps[i],"-all") || !strcmp(inps[i],"-ALL") ) {
195 dectlist +=" -ALL";
196 };
197 //
198 if ( !strcmp(inps[i],"+all") || !strcmp(inps[i],"+ALL") ) {
199 dectlist +=" +ALL";
200 };
201 if ( !strcmp(inps[i],"+auto") || !strcmp(inps[i],"+AUTO") ) {
202 dectlist +=" +AUTO";
203 };
204 if ( !strcmp(inps[i],"+CAL") ) {
205 dectlist +=" +CAL";
206 };
207 if ( !strcmp(inps[i],"+CAL1") ) {
208 dectlist +=" +CAL1";
209 };
210 if ( !strcmp(inps[i],"+TRK") ) {
211 dectlist +=" +TRK";
212 };
213 if ( !strcmp(inps[i],"+TRK1") ) {
214 dectlist +=" +TRK1";
215 };
216 if ( !strcmp(inps[i],"+TRKh") ) {
217 dectlist +=" +TRKh";
218 };
219 if ( !strcmp(inps[i],"+TOF") ) {
220 dectlist +=" +TOF";
221 };
222 if ( !strcmp(inps[i],"+TRG") ) {
223 dectlist +=" +TRG";
224 };
225 if ( !strcmp(inps[i],"+S4") ) {
226 dectlist +=" +S4";
227 };
228 if ( !strcmp(inps[i],"+ND") ) {
229 dectlist +=" +ND";
230 };
231 if ( !strcmp(inps[i],"+AC") ) {
232 dectlist +=" +AC";
233 };
234 if ( !strcmp(inps[i],"+RUN") ) {
235 dectlist +=" +RUN";
236 };
237 if ( !strcmp(inps[i],"+ORB") ) {
238 dectlist +=" +ORB";
239 };
240 //
241 i++;
242 };
243 //
244 } else {
245 //
246 // no input parameters exit with error, we need at least the run id.
247 //
248 amidalausage();
249 exit(-2);
250 };
251 //
252 if ( run && strcmp(dir.Data(),"") ){
253 amidalausage();
254 printf(" Cannot give as input both ID run and directory \n\n");
255 exit(-2);
256 };
257 if ( !run && !strcmp(dir.Data(),"") ){
258 amidalausage();
259 printf(" You must give as input or an ID run or a directory \n\n");
260 exit(-2);
261 };
262 //
263 // Connect to the DB
264 //
265 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
266 if( !dbc ) throw -2;
267 //
268 bool connect = dbc->IsConnected();
269 //
270 if( !connect ){
271 printf(" Error, not connected to DB\n");
272 exit(-1);
273 };
274 //
275 myquery.str("");
276 myquery << "SET time_zone='+0:00'";
277 dbc->Query(myquery.str().c_str());
278 //
279 RunGlue *rg = new RunGlue(dbc,run,dir,outdir);
280 //
281 if ( debug ) rg->SetDebug(true);
282 rg->SetDList(dectlist);
283 //
284 TList *l = 0;
285 //
286 Int_t RET=0;
287 //
288 // TString treelist="+AUTO";
289 //
290 while ( !rg->End() ){
291 //
292 l = rg->GetRunList();
293 //
294 if ( l ){
295 //
296 // if ( rg->OpenFile() ){
297 if ( rg->FileIsOpen() ){
298 //
299 rg->MergeRootfile(l);
300 //
301 if ( dbup ) rg->UpdateDB(l);
302 //
303 if ( delop ) rg->DeleteRunFiles(l);
304 //
305 rg->Clean();
306 //
307 } else {
308 RET = 255;
309 };
310 };
311 delete l;
312 //
313 };
314 //
315 delete rg;
316 //
317 // Close the DB connection
318 //
319 if ( dbc ) dbc->Close();
320 //
321 printf("\n");
322 //
323 exit(RET);
324 }

  ViewVC Help
Powered by ViewVC 1.1.23