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

Annotation of /PadmeAmidala/src/PadmeAmidala.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Fri Sep 7 13:26:10 2007 UTC (17 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: v2r00
Changes since 1.3: +6 -1 lines
New feature: it can write directly on CASTOR via RFIO

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

  ViewVC Help
Powered by ViewVC 1.1.23