/[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.8 - (hide annotations) (download)
Tue Sep 19 09:17:50 2006 UTC (18 years, 2 months ago) by mocchiut
Branch: MAIN
Changes since 1.7: +29 -65 lines
Small upgrade of R2D2

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 mocchiut 1.5 printf("\n -host name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");
36     printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n");
37     printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\n");
38 mocchiut 1.8 printf("\n -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n");
39     printf("\n -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n");
40     printf("\n -runat time returns run number which contains the given date,\n");
41     printf("\n for time use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");
42 mocchiut 1.1 printf("\nExamples: \n");
43     printf("\n R2-D2 -idRun 1085 \n");
44     printf("\n R2-D2 -filename DW_050208_00900.root \n");
45     printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n");
46     };
47     //
48     // Here the main
49     //
50     int main(int numinp, char *inps[]){
51     //
52     // Variables booking
53     //
54     TString message;
55     Int_t error = 0;
56     //
57 mocchiut 1.3 UInt_t run = 0ULL;
58 mocchiut 1.1 //
59     TString filename = "";
60     //
61     TSQLServer *dbc = 0;
62     TString host = "mysql://localhost/pamelaprod";
63     TString user = "anonymous";
64     TString psw = "";
65 mocchiut 1.5 //
66     const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
67     const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
68     const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
69 mocchiut 1.8 if ( !pamdbhost ) pamdbhost = "";
70     if ( !pamdbuser ) pamdbuser = "";
71     if ( !pamdbpsw ) pamdbpsw = "";
72 mocchiut 1.5 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
73     if ( strcmp(pamdbuser,"") ) user = pamdbuser;
74     if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
75     //
76 mocchiut 1.6 // printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data());
77 mocchiut 1.5 //
78 mocchiut 1.3 TString tzone = "MSK";
79     TString runtime = "1970-01-01 00:00:00";
80     UInt_t dbti = 0;
81     Bool_t convert = false;
82     Bool_t ruti = false;
83 mocchiut 1.1 //
84 mocchiut 1.4 TSQLResult *pResult;
85     TSQLRow *Row;
86     int t;
87     int r;
88     stringstream myquery;
89 mocchiut 1.1 //
90     // Checking input parameters
91     //
92     Int_t i = 0;
93     if ( numinp > 1 ){
94     while ( i < numinp ){
95     if ( !strcmp(inps[i],"--version") ){
96     DarthVaderInfo(true);
97     exit(0);
98     };
99     if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
100     r2d2usage();
101     exit(0);
102     };
103     if ( !strcmp(inps[i],"-idRun") ) {
104     if ( numinp-1 < i+1 ) {
105     r2d2usage();
106     exit(-3);
107     };
108 mocchiut 1.3 run = (UInt_t)atoll(inps[i+1]);
109 mocchiut 1.1 };
110     if ( !strcmp(inps[i],"-filename") ) {
111     if ( numinp-1 < i+1 ){
112     r2d2usage();
113     exit(-3);
114     };
115     filename = (TString)inps[i+1];
116     };
117     if ( !strcmp(inps[i],"-host") ) {
118     if ( numinp-1 < i+1 ){
119     r2d2usage();
120     exit(-3);
121     };
122     host = (TString)inps[i+1];
123     };
124     if ( !strcmp(inps[i],"-user") ) {
125     if ( numinp-1 < i+1 ){
126     r2d2usage();
127     exit(-3);
128     };
129     user = (TString)inps[i+1];
130     };
131     if ( !strcmp(inps[i],"-psw") ) {
132     if ( numinp-1 < i+1 ){
133     r2d2usage();
134     exit(-3);
135     };
136     psw = (TString)inps[i+1];
137     };
138 mocchiut 1.3 //
139 mocchiut 1.8 if ( !strcmp(inps[i],"-tzone") ) {
140     if ( numinp-1 < i+1 ){
141     r2d2usage();
142     exit(-3);
143     };
144     tzone = (TString)inps[i+1];
145     };
146     //
147 mocchiut 1.3 if ( !strcmp(inps[i],"-convert") ) {
148     convert = true;
149 mocchiut 1.8 if ( numinp-1 < i+1 ){
150     r2d2usage();
151     exit(-3);
152 mocchiut 1.3 };
153 mocchiut 1.8 dbti = (UInt_t)atoll(inps[i+1]);
154 mocchiut 1.3 };
155     //
156 mocchiut 1.4 if ( !strcmp(inps[i],"-runat") ) {
157     ruti = true;
158 mocchiut 1.8 if ( numinp-1 < i+1 ){
159     r2d2usage();
160     exit(-3);
161 mocchiut 1.4 };
162 mocchiut 1.8 runtime = (TString)inps[i+1];
163 mocchiut 1.4 };
164     //
165 mocchiut 1.1 i++;
166     };
167     //
168     } else {
169     //
170     // no input parameters exit with error, we need at least the run id.
171     //
172     r2d2usage();
173     exit(-2);
174     };
175     //
176     // Connect to the DB
177     //
178     dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
179     if( !dbc ) throw -2;
180     //
181     bool connect = dbc->IsConnected();
182     //
183     if( !connect ){
184     printf(" Error, not connected to DB\n");
185     exit(-1);
186     };
187     //
188     GL_ROOT *glroot = new GL_ROOT();
189     GL_RUN *glrun = new GL_RUN();
190 mocchiut 1.3 GL_TIMESYNC *dbtime = new GL_TIMESYNC();
191     //
192     // At which date correspond the DB time "dbti"?
193     //
194     if ( convert ){
195 mocchiut 1.8 printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data());
196 mocchiut 1.3 };
197 mocchiut 1.1 //
198 mocchiut 1.3 // Which run contains the date "runtime"?
199     //
200     if ( ruti ){
201 mocchiut 1.4 //
202     TDatime *time = new TDatime(runtime.Data());
203     UInt_t dbti = time->Convert();
204     //
205 mocchiut 1.8 TString thetime = dbtime->UnConvertTime(tzone,dbti);
206 mocchiut 1.4 //
207     TDatime *time2 = new TDatime(thetime.Data());
208     UInt_t mytime = time2->Convert();
209     //
210     myquery.str("");
211     myquery << "select ";
212     myquery << " ID ";
213     myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND "
214     << " RUNTRAILER_TIME>=" << mytime << " ;";
215     // printf("myquery is %s \n",myquery.str().c_str());
216     pResult = dbc->Query(myquery.str().c_str());
217     for( r=0; r < 1000; r++){
218     Row = pResult->Next();
219     if ( !r && !Row ){
220 mocchiut 1.8 printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone.Data(),mytime);
221 mocchiut 1.4 };
222     if( Row == NULL ) break;
223 mocchiut 1.8 printf("\n Date %s %s (DB time %u ) is contained in run %u \n",runtime.Data(),tzone.Data(),mytime,(UInt_t)atoll(Row->GetField(0)));
224 mocchiut 1.4 };
225 mocchiut 1.3 };
226     //
227     // To which file the run "run" belongs?
228     //
229     if ( run != 0 ){
230     glrun->Clear();
231 mocchiut 1.1 error = glrun->Query_GL_RUN(run,dbc);
232 mocchiut 1.3 glroot->Clear();
233     error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc);
234 mocchiut 1.7 if ( !glrun->ID_ROOT_L0 ){
235 mocchiut 1.3 printf("\n No run with ID=%u in the DB!\n",run);
236     } else {
237 mocchiut 1.7 if ( error ){
238     printf(" Error querying the DB! \n");
239     exit(-4);
240     };
241 mocchiut 1.3 printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data());
242     };
243 mocchiut 1.1 };
244 mocchiut 1.3 //
245     // Which runs are contained in the file "filename"?
246     //
247 mocchiut 1.1 if ( strcmp(filename.Data(),"") ){
248     // ----------------
249     Int_t ID = 0;
250     Int_t ID_RAW = 0;
251     //
252 mocchiut 1.2 const char *rawpath = "";
253     const char *rawname = "";
254 mocchiut 1.1 //
255     myquery.str("");
256     myquery << "select ";
257     myquery << " ID";
258     myquery << ",ID_RAW";
259     myquery << ",PATH";
260     myquery << ",NAME";
261     myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";
262     pResult = dbc->Query(myquery.str().c_str());
263     for( r=0; r < 1000; r++){
264     Row = pResult->Next();
265     if( Row == NULL ) break;
266     for( t = 0; t < pResult->GetFieldCount(); t++){
267     if(t==0) ID = atoi(Row->GetField(t));
268     if(t==1) ID_RAW = atoi(Row->GetField(t));
269     };
270     };
271     delete pResult;
272 mocchiut 1.3 if ( !ID && !ID_RAW ){
273     printf("\n No file with name %s in the DB!\n",filename.Data());
274     } else {
275     myquery.str("");
276     myquery << "select ";
277     myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";
278     myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";
279     pResult = dbc->Query(myquery.str().c_str());
280     for( r=0; r < 1000; r++){
281     Row = pResult->Next();
282     if ( !r && !Row ){
283 mocchiut 1.4 printf("\n No run associated to the file %s \n",filename.Data());
284 mocchiut 1.3 };
285     if( Row == NULL ) break;
286 mocchiut 1.4 if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data());
287 mocchiut 1.8 TString UTC="UTC";
288     printf(" => ID = %i _-_-_ the run started at %s UTC ended at %s UTC \n\n",(UInt_t)atoll(Row->GetField(0)),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(1))).Data(),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(2))).Data());
289 mocchiut 1.1 };
290 mocchiut 1.3 delete pResult;
291     myquery.str("");
292     myquery << "select ";
293     myquery << " PATH,NAME";
294     myquery << " from GL_RAW where ID=" << ID_RAW << ";";
295     pResult = dbc->Query(myquery.str().c_str());
296     for( r=0; r < 1000; r++){
297     Row = pResult->Next();
298     if( Row == NULL ) break;
299     for( t = 0; t < pResult->GetFieldCount(); t++){
300     if(t==0) rawpath = Row->GetField(t);
301     if(t==1) rawname = Row->GetField(t);
302     };
303 mocchiut 1.1 };
304 mocchiut 1.3 delete pResult;
305 mocchiut 1.4 printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname);
306 mocchiut 1.1 };
307     };
308     //
309     // Close the DB connection
310     //
311     if ( dbc ) dbc->Close();
312     //
313     printf("\n");
314     //
315     exit(0);
316     }

  ViewVC Help
Powered by ViewVC 1.1.23