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

Contents of /PadmeAmidala/src/PadmeAmidala.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations) (download)
Mon Oct 20 12:27:56 2014 UTC (10 years, 1 month ago) by mocchiut
Branch: MAIN
CVS Tags: v10RED, HEAD
Changes since 1.13: +7 -5 lines
Pedantic flag added

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(" -p | --pedantic merge only when all level2 run files are present (default NOT pedantic, merge whatever it finds)\n");
46 printf(" -idRun run merge all runs in the directory which have the same date of run \"run\"\n");
47 printf(" -outdir dir output directory \"dir\"\n");
48 printf(" -dir dir merge all runs in the directory \"dir\"\n");
49 printf(" -d | -delete delete original DarthVader runs once merged\n");
50 printf(" -no-DBupdate do not update the DB\n");
51 printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");
52 printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n");
53 printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n");
54 printf("\nExamples: \n");
55 printf(" Amidala -idRun 1085 \n");
56 printf(" Amidala -dir /home/pamela/level2/ \n\n");
57 };
58 //
59 // Here the main
60 //
61 int main(int numinp, char *inps[]){
62 //
63 // Variables booking
64 //
65 TString message;
66 //
67 UInt_t run = 0;
68 //
69 TString dir = "";
70 TString outdir = "";
71 TString dectlist = "";
72 //
73 TSQLServer *dbc = 0;
74 TString host = "mysql://localhost/pamelaprod";
75 TString user = "anonymous";
76 TString psw = "";
77 Bool_t debug = false;
78 Bool_t delop = false;
79 Bool_t dbup = true;
80 Bool_t pedantic = false;
81 //
82 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
83 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
84 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
85 if ( !pamdbhost ) pamdbhost = "";
86 if ( !pamdbuser ) pamdbuser = "";
87 if ( !pamdbpsw ) pamdbpsw = "";
88 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
89 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
90 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
91 //
92 stringstream myquery;
93 //
94 // Checking input parameters
95 //
96 Int_t i = 0;
97 if ( numinp > 1 ){
98 while ( i < numinp ){
99 if ( !strcmp(inps[i],"--version") ){
100 AmidalaInfo(true);
101 exit(0);
102 };
103 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
104 amidalausage();
105 exit(0);
106 };
107 if ( !strcmp(inps[i],"-g") || !strcmp(inps[i],"--debug") ){
108 debug = true;
109 };
110 if ( !strcmp(inps[i],"-d") || !strcmp(inps[i],"-delete") ){
111 delop = true;
112 };
113 if ( !strcmp(inps[i],"-p") || !strcmp(inps[i],"--pedantic") ){
114 pedantic = true;
115 }
116 if ( !strcmp(inps[i],"-no-DBupdate") ){
117 dbup = false;
118 };
119 if ( !strcmp(inps[i],"-idRun") ) {
120 if ( numinp-1 < i+1 ) {
121 amidalausage();
122 exit(-3);
123 };
124 run = (UInt_t)atoll(inps[i+1]);
125 };
126 if ( !strcmp(inps[i],"-dir") ) {
127 if ( numinp-1 < i+1 ){
128 amidalausage();
129 exit(-3);
130 };
131 dir = (TString)inps[i+1];
132 };
133 if ( !strcmp(inps[i],"-outdir") ) {
134 if ( numinp-1 < i+1 ){
135 amidalausage();
136 exit(-3);
137 };
138 outdir = (TString)inps[i+1];
139 };
140 if ( !strcmp(inps[i],"-host") ) {
141 if ( numinp-1 < i+1 ){
142 amidalausage();
143 exit(-3);
144 };
145 host = (TString)inps[i+1];
146 };
147 if ( !strcmp(inps[i],"-user") ) {
148 if ( numinp-1 < i+1 ){
149 amidalausage();
150 exit(-3);
151 };
152 user = (TString)inps[i+1];
153 };
154 if ( !strcmp(inps[i],"-psw") ) {
155 if ( numinp-1 < i+1 ){
156 amidalausage();
157 exit(-3);
158 };
159 psw = (TString)inps[i+1];
160 };
161 //
162 if ( !strcmp(inps[i],"-CAL") ) {
163 dectlist +=" -CAL";
164 };
165 if ( !strcmp(inps[i],"-CAL1") ) {
166 dectlist +=" -CAL1";
167 };
168 if ( !strcmp(inps[i],"-TRK") ) {
169 dectlist +=" -TRK";
170 };
171 if ( !strcmp(inps[i],"-TRK1") ) {
172 dectlist +=" -TRK1";
173 };
174 if ( !strcmp(inps[i],"-TRKh") ) {
175 dectlist +=" -TRKh";
176 };
177 if ( !strcmp(inps[i],"-TOF") ) {
178 dectlist +=" -TOF";
179 };
180 if ( !strcmp(inps[i],"-TRG") ) {
181 dectlist +=" -TRG";
182 };
183 if ( !strcmp(inps[i],"-S4") ) {
184 dectlist +=" -S4";
185 };
186 if ( !strcmp(inps[i],"-ND") ) {
187 dectlist +=" -ND";
188 };
189 if ( !strcmp(inps[i],"-AC") ) {
190 dectlist +=" -AC";
191 };
192 if ( !strcmp(inps[i],"-RUN") ) {
193 dectlist +=" -RUN";
194 };
195 if ( !strcmp(inps[i],"-ORB") ) {
196 dectlist +=" -ORB";
197 };
198 //
199 if ( !strcmp(inps[i],"-all") || !strcmp(inps[i],"-ALL") ) {
200 dectlist +=" -ALL";
201 };
202 //
203 if ( !strcmp(inps[i],"+all") || !strcmp(inps[i],"+ALL") ) {
204 dectlist +=" +ALL";
205 };
206 if ( !strcmp(inps[i],"+auto") || !strcmp(inps[i],"+AUTO") ) {
207 dectlist +=" +AUTO";
208 };
209 if ( !strcmp(inps[i],"+CAL") ) {
210 dectlist +=" +CAL";
211 };
212 if ( !strcmp(inps[i],"+CAL1") ) {
213 dectlist +=" +CAL1";
214 };
215 if ( !strcmp(inps[i],"+TRK") ) {
216 dectlist +=" +TRK";
217 };
218 if ( !strcmp(inps[i],"+TRK1") ) {
219 dectlist +=" +TRK1";
220 };
221 if ( !strcmp(inps[i],"+TRKh") ) {
222 dectlist +=" +TRKh";
223 };
224 if ( !strcmp(inps[i],"+TOF") ) {
225 dectlist +=" +TOF";
226 };
227 if ( !strcmp(inps[i],"+TRG") ) {
228 dectlist +=" +TRG";
229 };
230 if ( !strcmp(inps[i],"+S4") ) {
231 dectlist +=" +S4";
232 };
233 if ( !strcmp(inps[i],"+ND") ) {
234 dectlist +=" +ND";
235 };
236 if ( !strcmp(inps[i],"+AC") ) {
237 dectlist +=" +AC";
238 };
239 if ( !strcmp(inps[i],"+RUN") ) {
240 dectlist +=" +RUN";
241 };
242 if ( !strcmp(inps[i],"+ORB") ) {
243 dectlist +=" +ORB";
244 };
245 //
246 i++;
247 };
248 //
249 } else {
250 //
251 // no input parameters exit with error, we need at least the run id.
252 //
253 amidalausage();
254 exit(-2);
255 };
256 //
257 if ( run && strcmp(dir.Data(),"") ){
258 amidalausage();
259 printf(" Cannot give as input both ID run and directory \n\n");
260 exit(-2);
261 };
262 if ( !run && !strcmp(dir.Data(),"") ){
263 amidalausage();
264 printf(" You must give as input or an ID run or a directory \n\n");
265 exit(-2);
266 };
267 //
268 // Connect to the DB
269 //
270 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
271 if( !dbc ) throw -2;
272 //
273 bool connect = dbc->IsConnected();
274 //
275 if( !connect ){
276 printf(" Error, not connected to DB\n");
277 exit(-1);
278 };
279 //
280 myquery.str("");
281 myquery << "SET time_zone='+0:00';";
282 delete dbc->Query(myquery.str().c_str());
283 delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");
284 //
285 RunGlue *rg = new RunGlue(dbc,run,dir,outdir);
286 //
287 if ( debug ) rg->SetDebug(true);
288 if ( !dbup ) rg->SetUpgrade(false);
289 rg->SetDList(dectlist);
290 //
291 TList *l = 0;
292 //
293 Int_t RET=0;
294 //
295 // TString treelist="+AUTO";
296 //
297 while ( !rg->End() ){
298 //
299 l = rg->GetRunList();
300 //
301 if ( l && !(rg->HasDiscardedRuns() && pedantic) ){
302 //
303 if ( rg->FileIsOpen() ){
304 //
305 rg->MergeRootfile(l);
306 //
307 if ( dbup ) rg->UpdateDB(l);
308 //
309 if ( delop ) rg->DeleteRunFiles(l);
310 //
311 rg->Clean();
312 //
313 } else {
314 RET = 255;
315 };
316 } else {
317 RET = 255;
318 if (rg->HasDiscardedRuns() && pedantic){
319 printf(" Missing runs (and pedantic selected), cannot merge file %s \n",rg->GetFilename().Data());
320 rg->Clean();
321 }
322 }
323 delete l;
324 //
325 }
326 //
327 delete rg;
328 //
329 // Close the DB connection
330 //
331 if ( dbc ) dbc->Close();
332 //
333 if ( debug ) printf(" exit with error code %i \n",RET);
334 //
335 printf("\n");
336 //
337 exit(RET);
338 }

  ViewVC Help
Powered by ViewVC 1.1.23