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

Annotation of /PadmeAmidala/src/PadmeAmidala.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Jan 9 10:19:53 2007 UTC (17 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: v1r02, v1r03, v1r00
Changes since 1.2: +6 -1 lines
Important bugs fixed

1 mocchiut 1.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 mocchiut 1.3 printf(" -no-DBupdate do not update the DB\n");
50 mocchiut 1.1 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 mocchiut 1.3 Bool_t dbup = true;
79 mocchiut 1.1 //
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 mocchiut 1.3 if ( !strcmp(inps[i],"-no-DBupdate") ){
112     dbup = false;
113     };
114 mocchiut 1.1 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],"+CAL") ) {
202     dectlist +=" +CAL";
203     };
204     if ( !strcmp(inps[i],"+CAL1") ) {
205     dectlist +=" +CAL1";
206     };
207     if ( !strcmp(inps[i],"+TRK") ) {
208     dectlist +=" +TRK";
209     };
210     if ( !strcmp(inps[i],"+TRK1") ) {
211     dectlist +=" +TRK1";
212     };
213     if ( !strcmp(inps[i],"+TRKh") ) {
214     dectlist +=" +TRKh";
215     };
216     if ( !strcmp(inps[i],"+TOF") ) {
217     dectlist +=" +TOF";
218     };
219     if ( !strcmp(inps[i],"+TRG") ) {
220     dectlist +=" +TRG";
221     };
222     if ( !strcmp(inps[i],"+S4") ) {
223     dectlist +=" +S4";
224     };
225     if ( !strcmp(inps[i],"+ND") ) {
226     dectlist +=" +ND";
227     };
228     if ( !strcmp(inps[i],"+AC") ) {
229     dectlist +=" +AC";
230     };
231     if ( !strcmp(inps[i],"+RUN") ) {
232     dectlist +=" +RUN";
233     };
234     if ( !strcmp(inps[i],"+ORB") ) {
235     dectlist +=" +ORB";
236     };
237     //
238     i++;
239     };
240     //
241     } else {
242     //
243     // no input parameters exit with error, we need at least the run id.
244     //
245     amidalausage();
246     exit(-2);
247     };
248     //
249     if ( run && strcmp(dir.Data(),"") ){
250     amidalausage();
251     printf(" Cannot give as input both ID run and directory \n\n");
252     exit(-2);
253     };
254     if ( !run && !strcmp(dir.Data(),"") ){
255     amidalausage();
256     printf(" You must give as input or an ID run or a directory \n\n");
257     exit(-2);
258     };
259     //
260     // Connect to the DB
261     //
262     dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
263     if( !dbc ) throw -2;
264     //
265     bool connect = dbc->IsConnected();
266     //
267     if( !connect ){
268     printf(" Error, not connected to DB\n");
269     exit(-1);
270     };
271     //
272     myquery.str("");
273     myquery << "SET time_zone='+0:00'";
274     dbc->Query(myquery.str().c_str());
275     //
276     RunGlue *rg = new RunGlue(dbc,run,dir,outdir);
277     //
278     if ( debug ) rg->SetDebug(true);
279     rg->SetDList(dectlist);
280     //
281     TList *l = 0;
282     //
283     TString treelist="+ALL";
284     //
285     while ( !rg->End() ){
286     //
287     l = rg->GetRunList();
288     //
289     if ( l ){
290     //
291 mocchiut 1.2 // if ( rg->OpenFile() ){
292     if ( rg->FileIsOpen() ){
293 mocchiut 1.1 //
294     rg->MergeRootfile(l);
295     //
296 mocchiut 1.3 if ( dbup ) rg->UpdateDB(l);
297 mocchiut 1.1 //
298     if ( delop ) rg->DeleteRunFiles(l);
299     //
300     rg->Clean();
301     //
302     };
303     };
304     delete l;
305     //
306     };
307     //
308     delete rg;
309     //
310     // Close the DB connection
311     //
312     if ( dbc ) dbc->Close();
313     //
314     printf("\n");
315     //
316     exit(0);
317     }

  ViewVC Help
Powered by ViewVC 1.1.23