/[PAMELA software]/DarthVader/src/R2-D2.cpp
ViewVC logotype

Annotation of /DarthVader/src/R2-D2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Jun 14 09:53:26 2006 UTC (18 years, 5 months ago) by mocchiut
Branch: MAIN
CVS Tags: v0r02, v1r01beta, v1r00, v1r01
Changes since 1.1: +2 -3 lines
Compilation warnings in R2-D2 fixed

1 mocchiut 1.1 //
2     // C/C++ headers
3     //
4     #include <iostream>
5     #include <sstream>
6     //
7     // ROOT headers
8     //
9     #include <TString.h>
10     #include <TSQLServer.h>
11     #include <TFile.h>
12     #include <TSystem.h>
13     //
14     // Detector's package headers
15     //
16     #include <GLTables.h>
17     //
18     using namespace std;
19     //
20     //
21     //
22     #include <DarthVaderVerl2.h>
23     //
24     // Usage subroutine
25     //
26     void r2d2usage(){
27     printf("\nUsage:\n");
28     printf("\n DarthVader [-h | --help] [--version] [-idRun ID_RUN] [-filename filename]\n");
29     printf("\n [-host host] [-user username] [-psw password] \n");
30     printf("\n --version print informations about compilation and exit\n");
31     printf("\n -h | --help print this help and exit \n");
32     printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n");
33     printf("\n -idRun ID_RUN: ID number of the run \n");
34     printf("\n -filename output yoda filename \n");
35     printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n");
36     printf("\n -user username for the DB [default = anonymous] \n");
37     printf("\n -psw password for the DB [default = \"\"]\n");
38     printf("\nExamples: \n");
39     printf("\n R2-D2 -idRun 1085 \n");
40     printf("\n R2-D2 -filename DW_050208_00900.root \n");
41     printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n");
42     };
43     //
44     // Here the main
45     //
46     int main(int numinp, char *inps[]){
47     //
48     // Variables booking
49     //
50     TString message;
51     Int_t error = 0;
52     //
53     ULong64_t run = 0ULL;
54     //
55     TString filename = "";
56     //
57     TSQLServer *dbc = 0;
58     TString host = "mysql://localhost/pamelaprod";
59     TString user = "anonymous";
60     TString psw = "";
61     //
62     //
63     // Checking input parameters
64     //
65     Int_t i = 0;
66     if ( numinp > 1 ){
67     while ( i < numinp ){
68     if ( !strcmp(inps[i],"--version") ){
69     DarthVaderInfo(true);
70     exit(0);
71     };
72     if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
73     r2d2usage();
74     exit(0);
75     };
76     if ( !strcmp(inps[i],"-idRun") ) {
77     if ( numinp-1 < i+1 ) {
78     r2d2usage();
79     exit(-3);
80     };
81     char *pEnd;
82     run = strtoull(inps[i+1],&pEnd,0);
83     };
84     if ( !strcmp(inps[i],"-filename") ) {
85     if ( numinp-1 < i+1 ){
86     r2d2usage();
87     exit(-3);
88     };
89     filename = (TString)inps[i+1];
90     };
91     if ( !strcmp(inps[i],"-host") ) {
92     if ( numinp-1 < i+1 ){
93     r2d2usage();
94     exit(-3);
95     };
96     host = (TString)inps[i+1];
97     };
98     if ( !strcmp(inps[i],"-user") ) {
99     if ( numinp-1 < i+1 ){
100     r2d2usage();
101     exit(-3);
102     };
103     user = (TString)inps[i+1];
104     };
105     if ( !strcmp(inps[i],"-psw") ) {
106     if ( numinp-1 < i+1 ){
107     r2d2usage();
108     exit(-3);
109     };
110     psw = (TString)inps[i+1];
111     };
112     i++;
113     };
114     //
115     } else {
116     //
117     // no input parameters exit with error, we need at least the run id.
118     //
119     r2d2usage();
120     exit(-2);
121     };
122     //
123     // Connect to the DB
124     //
125     dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
126     if( !dbc ) throw -2;
127     //
128     bool connect = dbc->IsConnected();
129     //
130     if( !connect ){
131     printf(" Error, not connected to DB\n");
132     exit(-1);
133     };
134     //
135     GL_ROOT *glroot = new GL_ROOT();
136     GL_RUN *glrun = new GL_RUN();
137     //
138     if ( run != 0ULL ){
139     error = glrun->Query_GL_RUN(run,dbc);
140     error = glroot->Query_GL_ROOT(glrun->ID_REG_RUN,dbc);
141     if ( error ){
142     printf(" Error querying the DB! \n");
143     exit(-4);
144     };
145     printf("\n Run %llu belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data());
146     };
147     if ( strcmp(filename.Data(),"") ){
148     TSQLResult *pResult;
149     TSQLRow *Row;
150     int t;
151     int r;
152     stringstream myquery;
153     // ----------------
154     Int_t ID = 0;
155     Int_t ID_RAW = 0;
156     //
157 mocchiut 1.2 const char *rawpath = "";
158     const char *rawname = "";
159 mocchiut 1.1 //
160     myquery.str("");
161     myquery << "select ";
162     myquery << " ID";
163     myquery << ",ID_RAW";
164     myquery << ",PATH";
165     myquery << ",NAME";
166     myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";
167     pResult = dbc->Query(myquery.str().c_str());
168     if(!pResult->GetRowCount()) return (-51);
169     for( r=0; r < 1000; r++){
170     Row = pResult->Next();
171     if( Row == NULL ) break;
172     for( t = 0; t < pResult->GetFieldCount(); t++){
173     if(t==0) ID = atoi(Row->GetField(t));
174     if(t==1) ID_RAW = atoi(Row->GetField(t));
175     };
176     };
177     delete pResult;
178     printf("\n File %s contains the following runs: \n",filename.Data());
179     myquery.str("");
180     myquery << "select ";
181     myquery << " ID";
182     myquery << " from GL_RUN where ID_REG_RUN=" << ID << ";";
183     pResult = dbc->Query(myquery.str().c_str());
184     if(!pResult->GetRowCount()) return (-51);
185     for( r=0; r < 1000; r++){
186     Row = pResult->Next();
187     if( Row == NULL ) break;
188     for( t = 0; t < pResult->GetFieldCount(); t++){
189     if (t==0) printf(" => %i \n",atoi(Row->GetField(t)));
190     };
191     };
192     delete pResult;
193     myquery.str("");
194     myquery << "select ";
195     myquery << " PATH,NAME";
196     myquery << " from GL_RAW where ID=" << ID_RAW << ";";
197     pResult = dbc->Query(myquery.str().c_str());
198     if(!pResult->GetRowCount()) return (-51);
199     for( r=0; r < 1000; r++){
200     Row = pResult->Next();
201     if( Row == NULL ) break;
202     for( t = 0; t < pResult->GetFieldCount(); t++){
203     if(t==0) rawpath = Row->GetField(t);
204     if(t==1) rawname = Row->GetField(t);
205     };
206     };
207     delete pResult;
208     printf(" and belongs to raw data file %s/%s \n",rawpath,rawname);
209     };
210     //
211     // Close the DB connection
212     //
213     if ( dbc ) dbc->Close();
214     //
215     printf("\n");
216     //
217     exit(0);
218     }

  ViewVC Help
Powered by ViewVC 1.1.23